From 80b063fe8e453ae27cdc91bd6a779aa130b0febb Mon Sep 17 00:00:00 2001 From: George Tankersley Date: Tue, 11 Dec 2018 01:38:57 -0500 Subject: [PATCH] parser: expose little-endian hashes for harmony with wire format --- parser/block.go | 8 ++++---- parser/block_header.go | 4 ++-- parser/transaction.go | 6 +++--- storage/sqlite3_test.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/parser/block.go b/parser/block.go index cc9c477..1934ab0 100644 --- a/parser/block.go +++ b/parser/block.go @@ -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)) diff --git a/parser/block_header.go b/parser/block_header.go index f8d224f..55d5cb5 100644 --- a/parser/block_header.go +++ b/parser/block_header.go @@ -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 { diff --git a/parser/transaction.go b/parser/transaction.go index 38f4d66..5f4c7ed 100644 --- a/parser/transaction.go +++ b/parser/transaction.go @@ -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)), diff --git a/storage/sqlite3_test.go b/storage/sqlite3_test.go index 14717c8..4d61676 100644 --- a/storage/sqlite3_test.go +++ b/storage/sqlite3_test.go @@ -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