mirror of
https://github.com/status-im/keycard-redeem.git
synced 2025-02-16 22:16:56 +00:00
add relay
This commit is contained in:
parent
38eb174fe1
commit
bf00d10bd2
@ -16,7 +16,7 @@ const account = new Account(web3);
|
||||
const classPrefix = argv["nft"] ? "NFT" : "ERC20";
|
||||
|
||||
const BucketFactoryConfig = utils.loadJSON(`./dist/contracts/${classPrefix}BucketFactory.json`);
|
||||
const BucketFactory = new web3.eth.Contract(BucketFactoryConfig["abiDefinition"]);
|
||||
const BucketFactory = utils.json2Contract(web3, BucketFactoryConfig);
|
||||
const Bucket = utils.loadContract(web3, `./dist/contracts/${classPrefix}Bucket.json`);
|
||||
const ERC721 = utils.loadContract(web3, `./dist/contracts/IERC721.json`);
|
||||
const ERC20 = utils.loadContract(web3, `./dist/contracts/IERC20Detailed.json`);
|
||||
|
38
scripts/relay.js
Normal file
38
scripts/relay.js
Normal file
@ -0,0 +1,38 @@
|
||||
const express = require('express');
|
||||
const Web3 = require('web3');
|
||||
const parseArgs = require('minimist');
|
||||
const Account = require('./account.js');
|
||||
const utils = require('./utils.js');
|
||||
|
||||
|
||||
const argv = parseArgs(process.argv.slice(2), {string: ["sender"], default: {"endpoint": "ws://127.0.0.1:8546"}});
|
||||
const web3 = new Web3(argv["endpoint"]);
|
||||
const account = new Account(web3);
|
||||
|
||||
const BucketConfig = utils.loadJSON(`./dist/contracts/Bucket.json`);
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
async function redeem(bucket, blockNumber, blockHash, receiver, code, sig) {
|
||||
const Bucket = utils.json2Contract(web3, BucketConfig);
|
||||
Bucket.transactionConfirmationBlocks = 1;
|
||||
Bucket.options.address = bucket;
|
||||
let methodCall = Bucket.methods.redeem({blockNumber: blockNumber, blockHash: blockHash, receiver: receiver, code: code}, sig);
|
||||
return account.sendMethod(methodCall, Bucket.options.address);
|
||||
}
|
||||
|
||||
async function redeemRequest(req, res) {
|
||||
let receipt = redeem(req.body.bucket, req.body.blockNumber, req.body.blockHash, req.body.receiver, req.body.code, req.body.sig);
|
||||
res.json({tx: receipt.transactionHash});
|
||||
}
|
||||
|
||||
async function run() {
|
||||
await account.init(argv);
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
app.post('/redeem', redeemRequest);
|
||||
app.listen(port, () => console.log(`Relayer listening at http://localhost:${port}`));
|
||||
}
|
||||
|
||||
run();
|
@ -1,12 +1,16 @@
|
||||
const fs = require('fs');
|
||||
|
||||
module.exports.loadJSON = function(path) {
|
||||
module.exports.loadJSON = (path) => {
|
||||
let file = fs.readFileSync(path, "utf-8");
|
||||
let loadedAsset = JSON.parse(file);
|
||||
return loadedAsset;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.loadContract = function(web3, path) {
|
||||
let config = this.loadJSON(path);
|
||||
module.exports.json2Contract = (web3, config) => {
|
||||
return new web3.eth.Contract(config["abiDefinition"]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.loadContract = (web3, path) => {
|
||||
let config = this.loadJSON(path);
|
||||
return this.json2Contract(web3, config);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user