fix: accommodate cluster fees in budget-two-approvers
This commit is contained in:
committed by
Michael Vines
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,33 +58,44 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTransactionFee().then(feeCalculator => {
|
||||||
showBalance()
|
showBalance()
|
||||||
.then(airDrop)
|
.then(airDrop(feeCalculator))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`\n== Move 1 lamport to approver1`);
|
console.log(`\n== Move 1 lamport to approver1`);
|
||||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||||
account1.publicKey,
|
account1.publicKey,
|
||||||
approver1.publicKey,
|
approver1.publicKey,
|
||||||
1,
|
1 + feeCalculator.lamportsPerSignature,
|
||||||
|
);
|
||||||
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
|
connection,
|
||||||
|
transaction,
|
||||||
|
account1,
|
||||||
);
|
);
|
||||||
return connection.sendTransaction(transaction, account1);
|
|
||||||
})
|
})
|
||||||
.then(confirmTransaction)
|
.then(confirmTransaction)
|
||||||
|
.then(getTransactionFee)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`\n== Move 1 lamport to approver2`);
|
console.log(`\n== Move 1 lamport to approver2`);
|
||||||
const transaction = solanaWeb3.SystemProgram.transfer(
|
const transaction = solanaWeb3.SystemProgram.transfer(
|
||||||
account1.publicKey,
|
account1.publicKey,
|
||||||
approver2.publicKey,
|
approver2.publicKey,
|
||||||
1,
|
1 + feeCalculator.lamportsPerSignature,
|
||||||
|
);
|
||||||
|
return solanaWeb3.sendAndConfirmTransaction(
|
||||||
|
connection,
|
||||||
|
transaction,
|
||||||
|
account1,
|
||||||
);
|
);
|
||||||
return connection.sendTransaction(transaction, account1);
|
|
||||||
})
|
})
|
||||||
.then(confirmTransaction)
|
.then(confirmTransaction)
|
||||||
.then(showBalance)
|
.then(showBalance)
|
||||||
@ -138,3 +155,4 @@ showBalance()
|
|||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user