提交 3e95e8dd authored 作者: 崔大师's avatar 崔大师

bugfix

上级 4e6ee157
...@@ -14,7 +14,7 @@ const init = (mnemonic) => { ...@@ -14,7 +14,7 @@ const init = (mnemonic) => {
const hdwallet = HDWallet.fromSeed(seed) const hdwallet = HDWallet.fromSeed(seed)
const privateKey = hdwallet.derive('m/44\'/60\'/0\'/0/0').getPrivateKey() const privateKey = hdwallet.derive('m/44\'/60\'/0\'/0/0').getPrivateKey()
const address = utils.privateToAddress(privateKey) const address = utils.privateToAddress(privateKey)
console.log('Wallet: ' + toIban('0x'+address.toString('hex'))) console.log('Wallet: ' + toIban('0x' + address.toString('hex')))
web3.setProvider(new web3.providers.HttpProvider(rpxUrl)); web3.setProvider(new web3.providers.HttpProvider(rpxUrl));
web3.thk.defaultPrivateKey = privateKey web3.thk.defaultPrivateKey = privateKey
web3.thk.defaultAddress = '0x' + address.toString('hex').toLowerCase() web3.thk.defaultAddress = '0x' + address.toString('hex').toLowerCase()
...@@ -55,8 +55,8 @@ const setVal = (value) => { ...@@ -55,8 +55,8 @@ const setVal = (value) => {
const ether = (amount) => { const ether = (amount) => {
return web3.toWei(amount); return web3.toWei(amount);
} }
const toIban = (THAddress) => { const toIban = (address) => {
return web3.Iban.toIban(THAddress).toString() return web3.Iban.toIban(address).toString()
} }
const isIban = (THAddress) => { const isIban = (THAddress) => {
return web3.Iban.isValid(THAddress) return web3.Iban.isValid(THAddress)
...@@ -64,4 +64,7 @@ const isIban = (THAddress) => { ...@@ -64,4 +64,7 @@ const isIban = (THAddress) => {
const toAddress = (THAddress) => { const toAddress = (THAddress) => {
return web3.Iban.toAddress(THAddress).toString() return web3.Iban.toAddress(THAddress).toString()
} }
module.exports = { init, getTxHash, callContract, deployContract, ether, setVal,toIban,toAddress,isIban }; const isAddress = (address) => {
\ No newline at end of file return web3.isAddress(address).toString()
}
module.exports = { init, getTxHash, callContract, deployContract, ether, setVal, toIban, toAddress, isIban, isAddress };
\ No newline at end of file
#!/usr/bin/env node #!/usr/bin/env node
const { init, callContract, ether, getTxHash, toIban, toAddress, isIban } = require('./ThkContract.js'); const { init, callContract, ether, getTxHash, toIban, toAddress, isIban, isAddress } = require('./ThkContract.js');
const Web3 = require('web3');
const fs = require('fs'); const fs = require('fs');
const path = require("path"); const path = require("path");
const inquirer = require('inquirer'); const inquirer = require('inquirer');
...@@ -127,13 +126,13 @@ const call = async(functionName, inputs, outputs) => { ...@@ -127,13 +126,13 @@ const call = async(functionName, inputs, outputs) => {
name: inputs[i].name == "" ? inputs[i].desc : inputs[i].name, name: inputs[i].name == "" ? inputs[i].desc : inputs[i].name,
message: inputs[i].type + " " + inputs[i].desc + ':', message: inputs[i].type + " " + inputs[i].desc + ':',
validate: function (value) { validate: function (value) {
if (Web3.utils.isAddress(value)) { if (isAddress(value)) {
return true; return true;
} }
return '地址输入不正确'; return '地址输入不正确';
}, },
filter: function (value) { filter: function (value) {
return toAddress(val); return isAddress(value) ? value : toAddress(value);
} }
} }
) )
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论