block

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: AGPL-3.0, ISC Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProofVerificationFailed = errors.New("proof verification failed")
	ErrTxIsNil                 = errors.New("tx is nil")
	ErrVerifierIsNil           = errors.New("verifier is nil")
	ErrBlockIsNil              = errors.New("block is nil")
	ErrInvalidUnitID           = errors.New("unit id is invalid")
	ErrUCIsNil                 = errors.New("unicity certificate is nil")
)
View Source
var (
	ProofType_name = map[int32]string{
		0: "PRIM",
		1: "SEC",
		2: "ONLYSEC",
		3: "NOTRANS",
		4: "EMPTYBLOCK",
	}
	ProofType_value = map[string]int32{
		"PRIM":       0,
		"SEC":        1,
		"ONLYSEC":    2,
		"NOTRANS":    3,
		"EMPTYBLOCK": 4,
	}
)

Enum value maps for ProofType.

View Source
var File_bills_proto protoreflect.FileDescriptor
View Source
var File_block_proof_proto protoreflect.FileDescriptor
View Source
var File_block_proto protoreflect.FileDescriptor

Functions

func FromProtobuf added in v0.1.1

func FromProtobuf(chain []*MerklePathItem) []*mt.PathItem

FromProtobuf utility function that converts []*MerklePathItem to []*mt.PathItem

func FromProtobufHashChain added in v0.1.1

func FromProtobufHashChain(chain []*ChainItem) []*omt.Data

FromProtobufHashChain utility function that converts []ChainItem []omt.Data

func WriteBillsFile added in v0.1.1

func WriteBillsFile(path string, res *Bills) error

Types

type Bill added in v0.1.1

type Bill struct {
	Id       []byte   `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Value    uint64   `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
	TxHash   []byte   `protobuf:"bytes,3,opt,name=tx_hash,json=txHash,proto3" json:"tx_hash,omitempty"`
	IsDcBill bool     `protobuf:"varint,4,opt,name=is_dc_bill,json=isDcBill,proto3" json:"is_dc_bill,omitempty"`
	TxProof  *TxProof `protobuf:"bytes,5,opt,name=tx_proof,json=txProof,proto3" json:"tx_proof,omitempty"`
	// contains filtered or unexported fields
}

bill with tx proof

func (*Bill) Descriptor deprecated added in v0.1.1

func (*Bill) Descriptor() ([]byte, []int)

Deprecated: Use Bill.ProtoReflect.Descriptor instead.

func (*Bill) GetId added in v0.1.1

func (x *Bill) GetId() []byte

func (*Bill) GetIsDcBill added in v0.1.1

func (x *Bill) GetIsDcBill() bool

func (*Bill) GetTxHash added in v0.1.1

func (x *Bill) GetTxHash() []byte

func (*Bill) GetTxProof added in v0.1.1

func (x *Bill) GetTxProof() *TxProof

func (*Bill) GetValue added in v0.1.1

func (x *Bill) GetValue() uint64

func (*Bill) ProtoMessage added in v0.1.1

func (*Bill) ProtoMessage()

func (*Bill) ProtoReflect added in v0.1.1

func (x *Bill) ProtoReflect() protoreflect.Message

func (*Bill) Reset added in v0.1.1

func (x *Bill) Reset()

func (*Bill) String added in v0.1.1

func (x *Bill) String() string

func (*Bill) Verify added in v0.1.1

func (x *Bill) Verify(unitID []byte, txConverter TxConverter, verifiers map[string]abcrypto.Verifier) error

Verify validates struct and verifies proof.

type Bills added in v0.1.1

type Bills struct {
	Bills []*Bill `protobuf:"bytes,1,rep,name=bills,proto3" json:"bills,omitempty"`
	// contains filtered or unexported fields
}

bills with tx proofs

func (*Bills) Descriptor deprecated added in v0.1.1

func (*Bills) Descriptor() ([]byte, []int)

Deprecated: Use Bills.ProtoReflect.Descriptor instead.

func (*Bills) GetBills added in v0.1.1

func (x *Bills) GetBills() []*Bill

