-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from evias/add-alias-transaction
- Added AddressAliasTransaction + schema + buffer - Added MosaicAliasTransaction + schema + buffer
- Loading branch information
Showing
13 changed files
with
1,496 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2019 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { array, Schema, TypeSize, ubyte, uint, ushort } from './Schema'; | ||
|
||
/** | ||
* @module schema/AddressAliasTransactionSchema | ||
*/ | ||
|
||
/** | ||
* Address alias transaction schema | ||
* @const {module:schema/Schema} | ||
*/ | ||
export default new Schema([ | ||
uint('size'), | ||
array('signature'), | ||
array('signer'), | ||
ushort('version'), | ||
ushort('type'), | ||
array('fee', TypeSize.INT), | ||
array('deadline', TypeSize.INT), | ||
ubyte('actionType'), | ||
array('namespaceId', TypeSize.INT), | ||
array('address', TypeSize.BYTE) | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2019 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { array, Schema, TypeSize, ubyte, uint, ushort } from './Schema'; | ||
|
||
/** | ||
* @module schema/MosaicAliasTransactionSchema | ||
*/ | ||
|
||
/** | ||
* Mosaic alias transaction schema | ||
* @const {module:schema/Schema} | ||
*/ | ||
export default new Schema([ | ||
uint('size'), | ||
array('signature'), | ||
array('signer'), | ||
ushort('version'), | ||
ushort('type'), | ||
array('fee', TypeSize.INT), | ||
array('deadline', TypeSize.INT), | ||
ubyte('actionType'), | ||
array('namespaceId', TypeSize.INT), | ||
array('mosaicId', TypeSize.INT) | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2019 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {VerifiableTransaction} from "./VerifiableTransaction"; | ||
|
||
export declare class AddressAliasTransaction extends VerifiableTransaction { | ||
} | ||
|
||
export declare module AddressAliasTransaction { | ||
class Builder { | ||
|
||
addFee(fee): Builder; | ||
|
||
addVersion(version): Builder; | ||
|
||
addType(type): Builder; | ||
|
||
addDeadline(deadline): Builder; | ||
|
||
addActionType(direction): Builder; | ||
|
||
addNamespaceId(namespaceId): Builder; | ||
|
||
addAddress(address): Builder; | ||
|
||
build(): AddressAliasTransaction; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright 2019 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import VerifiableTransaction from './VerifiableTransaction'; | ||
import AddressAliasTransactionSchema from '../schema/AddressAliasTransactionSchema'; | ||
import AddressAliasTransactionBufferPackage from '../buffers/AddressAliasTransactionBuffer'; | ||
|
||
const { AddressAliasTransactionBuffer } = AddressAliasTransactionBufferPackage.Buffers; | ||
|
||
const { flatbuffers } = require('flatbuffers'); | ||
const addressEncoder = require('../coders/address').default; | ||
|
||
/** | ||
* @module transactions/AddressAliasTransaction | ||
*/ | ||
export default class AddressAliasTransaction extends VerifiableTransaction { | ||
static get Builder() { | ||
class Builder { | ||
constructor() { | ||
this.fee = [0, 0]; | ||
this.version = 36865; | ||
this.type = 0x424E; | ||
} | ||
|
||
addFee(fee) { | ||
this.fee = fee; | ||
return this; | ||
} | ||
|
||
addVersion(version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
addType(type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
addDeadline(deadline) { | ||
this.deadline = deadline; | ||
return this; | ||
} | ||
|
||
addActionType(actionType) { | ||
this.actionType = actionType; | ||
return this; | ||
} | ||
|
||
addNamespaceId(namespaceId) { | ||
this.namespaceId = namespaceId; | ||
return this; | ||
} | ||
|
||
addAddress(address) { | ||
this.address = addressEncoder.stringToAddress(address); | ||
return this; | ||
} | ||
|
||
build() { | ||
const builder = new flatbuffers.Builder(1); | ||
|
||
// Create vectors | ||
const signatureVector = AddressAliasTransactionBuffer | ||
.createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0)); | ||
const signerVector = AddressAliasTransactionBuffer | ||
.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0)); | ||
const deadlineVector = AddressAliasTransactionBuffer | ||
.createDeadlineVector(builder, this.deadline); | ||
const feeVector = AddressAliasTransactionBuffer | ||
.createFeeVector(builder, this.fee); | ||
const namespaceIdVector = AddressAliasTransactionBuffer | ||
.createNamespaceIdVector(builder, this.namespaceId); | ||
const addressVector = AddressAliasTransactionBuffer | ||
.createAddressVector(builder, this.address); | ||
|
||
|
||
AddressAliasTransactionBuffer.startAddressAliasTransactionBuffer(builder); | ||
AddressAliasTransactionBuffer.addSize(builder, 154); | ||
AddressAliasTransactionBuffer.addSignature(builder, signatureVector); | ||
AddressAliasTransactionBuffer.addSigner(builder, signerVector); | ||
AddressAliasTransactionBuffer.addVersion(builder, this.version); | ||
AddressAliasTransactionBuffer.addType(builder, this.type); | ||
AddressAliasTransactionBuffer.addFee(builder, feeVector); | ||
AddressAliasTransactionBuffer.addDeadline(builder, deadlineVector); | ||
AddressAliasTransactionBuffer.addActionType(builder, this.actionType); | ||
AddressAliasTransactionBuffer.addNamespaceId(builder, namespaceIdVector); | ||
AddressAliasTransactionBuffer.addAddress(builder, addressVector); | ||
|
||
// Calculate size | ||
const codedMosaicChangeSupply = AddressAliasTransactionBuffer.endAddressAliasTransactionBuffer(builder); | ||
builder.finish(codedMosaicChangeSupply); | ||
|
||
const bytes = builder.asUint8Array(); | ||
|
||
return new AddressAliasTransaction(bytes, AddressAliasTransactionSchema); | ||
} | ||
} | ||
|
||
return Builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2019 NEM | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {VerifiableTransaction} from "./VerifiableTransaction"; | ||
|
||
export declare class MosaicAliasTransaction extends VerifiableTransaction { | ||
} | ||
|
||
export declare module MosaicAliasTransaction { | ||
class Builder { | ||
|
||
addFee(fee): Builder; | ||
|
||
addVersion(version): Builder; | ||
|
||
addType(type): Builder; | ||
|
||
addDeadline(deadline): Builder; | ||
|
||
addActionType(direction): Builder; | ||
|
||
addNamespaceId(namespaceId): Builder; | ||
|
||
addMosaicId(mosaicName): Builder; | ||
|
||
build(): MosaicAliasTransaction; | ||
|
||
} | ||
} |
Oops, something went wrong.