rippled
LedgerFormats.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/protocol/LedgerFormats.h>
21 #include <ripple/protocol/ErrorCodes.h>
22 #include <ripple/protocol/jss.h>
23 #include <algorithm>
24 #include <array>
25 #include <utility>
26 
27 namespace ripple {
28 
30 {
31  // Fields shared by all ledger formats:
32  static const std::initializer_list<SOElement> commonFields
33  {
36  { sfFlags, soeREQUIRED },
37  };
38 
39  add (jss::AccountRoot, ltACCOUNT_ROOT,
40  {
54  { sfDomain, soeOPTIONAL },
56  },
57  commonFields);
58 
59  add (jss::DirectoryNode, ltDIR_NODE,
60  {
61  { sfOwner, soeOPTIONAL }, // for owner directories
62  { sfTakerPaysCurrency, soeOPTIONAL }, // for order book directories
63  { sfTakerPaysIssuer, soeOPTIONAL }, // for order book directories
64  { sfTakerGetsCurrency, soeOPTIONAL }, // for order book directories
65  { sfTakerGetsIssuer, soeOPTIONAL }, // for order book directories
66  { sfExchangeRate, soeOPTIONAL }, // for order book directories
71  },
72  commonFields);
73 
74  add (jss::Offer, ltOFFER,
75  {
86  },
87  commonFields);
88 
89  add (jss::RippleState, ltRIPPLE_STATE,
90  {
102  },
103  commonFields);
104 
105  add (jss::Escrow, ltESCROW,
106  {
107  { sfAccount, soeREQUIRED },
109  { sfAmount, soeREQUIRED },
119  },
120  commonFields);
121 
122  add (jss::LedgerHashes, ltLEDGER_HASHES,
123  {
124  { sfFirstLedgerSequence, soeOPTIONAL }, // Remove if we do a ledger restart
126  { sfHashes, soeREQUIRED },
127  },
128  commonFields);
129 
130  add (jss::Amendments, ltAMENDMENTS,
131  {
132  { sfAmendments, soeOPTIONAL }, // Enabled
134  },
135  commonFields);
136 
137  add (jss::FeeSettings, ltFEE_SETTINGS,
138  {
139  { sfBaseFee, soeREQUIRED },
143  },
144  commonFields);
145 
146  add (jss::Ticket, ltTICKET,
147  {
148  { sfAccount, soeREQUIRED },
149  { sfSequence, soeREQUIRED },
151  { sfTarget, soeOPTIONAL },
153  },
154  commonFields);
155 
156  // All fields are soeREQUIRED because there is always a
157  // SignerEntries. If there are no SignerEntries the node is deleted.
158  add (jss::SignerList, ltSIGNER_LIST,
159  {
166  },
167  commonFields);
168 
169  add (jss::PayChannel, ltPAYCHAN,
170  {
171  { sfAccount, soeREQUIRED },
173  { sfAmount, soeREQUIRED },
174  { sfBalance, soeREQUIRED },
185  },
186  commonFields);
187 
188  add (jss::Check, ltCHECK,
189  {
190  { sfAccount, soeREQUIRED },
192  { sfSendMax, soeREQUIRED },
193  { sfSequence, soeREQUIRED },
202  },
203  commonFields);
204 
205  add (jss::DepositPreauth, ltDEPOSIT_PREAUTH,
206  {
207  { sfAccount, soeREQUIRED },
212  },
213  commonFields);
214 }
215 
216 LedgerFormats const&
218 {
219  static LedgerFormats instance;
220  return instance;
221 }
222 
223 } // ripple
ripple::sfHighQualityIn
const SF_U32 sfHighQualityIn(access, STI_UINT32, 16, "HighQualityIn")
Definition: SField.h:353
ripple::KnownFormats< LedgerEntryType >::add
Item const & add(char const *name, LedgerEntryType type, std::initializer_list< SOElement > uniqueFields, std::initializer_list< SOElement > commonFields={})
Add a new format.
Definition: KnownFormats.h:148
ripple::sfRegularKey
const SF_Account sfRegularKey(access, STI_ACCOUNT, 8, "RegularKey")
Definition: SField.h:467
ripple::sfIndexNext
const SF_U64 sfIndexNext(access, STI_UINT64, 1, "IndexNext")
Definition: SField.h:379
ripple::sfTarget
const SF_Account sfTarget(access, STI_ACCOUNT, 7, "Target")
Definition: SField.h:466
utility
ripple::sfPreviousTxnLgrSeq
const SF_U32 sfPreviousTxnLgrSeq(access, STI_UINT32, 5, "PreviousTxnLgrSeq", SField::sMD_DeleteFinal)
Definition: SField.h:341
ripple::sfLedgerEntryType
const SF_U16 sfLedgerEntryType(access, STI_UINT16, 1, "LedgerEntryType", SField::sMD_Never)
Definition: SField.h:330
ripple::sfLedgerIndex
const SF_U256 sfLedgerIndex(access, STI_HASH256, 6, "LedgerIndex")
Definition: SField.h:406
ripple::sfSignerQuorum
const SF_U32 sfSignerQuorum(access, STI_UINT32, 35, "SignerQuorum")
Definition: SField.h:372
ripple::ltESCROW
@ ltESCROW
Definition: LedgerFormats.h:81
ripple::sfMessageKey
const SF_Blob sfMessageKey(access, STI_VL, 2, "MessageKey")
Definition: SField.h:441
ripple::sfSequence
const SF_U32 sfSequence(access, STI_UINT32, 4, "Sequence")
Definition: SField.h:340
ripple::sfAccount
const SF_Account sfAccount(access, STI_ACCOUNT, 1, "Account")
Definition: SField.h:460
ripple::sfFlags
const SF_U32 sfFlags(access, STI_UINT32, 2, "Flags")
Definition: SField.h:338
ripple::sfTakerPaysIssuer
const SF_U160 sfTakerPaysIssuer(access, STI_HASH160, 2, "TakerPaysIssuer")
Definition: SField.h:396
ripple::sfMajorities
const SField sfMajorities(access, STI_ARRAY, 16, "Majorities")
Definition: SField.h:502
ripple::sfWalletLocator
const SF_U256 sfWalletLocator(access, STI_HASH256, 7, "WalletLocator")
Definition: SField.h:407
ripple::sfTakerPays
const SF_Amount sfTakerPays(access, STI_AMOUNT, 4, "TakerPays")
Definition: SField.h:426
ripple::soeREQUIRED
@ soeREQUIRED
Definition: SOTemplate.h:35
ripple::ltLEDGER_HASHES
@ ltLEDGER_HASHES
Definition: LedgerFormats.h:75
ripple::ltAMENDMENTS
@ ltAMENDMENTS
Definition: LedgerFormats.h:77
ripple::sfOwnerNode
const SF_U64 sfOwnerNode(access, STI_UINT64, 4, "OwnerNode")
Definition: SField.h:382
ripple::ltSIGNER_LIST
@ ltSIGNER_LIST
Definition: LedgerFormats.h:71
ripple::sfTakerGetsCurrency
const SF_U160 sfTakerGetsCurrency(access, STI_HASH160, 3, "TakerGetsCurrency")
Definition: SField.h:397
ripple::sfAmount
const SF_Amount sfAmount(access, STI_AMOUNT, 1, "Amount")
Definition: SField.h:423
ripple::sfSignerEntries
const SField sfSignerEntries(access, STI_ARRAY, 4, "SignerEntries")
Definition: SField.h:496
ripple::sfOwnerCount
const SF_U32 sfOwnerCount(access, STI_UINT32, 13, "OwnerCount")
Definition: SField.h:349
ripple::sfReserveBase
const SF_U32 sfReserveBase(access, STI_UINT32, 31, "ReserveBase")
Definition: SField.h:368
ripple::sfHighLimit
const SF_Amount sfHighLimit(access, STI_AMOUNT, 7, "HighLimit")
Definition: SField.h:429
ripple::sfFinishAfter
const SF_U32 sfFinishAfter(access, STI_UINT32, 37, "FinishAfter")
Definition: SField.h:374
algorithm
ripple::ltTICKET
@ ltTICKET
Definition: LedgerFormats.h:69
ripple::sfAccountTxnID
const SF_U256 sfAccountTxnID(access, STI_HASH256, 9, "AccountTxnID")
Definition: SField.h:409
ripple::sfLowLimit
const SF_Amount sfLowLimit(access, STI_AMOUNT, 6, "LowLimit")
Definition: SField.h:428
ripple::ltCHECK
@ ltCHECK
Definition: LedgerFormats.h:86
ripple::sfDestinationTag
const SF_U32 sfDestinationTag(access, STI_UINT32, 14, "DestinationTag")
Definition: SField.h:350
ripple::sfIndexPrevious
const SF_U64 sfIndexPrevious(access, STI_UINT64, 2, "IndexPrevious")
Definition: SField.h:380
ripple::sfLastLedgerSequence
const SF_U32 sfLastLedgerSequence(access, STI_UINT32, 27, "LastLedgerSequence")
Definition: SField.h:364
ripple::sfOwner
const SF_Account sfOwner(access, STI_ACCOUNT, 2, "Owner")
Definition: SField.h:461
ripple::sfHighNode
const SF_U64 sfHighNode(access, STI_UINT64, 8, "HighNode")
Definition: SField.h:386
ripple::sfBookDirectory
const SF_U256 sfBookDirectory(access, STI_HASH256, 16, "BookDirectory")
Definition: SField.h:412
ripple::ltFEE_SETTINGS
@ ltFEE_SETTINGS
Definition: LedgerFormats.h:79
ripple::sfSendMax
const SF_Amount sfSendMax(access, STI_AMOUNT, 9, "SendMax")
Definition: SField.h:431
ripple::sfSignerListID
const SF_U32 sfSignerListID(access, STI_UINT32, 38, "SignerListID")
Definition: SField.h:375
ripple::soeOPTIONAL
@ soeOPTIONAL
Definition: SOTemplate.h:36
ripple::sfDestinationNode
const SF_U64 sfDestinationNode(access, STI_UINT64, 9, "DestinationNode")
Definition: SField.h:387
ripple::LedgerFormats::LedgerFormats
LedgerFormats()
Create the object.
Definition: LedgerFormats.cpp:29
array
ripple::sfReferenceFeeUnits
const SF_U32 sfReferenceFeeUnits(access, STI_UINT32, 30, "ReferenceFeeUnits")
Definition: SField.h:367
ripple::sfExchangeRate
const SF_U64 sfExchangeRate(access, STI_UINT64, 6, "ExchangeRate")
Definition: SField.h:384
ripple::sfLowQualityOut
const SF_U32 sfLowQualityOut(access, STI_UINT32, 19, "LowQualityOut")
Definition: SField.h:356
ripple::ltDEPOSIT_PREAUTH
@ ltDEPOSIT_PREAUTH
Definition: LedgerFormats.h:88
ripple::sfSourceTag
const SF_U32 sfSourceTag(access, STI_UINT32, 3, "SourceTag")
Definition: SField.h:339
ripple::sfIndexes
const SF_Vec256 sfIndexes(access, STI_VECTOR256, 1, "Indexes", SField::sMD_Never)
Definition: SField.h:473
ripple::sfExpiration
const SF_U32 sfExpiration(access, STI_UINT32, 10, "Expiration")
Definition: SField.h:346
ripple::sfFirstLedgerSequence
const SF_U32 sfFirstLedgerSequence(access, STI_UINT32, 26, "FirstLedgerSequence")
Definition: SField.h:363
ripple::LedgerFormats::getInstance
static LedgerFormats const & getInstance()
Definition: LedgerFormats.cpp:217
ripple::sfHashes
const SF_Vec256 sfHashes(access, STI_VECTOR256, 2, "Hashes")
Definition: SField.h:474
ripple::sfPublicKey
const SF_Blob sfPublicKey(access, STI_VL, 1, "PublicKey")
Definition: SField.h:440
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::ltRIPPLE_STATE
@ ltRIPPLE_STATE
Definition: LedgerFormats.h:67
ripple::sfWalletSize
const SF_U32 sfWalletSize(access, STI_UINT32, 12, "WalletSize")
Definition: SField.h:348
ripple::sfLowQualityIn
const SF_U32 sfLowQualityIn(access, STI_UINT32, 18, "LowQualityIn")
Definition: SField.h:355
ripple::sfBalance
const SF_Amount sfBalance(access, STI_AMOUNT, 2, "Balance")
Definition: SField.h:424
ripple::sfTakerPaysCurrency
const SF_U160 sfTakerPaysCurrency(access, STI_HASH160, 1, "TakerPaysCurrency")
Definition: SField.h:395
ripple::sfReserveIncrement
const SF_U32 sfReserveIncrement(access, STI_UINT32, 32, "ReserveIncrement")
Definition: SField.h:369
ripple::sfCondition
const SF_Blob sfCondition(access, STI_VL, 17, "Condition")
Definition: SField.h:456
ripple::sfSettleDelay
const SF_U32 sfSettleDelay(access, STI_UINT32, 39, "SettleDelay")
Definition: SField.h:376
ripple::sfTakerGets
const SF_Amount sfTakerGets(access, STI_AMOUNT, 5, "TakerGets")
Definition: SField.h:427
ripple::LedgerFormats
Holds the list of known ledger entry formats.
Definition: LedgerFormats.h:164
ripple::sfDestination
const SF_Account sfDestination(access, STI_ACCOUNT, 3, "Destination")
Definition: SField.h:462
ripple::ltPAYCHAN
@ ltPAYCHAN
Definition: LedgerFormats.h:84
ripple::sfRootIndex
const SF_U256 sfRootIndex(access, STI_HASH256, 8, "RootIndex", SField::sMD_Always)
Definition: SField.h:408
ripple::sfTransferRate
const SF_U32 sfTransferRate(access, STI_UINT32, 11, "TransferRate")
Definition: SField.h:347
ripple::sfLowNode
const SF_U64 sfLowNode(access, STI_UINT64, 7, "LowNode")
Definition: SField.h:385
ripple::ltDIR_NODE
@ ltDIR_NODE
Directory node.
Definition: LedgerFormats.h:65
ripple::ltOFFER
@ ltOFFER
Definition: LedgerFormats.h:73
ripple::sfAmendments
const SF_Vec256 sfAmendments(access, STI_VECTOR256, 3, "Amendments")
Definition: SField.h:475
ripple::sfBookNode
const SF_U64 sfBookNode(access, STI_UINT64, 3, "BookNode")
Definition: SField.h:381
ripple::sfBaseFee
const SF_U64 sfBaseFee(access, STI_UINT64, 5, "BaseFee")
Definition: SField.h:383
ripple::sfAuthorize
const SF_Account sfAuthorize(access, STI_ACCOUNT, 5, "Authorize")
Definition: SField.h:464
ripple::ltACCOUNT_ROOT
@ ltACCOUNT_ROOT
Definition: LedgerFormats.h:54
ripple::sfHighQualityOut
const SF_U32 sfHighQualityOut(access, STI_UINT32, 17, "HighQualityOut")
Definition: SField.h:354
ripple::sfPreviousTxnID
const SF_U256 sfPreviousTxnID(access, STI_HASH256, 5, "PreviousTxnID", SField::sMD_DeleteFinal)
Definition: SField.h:405
ripple::sfCancelAfter
const SF_U32 sfCancelAfter(access, STI_UINT32, 36, "CancelAfter")
Definition: SField.h:373
ripple::sfEmailHash
const SF_U128 sfEmailHash(access, STI_HASH128, 1, "EmailHash")
Definition: SField.h:392
ripple::sfTickSize
const SF_U8 sfTickSize(access, STI_UINT8, 16, "TickSize")
Definition: SField.h:327
ripple::sfInvoiceID
const SF_U256 sfInvoiceID(access, STI_HASH256, 17, "InvoiceID")
Definition: SField.h:413
std::initializer_list
ripple::sfTakerGetsIssuer
const SF_U160 sfTakerGetsIssuer(access, STI_HASH160, 4, "TakerGetsIssuer")
Definition: SField.h:398
ripple::sfDomain
const SF_Blob sfDomain(access, STI_VL, 7, "Domain")
Definition: SField.h:445