提交 11151b84 authored 作者: 崔大师's avatar 崔大师

Initial commit

上级
node_modules
.secret
\ No newline at end of file
[
{
"desc": "查询委员会成员地址数组",
"constant": true,
"inputs": [],
"name": "getCommitees",
"outputs": [
{
"name": "",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "添加委员会成员",
"constant": false,
"inputs": [
{
"desc": "成员地址",
"name": "commitee",
"type": "address"
}
],
"name": "addCommitee",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "根据交易ID查询委员是否确认",
"constant": true,
"inputs": [
{
"name": "",
"type": "uint256",
"desc": "交易ID"
},
{
"name": "",
"type": "address",
"desc": "委员地址"
}
],
"name": "confirmations",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "根据交易ID查询交易数据",
"constant": true,
"inputs": [
{
"desc": "交易ID",
"name": "",
"type": "uint256"
}
],
"name": "transactions",
"outputs": [
{
"name": "destination",
"type": "address"
},
{
"name": "value",
"type": "uint256"
},
{
"name": "executed",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "提交并确认交易",
"constant": false,
"inputs": [
{
"desc": "转帐目的地址",
"name": "destination",
"type": "address"
},
{
"desc": "转帐数额",
"name": "value",
"type": "uint256"
}
],
"name": "submitTransaction",
"outputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "确认交易",
"constant": false,
"inputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"name": "confirmTransaction",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "撤销确认交易",
"constant": false,
"inputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"name": "revokeConfirmation",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "查询交易ID是否已确认",
"constant": true,
"inputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"name": "isConfirmed",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询交易ID的确认数量",
"constant": true,
"inputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"name": "getConfirmationCount",
"outputs": [
{
"name": "count",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "根据交易ID查询已确认的成员地址",
"constant": true,
"inputs": [
{
"desc": "交易ID",
"name": "transactionId",
"type": "uint256"
}
],
"name": "getConfirmations",
"outputs": [
{
"name": "_confirmations",
"type": "address[]"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询最小确认数",
"constant": true,
"inputs": [],
"name": "required",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询TOKEN地址",
"constant": true,
"inputs": [],
"name": "token",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询合约账户余额",
"constant": true,
"inputs": [],
"name": "getTotalBalance",
"outputs": [
{
"name": "tokensCurrentlyInVault",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
\ No newline at end of file
[
{
"constant": true,
"inputs": [
{
"desc": "账户地址",
"name": "account",
"type": "address"
}
],
"name": "isPauser",
"desc": "查询是否拥有暂停权",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "给账户添加暂停权",
"constant": false,
"inputs": [
{
"desc": "账户地址",
"name": "account",
"type": "address"
}
],
"name": "addPauser",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "撤销当前账户的暂停权",
"constant": false,
"inputs": [],
"name": "renouncePauser",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "暂停合约",
"constant": false,
"inputs": [],
"name": "pause",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "unpause",
"desc": "取消合约暂停状态",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"desc": "查询是否已暂停",
"name": "paused",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"desc": "根据索引查询委员会成员地址",
"inputs": [
{
"desc": "成员索引",
"name": "",
"type": "uint256"
}
],
"name": "commitees",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询账户是否属于委员会成员",
"constant": true,
"inputs": [
{
"desc": "账户地址",
"name": "",
"type": "address"
}
],
"name": "isCommitee",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "移除委员会成员",
"constant": false,
"inputs": [
{
"desc": "成员地址",
"name": "commitee",
"type": "address"
}
],
"name": "removeCommitee",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "修改最小确认数",
"constant": false,
"inputs": [
{
"desc": "最小确认数",
"name": "_required",
"type": "uint256"
}
],
"name": "changeRequirement",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "查询最小确认数",
"constant": true,
"inputs": [],
"name": "required",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询交易数量",
"constant": true,
"inputs": [],
"name": "transactionCount",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询TOKEN地址",
"constant": true,
"inputs": [],
"name": "token",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询合约账户余额",
"constant": true,
"inputs": [],
"name": "getTotalBalance",
"outputs": [
{
"name": "tokensCurrentlyInVault",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "转移合约所有权",
"constant": false,
"inputs": [
{
"desc": "新所有权账户地址",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"desc": "查询合约拥有者地址",
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"desc": "查询账户是否属于账户拥有者",
"constant": true,
"inputs": [],
"name": "isOwner",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
\ No newline at end of file
const utils = require('ethereumjs-util');
const bip39 = require('bip39');
const HDWallet = require('ethereum-hdwallet')
const Web3 = require('web3.js-thk');
const fs = require('fs');
const web3 = new Web3();
const rpxUrl = "http://rpctest.chainopen.cn"
const init = () => {
return new Promise(async (resolve, reject) => {
const {mnemonic} = require("./config.json");
const seed = await bip39.mnemonicToSeed(mnemonic.trim())
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'))
web3.setProvider(new web3.providers.HttpProvider(rpxUrl));
web3.thk.defaultPrivateKey = privateKey
web3.thk.defaultAddress = '0x' + address.toString('hex').toLowerCase()
web3.thk.defaultChainId = "1"
resolve(true)
})
}
const getTxHash = (transactionHash) => {
return new Promise(async (resolve, reject) => {
var i=0;
do {
var conresp = web3.thk.GetTransactionByHash(web3.thk.defaultChainId, transactionHash);
i++;
} while (conresp.errCode == 4003 && i<20)
resolve(conresp)
})
}
const callContract = (abi, contractAddress) => {
return new Promise(async (resolve, reject) => {
const contractObj = web3.thk.contract(abi, contractAddress).at(contractAddress);
resolve(contractObj);
})
}
const deployContract = (contract, param) => {
return new Promise(async (resolve, reject) => {
deploy(contract, param).then((contracts) => {
console.log('transactionHash: ', contracts.transactionHash)
getTxHash(contracts.transactionHash).then((Address) => {
console.log('contract Address: ', Address)
callContract(contracts.abi, Address).then((Instance) => {
resolve(Instance);
})
})
})
})
}
const setVal = (value) => {
web3.thk.setVal(ether(value));
}
const ether = (amount) => {
return web3.toWei(amount);
}
module.exports = { init, getTxHash, callContract, deployContract, ether, setVal };
\ No newline at end of file
#!/usr/bin/env node
const Web3 = require('web3.js-thk');
const bip39 = require('bip39');
const HDWallet = require('ethereum-hdwallet')
const utils = require('ethereumjs-util');
const fs = require('fs');
const web3 = new Web3();
const rpxUrl = "http://rpctest.chainopen.cn"
web3.setProvider(new web3.providers.HttpProvider(rpxUrl));
const mnemonic = fs.readFileSync(".secret").toString().trim();
const getPrivateKey = async (mnemonic,n) => {
const seed = await bip39.mnemonicToSeed(mnemonic.trim())
const hdwallet = HDWallet.fromSeed(seed)
const privateKey = hdwallet.derive('m/44\'/60\'/0\'/0/'+n).getPrivateKey();
const address = utils.privateToAddress((privateKey))
var account = web3.thk.GetAccount('1', '0x'+address.toString('hex'));
var balance = account.balance;
console.log("0x"+privateKey.toString('hex'),":","0x"+address.toString('hex'),"("+web3.fromWei(balance,'ether')+" ether)")
}
for(var i=0;i<10;i++){
getPrivateKey(mnemonic,i);
}
{
"mnemonic": "alley absorb wait alpha teach path pizza people home cloud announce kiwi",
"contractAddress": "0xd66ee8b1a4fb4d8855b5d7bc798a29e10049a5a2"
}
\ No newline at end of file
#!/usr/bin/env node
const multiSign = require('./multiSign.inc.js');
const contractAbi = require('./TUEMultiSign.json');
const contractAdminAbi = require('./TUEMultiSignAdmin.json');
var arguments = process.argv.splice(2);
if(arguments[0] == 'admin'){
multiSign(contractAdminAbi);
}else{
multiSign(contractAbi);
}
\ No newline at end of file
#!/usr/bin/env node
const { init, callContract, ether, getTxHash } = require('./ThkContract.js');
const Web3 = require('web3');
const fs = require('fs');
const inquirer = require('inquirer');
const colors = require('colors');
const config = JSON.parse(fs.readFileSync("./config.json"));
let contractInstance;
let choiceList = [];
module.exports = (contractAbi) => {
inquirer.prompt([
{
type: 'input',
name: 'mnemonic',
message: "输入助记词",
default: function () {
return config.mnemonic;
}
}, {
type: 'input',
name: 'contractAddress',
message: "输入合约地址",
validate: function (value) {
if (Web3.utils.isAddress(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)
})
});
}
const open = (contractAbi, contractAddress) => {
init().then(async () => {
contractInstance = await callContract(contractAbi, contractAddress);
choiceList = formatChoice(contractAbi);
choice();
})
}
const formatChoice = (contractAbi) => {
let _choiceList = [];
for (let i = 0; i < contractAbi.length; i++) {
if (contractAbi[i].type == 'function') {
let params = '';
if (typeof contractAbi[i].inputs != 'undefined') {
if (contractAbi[i].inputs.length > 0) {
for (let j = 0; j < contractAbi[i].inputs.length; j++) {
if (j > 0) params = params + ', ';
params = params + contractAbi[i].inputs[j].type + ' ' + contractAbi[i].inputs[j].name;
}
}
}
let name = contractAbi[i].desc;
let obj = {
name: name,
value: _choiceList.length,
function: contractAbi[i].name,
type: contractAbi[i].stateMutability,
inputs: typeof contractAbi[i].inputs == 'undefined' ? [] : contractAbi[i].inputs
};
_choiceList.push(obj);
}
}
return _choiceList;
}
const choice = () => {
console.log("");
inquirer.prompt([
{
type: 'list',
name: 'function',
message: "选择方法:",
choices: choiceList
}
])
.then(answers => {
answer(choiceList[answers.function])
});
}
const answer = (answers) => {
console.log("");
let params = '';
if (answers.inputs.length > 0) {
for (let j = 0; j < answers.inputs.length; j++) {
if (j > 0) params = params + ', ';
params = params + answers.inputs[j].type + ' ' + answers.inputs[j].name;
}
}
call(answers.function, answers.inputs, answers.type);
}
const call = (functionName, inputs, type) => {
if (inputs.length > 0) {
let questions = [];
for (let i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'address') {
questions.push(
{
type: 'input',
name: inputs[i].name == "" ? inputs[i].desc : inputs[i].name,
message: inputs[i].type + " " + inputs[i].desc + ':',
validate: function (value) {
if (Web3.utils.isAddress(value)) {
return true;
}
return '地址输入不正确';
}
}
)
} else if (inputs[i].type == 'uint256') {
questions.push(
{
type: 'input',
name: inputs[i].name == "" ? inputs[i].desc : inputs[i].name,
message: inputs[i].type + " " + inputs[i].desc + ':',
validate: function (value) {
var re = /^[0-9]*$/;
if (re.test(value)) {
return true;
}
return '数额输入不正确';
}
}
);
} else {
questions.push(
{
type: 'input',
name: inputs[i].name == "" ? inputs[i].desc : inputs[i].name,
message: inputs[i].type + " " + inputs[i].desc + ':',
}
);
}
}
inquirer.prompt(questions)
.then(answers => {
let params = [];
for (let i = 0; i < inputs.length; i++) {
params.push(answers[inputs[i].name == "" ? inputs[i].desc : inputs[i].name].toLowerCase());
}
let result = contractInstance[functionName](...params);
txResult(result);
});
} else {
let result = contractInstance[functionName]();
txResult(result);
}
}
const txResult = (result) => {
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
console.log('调用成功!'.green, out.yellow)
} else {
console.log('调用失败'.red, result.TXhash, conresp)
}
choice();
})
} else {
console.log('输出结果:'.green, JSON.stringify(result).yellow);
choice();
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论