refactor: employ prettier
This commit is contained in:
@ -25,18 +25,31 @@ function showBalance() {
|
||||
connection.getBalance(account2.publicKey),
|
||||
connection.getBalance(contractFunds.publicKey),
|
||||
connection.getBalance(contractState.publicKey),
|
||||
]).then(([fromBalance, toBalance, contractFundsBalance, contractStateBalance]) => {
|
||||
console.log(`Account1: ${account1.publicKey} has a balance of ${fromBalance}`);
|
||||
console.log(`Account2: ${account2.publicKey} has a balance of ${toBalance}`);
|
||||
console.log(`Contract Funds: ${contractFunds.publicKey} has a balance of ${contractFundsBalance}`);
|
||||
console.log(`Contract State: ${contractState.publicKey} has a balance of ${contractStateBalance}`);
|
||||
});
|
||||
]).then(
|
||||
([fromBalance, toBalance, contractFundsBalance, contractStateBalance]) => {
|
||||
console.log(
|
||||
`Account1: ${account1.publicKey} has a balance of ${fromBalance}`,
|
||||
);
|
||||
console.log(
|
||||
`Account2: ${account2.publicKey} has a balance of ${toBalance}`,
|
||||
);
|
||||
console.log(
|
||||
`Contract Funds: ${
|
||||
contractFunds.publicKey
|
||||
} has a balance of ${contractFundsBalance}`,
|
||||
);
|
||||
console.log(
|
||||
`Contract State: ${
|
||||
contractState.publicKey
|
||||
} has a balance of ${contractStateBalance}`,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function confirmTransaction(signature) {
|
||||
console.log('Confirming transaction:', signature);
|
||||
return connection.getSignatureStatus(signature)
|
||||
.then((confirmation) => {
|
||||
return connection.getSignatureStatus(signature).then(confirmation => {
|
||||
if (confirmation !== 'Confirmed') {
|
||||
throw new Error(`Transaction was not confirmed (${confirmation})`);
|
||||
}
|
||||
@ -46,69 +59,73 @@ function confirmTransaction(signature) {
|
||||
|
||||
function airDrop() {
|
||||
console.log(`\n== Requesting airdrop of 100 to ${account1.publicKey}`);
|
||||
return connection.requestAirdrop(account1.publicKey, 100)
|
||||
.then(confirmTransaction);
|
||||
return connection
|
||||
.requestAirdrop(account1.publicKey, 100)
|
||||
.then(confirmTransaction);
|
||||
}
|
||||
|
||||
showBalance()
|
||||
.then(airDrop)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Creating account for the contract funds`);
|
||||
const transaction = solanaWeb3.SystemProgram.createAccount(
|
||||
account1.publicKey,
|
||||
contractFunds.publicKey,
|
||||
50, // number of tokens to transfer
|
||||
0,
|
||||
solanaWeb3.BudgetProgram.programId,
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Creating account for the contract state`);
|
||||
const transaction = solanaWeb3.SystemProgram.createAccount(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
1, // account1 pays 1 token to hold the contract state
|
||||
solanaWeb3.BudgetProgram.space,
|
||||
solanaWeb3.BudgetProgram.programId,
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Initializing contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.pay(
|
||||
contractFunds.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
50,
|
||||
solanaWeb3.BudgetProgram.timestampCondition(account1.publicKey, new Date('2050')),
|
||||
);
|
||||
return connection.sendTransaction(contractFunds, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Witness contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.applyTimestamp(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
new Date('2050'),
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(airDrop)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Creating account for the contract funds`);
|
||||
const transaction = solanaWeb3.SystemProgram.createAccount(
|
||||
account1.publicKey,
|
||||
contractFunds.publicKey,
|
||||
50, // number of tokens to transfer
|
||||
0,
|
||||
solanaWeb3.BudgetProgram.programId,
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Creating account for the contract state`);
|
||||
const transaction = solanaWeb3.SystemProgram.createAccount(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
1, // account1 pays 1 token to hold the contract state
|
||||
solanaWeb3.BudgetProgram.space,
|
||||
solanaWeb3.BudgetProgram.programId,
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Initializing contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.pay(
|
||||
contractFunds.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
50,
|
||||
solanaWeb3.BudgetProgram.timestampCondition(
|
||||
account1.publicKey,
|
||||
new Date('2050'),
|
||||
),
|
||||
);
|
||||
return connection.sendTransaction(contractFunds, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
.then(() => {
|
||||
console.log(`\n== Witness contract`);
|
||||
const transaction = solanaWeb3.BudgetProgram.applyTimestamp(
|
||||
account1.publicKey,
|
||||
contractState.publicKey,
|
||||
account2.publicKey,
|
||||
new Date('2050'),
|
||||
);
|
||||
return connection.sendTransaction(account1, transaction);
|
||||
})
|
||||
.then(confirmTransaction)
|
||||
.then(showBalance)
|
||||
|
||||
.then(() => {
|
||||
console.log('\nDone');
|
||||
})
|
||||
.then(() => {
|
||||
console.log('\nDone');
|
||||
})
|
||||
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
|
Reference in New Issue
Block a user