Page tree
Skip to end of metadata
Go to start of metadata

初始化一个LedgerHash过程:

  • Serializer s;

// 构造函数,默认长度是2048Bit,即256字节的hash字符串
Serializer (int n = 2048)
{
    mData.reserve (n);
}
 
// 其中mData字符数组类型:
typedef std::vector <unsigned char> Blob;

  • s.add32 (HashPrefix::ledgerMaster);

// 先填充Ledger前缀字段
HashPrefix const HashPrefix::transactionID               ('T''X''N');
HashPrefix const HashPrefix::txNode                      ('S''N''D');
HashPrefix const HashPrefix::leafNode                    ('M''L''N');
HashPrefix const HashPrefix::innerNode                   ('M''I''N');
HashPrefix const HashPrefix::ledgerMaster                ('L''W''R');
HashPrefix const HashPrefix::txSign                      ('S''T''X');
HashPrefix const HashPrefix::validation                  ('V''A''L');
HashPrefix const HashPrefix::proposal                    ('P''R''P');

  • addRaw (s);

// 将Ledger成员变量值填充到Ledger字符串当中
    s.add32 (mLedgerSeq);
    s.add64 (mTotCoins);
    s.add64 (mTotCoinsVBC);
    s.add256 (mParentHash);
    s.add256 (mTransHash);
    s.add256 (mAccountHash);
    s.add32 (mParentCloseTime);
    s.add32 (mCloseTime);
    s.add32 (mDividendLedger);
    s.add8 (mCloseResolution);
    s.add8 (mCloseFlags);

  • mHash = s.getSHA512Half ();

// 得到最终的LedgerHash值
// 使用SHA512计算hash值,再取256长度

  • No labels