Documentation ¶
Index ¶
- Constants
- Variables
- func DepositAddress(subChainAddr []byte, depositIndex uint64) hash.Hash160
- type BlockProof
- type Deposit
- type InOperation
- type MerkleRoot
- type Protocol
- func (p *Protocol) Deposit(subChainAddr address.Address, depositIndex uint64) (*Deposit, error)
- func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.StateManager) (*action.Receipt, error)
- func (p *Protocol) ReadState(context.Context, protocol.StateManager, []byte, ...[]byte) ([]byte, error)
- func (p *Protocol) SubChain(addr address.Address) (*SubChain, error)
- func (p *Protocol) SubChainsInOperation() (SubChainsInOperation, error)
- func (p *Protocol) Validate(ctx context.Context, act action.Action) error
- type StartSubChainReceipt
- type SubChain
- type SubChainsInOperation
- func (s SubChainsInOperation) Append(in InOperation) SubChainsInOperation
- func (s SubChainsInOperation) Delete(id uint32) (SubChainsInOperation, bool)
- func (s *SubChainsInOperation) Deserialize(data []byte) error
- func (s SubChainsInOperation) Get(id uint32) (InOperation, bool)
- func (s SubChainsInOperation) Len() int
- func (s SubChainsInOperation) Less(i, j int) bool
- func (s SubChainsInOperation) Serialize() ([]byte, error)
- func (s SubChainsInOperation) Sort()
- func (s SubChainsInOperation) Swap(i, j int)
Constants ¶
const ProtocolID = "multi-chain_main-chain"
ProtocolID is the protocol ID TODO: it works only for one instance per protocol definition now
Variables ¶
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 ¶
Types ¶
type BlockProof ¶
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 ¶
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 ¶
Deposit represents the state of a deposit
func (*Deposit) Deserialize ¶
Deserialize deserializes bytes into deposit state
type InOperation ¶
InOperation represents a record of a sub-chain in operation
type MerkleRoot ¶
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) Handle ¶
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 ¶ added in v0.5.0
func (p *Protocol) ReadState(context.Context, protocol.StateManager, []byte, ...[]byte) ([]byte, error)
ReadState read the state on blockchain via protocol
func (*Protocol) SubChainsInOperation ¶
func (p *Protocol) SubChainsInOperation() (SubChainsInOperation, error)
SubChainsInOperation returns the used chain IDs
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 crypto.PublicKey CurrentHeight uint64 DepositCount uint64 }
SubChain represents the state of a sub-chain in the state factory
func (*SubChain) Deserialize ¶
Deserialize deserializes bytes into sub-chain state
type SubChainsInOperation ¶
type SubChainsInOperation []InOperation
SubChainsInOperation is a list of InOperation.
func (SubChainsInOperation) Append ¶
func (s SubChainsInOperation) Append(in InOperation) SubChainsInOperation
Append appends an element and return the new list.
func (SubChainsInOperation) Delete ¶
func (s SubChainsInOperation) Delete(id uint32) (SubChainsInOperation, bool)
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 ¶
func (s SubChainsInOperation) Get(id uint32) (InOperation, bool)
Get gets an element with given ID.
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.