func (*Bills) ProtoMessage added in v0.1.1

func (*Bills) ProtoMessage()

func (*Bills) ProtoReflect added in v0.1.1

func (x *Bills) ProtoReflect() protoreflect.Message

func (*Bills) Reset added in v0.1.1

func (x *Bills) Reset()

func (*Bills) String added in v0.1.1

func (x *Bills) String() string

func (*Bills) Verify added in v0.1.1

func (x *Bills) Verify(txConverter TxConverter, verifiers map[string]abcrypto.Verifier) error

Verify validates struct and verifies proofs.

type Block

type Block struct {
	SystemIdentifier   []byte                           `protobuf:"bytes,1,opt,name=system_identifier,json=systemIdentifier,proto3" json:"system_identifier,omitempty"`
	BlockNumber        uint64                           `protobuf:"varint,2,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"`
	PreviousBlockHash  []byte                           `protobuf:"bytes,3,opt,name=previous_block_hash,json=previousBlockHash,proto3" json:"previous_block_hash,omitempty"`
	Transactions       []*txsystem.Transaction          `protobuf:"bytes,4,rep,name=transactions,proto3" json:"transactions,omitempty"`
	UnicityCertificate *certificates.UnicityCertificate `protobuf:"bytes,5,opt,name=unicity_certificate,json=unicityCertificate,proto3" json:"unicity_certificate,omitempty"`
	// contains filtered or unexported fields
}

func (*Block) AddHeaderToHasher

func (x *Block) AddHeaderToHasher(hasher hash.Hash)

func (*Block) Descriptor deprecated

func (*Block) Descriptor() ([]byte, []int)

Deprecated: Use Block.ProtoReflect.Descriptor instead.

func (*Block) GetBlockNumber

func (x *Block) GetBlockNumber() uint64

func (*Block) GetPreviousBlockHash

func (x *Block) GetPreviousBlockHash() []byte

func (*Block) GetSystemIdentifier

func (x *Block) GetSystemIdentifier() []byte

func (*Block) GetTransactions

func (x *Block) GetTransactions() []*txsystem.Transaction

func (*Block) GetUnicityCertificate

func (x *Block) GetUnicityCertificate() *certificates.UnicityCertificate

func (*Block) Hash

func (x *Block) Hash(txConverter TxConverter, hashAlgorithm crypto.Hash) ([]byte, error)

Hash returns the hash of the block.

func (*Block) HashHeader

func (x *Block) HashHeader(hashAlgorithm crypto.Hash) []byte

func (*Block) ProtoMessage

func (*Block) ProtoMessage()

func (*Block) ProtoReflect

func (x *Block) ProtoReflect() protoreflect.Message

func (*Block) Reset

func (x *Block) Reset()

func (*Block) String

func (x *Block) String() string

func (*Block) ToGenericBlock added in v0.1.1

func (x *Block) ToGenericBlock(txConverter TxConverter) (*GenericBlock, error)

type BlockProof added in v0.1.1

type BlockProof struct {
	ProofType        ProofType `protobuf:"varint,1,opt,name=proof_type,json=proofType,proto3,enum=ProofType" json:"proof_type,omitempty"`
	BlockHeaderHash  []byte    `protobuf:"bytes,2,opt,name=block_header_hash,json=blockHeaderHash,proto3" json:"block_header_hash,omitempty"`
	TransactionsHash []byte    `protobuf:"bytes,3,opt,name=transactions_hash,json=transactionsHash,proto3" json:"transactions_hash,omitempty"`
	// hash value of either primary tx or secondary txs or zero hash, depending on proof type
	HashValue          []byte                           `protobuf:"bytes,4,opt,name=hash_value,json=hashValue,proto3" json:"hash_value,omitempty"`
	BlockTreeHashChain *BlockTreeHashChain              `protobuf:"bytes,5,opt,name=block_tree_hash_chain,json=blockTreeHashChain,proto3" json:"block_tree_hash_chain,omitempty"`
	SecTreeHashChain   *SecTreeHashChain                `protobuf:"bytes,6,opt,name=sec_tree_hash_chain,json=secTreeHashChain,proto3" json:"sec_tree_hash_chain,omitempty"`
	UnicityCertificate *certificates.UnicityCertificate `protobuf:"bytes,7,opt,name=unicity_certificate,json=unicityCertificate,proto3" json:"unicity_certificate,omitempty"`
	// contains filtered or unexported fields
}

