Redeem cheque script and task with args

This commit is contained in:
Oskar Thoren 2021-02-09 12:23:59 +08:00
parent dfbd26d195
commit 1b615e9604
2 changed files with 30 additions and 0 deletions

View File

@ -36,6 +36,14 @@ task("signCheque", "Sign cheque")
console.log(JSON.stringify(resp));
});
task("redeemCheque", "Redeem cheque")
.addParam("swapaddress", "Address to Swap Contract (Assumed to belong to Alice)")
.addParam("signature", "Cheque signature that can be redeemed")
.setAction(async taskArgs => {
var resp = await swap.redeemCheque(taskArgs.swapaddress, taskArgs.signature);
console.log(JSON.stringify(resp));
});
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

View File

@ -137,6 +137,28 @@ async function signCheque(swapAddress) {
return {signer: aliceSigner.adress, signature: signature};
}
async function redeemCheque(aliceSwapAddress, issuerSig) {
var recipient = bobAddress;
var cumulativePayout = 500;
var signers = await ethers.getSigners();
var aliceSigner = signers[0];
var bobSigner = signers[1];
var swapArtifact = await artifacts.readArtifact("ERC20SimpleSwap");
var swapContract = new ethers.Contract(aliceSwapAddress, swapArtifact.abi, bobSigner);
var foo = await swapContract.cashChequeBeneficiary(recipient, cumulativePayout, issuerSig);
console.log("Resp", foo);
// Reproduced error here:
// ProviderError: VM Exception while processing transaction: revert SimpleSwap: invalid issuer signature
// TODO Fix it
return {resp: foo}
};
module.exports.setupSwap = setupSwap;
module.exports.signCheque = signCheque;
module.exports.redeemCheque = redeemCheque;