ibc

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NameIBC is the name of this module
	NameIBC = "ibc"
	// OptionRegistrar is the option name to set the actor
	// to handle ibc chain registration
	OptionRegistrar = "registrar"
)
View Source
const (
	// 0x3? series for ibc
	ByteRegisterChain = byte(0x30)
	ByteUpdateChain   = byte(0x31)
	ByteCreatePacket  = byte(0x32)
	BytePostPacket    = byte(0x33)

	TypeRegisterChain = NameIBC + "/register"
	TypeUpdateChain   = NameIBC + "/update"
	TypeCreatePacket  = NameIBC + "/create"
	TypePostPacket    = NameIBC + "/post"
)

nolint

Variables

View Source
var (
	IBCCodeChainNotRegistered    = abci.CodeType(1001)
	IBCCodeChainAlreadyExists    = abci.CodeType(1002)
	IBCCodeUnknownChain          = abci.CodeType(1003)
	IBCCodeInvalidPacketSequence = abci.CodeType(1004)
	IBCCodeUnknownHeight         = abci.CodeType(1005)
	IBCCodeInvalidCommit         = abci.CodeType(1006)
	IBCCodeInvalidProof          = abci.CodeType(1007)
	IBCCodeInvalidCall           = abci.CodeType(1008)
)

nolint

Functions

func AllowIBC

func AllowIBC(app string) sdk.Actor

AllowIBC returns a specially crafted Actor that enables sending IBC packets for this app type

func ChainKey

func ChainKey(chainID string) []byte

ChainKey is the key to get info on one chain

func ChainsKey

func ChainsKey() []byte

ChainsKey is the key to get info on all chains

func ErrAlreadyRegistered

func ErrAlreadyRegistered(chainID string) error

func ErrCannotSetPermission

func ErrCannotSetPermission() error

func ErrHeaderNotFound

func ErrHeaderNotFound(h int) error

func ErrInvalidCommit

func ErrInvalidCommit(err error) error

func ErrInvalidProof

func ErrInvalidProof() error

func ErrInvalidProofWithReason

func ErrInvalidProofWithReason(err error) error

func ErrNeedsIBCPermission

func ErrNeedsIBCPermission() error

func ErrNotRegistered

func ErrNotRegistered(chainID string) error

func ErrPacketAlreadyExists

func ErrPacketAlreadyExists() error

func ErrPacketOutOfOrder

func ErrPacketOutOfOrder(seq uint64) error

func ErrWrongDestChain

func ErrWrongDestChain(chainID string) error

func HandlerKey

func HandlerKey() []byte

HandlerKey is used for the global permission info

func InputQueue

func InputQueue(store state.SimpleDB, chainID string) *state.Queue

InputQueue returns the queue of input packets from this chain

func IsAlreadyRegisteredErr

func IsAlreadyRegisteredErr(err error) bool

func IsCannotSetPermissionErr

func IsCannotSetPermissionErr(err error) bool

func IsHeaderNotFoundErr

func IsHeaderNotFoundErr(err error) bool

func IsInvalidCommitErr

func IsInvalidCommitErr(err error) bool

func IsInvalidProofErr

func IsInvalidProofErr(err error) bool

func IsNeedsIBCPermissionErr

func IsNeedsIBCPermissionErr(err error) bool

func IsNotRegisteredErr

func IsNotRegisteredErr(err error) bool

func IsPacketAlreadyExistsErr

func IsPacketAlreadyExistsErr(err error) bool

func IsPacketOutOfOrderErr

func IsPacketOutOfOrderErr(err error) bool

func IsWrongDestChainErr

func IsWrongDestChainErr(err error) bool

func OutputQueue

func OutputQueue(store state.SimpleDB, chainID string) *state.Queue

OutputQueue returns the queue of output packets destined for this chain

func QueueInKey

func QueueInKey(chainID string) []byte

QueueInKey is the key to get newest of the input queue from this chain

func QueueInPacketKey

func QueueInPacketKey(chainID string, seq uint64) []byte

QueueInPacketKey is the key to get given packet from this chain's input queue

func QueueOutKey