func NewPrimaryProof added in v0.1.1

func NewPrimaryProof(b *GenericBlock, unitID []byte, hashAlgorithm crypto.Hash) (*BlockProof, error)

NewPrimaryProof creates primary proof for given unit and block.

func NewSecondaryProof added in v0.1.1

func NewSecondaryProof(b *GenericBlock, unitID []byte, secTxIdx int, hashAlgorithm crypto.Hash) (*BlockProof, error)

NewSecondaryProof creates secondary proof for given unit and block.

func (*BlockProof) AddToHasher added in v0.1.1

func (x *BlockProof) AddToHasher(hasher gohash.Hash)

func (*BlockProof) Bytes added in v0.1.1

func (x *BlockProof) Bytes() []byte

func (*BlockProof) Descriptor deprecated added in v0.1.1

func (*BlockProof) Descriptor() ([]byte, []int)

Deprecated: Use BlockProof.ProtoReflect.Descriptor instead.

func (*BlockProof) GetBlockHeaderHash added in v0.1.1

func (x *BlockProof) GetBlockHeaderHash() []byte

func (*BlockProof) GetBlockTreeHashChain added in v0.1.1

func (x *BlockProof) GetBlockTreeHashChain() *BlockTreeHashChain

func (*BlockProof) GetHashValue added in v0.1.1

func (x *BlockProof) GetHashValue() []byte

func (*BlockProof) GetProofType added in v0.1.1

func (x *BlockProof) GetProofType() ProofType

func (*BlockProof) GetSecTreeHashChain added in v0.1.1

func (x *BlockProof) GetSecTreeHashChain() *SecTreeHashChain

func (*BlockProof) GetTransactionsHash added in v0.1.1

func (x *BlockProof) GetTransactionsHash() []byte

func (*BlockProof) GetUnicityCertificate added in v0.1.1

func (x *BlockProof) GetUnicityCertificate() *certificates.UnicityCertificate

func (*BlockProof) ProtoMessage added in v0.1.1

func (*BlockProof) ProtoMessage()

func (*BlockProof) ProtoReflect added in v0.1.1

func (x *BlockProof) ProtoReflect() protoreflect.Message

func (*BlockProof) Reset added in v0.1.1

func (x *BlockProof) Reset()

func (*BlockProof) String added in v0.1.1

func (x *BlockProof) String() string

func (*BlockProof) Verify added in v0.1.1

func (x *BlockProof) Verify(unitID []byte, tx txsystem.GenericTransaction, verifiers map[string]abcrypto.Verifier, hashAlgorithm crypto.Hash) error

Verify verifies the proof against given transaction, returns error if verification failed, or nil if verification succeeded.

type BlockTreeHashChain added in v0.1.1

type BlockTreeHashChain struct {
	Items []*ChainItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
	// contains filtered or unexported fields
}

func (*BlockTreeHashChain) Descriptor deprecated added in v0.1.1

func (*BlockTreeHashChain) Descriptor() ([]byte, []int)

Deprecated: Use BlockTreeHashChain.ProtoReflect.Descriptor instead.

func (*BlockTreeHashChain) GetItems added in v0.1.1

func (x *BlockTreeHashChain) GetItems() []*ChainItem

func (*BlockTreeHashChain) ProtoMessage added in v0.1.1

func (*BlockTreeHashChain) ProtoMessage()

func (*BlockTreeHashChain) ProtoReflect added in v0.1.1

func (x *BlockTreeHashChain) ProtoReflect() protoreflect.Message

func (*BlockTreeHashChain) Reset added in v0.1.1

func (x *BlockTreeHashChain) Reset()

func (*BlockTreeHashChain) String added in v0.1.1

