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 ¶
- type Block
- type Content
- type FileInfo
- type FileMeta
- type FlowControlMeta
- type MerkleTree
- func (m *MerkleTree) GetMerklePath(content Content) ([][]byte, []int64, error)
- func (m *MerkleTree) MerkleRoot() []byte
- func (m *MerkleTree) RebuildTree() error
- func (m *MerkleTree) RebuildTreeWith(cs []Content) error
- func (m *MerkleTree) String() string
- func (m *MerkleTree) VerifyContent(content Content) (bool, error)
- func (m *MerkleTree) VerifyTree() (bool, error)
- type Node
- type Transaction
- type TxReceipt
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 ¶
MarshalJSON marshals as JSON.
func (*Block) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.
type Content ¶
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 ¶
MarshalJSON marshals as JSON.
func (*FileInfo) UnmarshalJSON ¶
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 ¶
MarshalJSON marshals as JSON.
func (*FileMeta) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.
type FlowControlMeta ¶
type MerkleTree ¶
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.
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) MarshalJSON ¶
func (t Transaction) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
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 ¶
MarshalJSON marshals as JSON.
func (*TxReceipt) UnmarshalJSON ¶
UnmarshalJSON unmarshals from JSON.