|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { SignSchema } from '../../core/crypto'; |
18 | | -import { Builder } from '../../infrastructure/builders/AggregateTransaction'; |
| 18 | +import { Convert } from '../../core/format'; |
19 | 19 | import { AggregateTransaction as AggregatedTransactionCore} from '../../infrastructure/builders/AggregateTransaction'; |
| 20 | +import { Builder } from '../../infrastructure/builders/AggregateTransaction'; |
| 21 | +import { AggregateTransactionBuilder } from '../../infrastructure/catbuffer/AggregateTransactionBuilder'; |
| 22 | +import { AmountDto } from '../../infrastructure/catbuffer/AmountDto'; |
| 23 | +import { CosignatureBuilder } from '../../infrastructure/catbuffer/CosignatureBuilder'; |
| 24 | +import { GeneratorUtils } from '../../infrastructure/catbuffer/GeneratorUtils'; |
| 25 | +import { KeyDto } from '../../infrastructure/catbuffer/KeyDto'; |
| 26 | +import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto'; |
| 27 | +import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto'; |
20 | 28 | import { Account } from '../account/Account'; |
21 | 29 | import { PublicAccount } from '../account/PublicAccount'; |
22 | 30 | import { NetworkType } from '../blockchain/NetworkType'; |
@@ -209,14 +217,47 @@ export class AggregateTransaction extends Transaction { |
209 | 217 | * @returns {Uint8Array} |
210 | 218 | */ |
211 | 219 | protected generateBytes(): Uint8Array { |
212 | | - throw new Error('Not implemented'); |
| 220 | + const signerBuffer = new Uint8Array(32); |
| 221 | + const signatureBuffer = new Uint8Array(64); |
| 222 | + |
| 223 | + let transactions = Uint8Array.from([]); |
| 224 | + this.innerTransactions.forEach((transaction) => { |
| 225 | + const transactionByte = transaction.toAggregateTransactionBytes(); |
| 226 | + transactions = GeneratorUtils.concatTypedArrays(transactions, transactionByte); |
| 227 | + }); |
| 228 | + |
| 229 | + const cosignatures = Uint8Array.from([]); |
| 230 | + this.cosignatures.forEach((cosignature) => { |
| 231 | + const signerBytes = Convert.hexToUint8(cosignature.signer.publicKey); |
| 232 | + const signatureBytes = Convert.hexToUint8(cosignature.signature); |
| 233 | + const cosignatureBytes = new CosignatureBuilder( |
| 234 | + new KeyDto(signerBytes), |
| 235 | + new SignatureDto(signatureBytes), |
| 236 | + ).serialize(); |
| 237 | + transactions = GeneratorUtils.concatTypedArrays(cosignatures, cosignatureBytes); |
| 238 | + }); |
| 239 | + |
| 240 | + console.log('cosignatures', Convert.uint8ToHex(cosignatures)); |
| 241 | + console.log('transactions', Convert.uint8ToHex(transactions)); |
| 242 | + |
| 243 | + const transactionBuilder = new AggregateTransactionBuilder( |
| 244 | + new SignatureDto(signatureBuffer), |
| 245 | + new KeyDto(signerBuffer), |
| 246 | + this.versionToDTO(), |
| 247 | + this.type.valueOf(), |
| 248 | + new AmountDto(this.maxFee.toDTO()), |
| 249 | + new TimestampDto(this.deadline.toDTO()), |
| 250 | + transactions, |
| 251 | + cosignatures, |
| 252 | + ); |
| 253 | + return transactionBuilder.serialize(); |
213 | 254 | } |
214 | 255 |
|
215 | 256 | /** |
216 | 257 | * @internal |
217 | 258 | * @returns {Uint8Array} |
218 | 259 | */ |
219 | 260 | protected generateEmbeddedBytes(): Uint8Array { |
220 | | - throw new Error('Not implemented'); |
| 261 | + throw new Error('Method not implemented'); |
221 | 262 | } |
222 | 263 | } |
0 commit comments