mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-01 21:17:13 +00:00
WalletProtobufSerializer: Fix protobuf serialization of large sequence numbers.
This commit is contained in:
@@ -623,9 +623,8 @@ public class WalletProtobufSerializer {
|
|||||||
);
|
);
|
||||||
Coin value = inputProto.hasValue() ? Coin.valueOf(inputProto.getValue()) : null;
|
Coin value = inputProto.hasValue() ? Coin.valueOf(inputProto.getValue()) : null;
|
||||||
TransactionInput input = new TransactionInput(params, tx, scriptBytes, outpoint, value);
|
TransactionInput input = new TransactionInput(params, tx, scriptBytes, outpoint, value);
|
||||||
if (inputProto.hasSequence()) {
|
if (inputProto.hasSequence())
|
||||||
input.setSequenceNumber(inputProto.getSequence());
|
input.setSequenceNumber(0xffffffffL & inputProto.getSequence());
|
||||||
}
|
|
||||||
tx.addInput(input);
|
tx.addInput(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import java.util.Set;
|
|||||||
import static org.bitcoinj.core.Coin.*;
|
import static org.bitcoinj.core.Coin.*;
|
||||||
import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
|
import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
public class WalletProtobufSerializerTest {
|
public class WalletProtobufSerializerTest {
|
||||||
private static final NetworkParameters PARAMS = UnitTestParams.get();
|
private static final NetworkParameters PARAMS = UnitTestParams.get();
|
||||||
@@ -206,6 +207,22 @@ public class WalletProtobufSerializerTest {
|
|||||||
assertEquals(genesisBlock.getHash(), wallet2.getLastBlockSeenHash());
|
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
|
@Test
|
||||||
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
|
public void testAppearedAtChainHeightDepthAndWorkDone() throws Exception {
|
||||||
// Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.
|
// Test the TransactionConfidence appearedAtChainHeight, depth and workDone field are stored.
|
||||||
|
|||||||
Reference in New Issue
Block a user