support sending funds to external wallet

This commit is contained in:
Josh Harvey 2018-05-17 09:35:22 +03:00
parent dd04b9bb91
commit be53de7326
5 changed files with 2446 additions and 1718 deletions

View file

@ -4,6 +4,7 @@ const Web3 = require('web3')
const web3 = new Web3()
const hdkey = require('ethereumjs-wallet/hdkey')
const Tx = require('ethereumjs-tx')
const util = require('ethereumjs-util')
const pify = require('pify')
const coinUtils = require('../../../coin-utils')
@ -27,7 +28,8 @@ module.exports = {
defaultAddress,
supportsHd: true,
newFunding,
privateKey
privateKey,
isStrictAddress
}
if (!web3.isConnected()) {
@ -40,6 +42,10 @@ function privateKey (account) {
return defaultWallet(account).getPrivateKey()
}
function isStrictAddress (cryptoCode, toAddress) {
return cryptoCode === 'ETH' && util.isValidChecksumAddress(toAddress)
}
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
.then(pify(web3.eth.sendRawTransaction))

View file

@ -8,7 +8,6 @@ const fs = pify(require('fs'))
const options = require('./options')
const ph = require('./plugin-helper')
const logger = require('./logger')
const FETCH_INTERVAL = 5000
const INSUFFICIENT_FUNDS_CODE = 570
@ -153,6 +152,16 @@ function cryptoNetwork (settings, cryptoCode) {
return wallet.cryptoNetwork(account, cryptoCode)
}
function isStrictAddress (settings, cryptoCode, toAddress) {
// Note: For now, only for wallets that specifically check for this.
return fetchWallet(settings, cryptoCode)
.then(r => {
if (!r.wallet.isStrictAddress) return true
return r.wallet.isStrictAddress(cryptoCode, toAddress)
})
}
const balance = mem(_balance, {
maxAge: FETCH_INTERVAL,
cacheKey: (settings, cryptoCode) => cryptoCode
@ -163,6 +172,7 @@ module.exports = {
sendCoins,
newAddress,
getStatus,
isStrictAddress,
sweep,
isHd,
newFunding,