Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions chains/debug/chain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package debug

import (
"context"
"time"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"

"github.com/hyperledger-labs/yui-relayer/core"
)

type Chain struct {
config ChainConfig
OriginChain core.Chain
}

var _ core.Chain = (*Chain)(nil)

func (c *Chain) ChainID() string {
return c.OriginChain.ChainID()
}

func (c *Chain) Codec() codec.ProtoCodecMarshaler {
return c.OriginChain.Codec()
}

func (c *Chain) GetAddress() (sdk.AccAddress, error) {
return c.OriginChain.GetAddress()
}

// SetRelayInfo sets source's path and counterparty's info to the chain
func (c *Chain) SetRelayInfo(path *core.PathEnd, counterparty *core.ProvableChain, counterpartyPath *core.PathEnd) error {
return c.OriginChain.SetRelayInfo(path, counterparty, counterpartyPath)
}

func (c *Chain) Path() *core.PathEnd {
return c.OriginChain.Path()
}

func (c *Chain) Init(homePath string, timeout time.Duration, codec codec.ProtoCodecMarshaler, debug bool) error {
return c.OriginChain.Init(homePath, timeout, codec, debug)
}

func (c *Chain) SetupForRelay(ctx context.Context) error {
return c.OriginChain.SetupForRelay(ctx)
}

// LatestHeight queries the chain for the latest height and returns it
func (c *Chain) LatestHeight(ctx context.Context) (ibcexported.Height, error) {
return c.OriginChain.LatestHeight(ctx)
}

func (c *Chain) Timestamp(ctx context.Context, height ibcexported.Height) (time.Time, error) {
return c.OriginChain.Timestamp(ctx, height)
}

func (c *Chain) AverageBlockTime() time.Duration {
return c.OriginChain.AverageBlockTime()
}

func (c *Chain) RegisterMsgEventListener(listener core.MsgEventListener) {
c.OriginChain.RegisterMsgEventListener(listener)
}

func (c *Chain) SendMsgs(ctx context.Context, msgs []sdk.Msg) ([]core.MsgID, error) {
return c.OriginChain.SendMsgs(ctx, msgs)
}

func (c *Chain) GetMsgResult(ctx context.Context, id core.MsgID) (core.MsgResult, error) {
return c.OriginChain.GetMsgResult(ctx, id)
}
15 changes: 15 additions & 0 deletions chains/debug/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package debug

import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/hyperledger-labs/yui-relayer/core"
)

// RegisterInterfaces register the module interfaces to protobuf
// Any.
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*core.ChainConfig)(nil),
&ChainConfig{},
)
}
45 changes: 45 additions & 0 deletions chains/debug/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package debug

import (
"fmt"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/hyperledger-labs/yui-relayer/core"
)

var _ core.ChainConfig = (*ChainConfig)(nil)

var _ codectypes.UnpackInterfacesMessage = (*ChainConfig)(nil)

func (cfg *ChainConfig) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error {
if cfg == nil {
return nil
}
if err := unpacker.UnpackAny(cfg.OriginChain, new(core.ChainConfig)); err != nil {
return err
}
return nil
}

func (c ChainConfig) Build() (core.Chain, error) {
if c.OriginChain == nil {
return nil, fmt.Errorf("OriginChain must be set")
}
if c.OriginChain.GetCachedValue() == nil {
return nil, fmt.Errorf("OriginChain.GetCachedValue() must be set")
}

originChain, err := c.OriginChain.GetCachedValue().(core.ChainConfig).Build()
if err != nil {
return nil, err
}

return &Chain{
config: c,
OriginChain: originChain,
}, nil
}

func (c ChainConfig) Validate() error {
return nil
}
Loading
Loading