Skip to content

Commit e037fb6

Browse files
author
Grégory Saive
authored
Merge pull request #172 from rg911/task/g95_merge_library_transaction_builder
4 - Issue: #95 Merge library transaction builder
2 parents 8c580c1 + e189f6a commit e037fb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2395
-54
lines changed

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"typings": "dist/index.d.ts",
3434
"devDependencies": {
3535
"@types/chai": "^4.0.4",
36+
"@types/crypto-js": "^3.1.43",
3637
"@types/lodash": "^4.14.85",
3738
"@types/mocha": "^2.2.44",
3839
"@types/request": "^2.47.0",
@@ -56,8 +57,8 @@
5657
"typescript-require": "^0.2.9-1"
5758
},
5859
"dependencies": {
59-
"@types/crypto-js": "^3.1.43",
6060
"crypto-js": "^3.1.9-1",
61+
"flatbuffers": "^1.11.0",
6162
"js-joda": "^1.6.2",
6263
"nem2-library": "0.10.2",
6364
"request": "^2.83.0",
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright 2019 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @module transactions/AccountLinkTransaction
19+
*/
20+
import { Convert as convert } from '../../core/format';
21+
import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer';
22+
import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema';
23+
import {
24+
VerifiableTransaction,
25+
} from './VerifiableTransaction';
26+
27+
const {
28+
flatbuffers,
29+
} = require('flatbuffers');
30+
31+
const {
32+
AccountLinkTransactionBuffer,
33+
} = AccountLinkTransactionBufferPackage.Buffers;
34+
35+
export class AccountLinkTransaction extends VerifiableTransaction {
36+
constructor(bytes) {
37+
super(bytes, AccountLinkTransactionSchema);
38+
}
39+
}
40+
41+
// tslint:disable-next-line:max-classes-per-file
42+
export class Builder {
43+
fee: any;
44+
version: any;
45+
type: any;
46+
deadline: any;
47+
remoteAccountKey: any;
48+
linkAction: any;
49+
constructor() {
50+
this.fee = [0, 0];
51+
this.version = 36867;
52+
this.type = 0x414C;
53+
}
54+
55+
addFee(fee) {
56+
this.fee = fee;
57+
return this;
58+
}
59+
60+
addVersion(version) {
61+
this.version = version;
62+
return this;
63+
}
64+
65+
addType(type) {
66+
this.type = type;
67+
return this;
68+
}
69+
70+
addDeadline(deadline) {
71+
this.deadline = deadline;
72+
return this;
73+
}
74+
75+
addRemoteAccountKey(remoteAccountKey) {
76+
this.remoteAccountKey = convert.hexToUint8(remoteAccountKey);
77+
return this;
78+
}
79+
80+
addLinkAction(linkAction) {
81+
this.linkAction = linkAction;
82+
return this;
83+
}
84+
build() {
85+
const builder = new flatbuffers.Builder(1);
86+
87+
// Create vectors
88+
const signatureVector = AccountLinkTransactionBuffer
89+
.createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0));
90+
const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0));
91+
const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline);
92+
const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.fee);
93+
const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey);
94+
95+
AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder);
96+
AccountLinkTransactionBuffer.addSize(builder, 153);
97+
AccountLinkTransactionBuffer.addSignature(builder, signatureVector);
98+
AccountLinkTransactionBuffer.addSigner(builder, signerVector);
99+
AccountLinkTransactionBuffer.addVersion(builder, this.version);
100+
AccountLinkTransactionBuffer.addType(builder, this.type);
101+
AccountLinkTransactionBuffer.addFee(builder, feeVector);
102+
AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector);
103+
AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector);
104+
AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction);
105+
106+
// Calculate size
107+
108+
const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder);
109+
builder.finish(codedTransfer);
110+
111+
const bytes = builder.asUint8Array();
112+
return new AccountLinkTransaction(bytes);
113+
}
114+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* Copyright 2019 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* @module transactions/AccountPropertiesAddressTransaction
19+
*/
20+
import { RawAddress as address } from '../../core/format';
21+
import AccountPropertiesAddressTransactionBufferPackage from '../buffers/AccountPropertiesAddressTransactionBuffer';
22+
import AccountPropertiesAddressModificationTransactionSchema from '../schemas/AccountPropertiesAddressModificationTransactionSchema';
23+
import { VerifiableTransaction } from './VerifiableTransaction';
24+
const {
25+
AccountPropertiesAddressTransactionBuffer,
26+
PropertyAddressModificationBuffer,
27+
} = AccountPropertiesAddressTransactionBufferPackage.Buffers;
28+
29+
const {
30+
flatbuffers
31+
} = require('flatbuffers');
32+
33+
export default class AccountPropertiesAddressTransaction extends VerifiableTransaction {
34+
constructor(bytes) {
35+
super(bytes, AccountPropertiesAddressModificationTransactionSchema);
36+
}
37+
}
38+
39+
// tslint:disable-next-line:max-classes-per-file
40+
export class Builder {
41+
fee: any;
42+
version: any;
43+
type: any;
44+
deadline: any;
45+
propertyType: any;
46+
modifications: any;
47+
constructor() {
48+
this.fee = [0, 0];
49+
this.version = 36865;
50+
this.type = 0x4150;
51+
}
52+
53+
addFee(fee) {
54+
this.fee = fee;
55+
return this;
56+
}
57+
58+
addVersion(version) {
59+
this.version = version;
60+
return this;
61+
}
62+
63+
addType(type) {
64+
this.type = type;
65+
return this;
66+
}
67+
68+
addDeadline(deadline) {
69+
this.deadline = deadline;
70+
return this;
71+
}
72+
73+
addPropertyType(propertyType) {
74+
this.propertyType = propertyType;
75+
return this;
76+
}
77+
78+
addModifications(modifications) {
79+
this.modifications = modifications;
80+
return this;
81+
}
82+
83+
build() {
84+
const builder = new flatbuffers.Builder(1);
85+
86+
// Create modifications
87+
const modificationsArray: any = [];
88+
this.modifications.forEach(modification => {
89+
const addressModificationVector = PropertyAddressModificationBuffer
90+
.createValueVector(builder, address.stringToAddress(modification.value));
91+
PropertyAddressModificationBuffer.startPropertyAddressModificationBuffer(builder);
92+
PropertyAddressModificationBuffer.addModificationType(builder, modification.type);
93+
PropertyAddressModificationBuffer.addValue(builder, addressModificationVector);
94+
modificationsArray.push(PropertyAddressModificationBuffer.endPropertyAddressModificationBuffer(builder));
95+
});
96+
97+
// Create vectors
98+
const signatureVector = AccountPropertiesAddressTransactionBuffer
99+
.createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0));
100+
const signerVector = AccountPropertiesAddressTransactionBuffer
101+
.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0));
102+
const deadlineVector = AccountPropertiesAddressTransactionBuffer
103+
.createDeadlineVector(builder, this.deadline);
104+
const feeVector = AccountPropertiesAddressTransactionBuffer
105+
.createFeeVector(builder, this.fee);
106+
const modificationVector = AccountPropertiesAddressTransactionBuffer
107+
.createModificationsVector(builder, modificationsArray);
108+
109+
AccountPropertiesAddressTransactionBuffer.startAccountPropertiesAddressTransactionBuffer(builder);
110+
AccountPropertiesAddressTransactionBuffer.addSize(builder, 122 + (26 * this.modifications.length));
111+
AccountPropertiesAddressTransactionBuffer.addSignature(builder, signatureVector);
112+
AccountPropertiesAddressTransactionBuffer.addSigner(builder, signerVector);
113+
AccountPropertiesAddressTransactionBuffer.addVersion(builder, this.version);
114+
AccountPropertiesAddressTransactionBuffer.addType(builder, this.type);
115+
AccountPropertiesAddressTransactionBuffer.addFee(builder, feeVector);
116+
AccountPropertiesAddressTransactionBuffer.addDeadline(builder, deadlineVector);
117+
AccountPropertiesAddressTransactionBuffer.addPropertyType(builder, this.propertyType);
118+
AccountPropertiesAddressTransactionBuffer.addModificationCount(builder, this.modifications.length);
119+
AccountPropertiesAddressTransactionBuffer.addModifications(builder, modificationVector);
120+
121+
// Calculate size
122+
const codedAccountPropertiesAddress =
123+
AccountPropertiesAddressTransactionBuffer.endAccountPropertiesAddressTransactionBuffer(builder);
124+
builder.finish(codedAccountPropertiesAddress);
125+
126+
const bytes = builder.asUint8Array();
127+
128+
return new AccountPropertiesAddressTransaction(bytes);
129+
}
130+
}

0 commit comments

Comments
 (0)