parser: expose little-endian hashes for harmony with wire format
This commit is contained in:
parent
677b74359b
commit
80b063fe8e
|
@ -32,9 +32,9 @@ func (b *block) GetDisplayHash() []byte {
|
||||||
|
|
||||||
// TODO: encode hash endianness in a type?
|
// TODO: encode hash endianness in a type?
|
||||||
|
|
||||||
// getEncodableHash returns the block hash in little-endian wire order.
|
// GetEncodableHash returns the block hash in little-endian wire order.
|
||||||
func (b *block) getEncodableHash() []byte {
|
func (b *block) GetEncodableHash() []byte {
|
||||||
return b.hdr.getEncodableHash()
|
return b.hdr.GetEncodableHash()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *block) HasSaplingTransactions() bool {
|
func (b *block) HasSaplingTransactions() bool {
|
||||||
|
@ -72,7 +72,7 @@ func (b *block) ToCompact() *rpc.CompactBlock {
|
||||||
compactBlock := &rpc.CompactBlock{
|
compactBlock := &rpc.CompactBlock{
|
||||||
//TODO ProtoVersion: 1,
|
//TODO ProtoVersion: 1,
|
||||||
Height: uint64(b.GetHeight()),
|
Height: uint64(b.GetHeight()),
|
||||||
Hash: b.getEncodableHash(),
|
Hash: b.GetEncodableHash(),
|
||||||
//TODO Time: b.hdr.Time,
|
//TODO Time: b.hdr.Time,
|
||||||
}
|
}
|
||||||
compactBlock.Vtx = make([]*rpc.CompactTx, len(b.vtx))
|
compactBlock.Vtx = make([]*rpc.CompactTx, len(b.vtx))
|
||||||
|
|
|
@ -176,8 +176,8 @@ func (hdr *blockHeader) GetDisplayHash() []byte {
|
||||||
return hdr.cachedHash
|
return hdr.cachedHash
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEncodableHash returns the bytes of a block hash in little-endian wire order.
|
// GetEncodableHash returns the bytes of a block hash in little-endian wire order.
|
||||||
func (hdr *blockHeader) getEncodableHash() []byte {
|
func (hdr *blockHeader) GetEncodableHash() []byte {
|
||||||
serializedHeader, err := hdr.MarshalBinary()
|
serializedHeader, err := hdr.MarshalBinary()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -289,8 +289,8 @@ func (tx *transaction) GetDisplayHash() []byte {
|
||||||
return tx.txId
|
return tx.txId
|
||||||
}
|
}
|
||||||
|
|
||||||
// getEncodableHash returns the transaction hash in little-endian wire format order.
|
// GetEncodableHash returns the transaction hash in little-endian wire format order.
|
||||||
func (tx *transaction) getEncodableHash() []byte {
|
func (tx *transaction) GetEncodableHash() []byte {
|
||||||
digest := sha256.Sum256(tx.rawBytes)
|
digest := sha256.Sum256(tx.rawBytes)
|
||||||
digest = sha256.Sum256(digest[:])
|
digest = sha256.Sum256(digest[:])
|
||||||
return digest[:]
|
return digest[:]
|
||||||
|
@ -303,7 +303,7 @@ func (tx *transaction) HasSaplingTransactions() bool {
|
||||||
func (tx *transaction) ToCompact(index int) *rpc.CompactTx {
|
func (tx *transaction) ToCompact(index int) *rpc.CompactTx {
|
||||||
ctx := &rpc.CompactTx{
|
ctx := &rpc.CompactTx{
|
||||||
Index: uint64(index), // index is contextual
|
Index: uint64(index), // index is contextual
|
||||||
Hash: tx.getEncodableHash(),
|
Hash: tx.GetEncodableHash(),
|
||||||
//Fee: 0, // TODO: calculate fees
|
//Fee: 0, // TODO: calculate fees
|
||||||
Spends: make([]*rpc.CompactSpend, len(tx.shieldedSpends)),
|
Spends: make([]*rpc.CompactSpend, len(tx.shieldedSpends)),
|
||||||
Outputs: make([]*rpc.CompactOutput, len(tx.shieldedOutputs)),
|
Outputs: make([]*rpc.CompactOutput, len(tx.shieldedOutputs)),
|
||||||
|
|
|
@ -55,7 +55,7 @@ func TestSqliteStorage(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
height := block.GetHeight()
|
height := block.GetHeight()
|
||||||
hash := hex.EncodeToString(block.GetDisplayHash())
|
hash := hex.EncodeToString(block.GetEncodableHash())
|
||||||
hasSapling := block.HasSaplingTransactions()
|
hasSapling := block.HasSaplingTransactions()
|
||||||
protoBlock := block.ToCompact()
|
protoBlock := block.ToCompact()
|
||||||
version := 1
|
version := 1
|
||||||
|
|
Loading…
Reference in New Issue