Wallet protobuf serialization for RAISE_FEE transaction purpose.

This commit is contained in:
Andreas Schildbach
2015-07-14 10:33:57 +02:00
parent 15dc260cde
commit 7fb9b6c5ce
5 changed files with 434 additions and 554 deletions

View File

@@ -154,6 +154,8 @@ public class Transaction extends ChildMessage implements Serializable {
/** Raise fee, e.g. child-pays-for-parent. */
RAISE_FEE,
// In future: de/refragmentation, privacy boosting/mixing, etc.
// When adding a value, it also needs to be added to wallet.proto, WalletProtobufSerialize.makeTxProto()
// and WalletProtobufSerializer.readTransaction()!
}
private Purpose purpose = Purpose.UNKNOWN;

View File

@@ -299,6 +299,7 @@ public class WalletProtobufSerializer {
case ASSURANCE_CONTRACT_CLAIM: purpose = Protos.Transaction.Purpose.ASSURANCE_CONTRACT_CLAIM; break;
case ASSURANCE_CONTRACT_PLEDGE: purpose = Protos.Transaction.Purpose.ASSURANCE_CONTRACT_PLEDGE; break;
case ASSURANCE_CONTRACT_STUB: purpose = Protos.Transaction.Purpose.ASSURANCE_CONTRACT_STUB; break;
case RAISE_FEE: purpose = Protos.Transaction.Purpose.RAISE_FEE; break;
default:
throw new RuntimeException("New tx purpose serialization not implemented.");
}
@@ -595,6 +596,7 @@ public class WalletProtobufSerializer {
case ASSURANCE_CONTRACT_CLAIM: tx.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_CLAIM); break;
case ASSURANCE_CONTRACT_PLEDGE: tx.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_PLEDGE); break;
case ASSURANCE_CONTRACT_STUB: tx.setPurpose(Transaction.Purpose.ASSURANCE_CONTRACT_STUB); break;
case RAISE_FEE: tx.setPurpose(Transaction.Purpose.RAISE_FEE); break;
default: throw new RuntimeException("New purpose serialization not implemented");
}
} else {

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,7 @@ package org.bitcoinj.store;
import org.bitcoinj.core.*;
import org.bitcoinj.core.Transaction.Purpose;
import org.bitcoinj.core.TransactionConfidence.ConfidenceType;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.params.MainNetParams;
@@ -133,6 +134,18 @@ public class WalletProtobufSerializerTest {
assertEquals(t1p.getTransactionOutput(0).getValue(), v1.value);
}
@Test
public void raiseFeeTx() throws Exception {
// Check basic tx serialization.
Coin v1 = COIN;
Transaction t1 = createFakeTx(params, v1, myAddress);
t1.setPurpose(Purpose.RAISE_FEE);
myWallet.receivePending(t1, null);
Wallet wallet1 = roundTrip(myWallet);
Transaction t1copy = wallet1.getTransaction(t1.getHash());
assertEquals(Purpose.RAISE_FEE, t1copy.getPurpose());
}
@Test
public void doubleSpend() throws Exception {
// Check that we can serialize double spends correctly, as this is a slightly tricky case.

View File

@@ -271,6 +271,8 @@ message Transaction {
ASSURANCE_CONTRACT_CLAIM = 3;
ASSURANCE_CONTRACT_PLEDGE = 4;
ASSURANCE_CONTRACT_STUB = 5;
// Raise fee, e.g. child-pays-for-parent.
RAISE_FEE = 6;
// In future: de/refragmentation, privacy boosting/mixing, child-pays-for-parent fees, etc.
}
optional Purpose purpose = 10 [default = UNKNOWN];