Skip to content

Commit

Permalink
Merge PR: add ibc transfer (#152)
Browse files Browse the repository at this point in the history
* add ibc transfer

* add query denom-trace、 query denom-traces、query params、query rscrow Address

* update ibc-transfer coin denom

* update go.mod

* add all ibc query

* update ibc

* add query tx

* add query header

* update ibc private key type

* update ibc private key type

Co-authored-by: finefine <[email protected]>
  • Loading branch information
FineKe and finefine authored Jun 20, 2022
1 parent 2346790 commit 71ab89f
Show file tree
Hide file tree
Showing 11 changed files with 1,248 additions and 18 deletions.
7 changes: 7 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package gosdk

import (
"fmt"
"github.com/okex/exchain-go-sdk/module/ibc"
ibcTypes "github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types"

"github.com/okex/exchain-go-sdk/exposed"
"github.com/okex/exchain-go-sdk/module"
Expand Down Expand Up @@ -63,6 +65,7 @@ func NewClient(config gosdktypes.ClientConfig) Client {
slashing.NewSlashingClient(pBaseClient),
token.NewTokenClient(pBaseClient),
tendermint.NewTendermintClient(pBaseClient),
ibc.NewIbcClient(pBaseClient),
)

return *pClient
Expand Down Expand Up @@ -124,3 +127,7 @@ func (cli *Client) Tendermint() exposed.Tendermint {
func (cli *Client) Token() exposed.Token {
return cli.modules[tokentypes.ModuleName].(exposed.Token)
}

func (cli *Client) Ibc() exposed.Ibc {
return cli.modules[ibcTypes.ModuleName].(exposed.Ibc)
}
90 changes: 90 additions & 0 deletions exposed/ibc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package exposed

import (
gosdktypes "github.com/okex/exchain-go-sdk/types"

sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
"github.com/okex/exchain/libs/cosmos-sdk/types/query"
ibcTypes "github.com/okex/exchain/libs/ibc-go/modules/apps/transfer/types"
client_types "github.com/okex/exchain/libs/ibc-go/modules/core/02-client/types"
chantypes "github.com/okex/exchain/libs/ibc-go/modules/core/04-channel/types"
ibcexported "github.com/okex/exchain/libs/ibc-go/modules/core/exported"
tmcrypto "github.com/okex/exchain/libs/tendermint/crypto"
ctypes "github.com/okex/exchain/libs/tendermint/rpc/core/types"
)

// Ibc shows the expected behavior for inner ibc client
type Ibc interface {
gosdktypes.Module
IbcTx
IbcQuery
}

// IbcTx send ibc tx
type IbcTx interface {

// Transfer transfer token to destination chain
Transfer(priKey tmcrypto.PrivKey, srcChannel string, receiver string, amount string, fee sdk.CoinAdapters, memo string, timeoutHeight client_types.Height) (resp sdk.TxResponse, err error)
}

// IbcQuery shows the ibc query info
type IbcQuery interface {

// QueryDenomTrace query a a denomination trace from a given hash.
QueryDenomTrace(hash string) (*ibcTypes.QueryDenomTraceResponse, error)

// QueryDenomTraces query all the denomination trace infos.
QueryDenomTraces(page *query.PageRequest) (*ibcTypes.QueryDenomTracesResponse, error)

// QueryIbcParams ibc-transfer parameter querying.
QueryIbcParams() (*ibcTypes.QueryParamsResponse, error)

// QueryEscrowAddress ibc-transfer parameter querying.
QueryEscrowAddress(portID, channelID string) sdk.AccAddress

// QueryChannels query channels
QueryChannels() (*chantypes.QueryChannelsResponse, error)

// QueryTx query a tx
QueryTx(hash string) (*ctypes.ResultTx, error)

// QueryTxs
QueryTxs(page, limit int, events []string) ([]*ctypes.ResultTx, error)

// QueryHeaderAtHeight
QueryHeaderAtHeight(height int64) (ibcexported.Header, error)

// QueryChannel
QueryChannel(req *chantypes.QueryChannelRequest) (*chantypes.QueryChannelResponse, error)

// ConnectionChannels queries all the channels associated with a connection
// end.
ConnectionChannels(req *chantypes.QueryConnectionChannelsRequest) (*chantypes.QueryConnectionChannelsResponse, error)
// ChannelClientState queries for the client state for the channel associated
// with the provided channel identifiers.
ChannelClientState(req *chantypes.QueryChannelClientStateRequest) (*chantypes.QueryChannelClientStateResponse, error)
// ChannelConsensusState queries for the consensus state for the channel
// associated with the provided channel identifiers.
ChannelConsensusState(req *chantypes.QueryChannelConsensusStateRequest) (*chantypes.QueryChannelConsensusStateResponse, error)
// PacketCommitment queries a stored packet commitment hash.
PacketCommitment(req *chantypes.QueryPacketCommitmentRequest) (*chantypes.QueryPacketCommitmentResponse, error)
// PacketCommitments returns all the packet commitments hashes associated
// with a channel.
PacketCommitments(req *chantypes.QueryPacketCommitmentsRequest) (*chantypes.QueryPacketCommitmentsResponse, error)
// PacketReceipt queries if a given packet sequence has been received on the
// queried chain
PacketReceipt(req *chantypes.QueryPacketReceiptRequest) (*chantypes.QueryPacketReceiptResponse, error)
// PacketAcknowledgement queries a stored packet acknowledgement hash.
PacketAcknowledgement(req *chantypes.QueryPacketAcknowledgementRequest) (*chantypes.QueryPacketAcknowledgementResponse, error)
// PacketAcknowledgements returns all the packet acknowledgements associated
// with a channel.
PacketAcknowledgements(req *chantypes.QueryPacketAcknowledgementsRequest) (*chantypes.QueryPacketAcknowledgementsResponse, error)
// UnreceivedPackets returns all the unreceived IBC packets associated with a
// channel and sequences.
UnreceivedPackets(req *chantypes.QueryUnreceivedPacketsRequest) (*chantypes.QueryUnreceivedPacketsResponse, error)
// UnreceivedAcks returns all the unreceived IBC acknowledgements associated
// with a channel and sequences.
UnreceivedAcks(req *chantypes.QueryUnreceivedAcksRequest) (*chantypes.QueryUnreceivedAcksResponse, error)
// NextSequenceReceive returns the next receive sequence for a given channel.
NextSequenceReceive(req *chantypes.QueryNextSequenceReceiveRequest) (*chantypes.QueryNextSequenceReceiveResponse, error)
}
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ go 1.16
require (
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d
github.com/ethereum/go-ethereum v1.10.8
github.com/golang/mock v1.5.0
github.com/okex/exchain v1.2.1-0.20220414063812-5b9519a911d7
github.com/stretchr/testify v1.7.0
github.com/golang/mock v1.6.0
github.com/google/pprof v0.0.0-20220318212150-b2ab0324ddda // indirect
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2 // indirect
github.com/kisielk/godepgraph v0.0.0-20190626013829-57a7e4a651a9 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/minio/highwayhash v1.0.1 // indirect
github.com/okex/exchain v1.5.3 // indirect
github.com/prometheus/client_golang v1.8.0 // indirect
github.com/stretchr/testify v1.7.1
github.com/tendermint/tendermint v0.34.14
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f // indirect
)

replace (
Expand Down
Loading

0 comments on commit 71ab89f

Please sign in to comment.