64
64
}
65
65
66
66
/// Build bonding and unbonding transactions without connection to the internet
67
- async function buildBondingTxOffline ( stakerAddress : Address , validatorAddress : Address , withdrawalAddress : Address , amount : number , latestStateRoot : string , keyPaths : { } ) : Promise < Transaction [ ] > {
67
+ async function buildBondingTxOffline (
68
+ validatorAddress : Address ,
69
+ withdrawalAddress : Address ,
70
+ amount : number ,
71
+ latestStateRoot : string ,
72
+ keyPaths : { }
73
+ ) : Promise < Transaction [ ] > {
68
74
// Create an offline program manager
69
75
const programManager = new ProgramManager ( ) ;
70
76
@@ -87,8 +93,7 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
87
93
console . log ( "Creating offline key provider" ) ;
88
94
const offlineKeyProvider = new OfflineKeyProvider ( ) ;
89
95
90
- // Insert the proving keys into the offline key provider. The key provider will automatically insert the verifying
91
- // keys into the key manager.
96
+ // Insert the proving keys into the offline key provider
92
97
console . log ( "Inserting proving keys into key provider" ) ;
93
98
offlineKeyProvider . insertFeePublicKeys ( feePublicProvingKey ) ;
94
99
offlineKeyProvider . insertBondPublicKeys ( bondPublicProvingKey ) ;
@@ -100,38 +105,48 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
100
105
101
106
// Build the bonding transactions offline
102
107
console . log ( "Building a bond_public execution transaction offline" ) ;
108
+
109
+ if ( ! latestStateRoot ) {
110
+ throw new Error ( "latestStateRoot is undefined" ) ;
111
+ }
112
+
103
113
const bondPublicOptions = {
104
114
keySearchParams : OfflineSearchParams . bondPublicKeyParams ( ) ,
105
- offlineQuery : new OfflineQuery ( latestStateRoot )
115
+ offlineQuery : new OfflineQuery ( 0 , latestStateRoot )
106
116
} ;
107
-
117
+
108
118
109
119
const bondTx = < Transaction > await programManager . buildBondPublicTransaction (
110
- stakerAddress . to_string ( ) ,
111
120
validatorAddress . to_string ( ) ,
112
121
withdrawalAddress . to_string ( ) ,
113
122
amount ,
114
- bondPublicOptions ,
115
- )
123
+ bondPublicOptions
124
+ ) ;
125
+
116
126
console . log ( "\nbond_public transaction built!\n" ) ;
117
127
118
- console . log ( "Building an unbond_public execution transaction offline" )
119
128
const unbondPublicOptions = {
120
129
keySearchParams : OfflineSearchParams . unbondPublicKeyParams ( ) ,
121
- offlineQuery : new OfflineQuery ( latestStateRoot )
130
+ offlineQuery : new OfflineQuery ( 0 , latestStateRoot )
122
131
} ;
123
132
124
- const unBondTx = < Transaction > await programManager . buildUnbondPublicTransaction ( stakerAddress . to_string ( ) , amount , unbondPublicOptions ) ;
133
+ const unBondTx = < Transaction > await programManager . buildUnbondPublicTransaction (
134
+ stakerAddress . to_string ( ) ,
135
+ amount ,
136
+ unbondPublicOptions
137
+ ) ;
125
138
console . log ( "\nunbond_public transaction built!\n" ) ;
126
139
127
- console . log ( "Building a claim_unbond_public transaction offline" )
128
- // Build the claim unbonding transaction offline
140
+ console . log ( "Building a claim_unbond_public transaction offline" ) ;
129
141
const claimUnbondPublicOptions = {
130
142
keySearchParams : OfflineSearchParams . claimUnbondPublicKeyParams ( ) ,
131
- offlineQuery : new OfflineQuery ( latestStateRoot )
143
+ offlineQuery : new OfflineQuery ( 0 , latestStateRoot )
132
144
} ;
133
145
134
- const claimUnbondTx = < Transaction > await programManager . buildClaimUnbondPublicTransaction ( stakerAddress . to_string ( ) , claimUnbondPublicOptions ) ;
146
+ const claimUnbondTx = < Transaction > await programManager . buildClaimUnbondPublicTransaction (
147
+ stakerAddress . to_string ( ) ,
148
+ claimUnbondPublicOptions
149
+ ) ;
135
150
console . log ( "\nclaim_unbond_public transaction built!\n" ) ;
136
151
return [ bondTx , unBondTx , claimUnbondTx ] ;
137
152
}
@@ -159,7 +174,7 @@ console.log(`\n---------------transfer_public transaction---------------\n${tran
159
174
console . log ( `---------------------------------------------------------` ) ;
160
175
161
176
// Build bonding & unbonding transactions
162
- const bondTransactions = await buildBondingTxOffline ( stakerAddress , validatorAddress , withdrawalAddress , 100 , latestStateRoot , bondingKeyPaths ) ;
177
+ const bondTransactions = await buildBondingTxOffline ( validatorAddress , withdrawalAddress , 100 , latestStateRoot , bondingKeyPaths ) ;
163
178
console . log ( "Bonding transactions built offline!" ) ;
164
179
console . log ( `\n-----------------bond_public transaction-----------------\n${ bondTransactions [ 0 ] } ` ) ;
165
180
console . log ( `---------------------------------------------------------` ) ;
@@ -174,4 +189,4 @@ console.log(`---------------------------------------------------------`);
174
189
// ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
175
190
// Submit the transaction to the network
176
191
// const transferTxId = await networkClient.submitTransaction(transferTx);
177
- //---------------------------------------------------------
192
+ //---------------------------------------------------------
0 commit comments