types

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ModuleName is the name of the module
	ModuleName = "cross"

	// Version defines the current version the Cross
	// module supports
	Version = "cross-1"

	// PortID that Cross module binds to
	PortID = "cross"

	// StoreKey to be used when creating the KVStore
	StoreKey = ModuleName

	// RouterKey is the msg router key for the IBC module
	RouterKey string = ModuleName

	// QuerierRoute is the querier route for Cross
	QuerierRoute = ModuleName
)
View Source
const (
	TypeInitiate      = "cross_initiate"
	TypePrepare       = "cross_prepare"
	TypePrepareResult = "cross_prepare_result"
	TypeCommit        = "cross_commit"
	TypeAckCommit     = "cross_ack_commit"
)
View Source
const (
	KeyCoordinatorPrefix uint8 = iota
	KeyTxPrefix
	KeyContractResultPrefix
	KeyUnacknowledgedPacketPrefix
)
View Source
const (
	PREPARE_RESULT_OK uint8 = iota + 1
	PREPARE_RESULT_FAILED
)
View Source
const (
	QueryCoordinatorStatus     = "coordinator_status"
	QueryUnacknowledgedPackets = "unacknowledged_packets"
)
View Source
const (
	CO_STATUS_NONE uint8 = iota
	CO_STATUS_INIT
	CO_STATUS_DECIDED // abort or commit

	CO_DECISION_NONE uint8 = iota
	CO_DECISION_COMMIT
	CO_DECISION_ABORT
)
View Source
const (
	TX_STATUS_PREPARE uint8 = iota + 1
	TX_STATUS_COMMIT
	TX_STATUS_ABORT
)
View Source
const (
	MaxContractTransactoinNum = math.MaxUint8
)

Variables

View Source
var (
	ErrFailedInitiateTx             = sdkerrors.Register(ModuleName, 2, "failed to initiate a transaction")
	ErrFailedPrepare                = sdkerrors.Register(ModuleName, 3, "failed to prepare a commit")
	ErrFailedRecievePrepareResult   = sdkerrors.Register(ModuleName, 4, "failed to receive a PrepareResult")
	ErrFailedMulticastCommitPacket  = sdkerrors.Register(ModuleName, 5, "failed to multicast a CommitPacket")
	ErrFailedReceiveCommitPacket    = sdkerrors.Register(ModuleName, 6, "failed to receive a CommitPacket")
	ErrFailedSendAckCommitPacket    = sdkerrors.Register(ModuleName, 7, "failed to send an AckCommitPacket")
	ErrFailedReceiveAckCommitPacket = sdkerrors.Register(ModuleName, 8, "failed to receive an AckCommitPacket")

	ErrCoordinatorNotFound = sdkerrors.Register(ModuleName, 100, "coordinator not found")
)
View Source
var ModuleCdc = codec.New()

ModuleCdc is the codec for the module

Functions

func KeyContractResult

func KeyContractResult(txID TxID, txIndex TxIndex) []byte

func KeyCoordinator

func KeyCoordinator(txID TxID) []byte

func KeyPrefixBytes

func KeyPrefixBytes(prefix uint8) []byte

KeyPrefixBytes return the key prefix bytes from a URL string format

func KeyTx

func KeyTx(txID TxID, txIndex TxIndex) []byte

func KeyUnacknowledgedPacket

func KeyUnacknowledgedPacket(sourcePort, sourceChannel string, seq uint64) []byte

func MakeHashFromABCIHeader

func MakeHashFromABCIHeader(header abci.Header) *tmtypes.Header

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on the Amino codec

func SignersFromContext

func SignersFromContext(ctx sdk.Context) ([]sdk.AccAddress, bool)

func WithSigners

func WithSigners(ctx sdk.Context, signers []sdk.AccAddress) sdk.Context

Types

type ChannelInfo

type ChannelInfo struct {
	Port    string `json:"port" yaml:"port"`       // the port on which the packet will be sent
	Channel string `json:"channel" yaml:"channel"` // the channel by which the packet will be sent
}

func NewChannelInfo

func NewChannelInfo(port, channel string) ChannelInfo

func (ChannelInfo) ValidateBasic

func (c ChannelInfo) ValidateBasic() error

type ChannelKeeper

