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:
Davit Abulashvili 2019-01-04 20:34:50 +04:00 committed by Josh Harvey
parent fa69956963
commit 163473a7ee
9 changed files with 64 additions and 4 deletions

View file

@ -57,8 +57,9 @@ function postProcess (r, pi) {
if (!cashInLow.isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
return pi.sendCoins(r.tx)
.then(txHash => ({
txHash,
.then(txObj => ({
txHash: txObj.txid,
fee: txObj.fee,
sendConfirmed: true,
sendTime: 'now()^',
sendPending: false,

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const BN = require('../../../bn')
@ -41,6 +42,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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 => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const BN = require('../../../bn')
@ -41,6 +42,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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 => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err

View file

@ -57,7 +57,10 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return wallet.send(params)
})
.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 => {
if (err.message === 'insufficient funds') throw new E.InsufficientFundsError()

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const coinUtils = require('../../../coin-utils')
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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 => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err

View file

@ -6,6 +6,7 @@ const hdkey = require('ethereumjs-wallet/hdkey')
const Tx = require('ethereumjs-tx')
const util = require('ethereumjs-util')
const pify = require('pify')
const BN = require('../../../bn')
const NAME = 'geth'
exports.SUPPORTED_MODULES = ['wallet']
@ -47,6 +48,16 @@ function isStrictAddress (cryptoCode, toAddress) {
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
.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) {

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const coinUtils = require('../../../coin-utils')
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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 => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err

View file

@ -51,7 +51,7 @@ function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
console.log('[%s] DEBUG: Mock wallet sending %s cryptoAtoms to %s',
cryptoCode, cryptoAtoms.toString(), toAddress)
return resolve('<txHash>')
return resolve({ txid: '<txHash>', fee: BN(0) })
}, 2000)
})
}

View file

@ -1,3 +1,4 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const coinUtils = require('../../../coin-utils')
@ -42,6 +43,14 @@ function sendCoins (account, address, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.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 => {
if (err.code === -6) throw new E.InsufficientFundsError()
throw err