parser: expose little-endian hashes for harmony with wire format

This commit is contained in:
George Tankersley 2018-12-11 01:38:57 -05:00
parent 677b74359b
commit 80b063fe8e
4 changed files with 10 additions and 10 deletions

View File

@ -32,9 +32,9 @@ func (b *block) GetDisplayHash() []byte {
// TODO: encode hash endianness in a type?
// getEncodableHash returns the block hash in little-endian wire order.
func (b *block) getEncodableHash() []byte {
return b.hdr.getEncodableHash()
// GetEncodableHash returns the block hash in little-endian wire order.
func (b *block) GetEncodableHash() []byte {
return b.hdr.GetEncodableHash()
}
func (b *block) HasSaplingTransactions() bool {
@ -72,7 +72,7 @@ func (b *block) ToCompact() *rpc.CompactBlock {
compactBlock := &rpc.CompactBlock{
//TODO ProtoVersion: 1,
Height: uint64(b.GetHeight()),
Hash: b.getEncodableHash(),
Hash: b.GetEncodableHash(),
//TODO Time: b.hdr.Time,
}
compactBlock.Vtx = make([]*rpc.CompactTx, len(b.vtx))

View File

@ -176,8 +176,8 @@ func (hdr *blockHeader) GetDisplayHash() []byte {
return hdr.cachedHash
}
// getEncodableHash returns the bytes of a block hash in little-endian wire order.
func (hdr *blockHeader) getEncodableHash() []byte {
// GetEncodableHash returns the bytes of a block hash in little-endian wire order.
func (hdr *blockHeader) GetEncodableHash() []byte {
serializedHeader, err := hdr.MarshalBinary()
if err != nil {

View File

@ -289,8 +289,8 @@ func (tx *transaction) GetDisplayHash() []byte {
return tx.txId
}
// getEncodableHash returns the transaction hash in little-endian wire format order.
func (tx *transaction) getEncodableHash() []byte {
// GetEncodableHash returns the transaction hash in little-endian wire format order.
func (tx *transaction) GetEncodableHash() []byte {
digest := sha256.Sum256(tx.rawBytes)
digest = sha256.Sum256(digest[:])
return digest[:]
@ -303,7 +303,7 @@ func (tx *transaction) HasSaplingTransactions() bool {
func (tx *transaction) ToCompact(index int) *rpc.CompactTx {
ctx := &rpc.CompactTx{
Index: uint64(index), // index is contextual
Hash: tx.getEncodableHash(),
Hash: tx.GetEncodableHash(),
//Fee: 0, // TODO: calculate fees
Spends: make([]*rpc.CompactSpend, len(tx.shieldedSpends)),
Outputs: make([]*rpc.CompactOutput, len(tx.shieldedOutputs)),

View File

@ -55,7 +55,7 @@ func TestSqliteStorage(t *testing.T) {
}
height := block.GetHeight()
hash := hex.EncodeToString(block.GetDisplayHash())
hash := hex.EncodeToString(block.GetEncodableHash())
hasSapling := block.HasSaplingTransactions()
protoBlock := block.ToCompact()
version := 1