update scripts to load ABI or BIN files
This commit is contained in:
parent
712ebc1b34
commit
9befd72459
|
@ -15,14 +15,14 @@ const account = new Account(web3);
|
|||
|
||||
const classPrefix = argv["nft"] ? "NFT" : "ERC20";
|
||||
|
||||
const BucketFactoryConfig = utils.loadJSON(`./dist/contracts/${classPrefix}BucketFactory.json`);
|
||||
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`);
|
||||
const BucketFactoryCode = utils.loadContractCode(`${classPrefix}BucketFactory`);
|
||||
const BucketFactory = utils.loadContract(web3, `${classPrefix}BucketFactory`);
|
||||
const Bucket = utils.loadContract(web3, `${classPrefix}Bucket.json`);
|
||||
const ERC721 = utils.loadContract(web3, "IERC721");
|
||||
const ERC20 = utils.loadContract(web3, "IERC20Detailed");
|
||||
|
||||
async function deployFactory() {
|
||||
let code = "0x" + BucketFactoryConfig["code"];
|
||||
let code = "0x" + BucketFactoryCode;
|
||||
let methodCall = BucketFactory.deploy({data: code});
|
||||
let receipt = await account.sendMethod(methodCall, null);
|
||||
return receipt.contractAddress;
|
||||
|
|
|
@ -10,7 +10,7 @@ const argv = parseArgs(process.argv.slice(2), {string: ["sender", "bucket"], def
|
|||
const web3 = new Web3(argv["endpoint"]);
|
||||
const account = new Account(web3);
|
||||
|
||||
const BucketConfig = utils.loadJSON(`./dist/contracts/Bucket.json`);
|
||||
const Bucket = utils.loadContract(web3, "Bucket");
|
||||
|
||||
const port = process.env.PORT || 3000;
|
||||
const app = express();
|
||||
|
@ -19,7 +19,6 @@ app.use(morgan('combined'))
|
|||
let allowedBuckets = [];
|
||||
|
||||
async function redeem(bucket, message, sig) {
|
||||
const Bucket = utils.json2Contract(web3, BucketConfig);
|
||||
Bucket.transactionConfirmationBlocks = 1;
|
||||
Bucket.options.address = bucket;
|
||||
let methodCall = Bucket.methods.redeem(message, sig);
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
module.exports.loadJSON = (path) => {
|
||||
let file = fs.readFileSync(path, "utf-8");
|
||||
let loadedAsset = JSON.parse(file);
|
||||
return loadedAsset;
|
||||
const CONTRACTS_PATH="./contracts";
|
||||
|
||||
module.exports.loadContractFile = (fileName) => {
|
||||
let content = fs.readFileSync(path.join(__dirname, CONTRACTS_PATH, fileName), "utf-8");
|
||||
return content;
|
||||
};
|
||||
|
||||
module.exports.json2Contract = (web3, config) => {
|
||||
return new web3.eth.Contract(config["abiDefinition"]);
|
||||
module.exports.loadContractCode = (contractName) => {
|
||||
return loadContractFile(`${contractName}.bin`);
|
||||
};
|
||||
|
||||
module.exports.loadContract = (web3, path) => {
|
||||
let config = this.loadJSON(path);
|
||||
return this.json2Contract(web3, config);
|
||||
};
|
||||
module.exports.loadContract = (web3, contractName) => {
|
||||
let content = this.loadContractFile(`${contractName}.abi`);
|
||||
let abi = JSON.parse(content);
|
||||
return new web3.eth.Contract(abi);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue