format for latest standard

This commit is contained in:
Josh Harvey 2018-03-10 18:59:40 +00:00
parent 4108efd9c7
commit c2af183911
77 changed files with 1697 additions and 1693 deletions

View file

@ -42,7 +42,7 @@ function privateKey (account) {
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
.then(pify(web3.eth.sendRawTransaction))
.then(pify(web3.eth.sendRawTransaction))
}
function checkCryptoCode (cryptoCode) {
@ -52,7 +52,7 @@ function checkCryptoCode (cryptoCode) {
function balance (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => pendingBalance(defaultAddress(account)))
.then(() => pendingBalance(defaultAddress(account)))
}
const pendingBalance = address => _balance(true, address)
@ -81,31 +81,31 @@ function generateTx (_toAddress, wallet, amount, includesFee) {
]
return Promise.all(promises)
.then(arr => {
const gas = arr[0]
const gasPrice = arr[1]
const txCount = arr[2]
.then(arr => {
const gas = arr[0]
const gasPrice = arr[1]
const txCount = arr[2]
const toSend = includesFee
? amount.minus(gasPrice.times(gas))
: amount
const toSend = includesFee
? amount.minus(gasPrice.times(gas))
: amount
const rawTx = {
nonce: txCount,
gasPrice: hex(gasPrice),
gasLimit: gas,
to: toAddress,
from: fromAddress,
value: hex(toSend)
}
const rawTx = {
nonce: txCount,
gasPrice: hex(gasPrice),
gasLimit: gas,
to: toAddress,
from: fromAddress,
value: hex(toSend)
}
const tx = new Tx(rawTx)
const privateKey = wallet.getPrivateKey()
const tx = new Tx(rawTx)
const privateKey = wallet.getPrivateKey()
tx.sign(privateKey)
tx.sign(privateKey)
return '0x' + tx.serialize().toString('hex')
})
return '0x' + tx.serialize().toString('hex')
})
}
function defaultWallet (account) {
@ -121,12 +121,12 @@ function sweep (account, cryptoCode, hdIndex) {
const fromAddress = wallet.getChecksumAddressString()
return confirmedBalance(fromAddress)
.then(r => {
if (r.eq(0)) return
.then(r => {
if (r.eq(0)) return
return generateTx(defaultAddress(account), wallet, r, true)
.then(signedTx => pify(web3.eth.sendRawTransaction)(signedTx))
})
return generateTx(defaultAddress(account), wallet, r, true)
.then(signedTx => pify(web3.eth.sendRawTransaction)(signedTx))
})
}
function newAddress (account, info) {
@ -136,17 +136,17 @@ function newAddress (account, info) {
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => confirmedBalance(toAddress))
.then(confirmed => {
if (confirmed.gte(cryptoAtoms)) return {status: 'confirmed'}
.then(() => confirmedBalance(toAddress))
.then(confirmed => {
if (confirmed.gte(cryptoAtoms)) return {status: 'confirmed'}
return pendingBalance(toAddress)
.then(pending => {
if (pending.gte(cryptoAtoms)) return {status: 'published'}
if (pending.gt(0)) return {status: 'insufficientFunds'}
return {status: 'notSeen'}
return pendingBalance(toAddress)
.then(pending => {
if (pending.gte(cryptoAtoms)) return {status: 'published'}
if (pending.gt(0)) return {status: 'insufficientFunds'}
return {status: 'notSeen'}
})
})
})
}
function paymentHdNode (account) {
@ -165,19 +165,19 @@ function defaultHdNode (account) {
function newFunding (account, cryptoCode) {
return checkCryptoCode(cryptoCode)
.then(() => {
const fundingAddress = defaultAddress(account)
.then(() => {
const fundingAddress = defaultAddress(account)
const promises = [
pendingBalance(fundingAddress),
confirmedBalance(fundingAddress)
]
const promises = [
pendingBalance(fundingAddress),
confirmedBalance(fundingAddress)
]
return Promise.all(promises)
.then(([fundingPendingBalance, fundingConfirmedBalance]) => ({
fundingPendingBalance,
fundingConfirmedBalance,
fundingAddress
}))
})
return Promise.all(promises)
.then(([fundingPendingBalance, fundingConfirmedBalance]) => ({
fundingPendingBalance,
fundingConfirmedBalance,
fundingAddress
}))
})
}