mainchain

package
v0.5.0-rc4-hotfix Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolID = "multi-chain_main-chain"

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

Variables

View Source
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"))
)

Functions

func DepositAddress

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

DepositAddress returns the deposit address (20-byte)

Types

type BlockProof

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

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

func (*BlockProof) Deserialize

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

Deserialize deserialize bytes into block proof state

func (BlockProof) Serialize

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

Serialize serialize block proof state into bytes

type Deposit

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

Deposit represents the state of a deposit

func (*Deposit) Deserialize

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

Deserialize deserializes bytes into deposit state

func (Deposit) Serialize

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

Serialize serializes deposit state into bytes

type InOperation

type InOperation struct {
	ID   uint32
	Addr []byte
}

InOperation represents a record of a sub-chain in operation

type MerkleRoot

type MerkleRoot struct {
	Name  string
	Value hash.Hash256
}

MerkleRoot defines a merkle root in block proof.

type Protocol

type Protocol struct {
	// contains filtered or unexported fields
}

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

func NewProtocol

func NewProtocol(rootChain blockchain.Blockchain) *Protocol

NewProtocol instantiates the protocol of sub-chain

func (*Protocol) Deposit

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

Deposit returns the deposit record

func (*Protocol) Handle

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

func (*Protocol) ReadState

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

ReadState read the state on blockchain via protocol

func (*Protocol) SubChain

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

SubChain returns the confirmed sub-chain state

func (*Protocol) SubChainsInOperation

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

SubChainsInOperation returns the used chain IDs

func (*Protocol) Validate

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

Validate validates the multi-chain action on main-chain

type StartSubChainReceipt

type StartSubChainReceipt struct {
	SubChainAddress string
}

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

type SubChain

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

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

func (*SubChain) Deserialize

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

Deserialize deserializes bytes into sub-chain state

func (SubChain) Serialize

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

Serialize serializes sub-chain state into bytes

type SubChainsInOperation

type SubChainsInOperation []InOperation

SubChainsInOperation is a list of InOperation.

func (SubChainsInOperation) Append

Append appends an element and return the new list.

func (SubChainsInOperation) Delete

Delete deletes an element and return the new list.

func (*SubChainsInOperation) Deserialize

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

Deserialize deserializes list from binary.

func (SubChainsInOperation) Get

Get gets an element with given ID.

func (SubChainsInOperation) Len

func (s SubChainsInOperation) Len() int

Len returns length.

func (SubChainsInOperation) Less

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

Less compares InOperation in list.

func (SubChainsInOperation) Serialize

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

Serialize serializes list to binary.

func (SubChainsInOperation) Sort

func (s SubChainsInOperation) Sort()

Sort sorts SubChainsInOperation.

func (SubChainsInOperation) Swap

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

Swap swaps elements in list.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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