提交 16d36a89 authored 作者: 崔大师's avatar 崔大师

支持TH地址

上级 e88621e0
......@@ -66,6 +66,7 @@ node multiSign admin
```
node multiSign admin
```
1. 修改最小确认数
> 选择"修改最小确认数",输入"最小确认数",例如:3
......
......@@ -15,11 +15,11 @@ const init = () => {
const hdwallet = HDWallet.fromSeed(seed)
const privateKey = hdwallet.derive('m/44\'/60\'/0\'/0/0').getPrivateKey()
const address = utils.privateToAddress(privateKey)
console.log('Wallet: 0x' + address.toString('hex'))
console.log('Wallet: ' + toIban('0x'+address.toString('hex')))
web3.setProvider(new web3.providers.HttpProvider(rpxUrl));
web3.thk.defaultPrivateKey = privateKey
web3.thk.defaultAddress = '0x' + address.toString('hex').toLowerCase()
web3.thk.defaultChainId = "1"
web3.thk.defaultChainId = "103"
resolve(true)
})
}
......@@ -56,4 +56,13 @@ const setVal = (value) => {
const ether = (amount) => {
return web3.toWei(amount);
}
module.exports = { init, getTxHash, callContract, deployContract, ether, setVal };
\ No newline at end of file
const toIban = (THAddress) => {
return web3.Iban.toIban(THAddress).toString()
}
const isIban = (THAddress) => {
return web3.Iban.isValid(THAddress)
}
const toAddress = (THAddress) => {
return web3.Iban.toAddress(THAddress).toString()
}
module.exports = { init, getTxHash, callContract, deployContract, ether, setVal,toIban,toAddress,isIban };
\ No newline at end of file
{
"mnemonic": "oven bridge digital west better smile salon banana donor decrease tattoo project",
"contractAddress": "0xbb4a82cb62f0ec75c9dbe9857fae98d012efc889"
"contractAddress": "TH238X4LYFCDW2OZ48BQH9CK6DG5EU0HXPI"
}
\ No newline at end of file
#!/usr/bin/env node
const { init, callContract, ether, getTxHash } = require('./ThkContract.js');
const { init, callContract, ether, getTxHash,toIban,toAddress,isIban } = require('./ThkContract.js');
const Web3 = require('web3');
const fs = require('fs');
const inquirer = require('inquirer');
......@@ -23,20 +23,20 @@ module.exports = (contractAbi) => {
name: 'contractAddress',
message: "输入合约地址",
validate: function (value) {
if (Web3.utils.isAddress(value)) {
if (isIban(value)) {
return true;
}
return '地址输入不正确';
},
default: function () {
return config.contractAddress;
}
},
}
])
.then(answers => {
fs.writeFile('./config.json', JSON.stringify(answers, null, "\t"), function (err) {
if (err) { console.log(err) }
open(contractAbi, answers.contractAddress)
open(contractAbi, toAddress(answers.contractAddress));
})
});
}
......@@ -69,7 +69,8 @@ const formatChoice = (contractAbi) => {
value: _choiceList.length,
function: contractAbi[i].name,
type: contractAbi[i].stateMutability,
inputs: typeof contractAbi[i].inputs == 'undefined' ? [] : contractAbi[i].inputs
inputs: typeof contractAbi[i].inputs == 'undefined' ? [] : contractAbi[i].inputs,
outputs: contractAbi[i].outputs
};
_choiceList.push(obj);
}
......@@ -102,11 +103,11 @@ const answer = (answers) => {
}
}
call(answers.function, answers.inputs, answers.type);
call(answers.function, answers.inputs, answers.outputs);
}
const call = (functionName, inputs, type) => {
const call = (functionName, inputs, outputs) => {
if (inputs.length > 0) {
let questions = [];
for (let i = 0; i < inputs.length; i++) {
......@@ -121,6 +122,9 @@ const call = (functionName, inputs, type) => {
return true;
}
return '地址输入不正确';
},
filter: function (value) {
return toAddress(val);
}
}
)
......@@ -156,19 +160,19 @@ const call = (functionName, inputs, type) => {
params.push(answers[inputs[i].name == "" ? inputs[i].desc : inputs[i].name].toLowerCase());
}
let result = contractInstance[functionName](...params);
txResult(result);
txResult(result,outputs);
});
} else {
let result = contractInstance[functionName]();
txResult(result);
txResult(result,outputs);
}
}
const txResult = (result) => {
const txResult = (result,outputs) => {
if (result.TXhash != undefined) {
console.log(JSON.stringify(result).gray);
getTxHash(result.TXhash).then((conresp) => {
if (conresp.status == 1) {
out = conresp.out != '0x' ? '输出结果:' + conresp.out : 'TX Hash:' + result.TXhash
out = conresp.out != '0x' ? '输出结果:' + output(outputs,conresp.out) : 'TX Hash:' + result.TXhash
console.log('调用成功!'.green, out.yellow)
} else {
console.log('调用失败'.red, result.TXhash, conresp)
......@@ -176,7 +180,39 @@ const txResult = (result) => {
choice();
})
} else {
console.log('输出结果:'.green, JSON.stringify(result).yellow);
console.log('输出结果:'.green, output(outputs,result));
choice();
}
}
\ No newline at end of file
}
const output = (outputs,result) => {
var output = [];
if(outputs.length == 1){
output = formatOut(outputs[0].type,result);
}else if(outputs.length > 1){
for(var i=0;i<outputs.length;i++){
output[i] = formatOut(outputs[i].type,result[i]);
}
}
return output;
}
const formatOut = (type,result) =>{
var output = [];
switch (type){
case "uint256":
output = result.toString().substring(0, 2) === '0x' ? parseInt(result,16).toString(10) : result;
break;
case "address":
output = toIban(result);
break;
case "address[]":
var out = [];
for(var j=0;j<result.length;j++){
out[j] = toIban(result[j]);
}
output = out;
break;
default:
output = result;
}
return output;
}
\ No newline at end of file
差异被折叠。
......@@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "multiSign",
"main": "multiSign",
"bin": "multiSign",
"dependencies": {
"bip39": "^3.0.2",
"colors": "^1.4.0",
......@@ -11,10 +12,12 @@
"ethereumjs-util": "^7.0.2",
"inquirer": "^7.2.0",
"solc": "^0.5.0",
"thinkium-web3js": "^1.0.4",
"thinkium-web3js": "^1.0.8",
"web3": "^1.2.9"
},
"devDependencies": {},
"devDependencies": {
"pkg": "^4.4.9"
},
"scripts": {
"test": "test"
},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论