iotex-core: Index | Files | Directories

package mainchain

import ""


Package Files

createdeposit.go datamodel.go protocol.go putblock.go startsubchain.go stopsubchain.go


const ProtocolID = "multi-chain_main-chain"

ProtocolID is the protocol ID TODO: it works only for one instance per protocol definition now


var (
    // MinSecurityDeposit represents the security deposit minimal required for start a sub-chain, which is 1M iotx
    MinSecurityDeposit = big.NewInt(0).Mul(big.NewInt(1000000), big.NewInt(unit.Iotx))
    // SubChainsInOperationKey is to find the used chain IDs in the state factory
    // TODO: this is a not safe way to define the key, as other protocols could collide it
    SubChainsInOperationKey = hash.Hash160b([]byte("subChainsInOperation"))

func DepositAddress Uses

func DepositAddress(subChainAddr []byte, depositIndex uint64) hash.Hash160

DepositAddress returns the deposit address (20-byte)

type BlockProof Uses

type BlockProof struct {
    SubChainAddress   string
    Height            uint64
    Roots             []MerkleRoot
    ProducerPublicKey crypto.PublicKey
    ProducerAddress   string

BlockProof represents the block proof of a sub-chain in the state factory

func (*BlockProof) Deserialize Uses

func (bp *BlockProof) Deserialize(data []byte) error

Deserialize deserialize bytes into block proof state

func (BlockProof) Serialize Uses

func (bp BlockProof) Serialize() ([]byte, error)

Serialize serialize block proof state into bytes

type Deposit Uses

type Deposit struct {
    Amount    *big.Int
    Addr      []byte
    Confirmed bool

Deposit represents the state of a deposit

func (*Deposit) Deserialize Uses

func (bs *Deposit) Deserialize(data []byte) error

Deserialize deserializes bytes into deposit state

func (Deposit) Serialize Uses

func (bs Deposit) Serialize() ([]byte, error)

Serialize serializes deposit state into bytes

type InOperation Uses

type InOperation struct {
    ID   uint32
    Addr []byte

InOperation represents a record of a sub-chain in operation

type MerkleRoot Uses

type MerkleRoot struct {
    Name  string
    Value hash.Hash256

MerkleRoot defines a merkle root in block proof.

type Protocol Uses

type Protocol struct {
    // contains filtered or unexported fields

Protocol defines the protocol of handling multi-chain actions on main-chain

func NewProtocol Uses

func NewProtocol(rootChain blockchain.Blockchain) *Protocol

NewProtocol instantiates the protocol of sub-chain

func (*Protocol) Deposit Uses

func (p *Protocol) Deposit(subChainAddr address.Address, depositIndex uint64) (*Deposit, error)

Deposit returns the deposit record

func (*Protocol) Handle Uses

func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error)

Handle handles how to mutate the state db given the multi-chain action on main-chain

func (*Protocol) ReadState Uses

func (p *Protocol) ReadState(context.Context, protocol.StateManager, []byte, ...[]byte) ([]byte, error)

ReadState read the state on blockchain via protocol

func (*Protocol) SubChain Uses

func (p *Protocol) SubChain(addr address.Address) (*SubChain, error)

SubChain returns the confirmed sub-chain state

func (*Protocol) SubChainsInOperation Uses

func (p *Protocol) SubChainsInOperation() (SubChainsInOperation, error)

SubChainsInOperation returns the used chain IDs

func (*Protocol) Validate Uses

func (p *Protocol) Validate(ctx context.Context, act action.Action) error

Validate validates the multi-chain action on main-chain

type StartSubChainReceipt Uses

type StartSubChainReceipt struct {
    SubChainAddress string

StartSubChainReceipt is the receipt to user after executed start sub chain operation.

type SubChain Uses

type SubChain struct {
    ChainID            uint32
    SecurityDeposit    *big.Int
    OperationDeposit   *big.Int
    StartHeight        uint64
    StopHeight         uint64
    ParentHeightOffset uint64
    OwnerPublicKey     crypto.PublicKey
    CurrentHeight      uint64
    DepositCount       uint64

SubChain represents the state of a sub-chain in the state factory

func (*SubChain) Deserialize Uses

func (bs *SubChain) Deserialize(data []byte) error

Deserialize deserializes bytes into sub-chain state

func (SubChain) Serialize Uses

func (bs SubChain) Serialize() ([]byte, error)

Serialize serializes sub-chain state into bytes

type SubChainsInOperation Uses

type SubChainsInOperation []InOperation

SubChainsInOperation is a list of InOperation.

func (SubChainsInOperation) Append Uses

func (s SubChainsInOperation) Append(in InOperation) SubChainsInOperation

Append appends an element and return the new list.

func (SubChainsInOperation) Delete Uses

func (s SubChainsInOperation) Delete(id uint32) (SubChainsInOperation, bool)

Delete deletes an element and return the new list.

func (*SubChainsInOperation) Deserialize Uses

func (s *SubChainsInOperation) Deserialize(data []byte) error

Deserialize deserializes list from binary.

func (SubChainsInOperation) Get Uses

func (s SubChainsInOperation) Get(id uint32) (InOperation, bool)

Get gets an element with given ID.

func (SubChainsInOperation) Len Uses

func (s SubChainsInOperation) Len() int

Len returns length.

func (SubChainsInOperation) Less Uses

func (s SubChainsInOperation) Less(i, j int) bool

Less compares InOperation in list.

func (SubChainsInOperation) Serialize Uses

func (s SubChainsInOperation) Serialize() ([]byte, error)

Serialize serializes list to binary.

func (SubChainsInOperation) Sort Uses

func (s SubChainsInOperation) Sort()

Sort sorts SubChainsInOperation.

func (SubChainsInOperation) Swap Uses

func (s SubChainsInOperation) Swap(i, j int)

Swap swaps elements in list.



Package mainchain imports 18 packages (graph) and is imported by 1 packages. Updated 2019-07-31. Refresh now. Tools for package owners.