-
Notifications
You must be signed in to change notification settings - Fork 0
/
SendAggregateTx.ts
71 lines (54 loc) · 2.09 KB
/
SendAggregateTx.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// send AggregateTransaction
// You should turn off strictNullChecks when compile.
// [tsconfig.json]
// "strictNullChecks": false
/**
Step1. createInnerTxs( txAlice, txBob, txCarol )
Step2. Aggregate these txs with Aggregate(Bond)Tx
Step3. create & send LockFundsTx to send Aggregate(Bond)Tx
Step4. send Aggregate(Bond)Tx
Step5. create& send CosignatureTx
======================
= Aggregate(Bond)Tx =
= =
= initiator : Alice =
= =
= txs : =
= Alice to Dave =
= Bob to Dave =
= Carol to Dave =
======================
**/
import * as nem from 'nem2-sdk';
import { NemConst } from './share/NemConst';
import { TxUtil } from './share/TxUtil';
const netType = nem.NetworkType.MIJIN_TEST;
const currencyMosaicId = new nem.MosaicId(NemConst.CURRENCY_MOSAIC_ID);
// roles //
const alice = nem.Account.createFromPrivateKey('693BCC0958A527AED45EB107D8194CB01731F1B21B049A9A03C3A324A7DF141C', netType);
const bob = nem.Account.createFromPrivateKey('C11B69D9AAC313BBF319252B84B00875AA4A8FCFA136CC8B4ECB36A0D84194B1', netType);
const carol = nem.Account.createFromPrivateKey('B8BB5C3E43825E759EA6DD23021D418F268FE8E6B24DFFF3554A16BEC93ABC8D', netType);
const dave = nem.Account.createFromPrivateKey('EEDB38408CB76EC90B0680FB00DF40CEFBB7547A1DFE566726E2CD948E81862B', netType);
const cosigners = [alice, bob, carol];
function createInnerTx(senderAcc: nem.Account): nem.InnerTransaction {
const tx = nem.TransferTransaction.create(
nem.Deadline.create(),
dave.address, // recipient
[new nem.Mosaic(currencyMosaicId, nem.UInt64.fromUint(1000000000))], // send mosaics
nem.PlainMessage.create('Happy birthday dave'),
netType
);
return tx.toAggregate(senderAcc.publicAccount); // to inner tx
}
function createInnerTxs(): nem.InnerTransaction[] {
// create inner txs of bob, carol, and alice(initiator)
return cosigners.map(cosigner => { return createInnerTx(cosigner) });
}
const innerTxs = createInnerTxs();
const url = 'http://localhost:3000';
TxUtil.sendAggreagateBondedTx(
cosigners[0],
cosigners.slice(1),
innerTxs,
url
);