mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 06:42:16 +00:00
types: tx.go comments
This commit is contained in:
parent
77e45756f2
commit
eeab0efa56
20
types/tx.go
20
types/tx.go
@ -10,18 +10,18 @@ import (
|
|||||||
"github.com/tendermint/tmlibs/merkle"
|
"github.com/tendermint/tmlibs/merkle"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tx represents a transaction, which may contain arbitrary bytes.
|
// Tx is an arbitrary byte array.
|
||||||
|
// NOTE: Tx has no types at this level, so when go-wire encoded it's just length-prefixed.
|
||||||
|
// Alternatively, it may make sense to add types here and let
|
||||||
|
// []byte be type 0x1 so we can have versioned txs if need be in the future.
|
||||||
type Tx []byte
|
type Tx []byte
|
||||||
|
|
||||||
// Hash returns the hash of the go-wire encoded Tx.
|
// Hash computes the RIPEMD160 hash of the go-wire encoded transaction.
|
||||||
// Tx has no types at this level, so go-wire encoding only adds length-prefix.
|
|
||||||
// NOTE: It may make sense to add types here one day and let []byte be type 0x1
|
|
||||||
// so we can have versioned txs if need be in the future.
|
|
||||||
func (tx Tx) Hash() []byte {
|
func (tx Tx) Hash() []byte {
|
||||||
return merkle.SimpleHashFromBinary(tx)
|
return merkle.SimpleHashFromBinary(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a string representation of the Tx.
|
// String returns the hex-encoded transaction as a string.
|
||||||
func (tx Tx) String() string {
|
func (tx Tx) String() string {
|
||||||
return fmt.Sprintf("Tx{%X}", []byte(tx))
|
return fmt.Sprintf("Tx{%X}", []byte(tx))
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ func (tx Tx) String() string {
|
|||||||
// Txs is a slice of Tx.
|
// Txs is a slice of Tx.
|
||||||
type Txs []Tx
|
type Txs []Tx
|
||||||
|
|
||||||
// Hash returns the simple Merkle root hash of the Txs.
|
// Hash returns the simple Merkle root hash of the transactions.
|
||||||
func (txs Txs) Hash() []byte {
|
func (txs Txs) Hash() []byte {
|
||||||
// Recursive impl.
|
// Recursive impl.
|
||||||
// Copied from tmlibs/merkle to avoid allocations
|
// Copied from tmlibs/merkle to avoid allocations
|
||||||
@ -87,6 +87,7 @@ func (txs Txs) Proof(i int) TxProof {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree.
|
||||||
type TxProof struct {
|
type TxProof struct {
|
||||||
Index, Total int
|
Index, Total int
|
||||||
RootHash data.Bytes
|
RootHash data.Bytes
|
||||||
@ -94,12 +95,13 @@ type TxProof struct {
|
|||||||
Proof merkle.SimpleProof
|
Proof merkle.SimpleProof
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LeadHash returns the hash of the transaction this proof refers to.
|
||||||
func (tp TxProof) LeafHash() []byte {
|
func (tp TxProof) LeafHash() []byte {
|
||||||
return tp.Data.Hash()
|
return tp.Data.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate returns nil if it matches the dataHash, and is internally consistent
|
// Validate verifies the proof. It returns nil if the RootHash matches the dataHash argument,
|
||||||
// otherwise, returns a sensible error
|
// and if the proof is internally consistent. Otherwise, it returns a sensible error.
|
||||||
func (tp TxProof) Validate(dataHash []byte) error {
|
func (tp TxProof) Validate(dataHash []byte) error {
|
||||||
if !bytes.Equal(dataHash, tp.RootHash) {
|
if !bytes.Equal(dataHash, tp.RootHash) {
|
||||||
return errors.New("Proof matches different data hash")
|
return errors.New("Proof matches different data hash")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user