fix geth issues
This commit is contained in:
parent
f7856c7db7
commit
efd8e8220d
3 changed files with 64 additions and 9 deletions
|
|
@ -1,10 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
const _ = require('lodash/fp')
|
||||
const Web3 = require('web3')
|
||||
const web3 = new Web3()
|
||||
const hdkey = require('hdkey')
|
||||
const hdkey = require('ethereumjs-wallet/hdkey')
|
||||
const Tx = require('ethereumjs-tx')
|
||||
const pify = require('pify')
|
||||
|
||||
const NAME = 'geth'
|
||||
exports.SUPPORTED_MODULES = ['wallet']
|
||||
|
||||
const paymentPrefixPath = "m/44'/60'/0'/0'"
|
||||
const defaultPrefixPath = "m/44'/60'/1'/0'"
|
||||
|
|
@ -28,6 +32,7 @@ const hex = bigNum => '0x' + bigNum.truncated().toString(16)
|
|||
|
||||
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))
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +52,7 @@ 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)
|
||||
}
|
||||
|
||||
|
|
@ -68,6 +74,7 @@ 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]
|
||||
|
|
@ -84,6 +91,7 @@ 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()
|
||||
|
|
@ -103,19 +111,26 @@ 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())
|
||||
}
|
||||
|
|
@ -128,6 +143,7 @@ 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'}
|
||||
|
|
@ -139,12 +155,12 @@ function paymentHdNode (account) {
|
|||
const masterSeed = account.seed
|
||||
if (!masterSeed) throw new Error('No master seed!')
|
||||
const key = hdkey.fromMasterSeed(masterSeed)
|
||||
return key.derive(paymentPrefixPath)
|
||||
return key.derivePath(paymentPrefixPath)
|
||||
}
|
||||
|
||||
function defaultHdNode (account) {
|
||||
const masterSeed = account.seed
|
||||
if (!masterSeed) throw new Error('No master seed!')
|
||||
const key = hdkey.fromMasterSeed(masterSeed)
|
||||
return key.derive(defaultPrefixPath)
|
||||
return key.derivePath(defaultPrefixPath)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,11 @@
|
|||
"body-parser": "^1.15.1",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"ethereumjs-tx": "^1.3.0",
|
||||
"ethereumjs-wallet": "^0.6.0",
|
||||
"express": "^4.13.4",
|
||||
"express-limiter": "^1.6.0",
|
||||
"express-rate-limit": "^2.6.0",
|
||||
"got": "^6.6.3",
|
||||
"hdkey": "^0.7.1",
|
||||
"helmet": "^3.1.0",
|
||||
"lodash": "^4.17.2",
|
||||
"mem": "^1.1.0",
|
||||
|
|
|
|||
49
yarn.lock
49
yarn.lock
|
|
@ -56,6 +56,10 @@ acorn@^4.0.3:
|
|||
version "4.0.11"
|
||||
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.11.tgz#edcda3bd937e7556410d42ed5860f67399c794c0"
|
||||
|
||||
aes-js@^0.2.3:
|
||||
version "0.2.4"
|
||||
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d"
|
||||
|
||||
after@0.8.2:
|
||||
version "0.8.2"
|
||||
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
|
||||
|
|
@ -894,7 +898,7 @@ bs58check@1.0.4:
|
|||
dependencies:
|
||||
bs58 "^2.0.1"
|
||||
|
||||
bs58check@^1.0.5, bs58check@^1.0.6:
|
||||
bs58check@^1.0.5, bs58check@^1.0.6, bs58check@^1.0.8:
|
||||
version "1.3.4"
|
||||
resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-1.3.4.tgz#c52540073749117714fa042c3047eb8f9151cbf8"
|
||||
dependencies:
|
||||
|
|
@ -1729,7 +1733,7 @@ ethereumjs-tx@^1.3.0:
|
|||
ethereum-common "^0.0.18"
|
||||
ethereumjs-util "^5.0.0"
|
||||
|
||||
ethereumjs-util@^4.3.0, ethereumjs-util@^4.4.1:
|
||||
ethereumjs-util@^4.3.0, ethereumjs-util@^4.4.0, ethereumjs-util@^4.4.1:
|
||||
version "4.5.0"
|
||||
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-4.5.0.tgz#3e9428b317eebda3d7260d854fddda954b1f1bc6"
|
||||
dependencies:
|
||||
|
|
@ -1750,6 +1754,18 @@ ethereumjs-util@^5.0.0:
|
|||
rlp "^2.0.0"
|
||||
secp256k1 "^3.0.1"
|
||||
|
||||
ethereumjs-wallet@^0.6.0:
|
||||
version "0.6.0"
|
||||
resolved "https://registry.yarnpkg.com/ethereumjs-wallet/-/ethereumjs-wallet-0.6.0.tgz#82763b1697ee7a796be7155da9dfb49b2f98cfdb"
|
||||
dependencies:
|
||||
aes-js "^0.2.3"
|
||||
bs58check "^1.0.8"
|
||||
ethereumjs-util "^4.4.0"
|
||||
hdkey "^0.7.0"
|
||||
scrypt.js "^0.2.0"
|
||||
utf8 "^2.1.1"
|
||||
uuid "^2.0.1"
|
||||
|
||||
ethjs-util@^0.1.3:
|
||||
version "0.1.4"
|
||||
resolved "https://registry.yarnpkg.com/ethjs-util/-/ethjs-util-0.1.4.tgz#1c8b6879257444ef4d3f3fbbac2ded12cd997d93"
|
||||
|
|
@ -2253,7 +2269,7 @@ hawk@~3.1.3:
|
|||
hoek "2.x.x"
|
||||
sntp "1.x.x"
|
||||
|
||||
hdkey@^0.7.1:
|
||||
hdkey@^0.7.0:
|
||||
version "0.7.1"
|
||||
resolved "https://registry.yarnpkg.com/hdkey/-/hdkey-0.7.1.tgz#caee4be81aa77921e909b8d228dd0f29acaee632"
|
||||
dependencies:
|
||||
|
|
@ -3149,7 +3165,7 @@ multimatch@^2.1.0:
|
|||
arrify "^1.0.0"
|
||||
minimatch "^3.0.0"
|
||||
|
||||
nan@^2.0.5, nan@^2.2.1, nan@^2.3.0:
|
||||
nan@^2.0.5, nan@^2.0.8, nan@^2.2.1, nan@^2.3.0:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
|
||||
|
||||
|
|
@ -3509,7 +3525,7 @@ path-type@^2.0.0:
|
|||
dependencies:
|
||||
pify "^2.0.0"
|
||||
|
||||
pbkdf2@^3.0.9:
|
||||
pbkdf2@^3.0.3, pbkdf2@^3.0.9:
|
||||
version "3.0.9"
|
||||
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.9.tgz#f2c4b25a600058b3c3773c086c37dbbee1ffe693"
|
||||
dependencies:
|
||||
|
|
@ -4125,6 +4141,25 @@ scmp@0.0.3:
|
|||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/scmp/-/scmp-0.0.3.tgz#3648df2d7294641e7f78673ffc29681d9bad9073"
|
||||
|
||||
scrypt.js@^0.2.0:
|
||||
version "0.2.0"
|
||||
resolved "https://registry.yarnpkg.com/scrypt.js/-/scrypt.js-0.2.0.tgz#af8d1465b71e9990110bedfc593b9479e03a8ada"
|
||||
dependencies:
|
||||
scrypt "^6.0.2"
|
||||
scryptsy "^1.2.1"
|
||||
|
||||
scrypt@^6.0.2:
|
||||
version "6.0.3"
|
||||
resolved "https://registry.yarnpkg.com/scrypt/-/scrypt-6.0.3.tgz#04e014a5682b53fa50c2d5cce167d719c06d870d"
|
||||
dependencies:
|
||||
nan "^2.0.8"
|
||||
|
||||
scryptsy@^1.2.1:
|
||||
version "1.2.1"
|
||||
resolved "https://registry.yarnpkg.com/scryptsy/-/scryptsy-1.2.1.tgz#a3225fa4b2524f802700761e2855bdf3b2d92163"
|
||||
dependencies:
|
||||
pbkdf2 "^3.0.3"
|
||||
|
||||
secp256k1@3.2.5, secp256k1@^3.0.1:
|
||||
version "3.2.5"
|
||||
resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.2.5.tgz#0dde5b27e5021665f6dffca7b2c3e010c6c13c93"
|
||||
|
|
@ -4781,6 +4816,10 @@ utils-merge@1.0.0:
|
|||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.0.tgz#0294fb922bb9375153541c4f7096231f287c8af8"
|
||||
|
||||
uuid@^2.0.1:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a"
|
||||
|
||||
uuid@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue