diff --git a/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java b/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java index aa2b6ef27d2..75d27440d69 100644 --- a/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java +++ b/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java @@ -572,9 +572,8 @@ private void readTransaction(Protos.Transaction txProto, NetworkParameters param ); Coin value = inputProto.hasValue() ? Coin.valueOf(inputProto.getValue()) : null; TransactionInput input = new TransactionInput(params, tx, scriptBytes, outpoint, value); - if (inputProto.hasSequence()) { - input.setSequenceNumber(inputProto.getSequence()); - } + if (inputProto.hasSequence()) + input.setSequenceNumber(0xffffffffL & inputProto.getSequence()); tx.addInput(input); } diff --git a/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java b/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java index 68f317fc136..418dd037a4d 100644 --- a/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java +++ b/core/src/test/java/org/bitcoinj/store/WalletProtobufSerializerTest.java @@ -51,6 +51,7 @@ import static org.bitcoinj.core.Coin.*; import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx; import static org.junit.Assert.*; +import static com.google.common.base.Preconditions.checkNotNull; public class WalletProtobufSerializerTest { static final NetworkParameters params = UnitTestParams.get(); @@ -205,6 +206,22 @@ public void testLastBlockSeenHash() throws Exception { assertEquals(genesisBlock.getHash(), wallet2.getLastBlockSeenHash()); } + @Test + public void testSequenceNumber() throws Exception { + Wallet wallet = new Wallet(params); + Transaction tx1 = createFakeTx(params, Coin.COIN, wallet.currentReceiveAddress()); + tx1.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE); + wallet.receivePending(tx1, null); + Transaction tx2 = createFakeTx(params, Coin.COIN, wallet.currentReceiveAddress()); + tx2.getInput(0).setSequenceNumber(TransactionInput.NO_SEQUENCE - 1); + wallet.receivePending(tx2, null); + Wallet walletCopy = roundTrip(wallet); + Transaction tx1copy = checkNotNull(walletCopy.getTransaction(tx1.getHash())); + assertEquals(TransactionInput.NO_SEQUENCE, tx1copy.getInput(0).getSequenceNumber()); + Transaction tx2copy = checkNotNull(walletCopy.getTransaction(tx2.getHash())); + assertEquals(TransactionInput.NO_SEQUENCE - 1, tx2copy.getInput(0).getSequenceNumber()); + } + @Test public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception { // Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.