func QueueOutKey(chainID string) []byte

QueueOutKey is the key to get v of the output queue from this chain

func QueueOutPacketKey

func QueueOutPacketKey(chainID string, seq uint64) []byte

QueueOutPacketKey is the key to get given packet from this chain's output queue

Types

type AppChain

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

AppChain is ready to handle tx

func NewAppChain

func NewAppChain(app sdk.Handler, chainID string) *AppChain

NewAppChain returns a chain that is ready to respond to tx

func (*AppChain) DeliverTx

func (a *AppChain) DeliverTx(tx sdk.Tx, perms ...sdk.Actor) (sdk.DeliverResult, error)

DeliverTx runs the tx and commits the new tree, incrementing height by one.

func (*AppChain) GetStore

func (a *AppChain) GetStore(app string) state.SimpleDB

GetStore is used to get the app-specific sub-store

func (*AppChain) IncrementHeight

func (a *AppChain) IncrementHeight(delta int) int

IncrementHeight allows us to jump heights, more than the auto-step of 1. It returns the new height we are at.

func (*AppChain) InitState

func (a *AppChain) InitState(mod, key, value string) (string, error)

InitState sets the option on our app

func (*AppChain) Update

func (a *AppChain) Update(tx UpdateChainTx) error

Update is a shortcut to DeliverTx with this. Also one return value to test inline

type ChainInfo

type ChainInfo struct {
	RegisteredAt uint64 `json:"registered_at"`
	RemoteBlock  int    `json:"remote_block"`
}

ChainInfo is the global info we store for each registered chain, besides the headers, proofs, and packets

type ChainSet

type ChainSet struct {
	*state.Set
}

ChainSet is the set of all registered chains

func NewChainSet

func NewChainSet(store state.SimpleDB) ChainSet

NewChainSet loads or initialized the ChainSet

func (ChainSet) Register

func (c ChainSet) Register(chainID string, ourHeight uint64, theirHeight int) error

Register adds the named chain with some info returns error if already present

func (ChainSet) Update

func (c ChainSet) Update(chainID string, theirHeight int) error

Update sets the new tracked height on this chain returns error if not present

type CreatePacketTx

type CreatePacketTx struct {
	DestChain   string     `json:"dest_chain"`
	Permissions sdk.Actors `json:"permissions"`
	Tx          sdk.Tx     `json:"tx"`
}

CreatePacketTx is meant to be called by IPC, another module...

this is the tx that will be sent to another app and the permissions it comes with (which must be a subset of the permissions on the current tx)

If must have the special `AllowIBC` permission from the app that can send this packet (so only coins can request SendTx packet)

func (CreatePacketTx) ValidateBasic

func (p CreatePacketTx) ValidateBasic() error

ValidateBasic makes sure this is consistent - used to satisfy TxInner

func (CreatePacketTx) Wrap

func (p CreatePacketTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type Handler

type Handler struct {
	sdk.NopInitValidate
}

Handler updates the chain state or creates an ibc packet

func NewHandler

func NewHandler() Handler

NewHandler returns a Handler that allows all chains to connect via IBC. Set a Registrar via InitState to restrict it.

func (Handler) CheckTx

func (h Handler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error)

CheckTx verifies the packet is formated correctly, and has the proper sequence for a registered chain

func (Handler) DeliverTx

func (h Handler) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.DeliverResult, err error)

DeliverTx verifies all signatures on the tx and updates the chain state apropriately

func (Handler) InitState

func (h Handler) InitState(l log.Logger, store state.SimpleDB, module, key, value string) (log string, err error)

InitState sets the registrar for IBC

func (Handler) Name

func (Handler) Name() string

Name returns name space

type HandlerInfo

type HandlerInfo struct {
	Registrar sdk.Actor `json:"registrar"`
}

HandlerInfo is the global state of the ibc.Handler

func LoadInfo

func LoadInfo(store state.SimpleDB) (h HandlerInfo)

LoadInfo loads the HandlerInfo from the data store

func (HandlerInfo) Save

func (h HandlerInfo) Save(store state.SimpleDB)

Save the HandlerInfo to the store

type Middleware

