From a4070de73eddb1c54414b5e1d38d4b828b7bb7c1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 24 Sep 2012 13:04:24 -0700 Subject: [PATCH] Some work on the new binary formats that doesn't break current code. --- src/FieldNames.cpp | 98 ++++++++++++++++++++++++++++++++++++++ src/FieldNames.h | 15 ++++++ src/LedgerEntrySet.cpp | 3 ++ src/SerializedObject.h | 13 ++++- src/SerializedTypes.h | 37 +++++++------- src/Transaction.cpp | 6 +-- src/TransactionAction.cpp | 4 +- src/TransactionFormats.cpp | 6 +-- 8 files changed, 156 insertions(+), 26 deletions(-) create mode 100644 src/FieldNames.cpp create mode 100644 src/FieldNames.h diff --git a/src/FieldNames.cpp b/src/FieldNames.cpp new file mode 100644 index 000000000..5f1ff6130 --- /dev/null +++ b/src/FieldNames.cpp @@ -0,0 +1,98 @@ + +#include "FieldNames.h" + +#define S_FIELD(x) sf##x, #x + +FieldName FieldNames[]= +{ + + // 8-bit integers + { S_FIELD(CloseResolution), STI_UINT8, 1 }, + + // 32-bit integers (common) + { S_FIELD(Flags), STI_UINT32, 1 }, + { S_FIELD(SourceTag), STI_UINT32, 2 }, + { S_FIELD(Sequence), STI_UINT32, 3 }, + { S_FIELD(LastTxnSeq), STI_UINT32, 4 }, + { S_FIELD(LedgerSequence), STI_UINT32, 5 }, + { S_FIELD(CloseTime), STI_UINT32, 6 }, + { S_FIELD(ParentCloseTime), STI_UINT32, 7 }, + { S_FIELD(SigningTime), STI_UINT32, 8 }, + { S_FIELD(Expiration), STI_UINT32, 9 }, + { S_FIELD(TransferRate), STI_UINT32, 10 }, + { S_FIELD(PublishSize), STI_UINT32, 11 }, + + // 32-bit integers (rare) + { S_FIELD(HighQualityIn), STI_UINT32, 16 }, + { S_FIELD(HighQualityOut), STI_UINT32, 17 }, + { S_FIELD(LowQualityIn), STI_UINT32, 18 }, + { S_FIELD(LowQualityOut), STI_UINT32, 19 }, + { S_FIELD(QualityIn), STI_UINT32, 20 }, + { S_FIELD(QualityOut), STI_UINT32, 21 }, + { S_FIELD(StampEscrow), STI_UINT32, 22 }, + { S_FIELD(BondAmount), STI_UINT32, 23 }, + { S_FIELD(LoadFee), STI_UINT32, 24 }, + + // 64-bit integers + { S_FIELD(IndexNext), STI_UINT64, 1 }, + { S_FIELD(IndexPrevious), STI_UINT64, 2 }, + { S_FIELD(BookNode), STI_UINT64, 3 }, + { S_FIELD(OwnerNode), STI_UINT64, 4 }, + { S_FIELD(BaseFee), STI_UINT64, 5 }, + + // 128-bit + { S_FIELD(PublishSize), STI_HASH128, 1 }, + { S_FIELD(EmailHash), STI_HASH128, 2 }, + + // 256-bit + { S_FIELD(LedgerHash), STI_HASH256, 1 }, + { S_FIELD(ParentHash), STI_HASH256, 2 }, + { S_FIELD(TransactionHash), STI_HASH256, 3 }, + { S_FIELD(AccountHash), STI_HASH256, 4 }, + { S_FIELD(LastTxnID), STI_HASH256, 5 }, + { S_FIELD(WalletLocator), STI_HASH256, 6 }, + { S_FIELD(PublishHash), STI_HASH256, 7 }, + { S_FIELD(Nickname), STI_HASH256, 8 }, + + // currency amount + { S_FIELD(Amount), STI_AMOUNT, 1 }, + { S_FIELD(Balance), STI_AMOUNT, 2 }, + { S_FIELD(LimitAmount), STI_AMOUNT, 3 }, + { S_FIELD(TakerPays), STI_AMOUNT, 4 }, + { S_FIELD(TakerGets), STI_AMOUNT, 5 }, + { S_FIELD(LowLimit), STI_AMOUNT, 6 }, + { S_FIELD(HighLimit), STI_AMOUNT, 7 }, + { S_FIELD(MinimumOffer), STI_AMOUNT, 8 }, + + // variable length + { S_FIELD(PublicKey), STI_VL, 1 }, + { S_FIELD(MessageKey), STI_VL, 2 }, + { S_FIELD(SigningKey), STI_VL, 3 }, + { S_FIELD(Signature), STI_VL, 4 }, + { S_FIELD(Generator), STI_VL, 5 }, + { S_FIELD(Domain), STI_VL, 6 }, + + // account + { S_FIELD(Account), STI_ACCOUNT, 1 }, + { S_FIELD(Owner), STI_ACCOUNT, 2 }, + { S_FIELD(Destination), STI_ACCOUNT, 3 }, + { S_FIELD(Issuer), STI_ACCOUNT, 4 }, + { S_FIELD(HighID), STI_ACCOUNT, 5 }, + { S_FIELD(LowID), STI_ACCOUNT, 6 }, + { S_FIELD(Target), STI_ACCOUNT, 7 }, + + // path set + { S_FIELD(Paths), STI_PATHSET, 1 }, + + // vector of 256-bit + { S_FIELD(Indexes), STI_VECTOR256, 1 }, + + // inner object + { S_FIELD(MiddleTransaction), STI_OBJECT, 1 }, + { S_FIELD(InnerTransaction), STI_OBJECT, 2 }, + // OBJECT/15 is reserved for end of object + + // array of objects + { S_FIELD(SigningAccounts), STI_ARRAY, 1 }, + // ARRAY/15 is reserved for end of array +}; diff --git a/src/FieldNames.h b/src/FieldNames.h new file mode 100644 index 000000000..5d4979a30 --- /dev/null +++ b/src/FieldNames.h @@ -0,0 +1,15 @@ +#ifndef __FIELDNAMES__ +#define __FIELDNAMES__ + +#include "SerializedTypes.h" +#include "SerializedObject.h" + +struct FieldName +{ + SOE_Field field; + const char *fieldName; + SerializedTypeID fieldType; + int fieldValue; +}; + +#endif diff --git a/src/LedgerEntrySet.cpp b/src/LedgerEntrySet.cpp index 5408a4dca..59bc7359a 100644 --- a/src/LedgerEntrySet.cpp +++ b/src/LedgerEntrySet.cpp @@ -349,14 +349,17 @@ void LedgerEntrySet::calcRawMeta(Serializer& s) switch (it->second.mAction) { case taaMODIFY: + Log(lsTRACE) << "Modified Node " << it->first; nType = TMNModifiedNode; break; case taaDELETE: + Log(lsTRACE) << "Deleted Node " << it->first; nType = TMNDeletedNode; break; case taaCREATE: + Log(lsTRACE) << "Created Node " << it->first; nType = TMNCreatedNode; break; diff --git a/src/SerializedObject.h b/src/SerializedObject.h index 08377304c..e46bf479a 100644 --- a/src/SerializedObject.h +++ b/src/SerializedObject.h @@ -30,9 +30,11 @@ enum SOE_Field sfAcceptRate, sfAcceptStart, sfAccount, + sfAccountHash, sfAmount, sfAuthorizedKey, sfBalance, + sfBaseFee, sfBondAmount, sfBookDirectory, sfBookNode, @@ -42,6 +44,7 @@ enum SOE_Field sfBorrower, sfCreateCode, sfCloseTime, + sfCloseResolution, sfCurrency, sfCurrencyIn, sfCurrencyOut, @@ -65,18 +68,22 @@ enum SOE_Field sfIndexes, sfIndexNext, sfIndexPrevious, + sfInnerTransaction, sfInvoiceID, sfIssuer, sfLastNode, sfLastTxnID, sfLastTxnSeq, sfLedgerHash, + sfLedgerSequence, sfLimitAmount, + sfLoadFee, sfLowID, sfLowLimit, sfLowQualityIn, sfLowQualityOut, sfMessageKey, + sfMiddleTransaction, sfMinimumOffer, sfNextAcceptExpire, sfNextAcceptRate, @@ -88,8 +95,10 @@ enum SOE_Field sfOfferSequence, sfOwner, sfOwnerNode, + sfParentCloseTime, + sfParentHash, sfPaths, - sfPubKey, + sfPublicKey, sfPublishHash, sfPublishSize, sfQualityIn, @@ -99,6 +108,7 @@ enum SOE_Field sfSendMax, sfSequence, sfSignature, + sfSigningAccounts, sfSigningKey, sfSigningTime, sfSourceTag, @@ -107,6 +117,7 @@ enum SOE_Field sfTakerPays, sfTarget, sfTransferRate, + sfTransactionHash, sfVersion, sfWalletLocator, diff --git a/src/SerializedTypes.h b/src/SerializedTypes.h index 3a6417986..e7735bfc8 100644 --- a/src/SerializedTypes.h +++ b/src/SerializedTypes.h @@ -15,25 +15,28 @@ enum SerializedTypeID STI_DONE = -1, STI_NOTPRESENT = 0, - // standard types - STI_OBJECT = 1, - STI_UINT8 = 2, - STI_UINT16 = 3, - STI_UINT32 = 4, - STI_UINT64 = 5, - STI_HASH128 = 6, - STI_HASH160 = 7, - STI_HASH256 = 8, - STI_VL = 9, - STI_TL = 10, - STI_AMOUNT = 11, - STI_PATHSET = 12, - STI_VECTOR256 = 13, + // common types + STI_UINT32 = 1, + STI_UINT64 = 2, + STI_HASH128 = 3, + STI_HASH256 = 4, + STI_TL = 5, + STI_AMOUNT = 6, + STI_VL = 7, + STI_ACCOUNT = 8, + STI_OBJECT = 14, + STI_ARRAY = 15, + + // uncommon types + STI_UINT8 = 16, + STI_UINT16 = 17, + STI_HASH160 = 18, + STI_PATHSET = 19, + STI_VECTOR256 = 20, // high level types - STI_ACCOUNT = 100, - STI_TRANSACTION = 101, - STI_LEDGERENTRY = 102 + STI_TRANSACTION = 100001, + STI_LEDGERENTRY = 100002 }; enum PathFlags diff --git a/src/Transaction.cpp b/src/Transaction.cpp index 00988712d..526f433bf 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -194,7 +194,7 @@ Transaction::pointer Transaction::setClaim( const std::vector& vucSignature) { mTransaction->setITFieldVL(sfGenerator, vucGenerator); - mTransaction->setITFieldVL(sfPubKey, vucPubKey); + mTransaction->setITFieldVL(sfPublicKey, vucPubKey); mTransaction->setITFieldVL(sfSignature, vucSignature); sign(naPrivateKey); @@ -455,7 +455,7 @@ Transaction::pointer Transaction::setPasswordSet( { mTransaction->setITFieldAccount(sfAuthorizedKey, naAuthKeyID); mTransaction->setITFieldVL(sfGenerator, vucGenerator); - mTransaction->setITFieldVL(sfPubKey, vucPubKey); + mTransaction->setITFieldVL(sfPublicKey, vucPubKey); mTransaction->setITFieldVL(sfSignature, vucSignature); sign(naPrivateKey); @@ -542,7 +542,7 @@ Transaction::pointer Transaction::setWalletAdd( { mTransaction->setITFieldAmount(sfAmount, saAmount); mTransaction->setITFieldAccount(sfAuthorizedKey, naAuthKeyID); - mTransaction->setITFieldVL(sfPubKey, naNewPubKey.getAccountPublic()); + mTransaction->setITFieldVL(sfPublicKey, naNewPubKey.getAccountPublic()); mTransaction->setITFieldVL(sfSignature, vucSignature); sign(naPrivateKey); diff --git a/src/TransactionAction.cpp b/src/TransactionAction.cpp index f60ae0af5..19db581da 100644 --- a/src/TransactionAction.cpp +++ b/src/TransactionAction.cpp @@ -30,7 +30,7 @@ TER TransactionEngine::setAuthorized(const SerializedTransaction& txn, bool bMus // std::vector vucCipher = txn.getITFieldVL(sfGenerator); - std::vector vucPubKey = txn.getITFieldVL(sfPubKey); + std::vector vucPubKey = txn.getITFieldVL(sfPublicKey); std::vector vucSignature = txn.getITFieldVL(sfSignature); NewcoinAddress naAccountPublic = NewcoinAddress::createAccountPublic(vucPubKey); @@ -620,7 +620,7 @@ TER TransactionEngine::doWalletAdd(const SerializedTransaction& txn) { std::cerr << "WalletAdd>" << std::endl; - const std::vector vucPubKey = txn.getITFieldVL(sfPubKey); + const std::vector vucPubKey = txn.getITFieldVL(sfPublicKey); const std::vector vucSignature = txn.getITFieldVL(sfSignature); const uint160 uAuthKeyID = txn.getITFieldAccount(sfAuthorizedKey); const NewcoinAddress naMasterPubKey = NewcoinAddress::createAccountPublic(vucPubKey); diff --git a/src/TransactionFormats.cpp b/src/TransactionFormats.cpp index de18524c7..542e2683c 100644 --- a/src/TransactionFormats.cpp +++ b/src/TransactionFormats.cpp @@ -21,7 +21,7 @@ TransactionFormat InnerTxnFormats[]= { "Claim", ttCLAIM, { { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 }, { S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 }, - { S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 }, + { S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 }, { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 }, @@ -85,7 +85,7 @@ TransactionFormat InnerTxnFormats[]= { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 }, { S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 }, { S_FIELD(Generator), STI_VL, SOE_REQUIRED, 0 }, - { S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 }, + { S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 }, { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 }, @@ -106,7 +106,7 @@ TransactionFormat InnerTxnFormats[]= { S_FIELD(Flags), STI_UINT32, SOE_FLAGS, 0 }, { S_FIELD(Amount), STI_AMOUNT, SOE_REQUIRED, 0 }, { S_FIELD(AuthorizedKey), STI_ACCOUNT, SOE_REQUIRED, 0 }, - { S_FIELD(PubKey), STI_VL, SOE_REQUIRED, 0 }, + { S_FIELD(PublicKey), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(Signature), STI_VL, SOE_REQUIRED, 0 }, { S_FIELD(SourceTag), STI_UINT32, SOE_IFFLAG, 1 }, { S_FIELD(Extensions), STI_TL, SOE_IFFLAG, 0x02000000 },