Skip to content

Commit e22846b

Browse files
remove staker address from bond_public
1 parent 5117680 commit e22846b

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

create-leo-app/template-offline-public-transaction-ts/src/index.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ try {
6464
}
6565

6666
/// 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[]> {
6874
// Create an offline program manager
6975
const programManager = new ProgramManager();
7076

@@ -87,8 +93,7 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
8793
console.log("Creating offline key provider");
8894
const offlineKeyProvider = new OfflineKeyProvider();
8995

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
9297
console.log("Inserting proving keys into key provider");
9398
offlineKeyProvider.insertFeePublicKeys(feePublicProvingKey);
9499
offlineKeyProvider.insertBondPublicKeys(bondPublicProvingKey);
@@ -100,38 +105,48 @@ async function buildBondingTxOffline(stakerAddress: Address, validatorAddress:
100105

101106
// Build the bonding transactions offline
102107
console.log("Building a bond_public execution transaction offline");
108+
109+
if (!latestStateRoot) {
110+
throw new Error("latestStateRoot is undefined");
111+
}
112+
103113
const bondPublicOptions = {
104114
keySearchParams: OfflineSearchParams.bondPublicKeyParams(),
105-
offlineQuery: new OfflineQuery(latestStateRoot)
115+
offlineQuery: new OfflineQuery(0, latestStateRoot)
106116
};
107-
117+
108118

109119
const bondTx = <Transaction>await programManager.buildBondPublicTransaction(
110-
stakerAddress.to_string(),
111120
validatorAddress.to_string(),
112121
withdrawalAddress.to_string(),
113122
amount,
114-
bondPublicOptions,
115-
)
123+
bondPublicOptions
124+
);
125+
116126
console.log("\nbond_public transaction built!\n");
117127

118-
console.log("Building an unbond_public execution transaction offline")
119128
const unbondPublicOptions = {
120129
keySearchParams: OfflineSearchParams.unbondPublicKeyParams(),
121-
offlineQuery: new OfflineQuery(latestStateRoot)
130+
offlineQuery: new OfflineQuery(0, latestStateRoot)
122131
};
123132

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+
);
125138
console.log("\nunbond_public transaction built!\n");
126139

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");
129141
const claimUnbondPublicOptions = {
130142
keySearchParams: OfflineSearchParams.claimUnbondPublicKeyParams(),
131-
offlineQuery: new OfflineQuery(latestStateRoot)
143+
offlineQuery: new OfflineQuery(0, latestStateRoot)
132144
};
133145

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+
);
135150
console.log("\nclaim_unbond_public transaction built!\n");
136151
return [bondTx, unBondTx, claimUnbondTx];
137152
}
@@ -159,7 +174,7 @@ console.log(`\n---------------transfer_public transaction---------------\n${tran
159174
console.log(`---------------------------------------------------------`);
160175

161176
// 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);
163178
console.log("Bonding transactions built offline!");
164179
console.log(`\n-----------------bond_public transaction-----------------\n${bondTransactions[0]}`);
165180
console.log(`---------------------------------------------------------`);
@@ -174,4 +189,4 @@ console.log(`---------------------------------------------------------`);
174189
// ONLINE COMPONENT (Uncomment this part to send the transaction to the Aleo Network on an internet connected machine)
175190
// Submit the transaction to the network
176191
// const transferTxId = await networkClient.submitTransaction(transferTx);
177-
//---------------------------------------------------------
192+
//---------------------------------------------------------

sdk/src/program-manager.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ class ProgramManager {
843843
* const result = await programManager.networkClient.submitTransaction(tx);
844844
*
845845
* @returns string
846-
* @param {string} staker_address Address of the staker who is bonding the credits
847846
* @param {string} validator_address Address of the validator to bond to, if this address is the same as the staker (i.e. the
848847
* executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
849848
* requires a minimum of 10,000,000 credits to bond (subject to change). If the address is specified is an existing
@@ -853,15 +852,15 @@ class ProgramManager {
853852
* @param {number} amount The amount of credits to bond
854853
* @param {Partial<ExecuteOptions>} options - Override default execution options.
855854
*/
856-
async buildBondPublicTransaction(staker_address: string, validator_address: string, withdrawal_address: string, amount: number, options: Partial<ExecuteOptions> = {}) {
855+
async buildBondPublicTransaction(validator_address: string, withdrawal_address: string, amount: number, options: Partial<ExecuteOptions> = {}) {
857856
const scaledAmount = Math.trunc(amount * 1000000);
858857

859858
const {
860859
programName = "credits.aleo",
861860
functionName = "bond_public",
862861
fee = options.fee || 0.86,
863862
privateFee = false,
864-
inputs = [staker_address, validator_address, withdrawal_address, `${scaledAmount.toString()}u64`],
863+
inputs = [validator_address, withdrawal_address, `${scaledAmount.toString()}u64`],
865864
keySearchParams = new AleoKeyProviderParams({
866865
proverUri: CREDITS_PROGRAM_KEYS.bond_public.prover,
867866
verifierUri: CREDITS_PROGRAM_KEYS.bond_public.verifier,
@@ -900,7 +899,6 @@ class ProgramManager {
900899
* const tx_id = await programManager.bondPublic("aleo1jx8s4dvjepculny4wfrzwyhs3tlyv65r58ns3g6q2gm2esh7ps8sqy9s5j", "aleo1rhgdu77hgyqd3xjj8ucu3jj9r2krwz6mnzyd80gncr5fxcwlh5rsvzp9px", "aleo1feya8sjy9k2zflvl2dx39pdsq5tju28elnp2ektnn588uu9ghv8s84msv9", 2000000);
901900
*
902901
* @returns string
903-
* @param {string} staker_address Address of the staker who is bonding the credits
904902
* @param {string} validator_address Address of the validator to bond to, if this address is the same as the signer (i.e. the
905903
* executor of this function), it will attempt to bond the credits as a validator. Bonding as a validator currently
906904
* requires a minimum of 1,000,000 credits to bond (subject to change). If the address is specified is an existing
@@ -910,8 +908,8 @@ class ProgramManager {
910908
* @param {number} amount The amount of credits to bond
911909
* @param {Options} options Options for the execution
912910
*/
913-
async bondPublic(staker_address: string, validator_address: string, withdrawal_address:string, amount: number, options: Partial<ExecuteOptions> = {}) {
914-
const tx = <Transaction>await this.buildBondPublicTransaction(staker_address, validator_address, withdrawal_address, amount, options);
911+
async bondPublic(validator_address: string, withdrawal_address:string, amount: number, options: Partial<ExecuteOptions> = {}) {
912+
const tx = <Transaction>await this.buildBondPublicTransaction(validator_address, withdrawal_address, amount, options);
915913
return await this.networkClient.submitTransaction(tx);
916914
}
917915

0 commit comments

Comments
 (0)