type ChannelKeeper interface {
	GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channel.Channel, found bool)
	GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
	SendPacket(ctx sdk.Context, channelCap *capability.Capability, packet channelexported.PacketI) error
	PacketExecuted(ctx sdk.Context, chanCap *capability.Capability, packet channelexported.PacketI, acknowledgement []byte) error
}

ChannelKeeper defines the expected IBC channel keeper

type Committer

type Committer interface {
	Precommit(id []byte) error
	Commit(id []byte) error
	CommitImmediately() error
	Discard(id []byte) error
	OPs() OPs
}

type ContractCallInfo added in v0.0.3

type ContractCallInfo []byte

type ContractCallResult

type ContractCallResult struct {
	ChainID         string           `json:"chain_id" yaml:"chain_id"`
	Height          int64            `json:"height" yaml:"height"`
	Signers         []sdk.AccAddress `json:"signers" yaml:"signers"`
	CallInfo        ContractCallInfo `json:"call_info" yaml:"call_info"`
	StateConstraint StateConstraint  `json:"state_constraint" yaml:"state_constraint"`
}

func (ContractCallResult) String

func (r ContractCallResult) String() string

type ContractHandler

type ContractHandler interface {
	GetState(ctx sdk.Context, tp StateConstraintType, callInfo ContractCallInfo) (State, error)
	Handle(ctx sdk.Context, tp StateConstraintType, callInfo ContractCallInfo) (State, ContractHandlerResult, error)
	OnCommit(ctx sdk.Context, result ContractHandlerResult) ContractHandlerResult
}

type ContractHandlerAbortResult

type ContractHandlerAbortResult struct{}

func (ContractHandlerAbortResult) GetData

func (ContractHandlerAbortResult) GetData() []byte

func (ContractHandlerAbortResult) GetEvents

type ContractHandlerResult

type ContractHandlerResult interface {
	GetData() []byte
	GetEvents() sdk.Events
}

type ContractTransaction

type ContractTransaction struct {
	Source          ChannelInfo      `json:"source" yaml:"source"`
	Signers         []sdk.AccAddress `json:"signers" yaml:"signers"`
	CallInfo        ContractCallInfo `json:"call_info" yaml:"call_info"`
	StateConstraint StateConstraint  `json:"state_constraint" yaml:"state_constraint"`
}

func NewContractTransaction

func NewContractTransaction(src ChannelInfo, signers []sdk.AccAddress, callInfo ContractCallInfo, cond StateConstraint) ContractTransaction

func (ContractTransaction) ValidateBasic

func (t ContractTransaction) ValidateBasic() error

type ContractTransactions

type ContractTransactions = []ContractTransaction

type CoordinatorInfo

type CoordinatorInfo struct {
	Transactions []string      // {TransactionID => ConnectionID}
	Channels     []ChannelInfo // {TransactionID => Channel}

	Status                uint8
	Decision              uint8
	ConfirmedTransactions []TxIndex // [TransactionID]
	Acks                  []TxIndex // [TransactionID]
}

func NewCoordinatorInfo

func NewCoordinatorInfo(status uint8, tss []string, channels []ChannelInfo) CoordinatorInfo

func (*CoordinatorInfo) AddAck

func (ci *CoordinatorInfo) AddAck(txIndex TxIndex) bool

func (*CoordinatorInfo) Confirm

func (ci *CoordinatorInfo) Confirm(txIndex TxIndex, connectionID string) error

func (*CoordinatorInfo) IsCompleted

func (ci *CoordinatorInfo) IsCompleted() bool

func (*CoordinatorInfo) IsReceivedALLAcks

func (ci *CoordinatorInfo) IsReceivedALLAcks() bool

type HexByteArray32

type HexByteArray32 [32]byte

func (HexByteArray32) Bytes

func (bz HexByteArray32) Bytes() []byte

Allow it to fulfill various interfaces in light-client, etc...

func (HexByteArray32) Format

func (bz HexByteArray32) Format(s fmt.State, verb rune)

func (*HexByteArray32) FromString

func (bz *HexByteArray32) FromString(s string) error

func (HexByteArray32) Marshal

func (bz HexByteArray32) Marshal() ([]byte, error)

Marshal needed for protobuf compatibility

func (HexByteArray32) MarshalJSON

func (bz HexByteArray32) MarshalJSON() ([]byte, error)

This is the point of Bytes.

func (HexByteArray32) String

