Log miner fee (#237)
* Get miner fee written in some wallet plugins * Return txid and fee for geth. possible problem with txid (zero hash on pending transaction) * bitgo fee return * Wallet apis fees save in cryptoAtoms
This commit is contained in:
parent
fa69956963
commit
163473a7ee
9 changed files with 64 additions and 4 deletions
|
|
@ -57,8 +57,9 @@ function postProcess (r, pi) {
|
||||||
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
|
||||||
|
|
||||||
return pi.sendCoins(r.tx)
|
return pi.sendCoins(r.tx)
|
||||||
.then(txHash => ({
|
.then(txObj => ({
|
||||||
txHash,
|
txHash: txObj.txid,
|
||||||
|
fee: txObj.fee,
|
||||||
sendConfirmed: true,
|
sendConfirmed: true,
|
||||||
sendTime: 'now()^',
|
sendTime: 'now()^',
|
||||||
sendPending: false,
|
sendPending: false,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const BN = require('../../../bn')
|
const BN = require('../../../bn')
|
||||||
|
|
@ -41,6 +42,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||||
|
.then((txId) => fetch('gettransaction', txId))
|
||||||
|
.then((res) => _.pick(res, ['fee', 'txid']))
|
||||||
|
.then((pickedObj) => {
|
||||||
|
return {
|
||||||
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
txid: pickedObj.txid
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const BN = require('../../../bn')
|
const BN = require('../../../bn')
|
||||||
|
|
@ -41,6 +42,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||||
|
.then((txId) => fetch('gettransaction', txId))
|
||||||
|
.then((res) => _.pick(res, ['fee', 'txid']))
|
||||||
|
.then((pickedObj) => {
|
||||||
|
return {
|
||||||
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
txid: pickedObj.txid
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,10 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
return wallet.send(params)
|
return wallet.send(params)
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result.hash
|
let fee = parseFloat(result.transfer.feeString)
|
||||||
|
let txid = result.transfer.txid
|
||||||
|
|
||||||
|
return { txid: txid, fee: BN(fee).round() }
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const coinUtils = require('../../../coin-utils')
|
const coinUtils = require('../../../coin-utils')
|
||||||
|
|
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||||
|
.then((txId) => fetch('gettransaction', txId))
|
||||||
|
.then((res) => _.pick(res, ['fee', 'txid']))
|
||||||
|
.then((pickedObj) => {
|
||||||
|
return {
|
||||||
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
txid: pickedObj.txid
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ const hdkey = require('ethereumjs-wallet/hdkey')
|
||||||
const Tx = require('ethereumjs-tx')
|
const Tx = require('ethereumjs-tx')
|
||||||
const util = require('ethereumjs-util')
|
const util = require('ethereumjs-util')
|
||||||
const pify = require('pify')
|
const pify = require('pify')
|
||||||
|
const BN = require('../../../bn')
|
||||||
|
|
||||||
const NAME = 'geth'
|
const NAME = 'geth'
|
||||||
exports.SUPPORTED_MODULES = ['wallet']
|
exports.SUPPORTED_MODULES = ['wallet']
|
||||||
|
|
@ -47,6 +48,16 @@ function isStrictAddress (cryptoCode, toAddress) {
|
||||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
|
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
|
||||||
.then(pify(web3.eth.sendRawTransaction))
|
.then(pify(web3.eth.sendRawTransaction))
|
||||||
|
.then(r => {
|
||||||
|
return pify(web3.eth.getTransactionByHash)(r.result)
|
||||||
|
.then(tx => {
|
||||||
|
if (!tx) return { txid: r.result }
|
||||||
|
|
||||||
|
const fee = BN(tx.gas).multipliedBy(BN(tx.gasPrice)).round()
|
||||||
|
|
||||||
|
return { txid: r.result, fee }
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkCryptoCode (cryptoCode) {
|
function checkCryptoCode (cryptoCode) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const coinUtils = require('../../../coin-utils')
|
const coinUtils = require('../../../coin-utils')
|
||||||
|
|
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||||
|
.then((txId) => fetch('gettransaction', txId))
|
||||||
|
.then((res) => _.pick(res, ['fee', 'txid']))
|
||||||
|
.then((pickedObj) => {
|
||||||
|
return {
|
||||||
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
txid: pickedObj.txid
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms to %s',
|
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms to %s',
|
||||||
cryptoCode, cryptoAtoms.toString(), toAddress)
|
cryptoCode, cryptoAtoms.toString(), toAddress)
|
||||||
return resolve('<txHash>')
|
return resolve({ txid: '<txHash>', fee: BN(0) })
|
||||||
}, 2000)
|
}, 2000)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
const _ = require('lodash/fp')
|
||||||
const jsonRpc = require('../../common/json-rpc')
|
const jsonRpc = require('../../common/json-rpc')
|
||||||
|
|
||||||
const coinUtils = require('../../../coin-utils')
|
const coinUtils = require('../../../coin-utils')
|
||||||
|
|
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
|
||||||
|
|
||||||
return checkCryptoCode(cryptoCode)
|
return checkCryptoCode(cryptoCode)
|
||||||
.then(() => fetch('sendtoaddress', [address, coins]))
|
.then(() => fetch('sendtoaddress', [address, coins]))
|
||||||
|
.then((txId) => fetch('gettransaction', txId))
|
||||||
|
.then((res) => _.pick(res, ['fee', 'txid']))
|
||||||
|
.then((pickedObj) => {
|
||||||
|
return {
|
||||||
|
fee: BN(pickedObj.fee).abs().shift(unitScale).round(),
|
||||||
|
txid: pickedObj.txid
|
||||||
|
}
|
||||||
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.code === -6) throw new E.InsufficientFundsError()
|
if (err.code === -6) throw new E.InsufficientFundsError()
|
||||||
throw err
|
throw err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue