-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: remove cosmos/relayer
dependency
#429
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
56df3aa
moving relayer code
Lazar955 ed114fb
moves tests and rm excess
Lazar955 5199019
rm excess
Lazar955 9f5fe6c
cleanup
Lazar955 7433cfd
cleanup
Lazar955 28b7931
cleanup more
Lazar955 095b25e
cleanup more
Lazar955 d1985b8
moar cleanup
Lazar955 9aca0d2
lint fixes
Lazar955 44182cd
handling nil derefs
Lazar955 7313371
changelog
Lazar955 9bab3f4
rm fee grant
Lazar955 3742371
lint fixes
Lazar955 c9ee3bc
update gomod
Lazar955 0ba6efc
remove strangelove dep, use cmt client
Lazar955 561f681
remove fee grant leftovers
Lazar955 c95b01e
add notice headers
Lazar955 bc55285
rename package
Lazar955 fc55f54
cleanup more
Lazar955 0a1e13e
pr comments
Lazar955 9c8e50f
revert logger
Lazar955 f902757
gomod merge
Lazar955 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This file is derived from the Cosmos Relayer repository (https://github.com/cosmos/relayer), | ||
// originally licensed under the Apache License, Version 2.0. | ||
|
||
package babylonclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/metadata" | ||
) | ||
|
||
var _ client.AccountRetriever = &CosmosProvider{} | ||
|
||
// GetAccount queries for an account given an address and a block height. An | ||
// error is returned if the query or decoding fails. | ||
func (cc *CosmosProvider) GetAccount(clientCtx client.Context, addr sdk.AccAddress) (client.Account, error) { | ||
account, _, err := cc.GetAccountWithHeight(clientCtx, addr) | ||
return account, err | ||
} | ||
|
||
// GetAccountWithHeight queries for an account given an address. Returns the | ||
// height of the query with the account. An error is returned if the query | ||
// or decoding fails. | ||
func (cc *CosmosProvider) GetAccountWithHeight(_ client.Context, addr sdk.AccAddress) (client.Account, int64, error) { | ||
var header metadata.MD | ||
address, err := cc.EncodeBech32AccAddr(addr) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
queryClient := authtypes.NewQueryClient(cc) | ||
res, err := queryClient.Account(context.Background(), &authtypes.QueryAccountRequest{Address: address}, grpc.Header(&header)) | ||
if err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
blockHeight := header.Get(grpctypes.GRPCBlockHeightHeader) | ||
if l := len(blockHeight); l != 1 { | ||
return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected: %d", grpctypes.GRPCBlockHeightHeader, l, 1) | ||
} | ||
|
||
nBlockHeight, err := strconv.Atoi(blockHeight[0]) | ||
if err != nil { | ||
return nil, 0, fmt.Errorf("failed to parse block height: %w", err) | ||
} | ||
|
||
var acc sdk.AccountI | ||
if err := cc.Cdc.InterfaceRegistry.UnpackAny(res.Account, &acc); err != nil { | ||
return nil, 0, err | ||
} | ||
|
||
return acc, int64(nBlockHeight), nil | ||
} | ||
|
||
// EnsureExists returns an error if no account exists for the given address else nil. | ||
func (cc *CosmosProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error { | ||
if _, err := cc.GetAccount(clientCtx, addr); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// GetAccountNumberSequence returns sequence and account number for the given address. | ||
// It returns an error if the account couldn't be retrieved from the state. | ||
func (cc *CosmosProvider) GetAccountNumberSequence(clientCtx client.Context, addr sdk.AccAddress) (uint64, uint64, error) { | ||
acc, err := cc.GetAccount(clientCtx, addr) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
return acc.GetAccountNumber(), acc.GetSequence(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This file is derived from the Cosmos Relayer repository (https://github.com/cosmos/relayer), | ||
// originally licensed under the Apache License, Version 2.0. | ||
|
||
package babylonclient | ||
|
||
import ( | ||
"sync" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// This file is cursed and this mutex is too | ||
// you don't want none of this dewey cox. | ||
var sdkConfigMutex sync.Mutex | ||
|
||
// SetSDKContext sets the SDK config to the proper bech32 prefixes. | ||
// Don't use this unless you know what you're doing. | ||
// TODO: :dagger: :knife: :chainsaw: remove this function | ||
func (cc *CosmosProvider) SetSDKContext() func() { | ||
return SetSDKConfigContext(cc.PCfg.AccountPrefix) | ||
} | ||
|
||
// SetSDKConfigContext sets the SDK config to the given bech32 prefixes | ||
func SetSDKConfigContext(prefix string) func() { | ||
sdkConfigMutex.Lock() | ||
sdkConf := sdk.GetConfig() | ||
sdkConf.SetBech32PrefixForAccount(prefix, prefix+"pub") | ||
sdkConf.SetBech32PrefixForValidator(prefix+"valoper", prefix+"valoperpub") | ||
sdkConf.SetBech32PrefixForConsensusNode(prefix+"valcons", prefix+"valconspub") | ||
return sdkConfigMutex.Unlock | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This file is derived from the Cosmos Relayer repository (https://github.com/cosmos/relayer), | ||
// originally licensed under the Apache License, Version 2.0. | ||
|
||
package babylonclient | ||
|
||
import ( | ||
"context" | ||
) | ||
|
||
type BroadcastMode string | ||
|
||
const ( | ||
BroadcastModeSingle BroadcastMode = "single" | ||
BroadcastModeBatch BroadcastMode = "batch" | ||
) | ||
|
||
type ProviderConfig interface { | ||
NewProvider(homepath string, chainName string) (ChainProvider, error) | ||
Validate() error | ||
BroadcastMode() BroadcastMode | ||
} | ||
|
||
type RelayerMessage interface { | ||
Type() string | ||
MsgBytes() ([]byte, error) | ||
} | ||
|
||
type RelayerTxResponse struct { | ||
Height int64 | ||
TxHash string | ||
Codespace string | ||
Code uint32 | ||
Data string | ||
Events []RelayerEvent | ||
} | ||
|
||
type RelayerEvent struct { | ||
EventType string | ||
Attributes map[string]string | ||
} | ||
|
||
type ChainProvider interface { | ||
Init() error | ||
SendMessagesToMempool( | ||
ctx context.Context, | ||
msgs []RelayerMessage, | ||
memo string, | ||
asyncCtx context.Context, | ||
asyncCallbacks []func(*RelayerTxResponse, error), | ||
) error | ||
ChainName() string | ||
ChainId() string | ||
ProviderConfig() ProviderConfig | ||
Key() string | ||
Address() (string, error) | ||
Timeout() string | ||
SetRpcAddr(rpcAddr string) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// This file is derived from the Cosmos Relayer repository (https://github.com/cosmos/relayer), | ||
// originally licensed under the Apache License, Version 2.0. | ||
|
||
package babylonclient | ||
|
||
import ( | ||
"context" | ||
"github.com/cometbft/cometbft/libs/bytes" | ||
rpcclient "github.com/cometbft/cometbft/rpc/client" | ||
coretypes "github.com/cometbft/cometbft/rpc/core/types" | ||
tmtypes "github.com/cometbft/cometbft/types" | ||
) | ||
|
||
type RPCClient struct { | ||
c rpcclient.Client | ||
} | ||
|
||
func NewRPCClient(c rpcclient.Client) RPCClient { | ||
return RPCClient{c: c} | ||
} | ||
|
||
func (r RPCClient) ABCIInfo(ctx context.Context) (*coretypes.ResultABCIInfo, error) { | ||
return r.c.ABCIInfo(ctx) | ||
} | ||
|
||
func (r RPCClient) ABCIQuery( | ||
ctx context.Context, | ||
path string, | ||
data bytes.HexBytes, | ||
) (*coretypes.ResultABCIQuery, error) { | ||
return r.c.ABCIQuery(ctx, path, (data)) | ||
} | ||
|
||
func (r RPCClient) ABCIQueryWithOptions( | ||
ctx context.Context, | ||
path string, | ||
data bytes.HexBytes, | ||
opts rpcclient.ABCIQueryOptions, | ||
) (*coretypes.ResultABCIQuery, error) { | ||
return r.c.ABCIQueryWithOptions(ctx, path, data, opts) | ||
} | ||
|
||
func (r RPCClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTxCommit, error) { | ||
return r.c.BroadcastTxCommit(ctx, tx) | ||
} | ||
|
||
func (r RPCClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { | ||
return r.c.BroadcastTxAsync(ctx, tx) | ||
} | ||
|
||
func (r RPCClient) BroadcastTxSync(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) { | ||
return r.c.BroadcastTxSync(ctx, tx) | ||
} | ||
|
||
func (r RPCClient) Validators( | ||
ctx context.Context, | ||
height *int64, | ||
page, perPage *int, | ||
) (*coretypes.ResultValidators, error) { | ||
return r.c.Validators(ctx, height, page, perPage) | ||
} | ||
|
||
func (r RPCClient) Status(ctx context.Context) (*coretypes.ResultStatus, error) { | ||
return r.c.Status(ctx) | ||
} | ||
|
||
func (r RPCClient) Block(ctx context.Context, height *int64) (*coretypes.ResultBlock, error) { | ||
return r.c.Block(ctx, height) | ||
} | ||
|
||
func (r RPCClient) BlockByHash(ctx context.Context, hash []byte) (*coretypes.ResultBlock, error) { | ||
return r.c.BlockByHash(ctx, hash) | ||
} | ||
|
||
func (r RPCClient) BlockResults(ctx context.Context, height *int64) (*coretypes.ResultBlockResults, error) { | ||
return r.c.BlockResults(ctx, height) | ||
} | ||
|
||
func (r RPCClient) BlockchainInfo( | ||
ctx context.Context, | ||
minHeight, maxHeight int64, | ||
) (*coretypes.ResultBlockchainInfo, error) { | ||
return r.c.BlockchainInfo(ctx, minHeight, maxHeight) | ||
} | ||
|
||
func (r RPCClient) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) { | ||
return r.c.Commit(ctx, height) | ||
} | ||
|
||
func (r RPCClient) Tx(ctx context.Context, hash []byte, prove bool) (*coretypes.ResultTx, error) { | ||
return r.c.Tx(ctx, hash, prove) | ||
} | ||
|
||
func (r RPCClient) TxSearch( | ||
ctx context.Context, | ||
query string, | ||
prove bool, | ||
page, perPage *int, | ||
orderBy string, | ||
) (*coretypes.ResultTxSearch, error) { | ||
return r.c.TxSearch(ctx, query, prove, page, perPage, orderBy) | ||
} | ||
|
||
func (r RPCClient) BlockSearch( | ||
ctx context.Context, | ||
query string, | ||
page, perPage *int, | ||
orderBy string, | ||
) (*coretypes.ResultBlockSearch, error) { | ||
return r.c.BlockSearch(ctx, query, page, perPage, orderBy) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make a function that increases the account sequence also in the WalletState