删除分号 ;
This commit is contained in:
parent
8e38dfb330
commit
3d987c09e5
@ -1,9 +1,9 @@
|
||||
'use strict'
|
||||
const Coins = {}
|
||||
Coins.TIC = require('./tic.js').TIC;
|
||||
Coins.ETH = require('./eth.js').ETH;
|
||||
Coins.ERC20 = require('./eth.js').ERC20;
|
||||
Coins.BTC = require('./btc.js').BTC;
|
||||
Coins.TIC = require('./tic.js').TIC
|
||||
Coins.ETH = require('./eth.js').ETH
|
||||
Coins.ERC20 = require('./eth.js').ERC20
|
||||
Coins.BTC = require('./btc.js').BTC
|
||||
|
||||
class Account {
|
||||
constructor(coinType,privateKey,contractAddress){
|
||||
|
68
btc.js
68
btc.js
@ -1,12 +1,12 @@
|
||||
'use strict'
|
||||
|
||||
const axios = require('axios');
|
||||
const HDNode = require('./utils/hdnode');
|
||||
const bitcoinjs = require('bitcoinjs-lib');
|
||||
const Ticrypto = require('tic.crypto');
|
||||
const BTC_NODE = require('./netConfig').BTC_NODE;
|
||||
const BTC_NODE2 = require('./netConfig').BTC_NODE2;
|
||||
const BTC_TXFEE = 30;
|
||||
const axios = require('axios')
|
||||
const HDNode = require('./utils/hdnode')
|
||||
const bitcoinjs = require('bitcoinjs-lib')
|
||||
const Ticrypto = require('tic.crypto')
|
||||
const BTC_NODE = require('./netConfig').BTC_NODE
|
||||
const BTC_NODE2 = require('./netConfig').BTC_NODE2
|
||||
const BTC_TXFEE = 30
|
||||
|
||||
class BTC {
|
||||
constructor(privateKey){
|
||||
@ -30,23 +30,23 @@ class BTC {
|
||||
},
|
||||
"url" : {
|
||||
enumerable : true,
|
||||
get: function() { return this._url; },
|
||||
get: function() { return this._url },
|
||||
set: function(url) {
|
||||
if (typeof(url) !== 'string') { throw new Error('invalid url'); }
|
||||
this._url = url;
|
||||
if (typeof(url) !== 'string') { throw new Error('invalid url') }
|
||||
this._url = url
|
||||
}
|
||||
},
|
||||
"defaultGas":{
|
||||
enumerable: true,
|
||||
get: function() { return this._defaultGasFee; },
|
||||
get: function() { return this._defaultGasFee },
|
||||
set: function(value) {
|
||||
if (typeof(value) !== 'number') { throw new Error('invalid defaultGasFee'); }
|
||||
this._defaultGasFee = value;
|
||||
if (typeof(value) !== 'number') { throw new Error('invalid defaultGasFee') }
|
||||
this._defaultGasFee = value
|
||||
}
|
||||
}
|
||||
})
|
||||
this._url = BTC_NODE;
|
||||
this._defaultGasFee = BTC_TXFEE;
|
||||
this._url = BTC_NODE
|
||||
this._defaultGasFee = BTC_TXFEE
|
||||
|
||||
}
|
||||
static generateNewAccount(){
|
||||
@ -82,22 +82,22 @@ class BTC {
|
||||
return address.length == 34 && address[0] == '1'
|
||||
}
|
||||
async sendTransaction(toAddress, amount, option = {gasFee : BTC_TXFEE}){
|
||||
let set = bitcoinjs.ECPair.fromPrivateKey(Buffer.from(this.privateKey,'hex'));//导入私钥用于签名
|
||||
let txb = new bitcoinjs.TransactionBuilder();//初始化交易对象
|
||||
let set = bitcoinjs.ECPair.fromPrivateKey(Buffer.from(this.privateKey,'hex'))//导入私钥用于签名
|
||||
let txb = new bitcoinjs.TransactionBuilder()//初始化交易对象
|
||||
let tx = await BTC.getUTXO('1DEP8i3QJCsomS4BSMY2RpU1upv62aGvhD')
|
||||
if(!tx) return null
|
||||
var tot = 0;//用于记录UTXO总量
|
||||
amount+=1e4;//消费金额是转出金额加上10000的矿工费
|
||||
txb.setVersion(1);//设置交易版本号
|
||||
var tot = 0//用于记录UTXO总量
|
||||
amount+=1e4//消费金额是转出金额加上10000的矿工费
|
||||
txb.setVersion(1)//设置交易版本号
|
||||
for(var i=0;i<tx.length;i++){ //将UTXO的相关信息依次填入交易体中
|
||||
txb.addInput(tx[i].tx_hash_big_endian, tx[i].tx_output_n);
|
||||
tot+=tx[i].value;
|
||||
txb.addInput(tx[i].tx_hash_big_endian, tx[i].tx_output_n)
|
||||
tot+=tx[i].value
|
||||
}
|
||||
|
||||
txb.addOutput(toAddress, amount-1e4);//填入转出目标地址和对应的金额
|
||||
txb.addOutput(this.address, tot-amount); //填入找零地址,也就是原地址,并填入把找零金额
|
||||
txb.addOutput(toAddress, amount-1e4)//填入转出目标地址和对应的金额
|
||||
txb.addOutput(this.address, tot-amount) //填入找零地址,也就是原地址,并填入把找零金额
|
||||
for(var i=0;i<tx.length;i++){//对交易体中的UTXO依次签名
|
||||
txb.sign(i, set);
|
||||
txb.sign(i, set)
|
||||
}
|
||||
// let txBody = txb.buildIncomplete().toHex()
|
||||
let data = {tx : txb.buildIncomplete().toHex()}
|
||||
@ -111,21 +111,21 @@ class BTC {
|
||||
}
|
||||
// async sendTransaction(toAddress, amount, option = {gasFee : BTC_TXFEE}){
|
||||
// var privateKey = bitcore.PrivateKey(this.privateKey)
|
||||
// var ecdsa = new bitcore.crypto.ECDSA();
|
||||
// var ecdsa = new bitcore.crypto.ECDSA()
|
||||
|
||||
// var newtx = {
|
||||
// inputs: [{addresses: [this.address]}],
|
||||
// outputs: [{addresses: [toAddress], value: amount}]
|
||||
// };
|
||||
// }
|
||||
// try {
|
||||
// var tmptx = (await axios.post('https://api.blockcypher.com/v1/btc/test3/txs/new',newtx)).data;
|
||||
// tmptx.pubkeys = [];
|
||||
// var tmptx = (await axios.post('https://api.blockcypher.com/v1/btc/test3/txs/new',newtx)).data
|
||||
// tmptx.pubkeys = []
|
||||
// tmptx.pubkeys.push(privateKey.toPublicKey().toString("hex"))
|
||||
// ecdsa.hashbuf = bitcore.crypto.Hash.sha256(new Buffer(tmptx.tosign));
|
||||
// ecdsa.privkey = privateKey;
|
||||
// ecdsa.pubkey = privateKey.toPublicKey();
|
||||
// ecdsa.deterministicK();
|
||||
// let signatureExpected = ecdsa.sign();
|
||||
// ecdsa.hashbuf = bitcore.crypto.Hash.sha256(new Buffer(tmptx.tosign))
|
||||
// ecdsa.privkey = privateKey
|
||||
// ecdsa.pubkey = privateKey.toPublicKey()
|
||||
// ecdsa.deterministicK()
|
||||
// let signatureExpected = ecdsa.sign()
|
||||
// tmptx.signatures = [Buffer.from(signatureExpected.sig.toDER()).toString('hex')]
|
||||
// let res = (await axios.post('https://api.blockcypher.com/v1/btc/test3/txs/send',tmptx)).data
|
||||
// return res
|
||||
|
12
netConfig.js
12
netConfig.js
@ -1,10 +1,10 @@
|
||||
|
||||
const TIC_NODE = 'https://bank.bittic.net:60000/api';
|
||||
const BTC_NODE = 'https://api.blockcypher.com/v1/btc/main';
|
||||
const BTC_NODE2 = 'https://blockchain.info'//https://blockchain.info/unspent?active=12HnmPpLomtPL53Q4s6xEqRB4wkMHi5GEZ
|
||||
const ETH_NODE = 'https://mainnet.infura.io/8284219b092f4cc69f3de29e532b1eb2';
|
||||
const ETH_NODE2 = 'https://api.myetherapi.com/eth';
|
||||
const ETH_TEST_NODE = 'https://ropsten.infura.io/8284219b092f4cc69f3de29e532b1eb2';
|
||||
const TIC_NODE = 'https://bank.bittic.net:60000/api'
|
||||
const BTC_NODE = 'https://api.blockcypher.com/v1/btc/main'
|
||||
const BTC_NODE2 = 'https://blockchain.info' //https://blockchain.info/unspent?active=12HnmPpLomtPL53Q4s6xEqRB4wkMHi5GEZ
|
||||
const ETH_NODE = 'https://mainnet.infura.io/8284219b092f4cc69f3de29e532b1eb2'
|
||||
const ETH_NODE2 = 'https://api.myetherapi.com/eth'
|
||||
const ETH_TEST_NODE = 'https://ropsten.infura.io/8284219b092f4cc69f3de29e532b1eb2'
|
||||
|
||||
module.exports = {
|
||||
TIC_NODE,
|
||||
|
Loading…
Reference in New Issue
Block a user