3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 03:35:52 +00:00

WalletProtobufSerializer: Fix protobuf serialization of large sequence numbers.

This commit is contained in:
Andreas Schildbach 2016-03-23 14:11:35 +01:00
parent 645f2d2572
commit 5aa4b66c7e
2 changed files with 19 additions and 3 deletions

View File

@ -623,9 +623,8 @@ public class WalletProtobufSerializer {
);
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);
}

View File

@ -51,6 +51,7 @@ import java.util.Set;
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 {
private static final NetworkParameters PARAMS = UnitTestParams.get();
@ -206,6 +207,22 @@ public class WalletProtobufSerializerTest {
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.