func (bz HexByteArray32) String() string

func (*HexByteArray32) Unmarshal

func (bz *HexByteArray32) Unmarshal(data []byte) error

Unmarshal needed for protobuf compatibility

func (*HexByteArray32) UnmarshalJSON

func (bz *HexByteArray32) UnmarshalJSON(data []byte) error

This is the point of Bytes.

type MsgInitiate

type MsgInitiate struct {
	Sender               sdk.AccAddress
	ChainID              string // chainID of Coordinator node
	ContractTransactions []ContractTransaction
	TimeoutHeight        int64 // Timeout for this msg
	Nonce                uint64
}

func NewMsgInitiate

func NewMsgInitiate(sender sdk.AccAddress, chainID string, transactions []ContractTransaction, timeoutHeight int64, nonce uint64) MsgInitiate

func (MsgInitiate) GetSignBytes

func (msg MsgInitiate) GetSignBytes() []byte

GetSignBytes implements sdk.Msg

func (MsgInitiate) GetSigners

func (msg MsgInitiate) GetSigners() []sdk.AccAddress

GetSigners implements sdk.Msg GetSigners returns the addresses that must sign the transaction. Addresses are returned in a deterministic order. Duplicate addresses will be omitted.

func (MsgInitiate) Route

func (MsgInitiate) Route() string

Route implements sdk.Msg

func (MsgInitiate) Type

func (MsgInitiate) Type() string

Type implements sdk.Msg

func (MsgInitiate) ValidateBasic

func (msg MsgInitiate) ValidateBasic() error

ValidateBasic implements sdk.Msg

type OP

type OP interface {
	Equal(OP) bool
	String() string
}

type OPs

type OPs []OP

func (OPs) Equal

func (ops OPs) Equal(other OPs) bool

func (OPs) String

func (ops OPs) String() string

type PacketAcknowledgement

type PacketAcknowledgement interface {
	ValidateBasic() error
	GetBytes() []byte
	Type() string
}

type PacketCommitAcknowledgement

type PacketCommitAcknowledgement struct{}

func NewPacketCommitAcknowledgement

func NewPacketCommitAcknowledgement() PacketCommitAcknowledgement

func (PacketCommitAcknowledgement) GetBytes

func (p PacketCommitAcknowledgement) GetBytes() []byte

func (PacketCommitAcknowledgement) Type

func (PacketCommitAcknowledgement) ValidateBasic

func (p PacketCommitAcknowledgement) ValidateBasic() error

type PacketData

type PacketData interface {
	ValidateBasic() error
	GetBytes() []byte
	GetTimeoutHeight() uint64
	GetTimeoutTimestamp() uint64
	Type() string
}

type PacketDataCommit

type PacketDataCommit struct {
	TxID          TxID
	TxIndex       TxIndex
	IsCommittable bool
}

func NewPacketDataCommit

func NewPacketDataCommit(txID TxID, txIndex TxIndex, isCommittable bool) PacketDataCommit

func (PacketDataCommit) GetBytes

func (p PacketDataCommit) GetBytes() []byte

func (PacketDataCommit) GetTimeoutHeight

func (p PacketDataCommit) GetTimeoutHeight() uint64

func (PacketDataCommit) GetTimeoutTimestamp

func (p PacketDataCommit) GetTimeoutTimestamp() uint64

func (PacketDataCommit) Type

func (p PacketDataCommit) Type() string

func (PacketDataCommit) ValidateBasic

func (p PacketDataCommit) ValidateBasic() error

type PacketDataPrepare

type PacketDataPrepare struct {
	Sender              sdk.AccAddress
	TxID                TxID
	TxIndex             TxIndex
	ContractTransaction ContractTransaction
}

func NewPacketDataPrepare

func NewPacketDataPrepare(sender sdk.AccAddress, txID TxID, txIndex TxIndex, transaction ContractTransaction) PacketDataPrepare

func (PacketDataPrepare) GetBytes

func (p PacketDataPrepare) GetBytes() []byte

func (PacketDataPrepare) GetTimeoutHeight

func (p PacketDataPrepare) GetTimeoutHeight() uint64

func (PacketDataPrepare) GetTimeoutTimestamp

func (p PacketDataPrepare) GetTimeoutTimestamp() uint64

func (PacketDataPrepare) Type

func (p PacketDataPrepare) Type() string

