types

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: Apache-2.0 Imports: 18 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 MakeObjectKey added in v0.0.5

func MakeObjectKey(callInfo ContractCallInfo, signers []sdk.AccAddress) []byte

MakeObjectKey returns a key that can be used to identify a contract call

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 CallResultLink struct {
	ContractTransactionIndex TxIndex
}

CallResultLink is a link with an object returned from external contract call

func NewCallResultLink(idx TxIndex) CallResultLink

NewCallResultLink returns CallResultLink

func (CallResultLink) SourceIndex added in v0.0.5

func (l CallResultLink) SourceIndex() TxIndex

SourceIndex implements Link.SourceIndex

func (CallResultLink) Type added in v0.0.5

func (l CallResultLink) Type() LinkType

Type implements Link.Type

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 ConstantValueObject added in v0.0.5

type ConstantValueObject struct {
	K []byte
	V []byte
}

ConstantValueObject is an Object wraps a constant value

func MakeConstantValueObject added in v0.0.5

func MakeConstantValueObject(key []byte, value []byte) ConstantValueObject

MakeConstantValueObject returns ConstantValueObject

func (ConstantValueObject) Evaluate added in v0.0.5

func (l ConstantValueObject) Evaluate(bz []byte) ([]byte, error)

Evaluate returns a constant value

func (ConstantValueObject) Key added in v0.0.5

func (l ConstantValueObject) Key() []byte

Key implements Object.Key

func (ConstantValueObject) Type added in v0.0.5

Type implements Object.Type

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, callInfo ContractCallInfo, rtInfo ContractRuntimeInfo) (State, error)
	Handle(ctx sdk.Context, callInfo ContractCallInfo, rtInfo ContractRuntimeInfo) (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 ContractRuntimeInfo added in v0.0.5

type ContractRuntimeInfo struct {
	StateConstraintType    StateConstraintType
	ExternalObjectResolver ObjectResolver
}

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"`
	ReturnValue     *ReturnValue     `json:"return_value" yaml:"return_value"`
	Links           []Link           `json:"links" yaml:"links"`
}

func NewContractTransaction

func NewContractTransaction(src ChannelInfo, signers []sdk.AccAddress, callInfo ContractCallInfo, sc StateConstraint, rv *ReturnValue, links []Link) ContractTransaction

func (ContractTransaction) ValidateBasic

func (t ContractTransaction) ValidateBasic() error

type ContractTransactionInfo added in v0.0.5

type ContractTransactionInfo struct {
	Transaction ContractTransaction `json:"transaction" yaml:"transaction"`
	LinkObjects []Object            `json:"link_objects" yaml:"link_objects"`
}

func NewContractTransactionInfo added in v0.0.5

func NewContractTransactionInfo(tx ContractTransaction, linkObjects []Object) ContractTransactionInfo

func (ContractTransactionInfo) ValidateBasic added in v0.0.5

func (ti ContractTransactionInfo) 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 FakeResolver added in v0.0.5

type FakeResolver struct{}

FakeResolver is a resolver that always fails to resolve an object

func NewFakeResolver added in v0.0.5

func NewFakeResolver() FakeResolver

NewFakeResolver returns FakeResolver

func (FakeResolver) Resolve added in v0.0.5

func (FakeResolver) Resolve(key []byte) (Object, error)

Resolve implements ObjectResolver.Resolve

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 Link interface {
	Type() LinkType
	SourceIndex() TxIndex
}

Link is a link to an Object that is referenced in the call to the contract

type LinkType added in v0.0.5

type LinkType = uint8

LinkType is a type of link

const (
	// LinkTypeCallResult is LinkType that indicates a link with an object returned from external contract call
	LinkTypeCallResult LinkType = iota + 1
)

type Linker added in v0.0.5

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

Linker resolves links that each ContractTransaction has.

func MakeLinker added in v0.0.5

func MakeLinker(txs ContractTransactions) (*Linker, error)

MakeLinker returns Linker

func (Linker) Resolve added in v0.0.5

func (lkr Linker) Resolve(lks []Link) ([]Object, error)

Resolve resolves given links and returns resolved Object

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 Object added in v0.0.5

type Object interface {
	Type() ObjectType
	Key() []byte
	Evaluate([]byte) ([]byte, error)
}

Object wraps an actual value

type ObjectResolver added in v0.0.5

type ObjectResolver interface {
	Resolve(key []byte) (Object, error)
}

ObjectResolver resolves a given key to Object

type ObjectResolverProvider added in v0.0.5

type ObjectResolverProvider func(libs []Object) (ObjectResolver, error)

ObjectResolverProvider is a provider of ObjectResolver

func DefaultResolverProvider added in v0.0.5

func DefaultResolverProvider() ObjectResolverProvider

DefaultResolverProvider returns a default implements of ObjectResolver

type ObjectType added in v0.0.5

type ObjectType = uint8

ObjectType is a type of Object

const (
	// ObjectTypeConstantValue is ObjectType indicates a constant value
	ObjectTypeConstantValue ObjectType = iota + 1
)

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
	TxInfo  ContractTransactionInfo
}

func NewPacketDataPrepare

func NewPacketDataPrepare(sender sdk.AccAddress, txID TxID, txIndex TxIndex, txInfo ContractTransactionInfo) 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 ReturnValue added in v0.0.5

type ReturnValue []byte

func NewReturnValue added in v0.0.5

func NewReturnValue(v []byte) *ReturnValue

func (*ReturnValue) Equal added in v0.0.5

func (rv *ReturnValue) Equal(bz []byte) bool

func (*ReturnValue) IsNil added in v0.0.5

func (rv *ReturnValue) IsNil() bool

type SequentialResolver added in v0.0.5

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

SequentialResolver is a resolver that resolves an object in sequential

func NewSequentialResolver added in v0.0.5

func NewSequentialResolver(objects []Object) *SequentialResolver

NewSequentialResolver returns SequentialResolver

func (*SequentialResolver) Resolve added in v0.0.5

func (r *SequentialResolver) Resolve(key []byte) (Object, error)

Resolve implements ObjectResolver.Resolve If success, resolver increments the internal sequence

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