type Middleware struct {
	stack.PassInitState
	stack.PassInitValidate
}

Middleware allows us to verify the IBC proof on a packet and and if valid, attach this permission to the wrapped packet

func NewMiddleware

func NewMiddleware() Middleware

NewMiddleware creates a role-checking middleware

func (Middleware) CheckTx

func (m Middleware) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Checker) (res sdk.CheckResult, err error)

CheckTx verifies the named chain and height is present, and verifies the merkle proof in the packet

func (Middleware) DeliverTx

func (m Middleware) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx, next sdk.Deliver) (res sdk.DeliverResult, err error)

DeliverTx verifies the named chain and height is present, and verifies the merkle proof in the packet

func (Middleware) Name

func (Middleware) Name() string

Name - return name space

type MockChain

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

MockChain is used to simulate a chain for ibc tests. It is able to produce ibc packets and all verification for them, but cannot respond to any responses.

func NewMockChain

func NewMockChain(chainID string, numKeys int) MockChain

NewMockChain initializes a teststore and test validators

func (MockChain) GetRegistrationTx

func (m MockChain) GetRegistrationTx(h int) RegisterChainTx

GetRegistrationTx returns a valid tx to register this chain

func (MockChain) MakePostPacket

func (m MockChain) MakePostPacket(packet Packet, h int) (
	PostPacketTx, UpdateChainTx)

MakePostPacket commits the packet locally and returns the proof, in the form of two packets to update the header and prove this packet.

type Packet

type Packet struct {
	DestChain   string     `json:"dest_chain"`
	Sequence    uint64     `json:"sequence"`
	Permissions sdk.Actors `json:"permissions"`
	Tx          sdk.Tx     `json:"tx"`
}

Packet is a wrapped transaction and permission that we want to send off to another chain.

func NewPacket

func NewPacket(tx sdk.Tx, dest string, seq uint64, perm ...sdk.Actor) Packet

NewPacket creates a new outgoing packet

func (Packet) Bytes

func (p Packet) Bytes() []byte

Bytes returns a serialization of the Packet

type PostPacketTx

type PostPacketTx struct {
	// The immediate source of the packet, not always Packet.SrcChainID
	FromChainID string `json:"src_chain"`
	// The block height in which Packet was committed, to check Proof
	FromChainHeight uint64 `json:"src_height"`
	// this proof must match the header and the packet.Bytes()
	Proof  *iavl.KeyExistsProof `json:"proof"`
	Key    data.Bytes           `json:"key"`
	Packet Packet               `json:"packet"`
}

PostPacketTx takes a wrapped packet from another chain and TODO!!! also think... which chains can relay packets??? right now, enforce that these packets are only sent directly, not routed over the hub. add routing later.

func (PostPacketTx) ValidateBasic

func (p PostPacketTx) ValidateBasic() error

ValidateBasic makes sure this is consistent - used to satisfy TxInner

func (PostPacketTx) Wrap

func (p PostPacketTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type RegisterChainTx

type RegisterChainTx struct {
	Seed certifiers.Seed `json:"seed"`
}

RegisterChainTx allows you to register a new chain on this blockchain

func (RegisterChainTx) ChainID

func (r RegisterChainTx) ChainID() string

ChainID helps get the chain this tx refers to

func (RegisterChainTx) ValidateBasic

func (r RegisterChainTx) ValidateBasic() error

ValidateBasic makes sure this is consistent, without checking the sigs

func (RegisterChainTx) Wrap

func (r RegisterChainTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

type UpdateChainTx

type UpdateChainTx struct {
	Seed certifiers.Seed `json:"seed"`
}

UpdateChainTx updates the state of this chain

func (UpdateChainTx) ChainID

func (u UpdateChainTx) ChainID() string

ChainID helps get the chain this tx refers to

func (UpdateChainTx) ValidateBasic

func (u UpdateChainTx) ValidateBasic() error

ValidateBasic makes sure this is consistent, without checking the sigs

func (UpdateChainTx) Wrap

func (u UpdateChainTx) Wrap() sdk.Tx

Wrap - used to satisfy TxInner

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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