make compatible with ERC20-enabled wallets

This commit is contained in:
Michele Balistreri 2020-02-28 18:02:34 +03:00
parent 52a334eb72
commit 37182158e0
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
1 changed files with 5 additions and 5 deletions

View File

@ -4,8 +4,8 @@ import Web3 from 'web3';
import parseArgs from 'minimist';
import fs from 'fs';
const factoryABI = [{"constant":false,"inputs":[{"name":"_wallet","type":"address"},{"name":"_keycard","type":"address"}],"name":"unregisterFromOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x25a6e9a1"},{"constant":false,"inputs":[{"name":"_oldOwner","type":"address"},{"name":"_newOwner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x299a7bcc"},{"constant":false,"inputs":[{"name":"_oldKeycard","type":"address"},{"name":"_newKeycard","type":"address"}],"name":"setKeycard","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4349c8bc"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_keycard","type":"address"}],"name":"unregister","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4a45b60b"},{"constant":false,"inputs":[{"name":"keycard","type":"address"},{"components":[{"name":"maxTxValue","type":"uint256"},{"name":"minBlockDistance","type":"uint256"}],"name":"settings","type":"tuple"},{"name":"keycardIsOwner","type":"bool"}],"name":"create","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x5213737f"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"countWalletsForOwner","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x624de70e"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_keycard","type":"address"}],"name":"register","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xaa677354"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"keycardsWallets","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcf7661b9"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"ownersWallets","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xde59dda1"},{"anonymous":false,"inputs":[{"indexed":false,"name":"wallet","type":"address"}],"name":"NewWallet","type":"event","signature":"0xd627a1aeb13261b560c345aaf7d003d55a27193b9284c0b941f53cd62a045f16"}];
const argv = parseArgs(process.argv.slice(2), {string: ["registry", "keycard"], default: {"endpoint": "ws://127.0.0.1:8546", "maxTxValue": 100000000, "minBlockDistance": 5}});
const factoryABI = [{"constant":false,"inputs":[{"name":"keycard","type":"address"},{"components":[{"name":"maxTxValue","type":"uint256"},{"name":"minBlockDistance","type":"uint256"}],"name":"settings","type":"tuple"},{"name":"keycardIsOwner","type":"bool"},{"name":"optToken","type":"address"},{"name":"optTokenMaxTxAmount","type":"uint256"}],"name":"create","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x03fbbd28"},{"constant":false,"inputs":[{"name":"_wallet","type":"address"},{"name":"_keycard","type":"address"}],"name":"unregisterFromOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x25a6e9a1"},{"constant":false,"inputs":[{"name":"_oldOwner","type":"address"},{"name":"_newOwner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x299a7bcc"},{"constant":false,"inputs":[{"name":"_oldKeycard","type":"address"},{"name":"_newKeycard","type":"address"}],"name":"setKeycard","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4349c8bc"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_keycard","type":"address"}],"name":"unregister","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0x4a45b60b"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"countWalletsForOwner","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function","signature":"0x624de70e"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_keycard","type":"address"}],"name":"register","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function","signature":"0xaa677354"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"keycardsWallets","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xcf7661b9"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"ownersWallets","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function","signature":"0xde59dda1"},{"anonymous":false,"inputs":[{"indexed":false,"name":"wallet","type":"address"}],"name":"NewWallet","type":"event","signature":"0xd627a1aeb13261b560c345aaf7d003d55a27193b9284c0b941f53cd62a045f16"}];
const argv = parseArgs(process.argv.slice(2), {string: ["registry", "keycard"], default: {"endpoint": "ws://127.0.0.1:8546", "maxTxValue": 10000000000000, "minBlockDistance": 5, "token": "0x0000000000000000000000000000000000000000", "tokenMaxTxValue": 10000000000000}});
const web3 = new Web3(argv["endpoint"]);
const KeycardWalletFactory = new web3.eth.Contract(factoryABI, argv["registry"]);
@ -22,8 +22,8 @@ function loadAccount(account, passfile) {
return web3.eth.accounts.decrypt(json, pass);
}
async function createWallet(sender, keycard, maxTxValue, minBlockDistance) {
let methodCall = KeycardWalletFactory.methods.create(keycard.toLowerCase(), {maxTxValue: maxTxValue, minBlockDistance: minBlockDistance}, true);
async function createWallet(sender, keycard, maxTxValue, minBlockDistance, token, tokenMaxTxValue) {
let methodCall = KeycardWalletFactory.methods.create(keycard.toLowerCase(), {maxTxValue: maxTxValue, minBlockDistance: minBlockDistance}, true, token, tokenMaxTxValue);
try {
let receipt;
@ -83,7 +83,7 @@ async function run() {
sender = argv["sender"] || await getDefaultSender();
}
let walletAddresses = await Promise.all(keycards.map((keycard) => createWallet(sender, keycard, argv["maxTxValue"], argv["minBlockDistance"])));
let walletAddresses = await Promise.all(keycards.map((keycard) => createWallet(sender, keycard, argv["maxTxValue"], argv["minBlockDistance"], argv["token"], argv["tokenMaxTxValue"])));
let zippedAddresses = keycards.map((keycard, i) => [keycard, walletAddresses[i]]);
let fid;