|
1 | | -import { networkIDs, pvm, utils } from "@flarenetwork/flarejs"; |
| 1 | +import { networkIDs, pvm, UnsignedTx, utils } from "@flarenetwork/flarejs"; |
2 | 2 | import { issuePChainTx, localFlareContext } from "./utils"; |
3 | 3 | import { runTest } from "./runner"; |
4 | 4 |
|
5 | 5 | const nodeID = 'NodeID-MFrZFVCXPv5iCn6M9K6XduxGTYp891xXZ'; |
6 | 6 | const blsPublicKey = '0xadb0203ebc76627d28fb9440272a2701b85f5c5d4266352686ea42666f5026f1fdabab59529932f1eddb317a6f7435f9'; |
7 | 7 | const blsSignature = '0x926a1c21953babb12189ec88bfab5cb0060b385efa04c51abe4a3bc42266f80eebb84bcfaacfc8f075560ab444bda8de17bf9013ec20a80dfdfda4ae047a0b39669d153dcee94eb964fe194f5d55c5bba5939ff9ba07b728b6733d696c33ac5a' |
8 | 8 |
|
9 | | -async function addValidator(nodeID: string, endTime: number, weight: number) { |
| 9 | +async function addValidator(nodeId: string, endTime: number, weight: number) { |
10 | 10 | const ctx = await localFlareContext(); |
11 | 11 |
|
12 | 12 | // Create the transaction to add a validator |
13 | | - console.log(`Creating add validator transaction for node ${nodeID} with weight ${weight}...`); |
| 13 | + console.log(`Creating add validator transaction for node ${nodeId} with weight ${weight}...`); |
14 | 14 |
|
15 | 15 | const { utxos } = await ctx.pvmapi.getUTXOs({ |
16 | 16 | addresses: [ctx.addressP] |
17 | 17 | }); |
18 | | - const tx = pvm.newAddPermissionlessValidatorTx( |
19 | | - ctx.context, |
20 | | - utxos, |
21 | | - [utils.bech32ToBytes(ctx.addressP)], |
22 | | - nodeID, |
23 | | - networkIDs.PrimaryNetworkID.toString(), |
24 | | - BigInt(Date.now()) / 1000n, |
25 | | - BigInt(endTime), |
26 | | - BigInt(weight * 1e9), |
27 | | - [utils.bech32ToBytes(ctx.addressP)], |
28 | | - [utils.bech32ToBytes(ctx.addressP)], |
29 | | - 10_0000, |
30 | | - undefined, |
31 | | - 1, |
32 | | - 0n, |
33 | | - utils.hexToBuffer(blsPublicKey), |
34 | | - utils.hexToBuffer(blsSignature) |
35 | | - ); |
| 18 | + |
| 19 | + let tx: UnsignedTx; |
| 20 | + if (ctx.isEtnaForkActive) { |
| 21 | + console.log("Etna fork is active, using new transaction format."); |
| 22 | + const feeState = await ctx.pvmapi.getFeeState(); |
| 23 | + tx = pvm.e.newAddPermissionlessValidatorTx( |
| 24 | + { |
| 25 | + feeState, |
| 26 | + utxos, |
| 27 | + nodeId, |
| 28 | + subnetId: networkIDs.PrimaryNetworkID.toString(), |
| 29 | + start: BigInt(Date.now()) / 1000n, |
| 30 | + end: BigInt(endTime), |
| 31 | + weight: BigInt(weight * 1e9), |
| 32 | + shares: 10_0000, |
| 33 | + fromAddressesBytes: [utils.bech32ToBytes(ctx.addressP)], |
| 34 | + rewardAddresses: [utils.bech32ToBytes(ctx.addressP)], |
| 35 | + delegatorRewardsOwner: [utils.bech32ToBytes(ctx.addressP)], |
| 36 | + publicKey: utils.hexToBuffer(blsPublicKey), |
| 37 | + signature: utils.hexToBuffer(blsSignature), |
| 38 | + }, |
| 39 | + ctx.context, |
| 40 | + ); |
| 41 | + } else { |
| 42 | + console.log("Etna fork is not active, using legacy transaction format."); |
| 43 | + tx = pvm.newAddPermissionlessValidatorTx( |
| 44 | + ctx.context, |
| 45 | + utxos, |
| 46 | + [utils.bech32ToBytes(ctx.addressP)], |
| 47 | + nodeId, |
| 48 | + networkIDs.PrimaryNetworkID.toString(), |
| 49 | + BigInt(Date.now()) / 1000n, |
| 50 | + BigInt(endTime), |
| 51 | + BigInt(weight * 1e9), |
| 52 | + [utils.bech32ToBytes(ctx.addressP)], |
| 53 | + [utils.bech32ToBytes(ctx.addressP)], |
| 54 | + 10_0000, |
| 55 | + undefined, |
| 56 | + 1, |
| 57 | + 0n, |
| 58 | + utils.hexToBuffer(blsPublicKey), |
| 59 | + utils.hexToBuffer(blsSignature) |
| 60 | + ); |
| 61 | + } |
36 | 62 |
|
37 | 63 | await issuePChainTx(ctx.pvmapi, tx, ctx.privateKey); |
38 | 64 | } |
|
0 commit comments