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
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue