mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 18:45:52 +00:00
Get rid of the binary format magic numbers spread though the code.
This commit is contained in:
31
BinaryFormats.h
Normal file
31
BinaryFormats.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __BINARYFORMATS__
|
||||
#define __BINARYFORMATS__
|
||||
|
||||
// binary transaction
|
||||
const int BTxSize=145;
|
||||
const int BTxPDestAcct=0, BTxLDestAact=20; // destination account pubkey Hash160
|
||||
const int BTxPAmount=20, BTxLAmount=8; // amount
|
||||
const int BTxPSASeq=28, BTxLASeq=4; // source account sequence number
|
||||
const int BTxPSLIdx=32, BTxLSLIdx=4; // source ledger index
|
||||
const int BTxPSTag=36, BTxLSTag=4; // source tag
|
||||
const int BTxPSPubK=40, BTxLSPubK=33; // source public key
|
||||
const int BTxPSig=73, BTxLSig=72; // signature
|
||||
|
||||
// ledger (note: fields after the timestamp are not part of the hash)
|
||||
const int BLgSize=192;
|
||||
const int BLgPIndex=0, BLgLIndex=4; // ledger index
|
||||
const int BLgPFeeHeld=4, BLgLFeeHeld=8; // transaction fees held
|
||||
const int BLgPPrevLg=12, BLgLPrevLg=32; // previous ledger hash
|
||||
const int BLgPTxT=44, BLgLTxT=32; // transaction tree hash
|
||||
const int BLgPAcT=76, BLgLPAct=32; // account state hash
|
||||
const int BLgPClTs=108, BLgLClTs=8; // closing timestamp
|
||||
const int BLgPConf=116, BLgLPConf=4; // confidence
|
||||
const int BLgPSig=120, BLgLSig=72; // signature
|
||||
|
||||
// account status
|
||||
const int BAsSize=32;
|
||||
const int BAsPID=0, BAsLID=20; // account pubkey Hash160
|
||||
const int BAsPBalance=20, BAsLBalance=8; // account balance
|
||||
const int BAsPSequence=28, BASLSequence=4; // account sequence
|
||||
|
||||
#endif
|
||||
@@ -56,7 +56,7 @@ signed transaction.
|
||||
|
||||
|
||||
|
||||
3) Ledger (signed format)
|
||||
3) Ledger (signed format) - 192 bytes
|
||||
|
||||
Fields:
|
||||
1) 4-byte ledger index, unsigned BE integer
|
||||
@@ -64,7 +64,7 @@ Fields:
|
||||
3) 32-byte hash of previous ledger
|
||||
4) 32-byte hash of root of the transaction tree for this ledger
|
||||
5) 32-byte hash of root of the account tree for this ledger
|
||||
6) 8-byte timestamp
|
||||
6) 8-byte closing timestamp
|
||||
7) 4-byte confidence, unsigned BE integer (0 = closed/accepted)
|
||||
8) Signature:
|
||||
Accepted: Prefix (0x4C475200) of 120 byte fields 1-6
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Wallet.h"
|
||||
#include "Account.h"
|
||||
#include "BitcoinUtil.h"
|
||||
#include "BinaryFormats.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -29,16 +30,16 @@ Transaction::Transaction(TransStatus status, LocalAccount& fromLocalAccount, uin
|
||||
Transaction::Transaction(const std::vector<unsigned char> &t, bool validate) : mStatus(INVALID)
|
||||
{
|
||||
Serializer s(t);
|
||||
if(s.getLength()<145) { assert(false); return; }
|
||||
if(!s.get160(mAccountTo, 0)) { assert(false); return; }
|
||||
if(!s.get64(mAmount, 20)) { assert(false); return; }
|
||||
if(!s.get32(mFromAccountSeq, 28)) { assert(false); return; }
|
||||
if(!s.get32(mSourceLedger, 32)) { assert(false); return; }
|
||||
if(!s.get32(mIdent, 36)) { assert(false); return; }
|
||||
if(!s.getRaw(mSignature, 69, 72)) { assert(false); return; }
|
||||
if(s.getLength()<BTxSize) { assert(false); return; }
|
||||
if(!s.get160(mAccountTo, BTxPDestAcct)) { assert(false); return; }
|
||||
if(!s.get64(mAmount, BTxPAmount)) { assert(false); return; }
|
||||
if(!s.get32(mFromAccountSeq, BTxPSASeq)) { assert(false); return; }
|
||||
if(!s.get32(mSourceLedger, BTxPSLIdx)) { assert(false); return; }
|
||||
if(!s.get32(mIdent, BTxPSTag)) { assert(false); return; }
|
||||
if(!s.getRaw(mSignature, BTxPSig, BTxLSig)) { assert(false); return; }
|
||||
|
||||
std::vector<unsigned char> pubKey;
|
||||
if(!s.getRaw(pubKey, 40, 33)) { assert(false); return; }
|
||||
if(!s.getRaw(pubKey, BTxPSPubK, BTxLSPubK)) { assert(false); return; }
|
||||
mFromPubKey=CKey::pointer(new CKey());
|
||||
if(!mFromPubKey->SetPubKey(pubKey)) return;
|
||||
mAccountFrom=Hash160(pubKey);
|
||||
@@ -103,6 +104,7 @@ Serializer::pointer Transaction::getSigned() const
|
||||
{
|
||||
Serializer::pointer ret(getRaw(false));
|
||||
ret->addRaw(mSignature);
|
||||
assert(ret->getLength()==BTxSize);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user