Skip to content

Commit dfdeaba

Browse files
committed
detect RBF transactions on 'tx' event
1 parent b311172 commit dfdeaba

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

lib/transactions.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,25 @@ TxController.prototype.transformInvTransaction = function(transaction) {
201201
for (var i = 0; i < transaction.outputs.length; i++) {
202202
var output = transaction.outputs[i];
203203
valueOut += output.satoshis;
204-
if(output.script) {
204+
if (output.script) {
205205
var address = output.script.toAddress(self.node.network);
206-
if(address) {
206+
if (address) {
207207
var obj = {};
208208
obj[address.toString()] = output.satoshis;
209209
vout.push(obj);
210210
}
211211
}
212212
}
213213

214+
var isRBF = _.any(_.pluck(transaction.inputs, 'sequenceNumber'), function(seq) {
215+
return seq !== 0xffffffff;
216+
});
217+
214218
var transformed = {
215219
txid: transaction.hash,
216220
valueOut: valueOut / 1e8,
217-
vout: vout
221+
vout: vout,
222+
isRBF: isRBF,
218223
};
219224

220225
return transformed;

test/transactions.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ describe('Transactions', function() {
866866
{
867867
"12WvZmssxT85f81dD6wcmWznxbnFkEpNMS": 1993504
868868
}
869-
]
869+
],
870+
"isRBF": false,
870871
};
871872

872873
var rawTx = '01000000011760bc271a397bfb65b7506d430d96ebb1faff467ed957516238a9670e806a86010000006b483045022100f0056ae68a34cdb4194d424bd727c18f82653bca2a198e0d55ab6b4ee88bbdb902202a5745af4f72a5dbdca1e3d683af4667728a8b20e8001e0f8308a4d329ce3f96012102f3af6e66b61c9d99c74d9a9c3c1bec014a8c05d28bf339c8f5f395b5ce319e7dffffffff02c8af00000000000017a9148083b541ea15f1d18c5ca5e1fd47f9035cce24ed87206b1e00000000001976a91410a0e70cd91a45e0e6e409e227ab285bd61592b188ac00000000';
@@ -889,7 +890,8 @@ describe('Transactions', function() {
889890
{
890891
"n4eY3qiP9pi32MWC6FcJFHciSsfNiYFYgR": 12.5002 * 1e8
891892
}
892-
]
893+
],
894+
"isRBF": false,
893895
};
894896

895897
var rawTx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0403ebc108ffffffff04a0ca814a000000001976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000226a200000000000000000000000000000000000000000000000000000ffff0000000000000000000000001b6a1976a914fdb9fb622b0db8d9121475a983288a0876f4de4888ac0000000000000000326a303a791c8e85200500d89769b4f958e4db6b3ec388ddaa30233c4517d942d440c24ae903bff40d97ca06465fcf2714000000000000';
@@ -904,5 +906,28 @@ describe('Transactions', function() {
904906
var result = transactions.transformInvTransaction(tx);
905907
should(result).eql(insight);
906908
});
909+
it('should detect RBF txs', function() {
910+
var testCases = [{
911+
rawTx: '01000000017fa897c3556271c34cb28c03c196c2d912093264c9d293cb4980a2635474467d010000000f5355540b6f93598893578893588851ffffffff01501e0000000000001976a914aa2482ce71d219018ef334f6cc551ee88abd920888ac00000000',
912+
expected: false,
913+
}, {
914+
rawTx: '01000000017fa897c3556271c34cb28c03c196c2d912093264c9d293cb4980a2635474467d010000000f5355540b6f935988935788935888510000000001501e0000000000001976a914aa2482ce71d219018ef334f6cc551ee88abd920888ac00000000',
915+
expected: true,
916+
}, ];
917+
918+
var node = {
919+
network: bitcore.Networks.livenet
920+
};
921+
922+
var transactions = new TxController(node);
923+
924+
_.each(testCases, function(tc) {
925+
var tx = bitcore.Transaction().fromBuffer(new Buffer(tc.rawTx, 'hex'));
926+
var result = transactions.transformInvTransaction(tx);
927+
should.exist(result.isRBF);
928+
result.isRBF.should.equal(tc.expected);
929+
});
930+
});
931+
907932
});
908933
});

0 commit comments

Comments
 (0)