func (PacketDataPrepare) ValidateBasic

func (p PacketDataPrepare) ValidateBasic() error

type PacketPrepareAcknowledgement

type PacketPrepareAcknowledgement struct {
	Status uint8
}

func NewPacketPrepareAcknowledgement

func NewPacketPrepareAcknowledgement(status uint8) PacketPrepareAcknowledgement

func (PacketPrepareAcknowledgement) GetBytes

func (p PacketPrepareAcknowledgement) GetBytes() []byte

func (PacketPrepareAcknowledgement) IsOK

func (PacketPrepareAcknowledgement) Type

func (PacketPrepareAcknowledgement) ValidateBasic

func (p PacketPrepareAcknowledgement) ValidateBasic() error

type PortKeeper

type PortKeeper interface {
	BindPort(ctx sdk.Context, portID string) *capability.Capability
}

PortKeeper defines the expected IBC port keeper

type QueryCoordinatorStatusRequest

type QueryCoordinatorStatusRequest struct {
	TxID TxID `json:"tx_id" yaml:"tx_id"`
}

type QueryCoordinatorStatusResponse

type QueryCoordinatorStatusResponse struct {
	TxID            TxID            `json:"tx_id" yaml:"tx_id"`
	CoordinatorInfo CoordinatorInfo `json:"coordinator_info" yaml:"coordinator_info"`
	Completed       bool            `json:"completed" yaml:"completed"`
}

type QueryUnacknowledgedPacketsRequest

type QueryUnacknowledgedPacketsRequest struct{}

type QueryUnacknowledgedPacketsResponse

type QueryUnacknowledgedPacketsResponse struct {
	Packets []UnacknowledgedPacket `json:"packets" yaml:"packets"`
}

type State

type State interface {
	Store
	Committer
}

type StateConstraint added in v0.0.3

type StateConstraint struct {
	Type StateConstraintType `json:"type" yaml:"type"`
	OPs  OPs                 `json:"ops" yaml:"ops"`
}

func NewStateConstraint added in v0.0.3

func NewStateConstraint(tp StateConstraintType, ops OPs) StateConstraint

type StateConstraintType added in v0.0.3

type StateConstraintType = uint8
const (
	NoStateConstraint         StateConstraintType = iota // NoStateConstraint indicates that no constraints on the state before and after the precommit is performed
	ExactMatchStateConstraint                            // ExactMatchStateConstraint indicates the constraint on state state before and after the precommit is performed
	PreStateConstraint                                   // PreStateConstraint indicates the constraint on state before the precommit is performed
	PostStateConstraint                                  // PostStateConstraint indicates the constraint on state after the precommit is performed
)

type Store

type Store interface {
	// Get returns nil iff key doesn't exist. Panics on nil key.
	Get(key []byte) []byte

	// Has checks if a key exists. Panics on nil key.
	Has(key []byte) bool

	// Set sets the key. Panics on nil key or value.
	Set(key, value []byte)

	// Delete deletes the key. Panics on nil key.
	Delete(key []byte)
}

type TxID

type TxID = HexByteArray32

type TxIndex

type TxIndex = uint8

type TxInfo

type TxInfo struct {
	Status                  uint8  `json:"status" yaml:"status"`
	PrepareResult           uint8  `json:"prepare_result" yaml:"prepare_result"`
	CoordinatorConnectionID string `json:"coordinator_connection_id" yaml:"coordinator_connection_id"`
	ContractCallInfo        []byte `json:"contract_call_info" yaml:"contract_call_info"`
}

func NewTxInfo

func NewTxInfo(status, prepareResult uint8, coordinatorConnectionID string, contractCallInfo []byte) TxInfo

type UnacknowledgedPacket

type UnacknowledgedPacket struct {
	Sequence      uint64 `json:"sequence" yaml:"sequence"`             // number corresponds to the order of sends and receives, where a Packet with an earlier sequence number must be sent and received before a Packet with a later sequence number.
	SourcePort    string `json:"source_port" yaml:"source_port"`       // identifies the port on the sending chain.
	SourceChannel string `json:"source_channel" yaml:"source_channel"` // identifies the channel end on the sending chain.
}

func ParseUnacknowledgedPacketKey

func ParseUnacknowledgedPacketKey(key []byte) (*UnacknowledgedPacket, error)

Jump to

Keyboard shortcuts

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