fix: accommodate cluster fees in budget-two-approvers
This commit is contained in:
parent
9c880a8c99
commit
253e27014e
|
@ -18,6 +18,12 @@ url = 'http://localhost:8899';
|
||||||
//url = 'http://testnet.solana.com:8899';
|
//url = 'http://testnet.solana.com:8899';
|
||||||
const connection = new solanaWeb3.Connection(url);
|
const connection = new solanaWeb3.Connection(url);
|
||||||
|
|
||||||
|
function getTransactionFee() {
|
||||||
|
return connection.getRecentBlockhash().then(response => {
|
||||||
|
return response[1];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function showBalance() {
|
function showBalance() {
|
||||||
console.log(`\n== Account State`);
|
console.log(`\n== Account State`);
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
|
@ -52,89 +58,101 @@ function confirmTransaction(signature) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function airDrop() {
|
function airDrop(feeCalculator) {
|
||||||
console.log(`\n== Requesting airdrop of 100 to ${account1.publicKey}`);
|
const airdrop = 100 + 3 * feeCalculator.targetLamportsPerSignature;
|
||||||
|
console.log(`\n== Requesting airdrop of ${airdrop} to ${account1.publicKey}`);
|
||||||
return connection
|
return connection
|
||||||
.requestAirdrop(account1.publicKey, 100)
|
.requestAirdrop(account1.publicKey, airdrop)
|
||||||
.then(confirmTransaction);
|
.then(confirmTransaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
showBalance()
|
getTransactionFee().then(feeCalculator => {
|
||||||
.then(airDrop)
|
showBalance()
|
||||||
.then(() => {
|
.then(airDrop(feeCalculator))
|
||||||
console.log(`\n== Move 1 lamport to approver1`);
|
.then(() => {
|
||||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
console.log(`\n== Move 1 lamport to approver1`);
|
||||||
account1.publicKey,
|
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||||
approver1.publicKey,
|
account1.publicKey,
|
||||||
1,
|
approver1.publicKey,
|
||||||
);
|
1 + feeCalculator.lamportsPerSignature,
|
||||||
return connection.sendTransaction(transaction, account1);
|
);
|
||||||
})
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
.then(confirmTransaction)
|
connection,
|
||||||
.then(() => {
|
transaction,
|
||||||
console.log(`\n== Move 1 lamport to approver2`);
|
account1,
|
||||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
);
|
||||||
account1.publicKey,
|
})
|
||||||
approver2.publicKey,
|
.then(confirmTransaction)
|
||||||
1,
|
.then(getTransactionFee)
|
||||||
);
|
.then(() => {
|
||||||
return connection.sendTransaction(transaction, account1);
|
console.log(`\n== Move 1 lamport to approver2`);
|
||||||
})
|
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||||
.then(confirmTransaction)
|
account1.publicKey,
|
||||||
.then(showBalance)
|
approver2.publicKey,
|
||||||
.then(() => {
|
1 + feeCalculator.lamportsPerSignature,
|
||||||
console.log(`\n== Initializing contract`);
|
);
|
||||||
const transaction = solanaWeb3.BudgetProgram.payOnBoth(
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
account1.publicKey,
|
connection,
|
||||||
contractState.publicKey,
|
transaction,
|
||||||
account2.publicKey,
|
account1,
|
||||||
50,
|
);
|
||||||
solanaWeb3.BudgetProgram.signatureCondition(approver1.publicKey),
|
})
|
||||||
solanaWeb3.BudgetProgram.signatureCondition(approver2.publicKey),
|
.then(confirmTransaction)
|
||||||
);
|
.then(showBalance)
|
||||||
return solanaWeb3.sendAndConfirmTransaction(
|
.then(() => {
|
||||||
connection,
|
console.log(`\n== Initializing contract`);
|
||||||
transaction,
|
const transaction = solanaWeb3.BudgetProgram.payOnBoth(
|
||||||
account1,
|
account1.publicKey,
|
||||||
);
|
contractState.publicKey,
|
||||||
})
|
account2.publicKey,
|
||||||
.then(confirmTransaction)
|
50,
|
||||||
.then(showBalance)
|
solanaWeb3.BudgetProgram.signatureCondition(approver1.publicKey),
|
||||||
.then(() => {
|
solanaWeb3.BudgetProgram.signatureCondition(approver2.publicKey),
|
||||||
console.log(`\n== Apply approver 1`);
|
);
|
||||||
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
approver1.publicKey,
|
connection,
|
||||||
contractState.publicKey,
|
transaction,
|
||||||
account2.publicKey,
|
account1,
|
||||||
);
|
);
|
||||||
return solanaWeb3.sendAndConfirmTransaction(
|
})
|
||||||
connection,
|
.then(confirmTransaction)
|
||||||
transaction,
|
.then(showBalance)
|
||||||
approver1,
|
.then(() => {
|
||||||
);
|
console.log(`\n== Apply approver 1`);
|
||||||
})
|
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
||||||
.then(confirmTransaction)
|
approver1.publicKey,
|
||||||
.then(showBalance)
|
contractState.publicKey,
|
||||||
.then(() => {
|
account2.publicKey,
|
||||||
console.log(`\n== Apply approver 2`);
|
);
|
||||||
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
approver2.publicKey,
|
connection,
|
||||||
contractState.publicKey,
|
transaction,
|
||||||
account2.publicKey,
|
approver1,
|
||||||
);
|
);
|
||||||
return solanaWeb3.sendAndConfirmTransaction(
|
})
|
||||||
connection,
|
.then(confirmTransaction)
|
||||||
transaction,
|
.then(showBalance)
|
||||||
approver2,
|
.then(() => {
|
||||||
);
|
console.log(`\n== Apply approver 2`);
|
||||||
})
|
const transaction = solanaWeb3.BudgetProgram.applySignature(
|
||||||
.then(confirmTransaction)
|
approver2.publicKey,
|
||||||
.then(showBalance)
|
contractState.publicKey,
|
||||||
|
account2.publicKey,
|
||||||
|
);
|
||||||
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
|
connection,
|
||||||
|
transaction,
|
||||||
|
approver2,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then(confirmTransaction)
|
||||||
|
.then(showBalance)
|
||||||
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('\nDone');
|
console.log('\nDone');
|
||||||
})
|
})
|
||||||
|
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue