Chore: refactor generic wallet and wallet plugins
This commit is contained in:
parent
d2b7224c73
commit
b6d91f94bf
11 changed files with 110 additions and 87 deletions
|
|
@ -42,11 +42,12 @@ function privateKey (account) {
|
|||
return defaultWallet(account).getPrivateKey()
|
||||
}
|
||||
|
||||
function isStrictAddress (cryptoCode, toAddress) {
|
||||
function isStrictAddress (cryptoCode, toAddress, settings, operatorId) {
|
||||
return cryptoCode === 'ETH' && util.isValidChecksumAddress(toAddress)
|
||||
}
|
||||
|
||||
function sendCoins (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
function sendCoins (account, tx, settings, operatorId) {
|
||||
const { toAddress, cryptoAtoms } = tx
|
||||
return generateTx(toAddress, defaultWallet(account), cryptoAtoms, false)
|
||||
.then(pify(web3.eth.sendRawTransaction))
|
||||
.then(txid => {
|
||||
|
|
@ -66,7 +67,7 @@ function checkCryptoCode (cryptoCode) {
|
|||
return Promise.reject(new Error('cryptoCode must be ETH'))
|
||||
}
|
||||
|
||||
function balance (account, cryptoCode) {
|
||||
function balance (account, cryptoCode, settings, operatorId) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(defaultAddress(account)))
|
||||
}
|
||||
|
|
@ -139,7 +140,7 @@ function defaultAddress (account) {
|
|||
return defaultWallet(account).getChecksumAddressString()
|
||||
}
|
||||
|
||||
function sweep (account, cryptoCode, hdIndex) {
|
||||
function sweep (account, cryptoCode, hdIndex, settings, operatorId) {
|
||||
const wallet = paymentHdNode(account).deriveChild(hdIndex).getWallet()
|
||||
const fromAddress = wallet.getChecksumAddressString()
|
||||
|
||||
|
|
@ -152,20 +153,21 @@ function sweep (account, cryptoCode, hdIndex) {
|
|||
})
|
||||
}
|
||||
|
||||
function newAddress (account, info) {
|
||||
function newAddress (account, info, tx, settings, operatorId) {
|
||||
const childNode = paymentHdNode(account).deriveChild(info.hdIndex)
|
||||
return Promise.resolve(childNode.getWallet().getChecksumAddressString())
|
||||
}
|
||||
|
||||
function getStatus (account, toAddress, cryptoAtoms, cryptoCode) {
|
||||
function getStatus (account, tx, requested, settings, operatorId) {
|
||||
const { toAddress, cryptoCode } = tx
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => confirmedBalance(toAddress))
|
||||
.then(confirmed => {
|
||||
if (confirmed.gte(cryptoAtoms)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
if (confirmed.gte(requested)) return { receivedCryptoAtoms: confirmed, status: 'confirmed' }
|
||||
|
||||
return pendingBalance(toAddress)
|
||||
.then(pending => {
|
||||
if (pending.gte(cryptoAtoms)) return { receivedCryptoAtoms: pending, status: 'published' }
|
||||
if (pending.gte(requested)) return { receivedCryptoAtoms: pending, status: 'published' }
|
||||
if (pending.gt(0)) return { receivedCryptoAtoms: pending, status: 'insufficientFunds' }
|
||||
return { receivedCryptoAtoms: pending, status: 'notSeen' }
|
||||
})
|
||||
|
|
@ -186,7 +188,7 @@ function defaultHdNode (account) {
|
|||
return key.derivePath(defaultPrefixPath)
|
||||
}
|
||||
|
||||
function newFunding (account, cryptoCode) {
|
||||
function newFunding (account, cryptoCode, settings, operatorId) {
|
||||
return checkCryptoCode(cryptoCode)
|
||||
.then(() => {
|
||||
const fundingAddress = defaultAddress(account)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue