merkle

package
v1.3.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainType

type ChainType uint64

ChainType is the type of a chain belonging to an account.

const ChainTypeAnchor ChainType = 2

ChainTypeAnchor holds chain anchors.

const ChainTypeIndex ChainType = 4

ChainTypeIndex indexes other chains.

const ChainTypeTransaction ChainType = 1

ChainTypeTransaction holds transaction hashes.

const ChainTypeUnknown ChainType = 0

ChainTypeUnknown is used when the chain type is not known.

func ChainTypeByName

func ChainTypeByName(name string) (ChainType, bool)

ChainTypeByName returns the named Chain Type.

func (ChainType) GetEnumValue

func (v ChainType) GetEnumValue() uint64

GetEnumValue returns the value of the Chain Type

func (ChainType) MarshalJSON

func (v ChainType) MarshalJSON() ([]byte, error)

MarshalJSON marshals the Chain Type to JSON as a string.

func (*ChainType) SetEnumValue

func (v *ChainType) SetEnumValue(id uint64) bool

SetEnumValue sets the value. SetEnumValue returns false if the value is invalid.

func (ChainType) String

func (v ChainType) String() string

String returns the name of the Chain Type.

func (*ChainType) UnmarshalJSON

func (v *ChainType) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the Chain Type from JSON as a string.

type GetIntermediateFunc

type GetIntermediateFunc func(element, height int64) (l, r []byte, err error)

type Receipt

type Receipt struct {

	// Start is the entry for which we want a proof.
	Start      []byte `json:"start,omitempty" form:"start" query:"start" validate:"required"`
	StartIndex int64  `json:"startIndex,omitempty" form:"startIndex" query:"startIndex" validate:"required"`
	// End is the entry at the index where the anchor was created.
	End      []byte `json:"end,omitempty" form:"end" query:"end" validate:"required"`
	EndIndex int64  `json:"endIndex,omitempty" form:"endIndex" query:"endIndex" validate:"required"`
	// Anchor is the root expected once all nodes are applied.
	Anchor []byte `json:"anchor,omitempty" form:"anchor" query:"anchor" validate:"required"`
	// Entries is the list of hashes to apply to create an anchor.
	Entries []*ReceiptEntry `json:"entries,omitempty" form:"entries" query:"entries" validate:"required"`
	// contains filtered or unexported fields
}

func CombineReceipts

func CombineReceipts(receipts ...*Receipt) (*Receipt, error)

CombineReceipts combines multiple receipts.

func (*Receipt) Build

func (r *Receipt) Build(getIntermediate GetIntermediateFunc, anchorState *State) error

BuildReceipt takes the values collected by GetReceipt and flushes out the data structures in the receipt to represent a fully populated version.

func (*Receipt) Combine

func (r *Receipt) Combine(rm *Receipt) (*Receipt, error)

Combine Take a 2nd receipt, attach it to a root receipt, and return the resulting receipt. The idea is that if this receipt is anchored into another chain, Then we can create a receipt that proves the element in this receipt all the way down to an anchor in the root receipt. Note that both this receipt and the root receipt are expected to be good.

func (*Receipt) Contains

func (r *Receipt) Contains(other *Receipt) bool

Contains returns true if the 2nd receipt is equal to or contained within the first.

func (*Receipt) Copy

func (v *Receipt) Copy() *Receipt

func (*Receipt) CopyAsInterface

func (v *Receipt) CopyAsInterface() interface{}

func (*Receipt) Equal

func (v *Receipt) Equal(u *Receipt) bool

func (*Receipt) IsValid

func (v *Receipt) IsValid() error

func (*Receipt) MarshalBinary

func (v *Receipt) MarshalBinary() ([]byte, error)

func (*Receipt) MarshalJSON

func (v *Receipt) MarshalJSON() ([]byte, error)

func (*Receipt) UnmarshalBinary

func (v *Receipt) UnmarshalBinary(data []byte) error

func (*Receipt) UnmarshalBinaryFrom

func (v *Receipt) UnmarshalBinaryFrom(rd io.Reader) error

func (*Receipt) UnmarshalJSON

func (v *Receipt) UnmarshalJSON(data []byte) error

func (*Receipt) Validate

func (r *Receipt) Validate(opts *ValidateOptions) bool

Validate Take a receipt and validate that the element hash progresses to the Merkle Dag Root hash (MDRoot) in the receipt

type ReceiptEntry

type ReceiptEntry struct {
	Right bool   `json:"right,omitempty" form:"right" query:"right" validate:"required"`
	Hash  []byte `json:"hash,omitempty" form:"hash" query:"hash" validate:"required"`
	// contains filtered or unexported fields
}

func (*ReceiptEntry) Copy

func (v *ReceiptEntry) Copy() *ReceiptEntry

func (*ReceiptEntry) CopyAsInterface

func (v *ReceiptEntry) CopyAsInterface() interface{}

func (*ReceiptEntry) Equal

func (v *ReceiptEntry) Equal(u *ReceiptEntry) bool

func (*ReceiptEntry) IsValid

func (v *ReceiptEntry) IsValid() error

func (*ReceiptEntry) MarshalBinary

func (v *ReceiptEntry) MarshalBinary() ([]byte, error)

func (*ReceiptEntry) MarshalJSON

func (v *ReceiptEntry) MarshalJSON() ([]byte, error)

func (*ReceiptEntry) UnmarshalBinary

func (v *ReceiptEntry) UnmarshalBinary(data []byte) error

func (*ReceiptEntry) UnmarshalBinaryFrom

func (v *ReceiptEntry) UnmarshalBinaryFrom(rd io.Reader) error

func (*ReceiptEntry) UnmarshalJSON

func (v *ReceiptEntry) UnmarshalJSON(data []byte) error

type State

type State struct {

	// Count is the count of hashes added to the tree.
	Count int64 `json:"count,omitempty" form:"count" query:"count" validate:"required"`
	// Pending is the hashes that represent the left edge of the tree.
	Pending [][]byte `json:"pending,omitempty" form:"pending" query:"pending" validate:"required"`
	// HashList is the hashes added to the tree.
	HashList [][]byte `json:"hashList,omitempty" form:"hashList" query:"hashList" validate:"required"`
}

func (*State) Add

func (m *State) Add(hash_ []byte)

Add a Hash to the merkle tree and incrementally build the ChainHead

func (*State) Anchor

func (m *State) Anchor() (anchor []byte)

Anchor Compute the Merkle Directed Acyclic Graph (Merkle DAG or ChainHead) for the ChainHead at this point We take any trailing hashes in ChainHead, hash them up and combine to create the Merkle Dag Root. Getting the closing ListMDRoot is non-destructive, which is useful for some use cases.

Returns a nil if the MerkleSate is empty.

func (*State) Copy

func (v *State) Copy() *State

func (*State) CopyAsInterface

func (v *State) CopyAsInterface() interface{}

func (*State) Equal

func (m *State) Equal(m2 *State) (isEqual bool)

Equal Compares one State to another, and returns true if they are the same

func (*State) Marshal

func (m *State) Marshal() (MSBytes []byte, err error)

Marshal Encodes the Merkle State so it can be embedded into the Merkle Tree

func (*State) MarshalBinary

func (m *State) MarshalBinary() ([]byte, error)

func (*State) MarshalJSON

func (v *State) MarshalJSON() ([]byte, error)

func (*State) Pad

func (m *State) Pad()

Pad Add a nil to the end of the Pending list if one isn't there. We need to be able to add an element to Pending if needed while building receipts

func (*State) Trim

func (m *State) Trim()

Trim Remove any trailing nils from Pending hashes

func (*State) UnMarshal

func (m *State) UnMarshal(MSBytes []byte) (err error)

UnMarshal Take the state of an MSMarshal instance defined by MSBytes, and set all the values in this instance of MSMarshal to the state defined by MSBytes. It is assumed that the hash function has been set by the caller.

func (*State) UnmarshalBinary

func (m *State) UnmarshalBinary(data []byte) error

func (*State) UnmarshalBinaryFrom

func (m *State) UnmarshalBinaryFrom(rd io.Reader) error

func (*State) UnmarshalJSON

func (v *State) UnmarshalJSON(data []byte) error

type ValidateOptions

type ValidateOptions struct {
	Relaxed bool
}

Jump to

Keyboard shortcuts

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