Skip to content

Commit 0fb2071

Browse files
committed
Applied generated aggregate transaction from catbuffer-generator
1 parent 9df0aa1 commit 0fb2071

9 files changed

+449
-282
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder';
23+
import { AmountDto } from './AmountDto';
24+
import { EntityTypeDto } from './EntityTypeDto';
25+
import { GeneratorUtils } from './GeneratorUtils';
26+
import { KeyDto } from './KeyDto';
27+
import { SignatureDto } from './SignatureDto';
28+
import { TimestampDto } from './TimestampDto';
29+
import { TransactionBuilder } from './TransactionBuilder';
30+
31+
/** Binary layout for an aggregate bonded transaction. */
32+
export class AggregateBondedTransactionBuilder extends TransactionBuilder {
33+
/** Aggregate transaction body. */
34+
aggregateTransactionBody: AggregateTransactionBodyBuilder;
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param signature Entity signature.
40+
* @param signer Entity signer's public key.
41+
* @param version Entity version.
42+
* @param type Entity type.
43+
* @param fee Transaction fee.
44+
* @param deadline Transaction deadline.
45+
* @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes).
46+
* @param cosignatures Cosignatures data (fills remaining body space after transactions).
47+
*/
48+
// tslint:disable-next-line: max-line-length
49+
public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) {
50+
super(signature, signer, version, type, fee, deadline);
51+
this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures);
52+
}
53+
54+
/**
55+
* Creates an instance of AggregateBondedTransactionBuilder from binary payload.
56+
*
57+
* @param payload Byte payload to use to serialize the object.
58+
* @return Instance of AggregateBondedTransactionBuilder.
59+
*/
60+
public static loadFromBinary(payload: Uint8Array): AggregateBondedTransactionBuilder {
61+
const byteArray = Array.from(payload);
62+
const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray));
63+
byteArray.splice(0, superObject.getSize());
64+
const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray));
65+
byteArray.splice(0, aggregateTransactionBody.getSize());
66+
// tslint:disable-next-line: max-line-length
67+
return new AggregateBondedTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures);
68+
}
69+
70+
/**
71+
* Gets sub-transaction data (transactions are variable sized and payload size is in bytes).
72+
*
73+
* @return Sub-transaction data (transactions are variable sized and payload size is in bytes).
74+
*/
75+
public getTransactions(): Uint8Array {
76+
return this.aggregateTransactionBody.getTransactions();
77+
}
78+
79+
/**
80+
* Gets cosignatures data (fills remaining body space after transactions).
81+
*
82+
* @return Cosignatures data (fills remaining body space after transactions).
83+
*/
84+
public getCosignatures(): Uint8Array {
85+
return this.aggregateTransactionBody.getCosignatures();
86+
}
87+
88+
/**
89+
* Gets the size of the object.
90+
*
91+
* @return Size in bytes.
92+
*/
93+
public getSize(): number {
94+
let size: number = super.getSize();
95+
size += this.aggregateTransactionBody.getSize();
96+
return size;
97+
}
98+
99+
/**
100+
* Serializes an object to bytes.
101+
*
102+
* @return Serialized bytes.
103+
*/
104+
public serialize(): Uint8Array {
105+
let newArray = Uint8Array.from([]);
106+
const superBytes = super.serialize();
107+
newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes);
108+
const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize();
109+
newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes);
110+
return newArray;
111+
}
112+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { AggregateTransactionBodyBuilder } from './AggregateTransactionBodyBuilder';
23+
import { AmountDto } from './AmountDto';
24+
import { EntityTypeDto } from './EntityTypeDto';
25+
import { GeneratorUtils } from './GeneratorUtils';
26+
import { KeyDto } from './KeyDto';
27+
import { SignatureDto } from './SignatureDto';
28+
import { TimestampDto } from './TimestampDto';
29+
import { TransactionBuilder } from './TransactionBuilder';
30+
31+
/** Binary layout for an aggregate complete transaction. */
32+
export class AggregateCompleteTransactionBuilder extends TransactionBuilder {
33+
/** Aggregate transaction body. */
34+
aggregateTransactionBody: AggregateTransactionBodyBuilder;
35+
36+
/**
37+
* Constructor.
38+
*
39+
* @param signature Entity signature.
40+
* @param signer Entity signer's public key.
41+
* @param version Entity version.
42+
* @param type Entity type.
43+
* @param fee Transaction fee.
44+
* @param deadline Transaction deadline.
45+
* @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes).
46+
* @param cosignatures Cosignatures data (fills remaining body space after transactions).
47+
*/
48+
// tslint:disable-next-line: max-line-length
49+
public constructor(signature: SignatureDto, signer: KeyDto, version: number, type: EntityTypeDto, fee: AmountDto, deadline: TimestampDto, transactions: Uint8Array, cosignatures: Uint8Array) {
50+
super(signature, signer, version, type, fee, deadline);
51+
this.aggregateTransactionBody = new AggregateTransactionBodyBuilder(transactions, cosignatures);
52+
}
53+
54+
/**
55+
* Creates an instance of AggregateCompleteTransactionBuilder from binary payload.
56+
*
57+
* @param payload Byte payload to use to serialize the object.
58+
* @return Instance of AggregateCompleteTransactionBuilder.
59+
*/
60+
public static loadFromBinary(payload: Uint8Array): AggregateCompleteTransactionBuilder {
61+
const byteArray = Array.from(payload);
62+
const superObject = TransactionBuilder.loadFromBinary(Uint8Array.from(byteArray));
63+
byteArray.splice(0, superObject.getSize());
64+
const aggregateTransactionBody = AggregateTransactionBodyBuilder.loadFromBinary(Uint8Array.from(byteArray));
65+
byteArray.splice(0, aggregateTransactionBody.getSize());
66+
// tslint:disable-next-line: max-line-length
67+
return new AggregateCompleteTransactionBuilder(superObject.signature, superObject.signer, superObject.version, superObject.type, superObject.fee, superObject.deadline, aggregateTransactionBody.transactions, aggregateTransactionBody.cosignatures);
68+
}
69+
70+
/**
71+
* Gets sub-transaction data (transactions are variable sized and payload size is in bytes).
72+
*
73+
* @return Sub-transaction data (transactions are variable sized and payload size is in bytes).
74+
*/
75+
public getTransactions(): Uint8Array {
76+
return this.aggregateTransactionBody.getTransactions();
77+
}
78+
79+
/**
80+
* Gets cosignatures data (fills remaining body space after transactions).
81+
*
82+
* @return Cosignatures data (fills remaining body space after transactions).
83+
*/
84+
public getCosignatures(): Uint8Array {
85+
return this.aggregateTransactionBody.getCosignatures();
86+
}
87+
88+
/**
89+
* Gets the size of the object.
90+
*
91+
* @return Size in bytes.
92+
*/
93+
public getSize(): number {
94+
let size: number = super.getSize();
95+
size += this.aggregateTransactionBody.getSize();
96+
return size;
97+
}
98+
99+
/**
100+
* Serializes an object to bytes.
101+
*
102+
* @return Serialized bytes.
103+
*/
104+
public serialize(): Uint8Array {
105+
let newArray = Uint8Array.from([]);
106+
const superBytes = super.serialize();
107+
newArray = GeneratorUtils.concatTypedArrays(newArray, superBytes);
108+
const aggregateTransactionBodyBytes = this.aggregateTransactionBody.serialize();
109+
newArray = GeneratorUtils.concatTypedArrays(newArray, aggregateTransactionBodyBytes);
110+
return newArray;
111+
}
112+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// tslint:disable: jsdoc-format
2+
/**
3+
*** Copyright (c) 2016-present,
4+
*** Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp. All rights reserved.
5+
***
6+
*** This file is part of Catapult.
7+
***
8+
*** Catapult is free software: you can redistribute it and/or modify
9+
*** it under the terms of the GNU Lesser General Public License as published by
10+
*** the Free Software Foundation, either version 3 of the License, or
11+
*** (at your option) any later version.
12+
***
13+
*** Catapult is distributed in the hope that it will be useful,
14+
*** but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
*** GNU Lesser General Public License for more details.
17+
***
18+
*** You should have received a copy of the GNU Lesser General Public License
19+
*** along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20+
**/
21+
22+
import { GeneratorUtils } from './GeneratorUtils';
23+
24+
/** Binary layout for an aggregate transaction. */
25+
export class AggregateTransactionBodyBuilder {
26+
/** Sub-transaction data (transactions are variable sized and payload size is in bytes). */
27+
transactions: Uint8Array;
28+
/** Cosignatures data (fills remaining body space after transactions). */
29+
cosignatures: Uint8Array;
30+
31+
/**
32+
* Constructor.
33+
*
34+
* @param transactions Sub-transaction data (transactions are variable sized and payload size is in bytes).
35+
* @param cosignatures Cosignatures data (fills remaining body space after transactions).
36+
*/
37+
public constructor(transactions: Uint8Array, cosignatures: Uint8Array) {
38+
this.transactions = transactions;
39+
this.cosignatures = cosignatures;
40+
}
41+
42+
/**
43+
* Creates an instance of AggregateTransactionBodyBuilder from binary payload.
44+
*
45+
* @param payload Byte payload to use to serialize the object.
46+
* @return Instance of AggregateTransactionBodyBuilder.
47+
*/
48+
public static loadFromBinary(payload: Uint8Array): AggregateTransactionBodyBuilder {
49+
const byteArray = Array.from(payload);
50+
const payloadSize = GeneratorUtils.bufferToUint(GeneratorUtils.getBytes(Uint8Array.from(byteArray), 4));
51+
byteArray.splice(0, 4);
52+
const transactions = GeneratorUtils.getBytes(Uint8Array.from(byteArray), payloadSize);
53+
byteArray.splice(0, payloadSize);
54+
const cosignatures = Uint8Array.from(byteArray);
55+
return new AggregateTransactionBodyBuilder(transactions, cosignatures);
56+
}
57+
58+
/**
59+
* Gets sub-transaction data (transactions are variable sized and payload size is in bytes).
60+
*
61+
* @return Sub-transaction data (transactions are variable sized and payload size is in bytes).
62+
*/
63+
public getTransactions(): Uint8Array {
64+
return this.transactions;
65+
}
66+
67+
/**
68+
* Gets cosignatures data (fills remaining body space after transactions).
69+
*
70+
* @return Cosignatures data (fills remaining body space after transactions).
71+
*/
72+
public getCosignatures(): Uint8Array {
73+
return this.cosignatures;
74+
}
75+
76+
/**
77+
* Gets the size of the object.
78+
*
79+
* @return Size in bytes.
80+
*/
81+
public getSize(): number {
82+
let size = 0;
83+
size += 4; // payloadSize
84+
size += this.transactions.length;
85+
size += this.cosignatures.length;
86+
return size;
87+
}
88+
89+
/**
90+
* Serializes an object to bytes.
91+
*
92+
* @return Serialized bytes.
93+
*/
94+
public serialize(): Uint8Array {
95+
let newArray = Uint8Array.from([]);
96+
const payloadSizeBytes = GeneratorUtils.uintToBuffer(this.transactions.length, 4);
97+
newArray = GeneratorUtils.concatTypedArrays(newArray, payloadSizeBytes);
98+
newArray = GeneratorUtils.concatTypedArrays(newArray, this.transactions);
99+
newArray = GeneratorUtils.concatTypedArrays(newArray, this.cosignatures);
100+
return newArray;
101+
}
102+
}

0 commit comments

Comments
 (0)