Skip to content

Commit

Permalink
added RBF transactions support
Browse files Browse the repository at this point in the history
  • Loading branch information
alecalve committed Dec 2, 2015
1 parent ad2ea9f commit a233774
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
34 changes: 34 additions & 0 deletions blockchain_parser/tests/test_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2015 The bitcoin-blockchain-parser developers
#
# This file is part of bitcoin-blockchain-parser.
#
# It is subject to the license terms in the LICENSE file found in the top-level
# directory of this distribution.
#
# No part of bitcoin-blockchain-parser, including this file, may be copied,
# modified, propagated, or distributed except according to the terms contained
# in the LICENSE file.

import unittest
from binascii import a2b_hex
from blockchain_parser.transaction import Transaction


class TestTransaction(unittest.TestCase):
def test_rbf(self):
data = a2b_hex("01000000019222bbb054bb9f94571dfe769af5866835f2a97e8839"
"59fa757de4064bed8bca01000000035101b1000000000100000000"
"00000000016a01000000")
tx = Transaction(data)
self.assertTrue(tx.uses_replace_by_fee())

coinbase = a2b_hex("01000000010000000000000000000000000000000000000000"
"000000000000000000000000ffffffff4203c8e405fabe6d6d"
"98b0e98e3809941f1fd8cafe7c8236e27b8d1a776b1835aa54"
"8bb84fe5b5f3d7010000000000000002650300aaa757eb0000"
"002f736c7573682f0000000001baa98396000000001976a914"
"7c154ed1dc59609e3d26abb2df2ea3d587cd8c4188ac000000"
"00")
tx = Transaction(coinbase)
self.assertTrue(tx.is_coinbase())
self.assertFalse(tx.uses_replace_by_fee())
21 changes: 21 additions & 0 deletions blockchain_parser/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,24 @@ def hash(self):
if self._hash is None:
self._hash = format_hash(double_sha256(self.hex))
return self._hash

def is_coinbase(self):
"""Returns whether the transaction is a coinbase transaction"""
for input in self.inputs:
if input.transaction_hash == "0" * 64:
return True
return False

def uses_replace_by_fee(self):
"""Returns whether the transaction opted-in for RBF"""
# Coinbase transactions may have a sequence number that signals RBF
# but they cannot use it as it's only enforced for non-coinbase txs
if self.is_coinbase():
return False

# A transactions opts-in for RBF when having an input
# with a sequence number < MAX_INT - 1
for input in self.inputs:
if input.sequence_number < 4294967294:
return True
return False

0 comments on commit a233774

Please sign in to comment.