func (x *BlockTreeHashChain) String() string

type ChainItem added in v0.1.1

type ChainItem struct {
	Val  []byte `protobuf:"bytes,1,opt,name=val,proto3" json:"val,omitempty"`
	Hash []byte `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
	// contains filtered or unexported fields
}

func ToProtobufHashChain added in v0.1.1

func ToProtobufHashChain(chain []*omt.Data) []*ChainItem

ToProtobufHashChain utility function that converts []omt.Data to []ChainItem

func (*ChainItem) Descriptor deprecated added in v0.1.1

func (*ChainItem) Descriptor() ([]byte, []int)

Deprecated: Use ChainItem.ProtoReflect.Descriptor instead.

func (*ChainItem) GetHash added in v0.1.1

func (x *ChainItem) GetHash() []byte

func (*ChainItem) GetVal added in v0.1.1

func (x *ChainItem) GetVal() []byte

func (*ChainItem) ProtoMessage added in v0.1.1

func (*ChainItem) ProtoMessage()

func (*ChainItem) ProtoReflect added in v0.1.1

func (x *ChainItem) ProtoReflect() protoreflect.Message

func (*ChainItem) Reset added in v0.1.1

func (x *ChainItem) Reset()

func (*ChainItem) String added in v0.1.1

func (x *ChainItem) String() string

type GenericBlock added in v0.1.1

type GenericBlock struct {
	SystemIdentifier   []byte
	BlockNumber        uint64
	PreviousBlockHash  []byte
	Transactions       []txsystem.GenericTransaction
	UnicityCertificate *certificates.UnicityCertificate
}

GenericBlock same as Block but transactions are of type txsystem.GenericTransaction

func (*GenericBlock) AddHeaderToHasher added in v0.1.1

func (x *GenericBlock) AddHeaderToHasher(hasher hash.Hash)

func (*GenericBlock) Hash added in v0.1.1

func (x *GenericBlock) Hash(hashAlgorithm crypto.Hash) ([]byte, error)

Hash returns the hash of the block. Hash is computed from hash of block header fields || hash of raw block payload || tree hash of transactions

func (*GenericBlock) HashHeader added in v0.1.1

func (x *GenericBlock) HashHeader(hashAlgorithm crypto.Hash) []byte

func (*GenericBlock) ToProtobuf added in v0.1.1

func (x *GenericBlock) ToProtobuf() *Block

ToProtobuf converts GenericBlock to protobuf Block

type MerklePathItem added in v0.1.1

type MerklePathItem struct {

	// DirectionLeft direction from parent node; left=true right=false
	DirectionLeft bool `protobuf:"varint,1,opt,name=direction_left,json=directionLeft,proto3" json:"direction_left,omitempty"`
	// PathItem Hash of Merkle Tree node
	PathItem []byte `protobuf:"bytes,2,opt,name=path_item,json=pathItem,proto3" json:"path_item,omitempty"`
	// contains filtered or unexported fields
}

func ToProtobuf added in v0.1.1

func ToProtobuf(srcPathItmes []*mt.PathItem) []*MerklePathItem

ToProtobuf utility function that converts []*mt.PathItem to []*MerklePathItem

func (*MerklePathItem) Descriptor deprecated added in v0.1.1

func (*MerklePathItem) Descriptor() ([]byte, []int)

Deprecated: Use MerklePathItem.ProtoReflect.Descriptor instead.

func (*MerklePathItem) GetDirectionLeft added in v0.1.1

func (x *MerklePathItem) GetDirectionLeft() bool

func (*MerklePathItem) GetPathItem added in v0.1.1

func (x *MerklePathItem) GetPathItem() []byte

func (*MerklePathItem) ProtoMessage added in v0.1.1

func (*MerklePathItem) ProtoMessage()

func (*MerklePathItem) ProtoReflect added in v0.1.1

func (x *MerklePathItem) ProtoReflect() protoreflect.Message

func (*MerklePathItem) Reset added in v0.1.1

func (x *MerklePathItem) Reset()

func (*MerklePathItem) String added in v0.1.1

func (x *MerklePathItem) String() string

type PendingBlockProposal

type PendingBlockProposal struct {
	RoundNumber  uint64
	PrevHash     []byte
	StateHash    []byte
	Transactions []txsystem.GenericTransaction
}

type ProofType added in v0.1.1

type ProofType int32
const (
	ProofType_PRIM       ProofType = 0
	ProofType_SEC        ProofType = 1
	ProofType_ONLYSEC    ProofType = 2
	ProofType_NOTRANS    ProofType = 3
	ProofType_EMPTYBLOCK ProofType = 4
)

func (ProofType) Descriptor added in v0.1.1

func (ProofType) Descriptor() protoreflect.EnumDescriptor

func (ProofType) Enum added in v0.1.1

func (x ProofType) Enum() *ProofType

func (ProofType) EnumDescriptor deprecated added in v0.1.1

func (ProofType) EnumDescriptor() ([]byte, []int)

Deprecated: Use ProofType.Descriptor instead.

func (ProofType) Number added in v0.1.1

func (x ProofType) Number() protoreflect.EnumNumber

func (ProofType) String added in v0.1.1

func (x ProofType) String() string

func (ProofType) Type added in v0.1.1

type SecTreeHashChain added in v0.1.1

type SecTreeHashChain struct {
	Items []*MerklePathItem `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
	// contains filtered or unexported fields
}

func (*SecTreeHashChain) Descriptor deprecated added in v0.1.1

func (*SecTreeHashChain) Descriptor() ([]byte, []int)

Deprecated: Use SecTreeHashChain.ProtoReflect.Descriptor instead.

func (*SecTreeHashChain) GetItems added in v0.1.1

func (x *SecTreeHashChain) GetItems() []*MerklePathItem

func (*SecTreeHashChain) ProtoMessage added in v0.1.1

func (*SecTreeHashChain) ProtoMessage()

func (*SecTreeHashChain) ProtoReflect added in v0.1.1

func (x *SecTreeHashChain) ProtoReflect() protoreflect.Message

func (*SecTreeHashChain) Reset added in v0.1.1

func (x *SecTreeHashChain) Reset()

func (*SecTreeHashChain) String added in v0.1.1

func (x *SecTreeHashChain) String() string

type TxConverter added in v0.1.1

type TxConverter interface {
	ConvertTx(tx *txsystem.Transaction) (txsystem.GenericTransaction, error)
}

type TxProof added in v0.1.1

type TxProof struct {
	BlockNumber uint64                `protobuf:"varint,1,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"`
	Tx          *txsystem.Transaction `protobuf:"bytes,2,opt,name=tx,proto3" json:"tx,omitempty"`
	Proof       *BlockProof           `protobuf:"bytes,3,opt,name=proof,proto3" json:"proof,omitempty"`
	// contains filtered or unexported fields
}

tx proof context

func (*TxProof) Descriptor deprecated added in v0.1.1

func (*TxProof) Descriptor() ([]byte, []int)

Deprecated: Use TxProof.ProtoReflect.Descriptor instead.

func (*TxProof) GetBlockNumber added in v0.1.1

func (x *TxProof) GetBlockNumber() uint64

func (*TxProof) GetProof added in v0.1.1

func (x *TxProof) GetProof() *BlockProof

func (*TxProof) GetTx added in v0.1.1

func (x *TxProof) GetTx() *txsystem.Transaction

func (*TxProof) ProtoMessage added in v0.1.1

func (*TxProof) ProtoMessage()

func (*TxProof) ProtoReflect added in v0.1.1

func (x *TxProof) ProtoReflect() protoreflect.Message

func (*TxProof) Reset added in v0.1.1

func (x *TxProof) Reset()

func (*TxProof) String added in v0.1.1

func (x *TxProof) String() string

func (*TxProof) Verify added in v0.1.1

func (x *TxProof) Verify(unitID []byte, gtx txsystem.GenericTransaction, verifiers map[string]abcrypto.Verifier, hashAlgo crypto.Hash) error

Jump to

Keyboard shortcuts

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