Skip to content

Commit

Permalink
Fix condensing transactions with no comment
Browse files Browse the repository at this point in the history
  • Loading branch information
bitspill committed Dec 11, 2017
1 parent ba2294a commit 69ed4be
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
8 changes: 4 additions & 4 deletions wallet/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ Coin.prototype._buildTX = function (options) {
}

if (changeVout !== undefined) {
this.addUnconfirmed(getTxId(tx, txComment), changeVout, changeSat / this.coinInfo.satPerCoin, changeSat, spentInputs)
this.addUnconfirmed(this.getTxId(tx, txComment), changeVout, changeSat / this.coinInfo.satPerCoin, changeSat, spentInputs)
}

return {tx, changeVout, changeSat, spentInputs, txComment}
}

function getTxId (tx, txComment) {
Coin.prototype.getTxId = function (tx, txComment) {
let txh = tx.build().toHex()
if (txComment !== '') {
if (this.coinInfo.name === 'florincoin') {
txh += bitcoin.bufferutils.varIntBuffer(txComment.length).toString('hex') + Buffer.from(txComment).toString('hex')
}
return bcrypto.hash256(Buffer.from(txh, 'hex')).reverse().toString('hex')
Expand All @@ -264,7 +264,7 @@ Coin.prototype._directSendPayment = function (options) {

let rawTx = tx.build().toHex()

if (txComment !== '') {
if (this.coinInfo.name === 'florincoin') {
rawTx += bitcoin.bufferutils.varIntBuffer(txComment.length).toString('hex') + Buffer.from(txComment).toString('hex')
}

Expand Down
63 changes: 63 additions & 0 deletions wallet/key.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,66 @@ test('payto chain q', () => {
})
})
})

test('payto chain condense', () => {
expect.hasAssertions()

let key = new Key('RA4KK8pCiFuviH7M4e2k65mmLCH2bLr7kJ6wAHP2TPMdBPVnJoqW', 'florincoin')

key.coins['florincoin'].utxo = [
{
'address': 'FD42dYEYLfsdr88ukVZ9Pf3rDYs75McM7s',
'txid': 'd202718a3c574d5b28f284c6ad81e11819753570377684052447d4b1fecf4331',
'vout': 0,
'ts': 1511237053,
'scriptPubKey': '76a9144f3a411d38966b259484338306c46924e616b53388ac',
'amount': 0.0001,
'satoshis': 10000,
'confirmations': 6,
'confirmationsFromCache': true
},
{
'address': 'FD42dYEYLfsdr88ukVZ9Pf3rDYs75McM7s',
'txid': 'eaf5687248115795ce68618fb005311819cb54f083a5829b4788e2b6c2848044',
'vout': 0,
'ts': 1510620852,
'scriptPubKey': '76a9144f3a411d38966b259484338306c46924e616b53388ac',
'amount': 0.5,
'satoshis': 50000000,
'confirmations': 6,
'confirmationsFromCache': true
},
{
'address': 'FD42dYEYLfsdr88ukVZ9Pf3rDYs75McM7s',
'txid': '618b96acd5762f7d2f4b74777cdd8e12104a291e3524e43373a0caea6cbb14c8',
'vout': 1,
'ts': 1512688138,
'scriptPubKey': '76a9144f3a411d38966b259484338306c46924e616b53388ac',
'amount': 6.4,
'satoshis': 640000000,
'confirmations': 6,
'confirmationsFromCache': true
}
]

key.coins['florincoin'].balanceSat = 841410000

return key.payTo('florincoin', 'FD42dYEYLfsdr88ukVZ9Pf3rDYs75McM7s', 5, {q: true, fee: 0.001}).then((res) => {
return key.payTo('florincoin', 'FD42dYEYLfsdr88ukVZ9Pf3rDYs75McM7s', 4, {q: true, fee: 0.002}).then((res) => {
return key.payTo('florincoin', 'FDEAciuFexEHy1kiLKRt34e2PybTyhdGZC', 3, {q: true, fee: 0.003}).then((res) => {
return key.payTo('florincoin', 'FDEAciuFexEHy1kiLKRt34e2PybTyhdGZC', 2, {q: true, fee: 0.004, txComment: 'hello world'}).then((res) => {
return key.payTo('florincoin', 'FDEAciuFexEHy1kiLKRt34e2PybTyhdGZC', 1, {q: true}).then((res) => {
return key.payTo('florincoin', 'FDEAciuFexEHy1kiLKRt34e2PybTyhdGZC', 0.5, {q: true}).then((res) => {
return key.sendQueue('florincoin').then((res) => {
expect(res).toEqual([
{ txid: '5a421a1f5260676c50397c571b2ff4f828183c0399a852bc02dd88fc455f96d9' },
{ txid: 'ffd7394a2f0d9839c7ee8463d91a619b79ac2b68857be23fec0ecc8ba076daec' }
])
})
})
})
})
})
})
})
})
4 changes: 2 additions & 2 deletions wallet/paymentQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ PaymentQueue.prototype._buildCacheTX = function () {
if (noCom.outputSat[o]) {
noCom.outputSat[o] += qi.amountSat
} else {
noCom.amountSat[o] = qi.amountSat
noCom.outputSat[o] = qi.amountSat
}
}
}
Expand All @@ -78,7 +78,7 @@ PaymentQueue.prototype._buildCacheTX = function () {
this.cachedTX.push(this.coin._buildTX(btOptions))
}

if (noCom.amountSat > 0 && noCom.feeSat > 0) { this.cachedTX.push(this.coin._buildTX(noCom)) }
if (noCom.amountSat > 0 || noCom.feeSat > 0) { this.cachedTX.push(this.coin._buildTX(noCom)) }

this.stale = false
}
Expand Down

0 comments on commit 69ed4be

Please sign in to comment.