-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
47 lines (37 loc) · 1.22 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package clictx
import (
"github.com/b-harvest/gravity-dex-firestation/codec"
sdkclient "github.com/cosmos/cosmos-sdk/client"
sdktypes "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
rpcclient "github.com/tendermint/tendermint/rpc/client"
)
// Client wraps Cosmos SDK client context.
type Client struct {
sdkclient.Context
}
// NewClient creates Cosmos SDK client.
func NewClient(rpcURL string, rpcClient rpcclient.Client) *Client {
cliCtx := sdkclient.Context{}.
WithNodeURI(rpcURL).
WithClient(rpcClient).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithJSONMarshaler(codec.EncodingConfig.Marshaler).
WithLegacyAmino(codec.EncodingConfig.Amino).
WithTxConfig(codec.EncodingConfig.TxConfig).
WithInterfaceRegistry(codec.EncodingConfig.InterfaceRegistry)
return &Client{cliCtx}
}
// GetAccount checks account type and returns account interface.
func (c *Client) GetAccount(address string) (sdkclient.Account, error) {
accAddr, err := sdktypes.AccAddressFromBech32(address)
if err != nil {
return nil, err
}
ar := authtypes.AccountRetriever{}
acc, _, err := ar.GetAccountWithHeight(c.Context, accAddr)
if err != nil {
return nil, err
}
return acc, nil
}