merkleblock

package
v0.0.0-...-6ea28df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2021 License: ISC Imports: 5 Imported by: 13

README

merkleblock

Build Status ISC License GoDoc

Package merkleblock provides an API for creating and validating SPV proofs. An SPV proof is a cryptographic proof that a given transaction is contained in the block. Instead of the prover providing the full block he can provide the much smaller SPV proof.

Installation and Updating

$ go get -u github.com/gcash/bchutil/merkleblock

License

Package merkleblock is licensed under the copyfree ISC License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxTxnCount = wire.MaxBlockPayload() / 61

MaxTxnCount defines the maximum number of transactions we will process before aborting merkle tree traversal operations.

bitcoin core uses formula of max blocksize divided by segwit transaction size (240 bytes) to calculate max number of transactions that could fit in a block which at this time is 4000000/240=16666

bitcoin ABC has removed this check and has been marked "FIXME".

we have opted to use a similar calculation to core based on smallest possible transaction size spending OP_TRUE at 61 bytes with max block size variable

Functions

func NewMerkleBlockWithFilter

func NewMerkleBlockWithFilter(block *bchutil.Block, filter *bloom.Filter) (*wire.MsgMerkleBlock, []uint32)

NewMerkleBlockWithFilter returns a new *wire.MsgMerkleBlock and an array of the matched transaction index numbers based on the passed block and bloom filter.

func NewMerkleBlockWithTxnSet

func NewMerkleBlockWithTxnSet(block *bchutil.Block, txnSet []*chainhash.Hash) (*wire.MsgMerkleBlock, []uint32)

NewMerkleBlockWithTxnSet returns a new *wire.MsgMerkleBlock containing a partial merkle tree built using the list of transactions provided

func TxInSet

func TxInSet(tx *chainhash.Hash, set []*chainhash.Hash) bool

TxInSet checks if a given transaction is included in the given list of transactions

Types

type MerkleBlock

type MerkleBlock struct {
	// contains filtered or unexported fields
}

MerkleBlock is used to house intermediate information needed to generate a wire.MsgMerkleBlock

type PartialBlock

type PartialBlock struct {
	// contains filtered or unexported fields
}

PartialBlock is used to house intermediate information needed to decode a wire.MsgMerkleBlock

func NewMerkleBlockFromMsg

func NewMerkleBlockFromMsg(msg wire.MsgMerkleBlock) *PartialBlock

NewMerkleBlockFromMsg returns a MerkleBlock from parsing a wire.MsgMerkleBlock which can be used for extracting transaction matches from for verification on a partial merkle tree.

source code based off bitcoin c++ code at https://github.com/bitcoin/bitcoin/blob/master/src/merkleblock.cpp with protocol reference documentation at https://bitcoin.org/en/developer-examples#parsing-a-merkleblock

func (*PartialBlock) BadTree

func (m *PartialBlock) BadTree() bool

BadTree returns status of partial merkle tree traversal

func (*PartialBlock) ExtractMatches

func (m *PartialBlock) ExtractMatches() *chainhash.Hash

ExtractMatches traverses the partial merkle tree and returns the merkle root on successful traversal or nil if an error occured during traversal due to an invalid block being parsed

func (*PartialBlock) GetItems

func (m *PartialBlock) GetItems() []uint32

GetItems returns the item number of the matched transactions placement in the merkle block

func (*PartialBlock) GetMatches

func (m *PartialBlock) GetMatches() []*chainhash.Hash

GetMatches returns the transaction hashes matched in the partial merkle tree

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL