types

package
v1.9.55 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: GPL-3.0, GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright 2020 The CortexTheseus Authors This file is part of the CortexTheseus library.

The CortexTheseus library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The CortexTheseus library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the CortexTheseus library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Number uint64      `json:"number"           gencodec:"required"`
	Hash   common.Hash `json:"Hash"             gencodec:"required"`
	//ParentHash common.Hash   `json:"parentHash"       gencodec:"required"`
	Txs []Transaction `json:"Transactions"     gencodec:"required"`
}

gencodec -type Block -field-override blockMarshaling -out gen_block_json.go Block ... block struct

func (Block) MarshalJSON

func (b Block) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Block) UnmarshalJSON

func (b *Block) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Content

type Content interface {
	CalculateHash() ([]byte, error)
	Equals(other Content) (bool, error)
}

Content represents the data that is stored and verified by the tree. A type that implements this interface can be used as an item in the tree.

type FileInfo

type FileInfo struct {
	Meta *FileMeta
	// Transaction hash
	//TxHash *common.Hash
	// Contract Address
	ContractAddr *common.Address
	LeftSize     uint64
	Relate       []common.Address
}

func (FileInfo) MarshalJSON

func (f FileInfo) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*FileInfo) UnmarshalJSON

func (f *FileInfo) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type FileMeta

type FileMeta struct {
	InfoHash metainfo.Hash `json:"InfoHash"         gencodec:"required"`
	//	Name     string        `json:"Name"             gencodec:"required"`
	// The raw size of the file counted in bytes
	RawSize uint64 `json:"RawSize"          gencodec:"required"`
}

FileMeta ...

func (FileMeta) MarshalJSON

func (f FileMeta) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*FileMeta) UnmarshalJSON

func (f *FileMeta) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type FlowControlMeta

type FlowControlMeta struct {
	InfoHash       metainfo.Hash
	BytesRequested uint64
	IsCreate       bool
}

type MerkleTree

type MerkleTree struct {
	Root *Node

	Leafs []*Node
	// contains filtered or unexported fields
}

MerkleTree is the container for the tree. It holds a pointer to the root of the tree, a list of pointers to the leaf nodes, and the merkle root.

func NewTree

func NewTree(cs []Content) (*MerkleTree, error)

NewTree creates a new Merkle Tree using the content cs.

func NewTreeWithHashStrategy

func NewTreeWithHashStrategy(cs []Content, hashStrategy func() hash.Hash) (*MerkleTree, error)

NewTreeWithHashStrategy creates a new Merkle Tree using the content cs using the provided hash strategy. Note that the hash type used in the type that implements the Content interface must match the hash type profided to the tree.

func (*MerkleTree) GetMerklePath

func (m *MerkleTree) GetMerklePath(content Content) ([][]byte, []int64, error)

GetMerklePath: Get Merkle path and indexes(left leaf or right leaf)

func (*MerkleTree) MerkleRoot

func (m *MerkleTree) MerkleRoot() []byte

MerkleRoot returns the unverified Merkle Root (hash of the root node) of the tree.

func (*MerkleTree) RebuildTree

func (m *MerkleTree) RebuildTree() error

RebuildTree is a helper function that will rebuild the tree reusing only the content that it holds in the leaves.

func (*MerkleTree) RebuildTreeWith

func (m *MerkleTree) RebuildTreeWith(cs []Content) error

RebuildTreeWith replaces the content of the tree and does a complete rebuild; while the root of the tree will be replaced the MerkleTree completely survives this operation. Returns an error if the list of content cs contains no entries.

func (*MerkleTree) String

func (m *MerkleTree) String() string

String returns a string representation of the tree. Only leaf nodes are included in the output.

func (*MerkleTree) VerifyContent

func (m *MerkleTree) VerifyContent(content Content) (bool, error)

VerifyContent indicates whether a given content is in the tree and the hashes are valid for that content. Returns true if the expected Merkle Root is equivalent to the Merkle root calculated on the critical path for a given content. Returns true if valid and false otherwise.

func (*MerkleTree) VerifyTree

func (m *MerkleTree) VerifyTree() (bool, error)

VerifyTree verify tree validates the hashes at each level of the tree and returns true if the resulting hash at the root of the tree matches the resulting root hash; returns false otherwise.

type Node

type Node struct {
	Tree   *MerkleTree
	Parent *Node
	Left   *Node
	Right  *Node

	Hash []byte
	C    Content
	// contains filtered or unexported fields
}

Node represents a node, root, or leaf in the tree. It stores pointers to its immediate relationships, a hash, the content stored if it is a leaf, and other metadata.

func (*Node) String

func (n *Node) String() string

String returns a string representation of the node.

type Transaction

type Transaction struct {
	//Price     *big.Int        `json:"gasPrice" gencodec:"required"`
	Amount   *big.Int `json:"value"    gencodec:"required"`
	GasLimit uint64   `json:"gas"      gencodec:"required"`
	Payload  []byte   `json:"input"    gencodec:"required"`
	//From      *common.Address `json:"from"     gencodec:"required"`
	Recipient *common.Address `json:"to"       rlp:"nil"` // nil means contract creation
	Hash      *common.Hash    `json:"hash"     gencodec:"required"`
}

Transaction ... Tx struct

func (*Transaction) Data

func (t *Transaction) Data() []byte

Data ...

func (*Transaction) IsFlowControl

func (t *Transaction) IsFlowControl() bool

IsFlowControl ...

func (Transaction) MarshalJSON

func (t Transaction) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Transaction) Op

func (t *Transaction) Op() (op int)

Op ...

func (*Transaction) Parse

func (t *Transaction) Parse() *FileMeta

func (*Transaction) UnmarshalJSON

func (t *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type TxReceipt

type TxReceipt struct {
	// Contract Address
	ContractAddr *common.Address `json:"ContractAddress"  gencodec:"required"`
	// Transaction Hash
	TxHash *common.Hash `json:"TransactionHash"  gencodec:"required"`
	//Receipt   *TxReceipt      `json:"receipt"  rlp:"nil"`
	GasUsed uint64 `json:"gasUsed" gencodec:"required"`
	Status  uint64 `json:"status"`
}

TxReceipt ...

func (TxReceipt) MarshalJSON

func (r TxReceipt) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*TxReceipt) UnmarshalJSON

func (r *TxReceipt) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

Jump to

Keyboard shortcuts

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