coinUtils fixes
This commit is contained in:
parent
b7aa655587
commit
5a26f718c5
9 changed files with 63 additions and 71 deletions
|
|
@ -1,18 +1,22 @@
|
|||
'use strict'
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3()
|
||||
const hdkey = require('ethereumjs-wallet/hdkey')
|
||||
const Tx = require('ethereumjs-tx')
|
||||
const pify = require('pify')
|
||||
|
||||
const coinUtils = require('../../../coin-utils')
|
||||
|
||||
const NAME = 'geth'
|
||||
exports.SUPPORTED_MODULES = ['wallet']
|
||||
|
||||
const paymentPrefixPath = "m/44'/60'/0'/0'"
|
||||
const defaultPrefixPath = "m/44'/60'/1'/0'"
|
||||
|
||||
const cryptoRec = coinUtils.getCryptoCurrency('ETH')
|
||||
const defaultPort = cryptoRec.defaultPort
|
||||
|
||||
module.exports = {
|
||||
NAME,
|
||||
balance,
|
||||
|
|
@ -27,7 +31,7 @@ module.exports = {
|
|||
}
|
||||
|
||||
if (!web3.isConnected()) {
|
||||
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
|
||||
web3.setProvider(new web3.providers.HttpProvider(`http://localhost:${defaultPort}`))
|
||||
}
|
||||
|
||||
const hex = bigNum => '0x' + bigNum.truncated().toString(16)
|
||||
|
|
@ -38,7 +42,6 @@ function privateKey (account) {
|
|||
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
|
||||
.then(_.tap(r => console.log('DEBUG113: %s', r)))
|
||||
.then(pify(web3.eth.sendRawTransaction))
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +61,6 @@ const confirmedBalance = address => _balance(false, address)
|
|||
function _balance (includePending, address) {
|
||||
const block = includePending ? 'pending' : undefined
|
||||
|
||||
console.log('DEBUG140: %s', address)
|
||||
return pify(web3.eth.getBalance)(address.toLowerCase(), block)
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +82,6 @@ function generateTx (_toAddress, wallet, amount, includesFee) {
|
|||
|
||||
return Promise.all(promises)
|
||||
.then(arr => {
|
||||
console.log('DEBUG111')
|
||||
const gas = arr[0]
|
||||
const gasPrice = arr[1]
|
||||
const txCount = arr[2]
|
||||
|
|
@ -97,7 +98,6 @@ function generateTx (_toAddress, wallet, amount, includesFee) {
|
|||
from: fromAddress,
|
||||
value: hex(toSend)
|
||||
}
|
||||
console.log('DEBUG112: %j', rawTx)
|
||||
|
||||
const tx = new Tx(rawTx)
|
||||
const privateKey = wallet.getPrivateKey()
|
||||
|
|
@ -117,26 +117,19 @@ function defaultAddress (account) {
|
|||
}
|
||||
|
||||
function sweep (account, cryptoCode, hdIndex) {
|
||||
console.log('DEBUG115: %d', hdIndex)
|
||||
const wallet = paymentHdNode(account).deriveChild(hdIndex).getWallet()
|
||||
const fromAddress = wallet.getChecksumAddressString()
|
||||
|
||||
console.log('DEBUG115.1: %s', fromAddress)
|
||||
|
||||
return confirmedBalance(fromAddress)
|
||||
.then(r => {
|
||||
console.log('DEBUG116.0: %j', r)
|
||||
if (r.eq(0)) return
|
||||
|
||||
console.log('DEBUG116')
|
||||
|
||||
return generateTx(defaultAddress(account), wallet, r, true)
|
||||
.then(signedTx => pify(web3.eth.sendRawTransaction)(signedTx))
|
||||
})
|
||||
}
|
||||
|
||||
function newAddress (account, info) {
|
||||
console.log('DEBUG120: %d', info.hdIndex)
|
||||
const childNode = paymentHdNode(account).deriveChild(info.hdIndex)
|
||||
return Promise.resolve(childNode.getWallet().getChecksumAddressString())
|
||||
}
|
||||
|
|
@ -149,7 +142,6 @@ function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
|||
|
||||
return pendingBalance(toAddress)
|
||||
.then(pending => {
|
||||
console.log('DEBUG114: %s', pending.toString())
|
||||
if (pending.gte(cryptoAtoms)) return {status: 'published'}
|
||||
if (pending.gt(0)) return {status: 'insufficientFunds'}
|
||||
return {status: 'notSeen'}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue