From 86991f475923b94c684890ff8e8ff5cb850deb39 Mon Sep 17 00:00:00 2001 From: abel Date: Tue, 9 Apr 2024 15:52:31 -0300 Subject: [PATCH 1/2] (feat) Changed the cookies management to get the cookie info from every gRPC response received --- client/chain/chain.go | 480 +++++++++++++++++-------- client/common/api_request_assistant.go | 36 ++ client/common/network.go | 99 +++-- client/common/network_test.go | 219 +++-------- client/exchange/exchange.go | 266 ++++++-------- client/explorer/explorer.go | 78 ++-- 6 files changed, 626 insertions(+), 552 deletions(-) create mode 100644 client/common/api_request_assistant.go diff --git a/client/chain/chain.go b/client/chain/chain.go index e3cd4097..1ab1e0ac 100644 --- a/client/chain/chain.go +++ b/client/chain/chain.go @@ -22,6 +22,10 @@ import ( "google.golang.org/grpc/credentials/insecure" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" + chainstreamtypes "github.com/InjectiveLabs/sdk-go/chain/stream/types" + tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types" + "github.com/InjectiveLabs/sdk-go/client/common" log "github.com/InjectiveLabs/suplog" rpchttp "github.com/cometbft/cometbft/rpc/client/http" "github.com/cosmos/cosmos-sdk/client" @@ -37,12 +41,6 @@ import ( "github.com/pkg/errors" "github.com/shopspring/decimal" "google.golang.org/grpc" - "google.golang.org/grpc/metadata" - - exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" - chainstreamtypes "github.com/InjectiveLabs/sdk-go/chain/stream/types" - tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types" - "github.com/InjectiveLabs/sdk-go/client/common" ethcommon "github.com/ethereum/go-ethereum/common" ) @@ -469,22 +467,6 @@ func (c *chainClient) getAccSeq() uint64 { return c.accSeq } -func (c *chainClient) requestCookie() metadata.MD { - var header metadata.MD - _, err := c.bankQueryClient.Params(context.Background(), &banktypes.QueryParamsRequest{}, grpc.Header(&header)) - if err != nil { - panic(err) - } - return header -} - -func (c *chainClient) getCookie(ctx context.Context) context.Context { - provider := common.NewMetadataProvider(c.requestCookie) - cookie, _ := c.network.ChainMetadata(provider) - md := metadata.Pairs("cookie", cookie) - return metadata.NewOutgoingContext(ctx, md) -} - func (c *chainClient) GetAccNonce() (accNum uint64, accSeq uint64) { return c.accNum, c.accSeq } @@ -535,7 +517,9 @@ func (c *chainClient) GetBankBalances(ctx context.Context, address string) (*ban req := &banktypes.QueryAllBalancesRequest{ Address: address, } - return c.bankQueryClient.AllBalances(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.AllBalances, req) + + return res, err } func (c *chainClient) GetBankBalance(ctx context.Context, address string, denom string) (*banktypes.QueryBalanceResponse, error) { @@ -543,7 +527,9 @@ func (c *chainClient) GetBankBalance(ctx context.Context, address string, denom Address: address, Denom: denom, } - return c.bankQueryClient.Balance(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.Balance, req) + + return res, err } func (c *chainClient) GetBankSpendableBalances(ctx context.Context, address string, pagination *query.PageRequest) (*banktypes.QuerySpendableBalancesResponse, error) { @@ -551,7 +537,9 @@ func (c *chainClient) GetBankSpendableBalances(ctx context.Context, address stri Address: address, Pagination: pagination, } - return c.bankQueryClient.SpendableBalances(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.SpendableBalances, req) + + return res, err } func (c *chainClient) GetBankSpendableBalancesByDenom(ctx context.Context, address string, denom string) (*banktypes.QuerySpendableBalanceByDenomResponse, error) { @@ -559,27 +547,37 @@ func (c *chainClient) GetBankSpendableBalancesByDenom(ctx context.Context, addre Address: address, Denom: denom, } - return c.bankQueryClient.SpendableBalanceByDenom(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.SpendableBalanceByDenom, req) + + return res, err } func (c *chainClient) GetBankTotalSupply(ctx context.Context, pagination *query.PageRequest) (*banktypes.QueryTotalSupplyResponse, error) { req := &banktypes.QueryTotalSupplyRequest{Pagination: pagination} - return c.bankQueryClient.TotalSupply(ctx, req) + resp, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.TotalSupply, req) + + return resp, err } func (c *chainClient) GetBankSupplyOf(ctx context.Context, denom string) (*banktypes.QuerySupplyOfResponse, error) { req := &banktypes.QuerySupplyOfRequest{Denom: denom} - return c.bankQueryClient.SupplyOf(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.SupplyOf, req) + + return res, err } func (c *chainClient) GetDenomMetadata(ctx context.Context, denom string) (*banktypes.QueryDenomMetadataResponse, error) { req := &banktypes.QueryDenomMetadataRequest{Denom: denom} - return c.bankQueryClient.DenomMetadata(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.DenomMetadata, req) + + return res, err } func (c *chainClient) GetDenomsMetadata(ctx context.Context, pagination *query.PageRequest) (*banktypes.QueryDenomsMetadataResponse, error) { req := &banktypes.QueryDenomsMetadataRequest{Pagination: pagination} - return c.bankQueryClient.DenomsMetadata(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.DenomsMetadata, req) + + return res, err } func (c *chainClient) GetDenomOwners(ctx context.Context, denom string, pagination *query.PageRequest) (*banktypes.QueryDenomOwnersResponse, error) { @@ -587,7 +585,9 @@ func (c *chainClient) GetDenomOwners(ctx context.Context, denom string, paginati Denom: denom, Pagination: pagination, } - return c.bankQueryClient.DenomOwners(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.DenomOwners, req) + + return res, err } func (c *chainClient) GetBankSendEnabled(ctx context.Context, denoms []string, pagination *query.PageRequest) (*banktypes.QuerySendEnabledResponse, error) { @@ -595,7 +595,9 @@ func (c *chainClient) GetBankSendEnabled(ctx context.Context, denoms []string, p Denoms: denoms, Pagination: pagination, } - return c.bankQueryClient.SendEnabled(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.bankQueryClient.SendEnabled, req) + + return res, err } // Auth Module @@ -604,7 +606,9 @@ func (c *chainClient) GetAccount(ctx context.Context, address string) (*authtype req := &authtypes.QueryAccountRequest{ Address: address, } - return c.authQueryClient.Account(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.authQueryClient.Account, req) + + return res, err } // SyncBroadcastMsg sends Tx to chain and waits until Tx is included in block. @@ -640,7 +644,9 @@ func (c *chainClient) GetFeeDiscountInfo(ctx context.Context, account string) (* req := &exchangetypes.QueryFeeDiscountAccountInfoRequest{ Account: account, } - return c.exchangeQueryClient.FeeDiscountAccountInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FeeDiscountAccountInfo, req) + + return res, err } func (c *chainClient) SimulateMsg(clientCtx client.Context, msgs ...sdk.Msg) (*txtypes.SimulateResponse, error) { @@ -659,8 +665,9 @@ func (c *chainClient) SimulateMsg(clientCtx client.Context, msgs ...sdk.Msg) (*t } ctx := context.Background() - ctx = c.getCookie(ctx) - simRes, err := c.txClient.Simulate(ctx, &txtypes.SimulateRequest{TxBytes: simTxBytes}) + req := &txtypes.SimulateRequest{TxBytes: simTxBytes} + simRes, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.Simulate, req) + if err != nil { err = errors.Wrap(err, "failed to CalculateGas") return nil, err @@ -708,9 +715,11 @@ func (c *chainClient) BuildSignedTx(clientCtx client.Context, accNum, accSeq, in err = errors.Wrap(err, "failed to build sim tx bytes") return nil, err } - ctx := c.getCookie(context.Background()) - var header metadata.MD - simRes, err := c.txClient.Simulate(ctx, &txtypes.SimulateRequest{TxBytes: simTxBytes}, grpc.Header(&header)) + + ctx := context.Background() + req := &txtypes.SimulateRequest{TxBytes: simTxBytes} + simRes, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.Simulate, req) + if err != nil { err = errors.Wrap(err, "failed to CalculateGas") return nil, err @@ -750,8 +759,8 @@ func (c *chainClient) SyncBroadcastSignedTx(txBytes []byte) (*txtypes.BroadcastT } ctx := context.Background() - ctx = c.getCookie(ctx) - res, err := c.txClient.BroadcastTx(ctx, &req) + + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.BroadcastTx, &req) if err != nil { return res, err } @@ -797,9 +806,7 @@ func (c *chainClient) AsyncBroadcastSignedTx(txBytes []byte) (*txtypes.Broadcast } ctx := context.Background() - // use our own client to broadcast tx - ctx = c.getCookie(ctx) - res, err := c.txClient.BroadcastTx(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.BroadcastTx, &req) if err != nil { return nil, err } @@ -825,8 +832,9 @@ func (c *chainClient) broadcastTx( err = errors.Wrap(err, "failed to build sim tx bytes") return nil, err } - ctx := c.getCookie(ctx) - simRes, err := c.txClient.Simulate(ctx, &txtypes.SimulateRequest{TxBytes: simTxBytes}) + + req := &txtypes.SimulateRequest{TxBytes: simTxBytes} + simRes, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.Simulate, req) if err != nil { err = errors.Wrap(err, "failed to CalculateGas") return nil, err @@ -862,9 +870,8 @@ func (c *chainClient) broadcastTx( TxBytes: txBytes, Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC, } - // use our own client to broadcast tx - ctx = c.getCookie(ctx) - res, err := c.txClient.BroadcastTx(ctx, &req) + + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.BroadcastTx, &req) if !await || err != nil { return res, err } @@ -1028,7 +1035,9 @@ func (c *chainClient) Subaccount(account sdk.AccAddress, index int) eth.Hash { func (c *chainClient) GetSubAccountNonce(ctx context.Context, subaccountId eth.Hash) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) { req := &exchangetypes.QuerySubaccountTradeNonceRequest{SubaccountId: subaccountId.String()} - return c.exchangeQueryClient.SubaccountTradeNonce(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountTradeNonce, req) + + return res, err } // Deprecated: Use CreateSpotOrder instead @@ -1113,7 +1122,9 @@ func (c *chainClient) OrderCancel(defaultSubaccountID eth.Hash, d *OrderCancelDa } func (c *chainClient) GetAuthzGrants(ctx context.Context, req authztypes.QueryGrantsRequest) (*authztypes.QueryGrantsResponse, error) { - return c.authzQueryClient.Grants(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.authzQueryClient.Grants, &req) + + return res, err } func (c *chainClient) BuildGenericAuthz(granter string, grantee string, msgtype string, expireIn time.Time) *authztypes.MsgGrant { @@ -1399,14 +1410,17 @@ func (c *chainClient) StreamOrderbookUpdateEventsWithWebsocket(orderbookType Ord } func (c *chainClient) GetTx(ctx context.Context, txHash string) (*txtypes.GetTxResponse, error) { - return c.txClient.GetTx(ctx, &txtypes.GetTxRequest{ + req := &txtypes.GetTxRequest{ Hash: txHash, - }) + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.txClient.GetTx, req) + + return res, err } func (c *chainClient) ChainStream(ctx context.Context, req chainstreamtypes.StreamRequest) (chainstreamtypes.Stream_StreamClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.chainStreamClient.Stream(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ChainCookieAssistant, c.chainStreamClient.Stream, &req) + if err != nil { fmt.Println(err) return nil, err @@ -1421,7 +1435,9 @@ func (c *chainClient) FetchContractInfo(ctx context.Context, address string) (*w req := &wasmtypes.QueryContractInfoRequest{ Address: address, } - return c.wasmQueryClient.ContractInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.ContractInfo, req) + + return res, err } func (c *chainClient) FetchContractHistory(ctx context.Context, address string, pagination *query.PageRequest) (*wasmtypes.QueryContractHistoryResponse, error) { @@ -1429,7 +1445,9 @@ func (c *chainClient) FetchContractHistory(ctx context.Context, address string, Address: address, Pagination: pagination, } - return c.wasmQueryClient.ContractHistory(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.ContractHistory, req) + + return res, err } func (c *chainClient) FetchContractsByCode(ctx context.Context, codeId uint64, pagination *query.PageRequest) (*wasmtypes.QueryContractsByCodeResponse, error) { @@ -1437,7 +1455,9 @@ func (c *chainClient) FetchContractsByCode(ctx context.Context, codeId uint64, p CodeId: codeId, Pagination: pagination, } - return c.wasmQueryClient.ContractsByCode(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.ContractsByCode, req) + + return res, err } func (c *chainClient) FetchAllContractsState(ctx context.Context, address string, pagination *query.PageRequest) (*wasmtypes.QueryAllContractStateResponse, error) { @@ -1445,7 +1465,9 @@ func (c *chainClient) FetchAllContractsState(ctx context.Context, address string Address: address, Pagination: pagination, } - return c.wasmQueryClient.AllContractState(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.AllContractState, req) + + return res, err } func (c *chainClient) RawContractState( @@ -1453,13 +1475,13 @@ func (c *chainClient) RawContractState( contractAddress string, queryData []byte, ) (*wasmtypes.QueryRawContractStateResponse, error) { - return c.wasmQueryClient.RawContractState( - ctx, - &wasmtypes.QueryRawContractStateRequest{ - Address: contractAddress, - QueryData: queryData, - }, - ) + req := &wasmtypes.QueryRawContractStateRequest{ + Address: contractAddress, + QueryData: queryData, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.RawContractState, req) + + return res, err } func (c *chainClient) SmartContractState( @@ -1467,34 +1489,40 @@ func (c *chainClient) SmartContractState( contractAddress string, queryData []byte, ) (*wasmtypes.QuerySmartContractStateResponse, error) { - return c.wasmQueryClient.SmartContractState( - ctx, - &wasmtypes.QuerySmartContractStateRequest{ - Address: contractAddress, - QueryData: queryData, - }, - ) + req := &wasmtypes.QuerySmartContractStateRequest{ + Address: contractAddress, + QueryData: queryData, + } + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.SmartContractState, req) + + return res, err } func (c *chainClient) FetchCode(ctx context.Context, codeId uint64) (*wasmtypes.QueryCodeResponse, error) { req := &wasmtypes.QueryCodeRequest{ CodeId: codeId, } - return c.wasmQueryClient.Code(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.Code, req) + + return res, err } func (c *chainClient) FetchCodes(ctx context.Context, pagination *query.PageRequest) (*wasmtypes.QueryCodesResponse, error) { req := &wasmtypes.QueryCodesRequest{ Pagination: pagination, } - return c.wasmQueryClient.Codes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.Codes, req) + + return res, err } func (c *chainClient) FetchPinnedCodes(ctx context.Context, pagination *query.PageRequest) (*wasmtypes.QueryPinnedCodesResponse, error) { req := &wasmtypes.QueryPinnedCodesRequest{ Pagination: pagination, } - return c.wasmQueryClient.PinnedCodes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.PinnedCodes, req) + + return res, err } func (c *chainClient) FetchContractsByCreator(ctx context.Context, creator string, pagination *query.PageRequest) (*wasmtypes.QueryContractsByCreatorResponse, error) { @@ -1502,7 +1530,9 @@ func (c *chainClient) FetchContractsByCreator(ctx context.Context, creator strin CreatorAddress: creator, Pagination: pagination, } - return c.wasmQueryClient.ContractsByCreator(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.wasmQueryClient.ContractsByCreator, req) + + return res, err } // Tokenfactory module @@ -1516,7 +1546,9 @@ func (c *chainClient) FetchDenomAuthorityMetadata(ctx context.Context, creator s req.SubDenom = subDenom } - return c.tokenfactoryQueryClient.DenomAuthorityMetadata(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tokenfactoryQueryClient.DenomAuthorityMetadata, req) + + return res, err } func (c *chainClient) FetchDenomsFromCreator(ctx context.Context, creator string) (*tokenfactorytypes.QueryDenomsFromCreatorResponse, error) { @@ -1524,13 +1556,17 @@ func (c *chainClient) FetchDenomsFromCreator(ctx context.Context, creator string Creator: creator, } - return c.tokenfactoryQueryClient.DenomsFromCreator(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tokenfactoryQueryClient.DenomsFromCreator, req) + + return res, err } func (c *chainClient) FetchTokenfactoryModuleState(ctx context.Context) (*tokenfactorytypes.QueryModuleStateResponse, error) { req := &tokenfactorytypes.QueryModuleStateRequest{} - return c.tokenfactoryQueryClient.TokenfactoryModuleState(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tokenfactoryQueryClient.TokenfactoryModuleState, req) + + return res, err } type DerivativeOrderData struct { @@ -1564,21 +1600,27 @@ func (c *chainClient) FetchValidatorDistributionInfo(ctx context.Context, valida req := &distributiontypes.QueryValidatorDistributionInfoRequest{ ValidatorAddress: validatorAddress, } - return c.distributionQueryClient.ValidatorDistributionInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.ValidatorDistributionInfo, req) + + return res, err } func (c *chainClient) FetchValidatorOutstandingRewards(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorOutstandingRewardsResponse, error) { req := &distributiontypes.QueryValidatorOutstandingRewardsRequest{ ValidatorAddress: validatorAddress, } - return c.distributionQueryClient.ValidatorOutstandingRewards(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.ValidatorOutstandingRewards, req) + + return res, err } func (c *chainClient) FetchValidatorCommission(ctx context.Context, validatorAddress string) (*distributiontypes.QueryValidatorCommissionResponse, error) { req := &distributiontypes.QueryValidatorCommissionRequest{ ValidatorAddress: validatorAddress, } - return c.distributionQueryClient.ValidatorCommission(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.ValidatorCommission, req) + + return res, err } func (c *chainClient) FetchValidatorSlashes(ctx context.Context, validatorAddress string, startingHeight uint64, endingHeight uint64, pagination *query.PageRequest) (*distributiontypes.QueryValidatorSlashesResponse, error) { @@ -1588,7 +1630,9 @@ func (c *chainClient) FetchValidatorSlashes(ctx context.Context, validatorAddres EndingHeight: endingHeight, Pagination: pagination, } - return c.distributionQueryClient.ValidatorSlashes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.ValidatorSlashes, req) + + return res, err } func (c *chainClient) FetchDelegationRewards(ctx context.Context, delegatorAddress string, validatorAddress string) (*distributiontypes.QueryDelegationRewardsResponse, error) { @@ -1596,33 +1640,43 @@ func (c *chainClient) FetchDelegationRewards(ctx context.Context, delegatorAddre DelegatorAddress: delegatorAddress, ValidatorAddress: validatorAddress, } - return c.distributionQueryClient.DelegationRewards(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.DelegationRewards, req) + + return res, err } func (c *chainClient) FetchDelegationTotalRewards(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegationTotalRewardsResponse, error) { req := &distributiontypes.QueryDelegationTotalRewardsRequest{ DelegatorAddress: delegatorAddress, } - return c.distributionQueryClient.DelegationTotalRewards(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.DelegationTotalRewards, req) + + return res, err } func (c *chainClient) FetchDelegatorValidators(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorValidatorsResponse, error) { req := &distributiontypes.QueryDelegatorValidatorsRequest{ DelegatorAddress: delegatorAddress, } - return c.distributionQueryClient.DelegatorValidators(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.DelegatorValidators, req) + + return res, err } func (c *chainClient) FetchDelegatorWithdrawAddress(ctx context.Context, delegatorAddress string) (*distributiontypes.QueryDelegatorWithdrawAddressResponse, error) { req := &distributiontypes.QueryDelegatorWithdrawAddressRequest{ DelegatorAddress: delegatorAddress, } - return c.distributionQueryClient.DelegatorWithdrawAddress(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.DelegatorWithdrawAddress, req) + + return res, err } func (c *chainClient) FetchCommunityPool(ctx context.Context) (*distributiontypes.QueryCommunityPoolResponse, error) { req := &distributiontypes.QueryCommunityPoolRequest{} - return c.distributionQueryClient.CommunityPool(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.distributionQueryClient.CommunityPool, req) + + return res, err } // Chain exchange module @@ -1630,7 +1684,9 @@ func (c *chainClient) FetchSubaccountDeposits(ctx context.Context, subaccountId req := &exchangetypes.QuerySubaccountDepositsRequest{ SubaccountId: subaccountId, } - return c.exchangeQueryClient.SubaccountDeposits(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountDeposits, req) + + return res, err } func (c *chainClient) FetchSubaccountDeposit(ctx context.Context, subaccountId string, denom string) (*exchangetypes.QuerySubaccountDepositResponse, error) { @@ -1638,19 +1694,25 @@ func (c *chainClient) FetchSubaccountDeposit(ctx context.Context, subaccountId s SubaccountId: subaccountId, Denom: denom, } - return c.exchangeQueryClient.SubaccountDeposit(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountDeposit, req) + + return res, err } func (c *chainClient) FetchExchangeBalances(ctx context.Context) (*exchangetypes.QueryExchangeBalancesResponse, error) { req := &exchangetypes.QueryExchangeBalancesRequest{} - return c.exchangeQueryClient.ExchangeBalances(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.ExchangeBalances, req) + + return res, err } func (c *chainClient) FetchAggregateVolume(ctx context.Context, account string) (*exchangetypes.QueryAggregateVolumeResponse, error) { req := &exchangetypes.QueryAggregateVolumeRequest{ Account: account, } - return c.exchangeQueryClient.AggregateVolume(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AggregateVolume, req) + + return res, err } func (c *chainClient) FetchAggregateVolumes(ctx context.Context, accounts []string, marketIds []string) (*exchangetypes.QueryAggregateVolumesResponse, error) { @@ -1658,35 +1720,45 @@ func (c *chainClient) FetchAggregateVolumes(ctx context.Context, accounts []stri Accounts: accounts, MarketIds: marketIds, } - return c.exchangeQueryClient.AggregateVolumes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AggregateVolumes, req) + + return res, err } func (c *chainClient) FetchAggregateMarketVolume(ctx context.Context, marketId string) (*exchangetypes.QueryAggregateMarketVolumeResponse, error) { req := &exchangetypes.QueryAggregateMarketVolumeRequest{ MarketId: marketId, } - return c.exchangeQueryClient.AggregateMarketVolume(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AggregateMarketVolume, req) + + return res, err } func (c *chainClient) FetchAggregateMarketVolumes(ctx context.Context, marketIds []string) (*exchangetypes.QueryAggregateMarketVolumesResponse, error) { req := &exchangetypes.QueryAggregateMarketVolumesRequest{ MarketIds: marketIds, } - return c.exchangeQueryClient.AggregateMarketVolumes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AggregateMarketVolumes, req) + + return res, err } func (c *chainClient) FetchDenomDecimal(ctx context.Context, denom string) (*exchangetypes.QueryDenomDecimalResponse, error) { req := &exchangetypes.QueryDenomDecimalRequest{ Denom: denom, } - return c.exchangeQueryClient.DenomDecimal(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DenomDecimal, req) + + return res, err } func (c *chainClient) FetchDenomDecimals(ctx context.Context, denoms []string) (*exchangetypes.QueryDenomDecimalsResponse, error) { req := &exchangetypes.QueryDenomDecimalsRequest{ Denoms: denoms, } - return c.exchangeQueryClient.DenomDecimals(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DenomDecimals, req) + + return res, err } func (c *chainClient) FetchChainSpotMarkets(ctx context.Context, status string, marketIds []string) (*exchangetypes.QuerySpotMarketsResponse, error) { @@ -1696,14 +1768,18 @@ func (c *chainClient) FetchChainSpotMarkets(ctx context.Context, status string, if status != "" { req.Status = status } - return c.exchangeQueryClient.SpotMarkets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SpotMarkets, req) + + return res, err } func (c *chainClient) FetchChainSpotMarket(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMarketResponse, error) { req := &exchangetypes.QuerySpotMarketRequest{ MarketId: marketId, } - return c.exchangeQueryClient.SpotMarket(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SpotMarket, req) + + return res, err } func (c *chainClient) FetchChainFullSpotMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketsResponse, error) { @@ -1714,7 +1790,9 @@ func (c *chainClient) FetchChainFullSpotMarkets(ctx context.Context, status stri if status != "" { req.Status = status } - return c.exchangeQueryClient.FullSpotMarkets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FullSpotMarkets, req) + + return res, err } func (c *chainClient) FetchChainFullSpotMarket(ctx context.Context, marketId string, withMidPriceAndTob bool) (*exchangetypes.QueryFullSpotMarketResponse, error) { @@ -1722,7 +1800,9 @@ func (c *chainClient) FetchChainFullSpotMarket(ctx context.Context, marketId str MarketId: marketId, WithMidPriceAndTob: withMidPriceAndTob, } - return c.exchangeQueryClient.FullSpotMarket(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FullSpotMarket, req) + + return res, err } func (c *chainClient) FetchChainSpotOrderbook(ctx context.Context, marketId string, limit uint64, orderSide exchangetypes.OrderSide, limitCumulativeNotional sdk.Dec, limitCumulativeQuantity sdk.Dec) (*exchangetypes.QuerySpotOrderbookResponse, error) { @@ -1733,7 +1813,9 @@ func (c *chainClient) FetchChainSpotOrderbook(ctx context.Context, marketId stri LimitCumulativeNotional: &limitCumulativeNotional, LimitCumulativeQuantity: &limitCumulativeQuantity, } - return c.exchangeQueryClient.SpotOrderbook(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SpotOrderbook, req) + + return res, err } func (c *chainClient) FetchChainTraderSpotOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { @@ -1741,7 +1823,9 @@ func (c *chainClient) FetchChainTraderSpotOrders(ctx context.Context, marketId s MarketId: marketId, SubaccountId: subaccountId, } - return c.exchangeQueryClient.TraderSpotOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TraderSpotOrders, req) + + return res, err } func (c *chainClient) FetchChainAccountAddressSpotOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressSpotOrdersResponse, error) { @@ -1749,7 +1833,9 @@ func (c *chainClient) FetchChainAccountAddressSpotOrders(ctx context.Context, ma MarketId: marketId, AccountAddress: address, } - return c.exchangeQueryClient.AccountAddressSpotOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AccountAddressSpotOrders, req) + + return res, err } func (c *chainClient) FetchChainSpotOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QuerySpotOrdersByHashesResponse, error) { @@ -1758,7 +1844,9 @@ func (c *chainClient) FetchChainSpotOrdersByHashes(ctx context.Context, marketId SubaccountId: subaccountId, OrderHashes: orderHashes, } - return c.exchangeQueryClient.SpotOrdersByHashes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SpotOrdersByHashes, req) + + return res, err } func (c *chainClient) FetchChainSubaccountOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountOrdersResponse, error) { @@ -1766,7 +1854,9 @@ func (c *chainClient) FetchChainSubaccountOrders(ctx context.Context, subaccount SubaccountId: subaccountId, MarketId: marketId, } - return c.exchangeQueryClient.SubaccountOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountOrders, req) + + return res, err } func (c *chainClient) FetchChainTraderSpotTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderSpotOrdersResponse, error) { @@ -1774,21 +1864,27 @@ func (c *chainClient) FetchChainTraderSpotTransientOrders(ctx context.Context, m MarketId: marketId, SubaccountId: subaccountId, } - return c.exchangeQueryClient.TraderSpotTransientOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TraderSpotTransientOrders, req) + + return res, err } func (c *chainClient) FetchSpotMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QuerySpotMidPriceAndTOBResponse, error) { req := &exchangetypes.QuerySpotMidPriceAndTOBRequest{ MarketId: marketId, } - return c.exchangeQueryClient.SpotMidPriceAndTOB(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SpotMidPriceAndTOB, req) + + return res, err } func (c *chainClient) FetchDerivativeMidPriceAndTOB(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMidPriceAndTOBResponse, error) { req := &exchangetypes.QueryDerivativeMidPriceAndTOBRequest{ MarketId: marketId, } - return c.exchangeQueryClient.DerivativeMidPriceAndTOB(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeMidPriceAndTOB, req) + + return res, err } func (c *chainClient) FetchChainDerivativeOrderbook(ctx context.Context, marketId string, limit uint64, limitCumulativeNotional sdk.Dec) (*exchangetypes.QueryDerivativeOrderbookResponse, error) { @@ -1797,7 +1893,9 @@ func (c *chainClient) FetchChainDerivativeOrderbook(ctx context.Context, marketI Limit: limit, LimitCumulativeNotional: &limitCumulativeNotional, } - return c.exchangeQueryClient.DerivativeOrderbook(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeOrderbook, req) + + return res, err } func (c *chainClient) FetchChainTraderDerivativeOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { @@ -1805,7 +1903,9 @@ func (c *chainClient) FetchChainTraderDerivativeOrders(ctx context.Context, mark MarketId: marketId, SubaccountId: subaccountId, } - return c.exchangeQueryClient.TraderDerivativeOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TraderDerivativeOrders, req) + + return res, err } func (c *chainClient) FetchChainAccountAddressDerivativeOrders(ctx context.Context, marketId string, address string) (*exchangetypes.QueryAccountAddressDerivativeOrdersResponse, error) { @@ -1813,7 +1913,9 @@ func (c *chainClient) FetchChainAccountAddressDerivativeOrders(ctx context.Conte MarketId: marketId, AccountAddress: address, } - return c.exchangeQueryClient.AccountAddressDerivativeOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.AccountAddressDerivativeOrders, req) + + return res, err } func (c *chainClient) FetchChainDerivativeOrdersByHashes(ctx context.Context, marketId string, subaccountId string, orderHashes []string) (*exchangetypes.QueryDerivativeOrdersByHashesResponse, error) { @@ -1822,7 +1924,9 @@ func (c *chainClient) FetchChainDerivativeOrdersByHashes(ctx context.Context, ma SubaccountId: subaccountId, OrderHashes: orderHashes, } - return c.exchangeQueryClient.DerivativeOrdersByHashes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeOrdersByHashes, req) + + return res, err } func (c *chainClient) FetchChainTraderDerivativeTransientOrders(ctx context.Context, marketId string, subaccountId string) (*exchangetypes.QueryTraderDerivativeOrdersResponse, error) { @@ -1830,7 +1934,9 @@ func (c *chainClient) FetchChainTraderDerivativeTransientOrders(ctx context.Cont MarketId: marketId, SubaccountId: subaccountId, } - return c.exchangeQueryClient.TraderDerivativeTransientOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TraderDerivativeTransientOrders, req) + + return res, err } func (c *chainClient) FetchChainDerivativeMarkets(ctx context.Context, status string, marketIds []string, withMidPriceAndTob bool) (*exchangetypes.QueryDerivativeMarketsResponse, error) { @@ -1841,40 +1947,52 @@ func (c *chainClient) FetchChainDerivativeMarkets(ctx context.Context, status st if status != "" { req.Status = status } - return c.exchangeQueryClient.DerivativeMarkets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeMarkets, req) + + return res, err } func (c *chainClient) FetchChainDerivativeMarket(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketResponse, error) { req := &exchangetypes.QueryDerivativeMarketRequest{ MarketId: marketId, } - return c.exchangeQueryClient.DerivativeMarket(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeMarket, req) + + return res, err } func (c *chainClient) FetchDerivativeMarketAddress(ctx context.Context, marketId string) (*exchangetypes.QueryDerivativeMarketAddressResponse, error) { req := &exchangetypes.QueryDerivativeMarketAddressRequest{ MarketId: marketId, } - return c.exchangeQueryClient.DerivativeMarketAddress(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.DerivativeMarketAddress, req) + + return res, err } func (c *chainClient) FetchSubaccountTradeNonce(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountTradeNonceResponse, error) { req := &exchangetypes.QuerySubaccountTradeNonceRequest{ SubaccountId: subaccountId, } - return c.exchangeQueryClient.SubaccountTradeNonce(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountTradeNonce, req) + + return res, err } func (c *chainClient) FetchChainPositions(ctx context.Context) (*exchangetypes.QueryPositionsResponse, error) { req := &exchangetypes.QueryPositionsRequest{} - return c.exchangeQueryClient.Positions(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.Positions, req) + + return res, err } func (c *chainClient) FetchChainSubaccountPositions(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountPositionsResponse, error) { req := &exchangetypes.QuerySubaccountPositionsRequest{ SubaccountId: subaccountId, } - return c.exchangeQueryClient.SubaccountPositions(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountPositions, req) + + return res, err } func (c *chainClient) FetchChainSubaccountPositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountPositionInMarketResponse, error) { @@ -1882,7 +2000,9 @@ func (c *chainClient) FetchChainSubaccountPositionInMarket(ctx context.Context, SubaccountId: subaccountId, MarketId: marketId, } - return c.exchangeQueryClient.SubaccountPositionInMarket(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountPositionInMarket, req) + + return res, err } func (c *chainClient) FetchChainSubaccountEffectivePositionInMarket(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QuerySubaccountEffectivePositionInMarketResponse, error) { @@ -1890,114 +2010,150 @@ func (c *chainClient) FetchChainSubaccountEffectivePositionInMarket(ctx context. SubaccountId: subaccountId, MarketId: marketId, } - return c.exchangeQueryClient.SubaccountEffectivePositionInMarket(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountEffectivePositionInMarket, req) + + return res, err } func (c *chainClient) FetchChainPerpetualMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketInfoResponse, error) { req := &exchangetypes.QueryPerpetualMarketInfoRequest{ MarketId: marketId, } - return c.exchangeQueryClient.PerpetualMarketInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.PerpetualMarketInfo, req) + + return res, err } func (c *chainClient) FetchChainExpiryFuturesMarketInfo(ctx context.Context, marketId string) (*exchangetypes.QueryExpiryFuturesMarketInfoResponse, error) { req := &exchangetypes.QueryExpiryFuturesMarketInfoRequest{ MarketId: marketId, } - return c.exchangeQueryClient.ExpiryFuturesMarketInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.ExpiryFuturesMarketInfo, req) + + return res, err } func (c *chainClient) FetchChainPerpetualMarketFunding(ctx context.Context, marketId string) (*exchangetypes.QueryPerpetualMarketFundingResponse, error) { req := &exchangetypes.QueryPerpetualMarketFundingRequest{ MarketId: marketId, } - return c.exchangeQueryClient.PerpetualMarketFunding(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.PerpetualMarketFunding, req) + + return res, err } func (c *chainClient) FetchSubaccountOrderMetadata(ctx context.Context, subaccountId string) (*exchangetypes.QuerySubaccountOrderMetadataResponse, error) { req := &exchangetypes.QuerySubaccountOrderMetadataRequest{ SubaccountId: subaccountId, } - return c.exchangeQueryClient.SubaccountOrderMetadata(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.SubaccountOrderMetadata, req) + + return res, err } func (c *chainClient) FetchTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { req := &exchangetypes.QueryTradeRewardPointsRequest{ Accounts: accounts, } - return c.exchangeQueryClient.TradeRewardPoints(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TradeRewardPoints, req) + + return res, err } func (c *chainClient) FetchPendingTradeRewardPoints(ctx context.Context, accounts []string) (*exchangetypes.QueryTradeRewardPointsResponse, error) { req := &exchangetypes.QueryTradeRewardPointsRequest{ Accounts: accounts, } - return c.exchangeQueryClient.PendingTradeRewardPoints(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.PendingTradeRewardPoints, req) + + return res, err } func (c *chainClient) FetchTradeRewardCampaign(ctx context.Context) (*exchangetypes.QueryTradeRewardCampaignResponse, error) { req := &exchangetypes.QueryTradeRewardCampaignRequest{} - return c.exchangeQueryClient.TradeRewardCampaign(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TradeRewardCampaign, req) + + return res, err } func (c *chainClient) FetchFeeDiscountAccountInfo(ctx context.Context, account string) (*exchangetypes.QueryFeeDiscountAccountInfoResponse, error) { req := &exchangetypes.QueryFeeDiscountAccountInfoRequest{ Account: account, } - return c.exchangeQueryClient.FeeDiscountAccountInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FeeDiscountAccountInfo, req) + + return res, err } func (c *chainClient) FetchFeeDiscountSchedule(ctx context.Context) (*exchangetypes.QueryFeeDiscountScheduleResponse, error) { req := &exchangetypes.QueryFeeDiscountScheduleRequest{} - return c.exchangeQueryClient.FeeDiscountSchedule(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FeeDiscountSchedule, req) + + return res, err } func (c *chainClient) FetchBalanceMismatches(ctx context.Context, dustFactor int64) (*exchangetypes.QueryBalanceMismatchesResponse, error) { req := &exchangetypes.QueryBalanceMismatchesRequest{ DustFactor: dustFactor, } - return c.exchangeQueryClient.BalanceMismatches(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.BalanceMismatches, req) + + return res, err } func (c *chainClient) FetchBalanceWithBalanceHolds(ctx context.Context) (*exchangetypes.QueryBalanceWithBalanceHoldsResponse, error) { req := &exchangetypes.QueryBalanceWithBalanceHoldsRequest{} - return c.exchangeQueryClient.BalanceWithBalanceHolds(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.BalanceWithBalanceHolds, req) + + return res, err } func (c *chainClient) FetchFeeDiscountTierStatistics(ctx context.Context) (*exchangetypes.QueryFeeDiscountTierStatisticsResponse, error) { req := &exchangetypes.QueryFeeDiscountTierStatisticsRequest{} - return c.exchangeQueryClient.FeeDiscountTierStatistics(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.FeeDiscountTierStatistics, req) + + return res, err } func (c *chainClient) FetchMitoVaultInfos(ctx context.Context) (*exchangetypes.MitoVaultInfosResponse, error) { req := &exchangetypes.MitoVaultInfosRequest{} - return c.exchangeQueryClient.MitoVaultInfos(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.MitoVaultInfos, req) + + return res, err } func (c *chainClient) FetchMarketIDFromVault(ctx context.Context, vaultAddress string) (*exchangetypes.QueryMarketIDFromVaultResponse, error) { req := &exchangetypes.QueryMarketIDFromVaultRequest{ VaultAddress: vaultAddress, } - return c.exchangeQueryClient.QueryMarketIDFromVault(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.QueryMarketIDFromVault, req) + + return res, err } func (c *chainClient) FetchHistoricalTradeRecords(ctx context.Context, marketId string) (*exchangetypes.QueryHistoricalTradeRecordsResponse, error) { req := &exchangetypes.QueryHistoricalTradeRecordsRequest{ MarketId: marketId, } - return c.exchangeQueryClient.HistoricalTradeRecords(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.HistoricalTradeRecords, req) + + return res, err } func (c *chainClient) FetchIsOptedOutOfRewards(ctx context.Context, account string) (*exchangetypes.QueryIsOptedOutOfRewardsResponse, error) { req := &exchangetypes.QueryIsOptedOutOfRewardsRequest{ Account: account, } - return c.exchangeQueryClient.IsOptedOutOfRewards(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.IsOptedOutOfRewards, req) + + return res, err } func (c *chainClient) FetchOptedOutOfRewardsAccounts(ctx context.Context) (*exchangetypes.QueryOptedOutOfRewardsAccountsResponse, error) { req := &exchangetypes.QueryOptedOutOfRewardsAccountsRequest{} - return c.exchangeQueryClient.OptedOutOfRewardsAccounts(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.OptedOutOfRewardsAccounts, req) + + return res, err } func (c *chainClient) FetchMarketVolatility(ctx context.Context, marketId string, tradeHistoryOptions *exchangetypes.TradeHistoryOptions) (*exchangetypes.QueryMarketVolatilityResponse, error) { @@ -2005,7 +2161,9 @@ func (c *chainClient) FetchMarketVolatility(ctx context.Context, marketId string MarketId: marketId, TradeHistoryOptions: tradeHistoryOptions, } - return c.exchangeQueryClient.MarketVolatility(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.MarketVolatility, req) + + return res, err } func (c *chainClient) FetchChainBinaryOptionsMarkets(ctx context.Context, status string) (*exchangetypes.QueryBinaryMarketsResponse, error) { @@ -2013,7 +2171,9 @@ func (c *chainClient) FetchChainBinaryOptionsMarkets(ctx context.Context, status if status != "" { req.Status = status } - return c.exchangeQueryClient.BinaryOptionsMarkets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.BinaryOptionsMarkets, req) + + return res, err } func (c *chainClient) FetchTraderDerivativeConditionalOrders(ctx context.Context, subaccountId string, marketId string) (*exchangetypes.QueryTraderDerivativeConditionalOrdersResponse, error) { @@ -2021,43 +2181,57 @@ func (c *chainClient) FetchTraderDerivativeConditionalOrders(ctx context.Context SubaccountId: subaccountId, MarketId: marketId, } - return c.exchangeQueryClient.TraderDerivativeConditionalOrders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.TraderDerivativeConditionalOrders, req) + + return res, err } func (c *chainClient) FetchMarketAtomicExecutionFeeMultiplier(ctx context.Context, marketId string) (*exchangetypes.QueryMarketAtomicExecutionFeeMultiplierResponse, error) { req := &exchangetypes.QueryMarketAtomicExecutionFeeMultiplierRequest{ MarketId: marketId, } - return c.exchangeQueryClient.MarketAtomicExecutionFeeMultiplier(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.exchangeQueryClient.MarketAtomicExecutionFeeMultiplier, req) + + return res, err } // Tendermint module func (c *chainClient) FetchNodeInfo(ctx context.Context) (*tmservice.GetNodeInfoResponse, error) { req := &tmservice.GetNodeInfoRequest{} - return c.tendermintQueryClient.GetNodeInfo(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetNodeInfo, req) + + return res, err } func (c *chainClient) FetchSyncing(ctx context.Context) (*tmservice.GetSyncingResponse, error) { req := &tmservice.GetSyncingRequest{} - return c.tendermintQueryClient.GetSyncing(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetSyncing, req) + + return res, err } func (c *chainClient) FetchLatestBlock(ctx context.Context) (*tmservice.GetLatestBlockResponse, error) { req := &tmservice.GetLatestBlockRequest{} - return c.tendermintQueryClient.GetLatestBlock(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetLatestBlock, req) + + return res, err } func (c *chainClient) FetchBlockByHeight(ctx context.Context, height int64) (*tmservice.GetBlockByHeightResponse, error) { req := &tmservice.GetBlockByHeightRequest{ Height: height, } - return c.tendermintQueryClient.GetBlockByHeight(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetBlockByHeight, req) + + return res, err } func (c *chainClient) FetchLatestValidatorSet(ctx context.Context) (*tmservice.GetLatestValidatorSetResponse, error) { req := &tmservice.GetLatestValidatorSetRequest{} - return c.tendermintQueryClient.GetLatestValidatorSet(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetLatestValidatorSet, req) + + return res, err } func (c *chainClient) FetchValidatorSetByHeight(ctx context.Context, height int64, pagination *query.PageRequest) (*tmservice.GetValidatorSetByHeightResponse, error) { @@ -2065,7 +2239,9 @@ func (c *chainClient) FetchValidatorSetByHeight(ctx context.Context, height int6 Height: height, Pagination: pagination, } - return c.tendermintQueryClient.GetValidatorSetByHeight(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.GetValidatorSetByHeight, req) + + return res, err } func (c *chainClient) ABCIQuery(ctx context.Context, path string, data []byte, height int64, prove bool) (*tmservice.ABCIQueryResponse, error) { @@ -2075,5 +2251,7 @@ func (c *chainClient) ABCIQuery(ctx context.Context, path string, data []byte, h Height: height, Prove: prove, } - return c.tendermintQueryClient.ABCIQuery(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ChainCookieAssistant, c.tendermintQueryClient.ABCIQuery, req) + + return res, err } diff --git a/client/common/api_request_assistant.go b/client/common/api_request_assistant.go new file mode 100644 index 00000000..e5956792 --- /dev/null +++ b/client/common/api_request_assistant.go @@ -0,0 +1,36 @@ +package common + +import ( + "context" + "google.golang.org/grpc" + "google.golang.org/grpc/metadata" +) + +type ApiCall[Q any, R any] func(ctx context.Context, in *Q, opts ...grpc.CallOption) (*R, error) +type ApiStreamCall[Q any, S grpc.ClientStream] func(ctx context.Context, in *Q, opts ...grpc.CallOption) (S, error) + +func ExecuteCall[Q any, R any](ctx context.Context, cookieAssistant CookieAssistant, call ApiCall[Q, R], in *Q) (*R, error) { + var header metadata.MD + localCtx := metadata.NewOutgoingContext(ctx, cookieAssistant.RealMetadata()) + + response, err := call(localCtx, in, grpc.Header(&header)) + + cookieAssistant.ProcessResponseMetadata(header) + + return response, err +} + +func ExecuteStreamCall[Q any, S grpc.ClientStream](ctx context.Context, cookieAssistant CookieAssistant, call ApiStreamCall[Q, S], in *Q) (S, error) { + localCtx := metadata.NewOutgoingContext(ctx, cookieAssistant.RealMetadata()) + + stream, callError := call(localCtx, in) + + if callError == nil { + header, err := stream.Header() + if err == nil { + cookieAssistant.ProcessResponseMetadata(header) + } + } + + return stream, callError +} diff --git a/client/common/network.go b/client/common/network.go index ec50a01b..0fbbd499 100644 --- a/client/common/network.go +++ b/client/common/network.go @@ -41,6 +41,8 @@ func (provider *MetadataProvider) metadata() metadata.MD { type CookieAssistant interface { Metadata(provider MetadataProvider) (string, error) + RealMetadata() metadata.MD + ProcessResponseMetadata(header metadata.MD) } type ExpiringCookieAssistant struct { @@ -74,7 +76,7 @@ func (assistant *ExpiringCookieAssistant) checkCookieExpiration() { if err == nil { timestampDiff := time.Until(expirationTime) - if timestampDiff < SessionRenewalOffset { + if timestampDiff < 0 { assistant.cookie = "" } } @@ -95,6 +97,22 @@ func (assistant *ExpiringCookieAssistant) Metadata(provider MetadataProvider) (s return cookie, nil } +func (assistant *ExpiringCookieAssistant) RealMetadata() metadata.MD { + newMetadata := metadata.Pairs() + assistant.checkCookieExpiration() + if assistant.cookie != "" { + newMetadata.Append("cookie", assistant.cookie) + } + return newMetadata +} + +func (assistant *ExpiringCookieAssistant) ProcessResponseMetadata(header metadata.MD) { + cookieInfo := header.Get("set-cookie") + if len(cookieInfo) > 0 { + assistant.cookie = cookieInfo[0] + } +} + func TestnetKubernetesCookieAssistant() ExpiringCookieAssistant { assistant := ExpiringCookieAssistant{} assistant.expirationKey = "Expires" @@ -138,12 +156,33 @@ func (assistant *BareMetalLoadBalancedCookieAssistant) Metadata(provider Metadat return assistant.cookie, nil } +func (assistant *BareMetalLoadBalancedCookieAssistant) RealMetadata() metadata.MD { + newMetadata := metadata.Pairs() + if assistant.cookie != "" { + newMetadata.Append("cookie", assistant.cookie) + } + return newMetadata +} + +func (assistant *BareMetalLoadBalancedCookieAssistant) ProcessResponseMetadata(header metadata.MD) { + cookieInfo := header.Get("set-cookie") + if len(cookieInfo) > 0 { + assistant.cookie = cookieInfo[0] + } +} + type DisabledCookieAssistant struct{} func (assistant *DisabledCookieAssistant) Metadata(provider MetadataProvider) (string, error) { return "", nil } +func (assistant *DisabledCookieAssistant) RealMetadata() metadata.MD { + return metadata.Pairs() +} + +func (assistant *DisabledCookieAssistant) ProcessResponseMetadata(header metadata.MD) {} + type Network struct { LcdEndpoint string TmEndpoint string @@ -155,23 +194,11 @@ type Network struct { ExchangeTlsCert credentials.TransportCredentials ExplorerTlsCert credentials.TransportCredentials ChainId string - Fee_denom string + FeeDenom string Name string - chainCookieAssistant CookieAssistant - exchangeCookieAssistant CookieAssistant - explorerCookieAssistant CookieAssistant -} - -func (network *Network) ChainMetadata(provider MetadataProvider) (string, error) { - return network.chainCookieAssistant.Metadata(provider) -} - -func (network *Network) ExchangeMetadata(provider MetadataProvider) (string, error) { - return network.exchangeCookieAssistant.Metadata(provider) -} - -func (network *Network) ExplorerMetadata(provider MetadataProvider) (string, error) { - return network.explorerCookieAssistant.Metadata(provider) + ChainCookieAssistant CookieAssistant + ExchangeCookieAssistant CookieAssistant + ExplorerCookieAssistant CookieAssistant } func LoadNetwork(name string, node string) Network { @@ -186,11 +213,11 @@ func LoadNetwork(name string, node string) Network { ExchangeGrpcEndpoint: "tcp://devnet-1.api.injective.dev:9910", ExplorerGrpcEndpoint: "tcp://devnet-1.api.injective.dev:9911", ChainId: "injective-777", - Fee_denom: "inj", + FeeDenom: "inj", Name: "devnet-1", - chainCookieAssistant: &DisabledCookieAssistant{}, - exchangeCookieAssistant: &DisabledCookieAssistant{}, - explorerCookieAssistant: &DisabledCookieAssistant{}, + ChainCookieAssistant: &DisabledCookieAssistant{}, + ExchangeCookieAssistant: &DisabledCookieAssistant{}, + ExplorerCookieAssistant: &DisabledCookieAssistant{}, } case "devnet": return Network{ @@ -201,11 +228,11 @@ func LoadNetwork(name string, node string) Network { ExchangeGrpcEndpoint: "tcp://devnet.injective.dev:9910", ExplorerGrpcEndpoint: "tcp://devnet.api.injective.dev:9911", ChainId: "injective-777", - Fee_denom: "inj", + FeeDenom: "inj", Name: "devnet", - chainCookieAssistant: &DisabledCookieAssistant{}, - exchangeCookieAssistant: &DisabledCookieAssistant{}, - explorerCookieAssistant: &DisabledCookieAssistant{}, + ChainCookieAssistant: &DisabledCookieAssistant{}, + ExchangeCookieAssistant: &DisabledCookieAssistant{}, + ExplorerCookieAssistant: &DisabledCookieAssistant{}, } case "testnet": validNodes := []string{"lb", "sentry"} @@ -255,11 +282,11 @@ func LoadNetwork(name string, node string) Network { ExplorerGrpcEndpoint: explorerGrpcEndpoint, ExplorerTlsCert: explorerTlsCert, ChainId: "injective-888", - Fee_denom: "inj", + FeeDenom: "inj", Name: "testnet", - chainCookieAssistant: chainCookieAssistant, - exchangeCookieAssistant: exchangeCookieAssistant, - explorerCookieAssistant: explorerCookieAssistant, + ChainCookieAssistant: chainCookieAssistant, + ExchangeCookieAssistant: exchangeCookieAssistant, + ExplorerCookieAssistant: explorerCookieAssistant, } case "mainnet": validNodes := []string{"lb"} @@ -294,11 +321,11 @@ func LoadNetwork(name string, node string) Network { ExplorerGrpcEndpoint: explorerGrpcEndpoint, ExplorerTlsCert: explorerTlsCert, ChainId: "injective-1", - Fee_denom: "inj", + FeeDenom: "inj", Name: "mainnet", - chainCookieAssistant: chainCookieAssistant, - exchangeCookieAssistant: exchangeCookieAssistant, - explorerCookieAssistant: explorerCookieAssistant, + ChainCookieAssistant: chainCookieAssistant, + ExchangeCookieAssistant: exchangeCookieAssistant, + ExplorerCookieAssistant: explorerCookieAssistant, } } @@ -309,9 +336,9 @@ func LoadNetwork(name string, node string) Network { // It can be used to setup a custom environment from scratch. func NewNetwork() Network { return Network{ - chainCookieAssistant: &DisabledCookieAssistant{}, - exchangeCookieAssistant: &DisabledCookieAssistant{}, - explorerCookieAssistant: &DisabledCookieAssistant{}, + ChainCookieAssistant: &DisabledCookieAssistant{}, + ExchangeCookieAssistant: &DisabledCookieAssistant{}, + ExplorerCookieAssistant: &DisabledCookieAssistant{}, } } diff --git a/client/common/network_test.go b/client/common/network_test.go index 235c580e..3006b35e 100644 --- a/client/common/network_test.go +++ b/client/common/network_test.go @@ -10,227 +10,120 @@ import ( func TestMainnetKubernetesLoadBalancedCookieAssistant(t *testing.T) { assistant := MainnetKubernetesCookieAssistant() - expectedCookie := "GCLB=CMOO2-DdvKWMqQE; path=/; HttpOnly; expires=Sat, 16-Sep-2023 18:26:00 GMT" + expectedCookie := fmt.Sprintf("GCLB=CMOO2-DdvKWMqQE; path=/; HttpOnly; expires=%s", time.Now().Add(5*time.Hour).Format("Mon, 02-Jan-2006 15:04:05 MST")) - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", expectedCookie) - return md - } - - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) + localMetadata := metadata.Pairs("set-cookie", expectedCookie) - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } + assistant.ProcessResponseMetadata(localMetadata) + assistantMetadata := assistant.RealMetadata() + cookieInfo := assistantMetadata.Get("cookie") - if cookie != expectedCookie { - t.Fatalf("The parsed cookie is different than the expected cookie") + if len(cookieInfo) > 0 { + cookie := cookieInfo[0] + if cookie != expectedCookie { + t.Fatalf("The parsed cookie is different than the expected cookie") + } + } else { + t.Fatalf("The cookie was not parsed") } } func TestMainnetKubernetesLoadBalancedCookieAssistantRemovesExpiredCookie(t *testing.T) { assistant := MainnetKubernetesCookieAssistant() tt := time.Now() - closeExpirationTime := tt.Add(30 * time.Second) + closeExpirationTime := tt.Add(-30 * time.Second) - soonToExpireCookie := fmt.Sprintf( + expiredCookie := fmt.Sprintf( "GCLB=CMOO2-DdvKWMqQE; path=/; HttpOnly; expires=%s", closeExpirationTime.Format("Mon, 02-Jan-2006 15:04:05 MST"), ) - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", soonToExpireCookie) - return md - } - - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) - - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != soonToExpireCookie { - t.Fatalf("The parsed cookie is different than the expected cookie") - } - - nextExpirationTime := tt.Add(5 * time.Minute) - secondCookie := fmt.Sprintf( - "GCLB=CMOO2-DdvKWMqQE; path=/; HttpOnly; expires=%s", - nextExpirationTime.Format("Mon, 02-Jan-2006 15:04:05 MST"), - ) - - providerFunc = func() metadata.MD { - md := metadata.Pairs("set-cookie", secondCookie) - return md - } - - provider = NewMetadataProvider(providerFunc) - cookie, err = assistant.Metadata(provider) + localMetadata := metadata.Pairs("set-cookie", expiredCookie) - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } + assistant.ProcessResponseMetadata(localMetadata) + cookieInfo := assistant.RealMetadata() - if cookie != secondCookie { + if len(cookieInfo) > 0 { t.Fatalf("The expired cookie was not removed") } - farFutureTime := tt.Add(5 * time.Hour) - notRequiredCookie := fmt.Sprintf( - "GCLB=CMOO2-DdvKWMqQE; path=/; HttpOnly; expires=%s", - farFutureTime.Format("Mon, 02-Jan-2006 15:04:05 MST"), - ) - - providerFunc = func() metadata.MD { - md := metadata.Pairs("set-cookie", notRequiredCookie) - return md - } - - provider = NewMetadataProvider(providerFunc) - cookie, err = assistant.Metadata(provider) - - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != secondCookie { - t.Fatalf("The cookie assistant removed a cookie that was not expired") - } - } func TestTestnetKubernetesLoadBalancedCookieAssistant(t *testing.T) { assistant := TestnetKubernetesCookieAssistant() - expectedCookie := "grpc-cookie=d97c7a00bcb7bc8b69b26fb0303b60d4; Expires=Sun, 17-Sep-23 13:18:08 GMT; Max-Age=172800; Path=/; Secure; HttpOnly" + expectedCookie := fmt.Sprintf( + "grpc-cookie=d97c7a00bcb7bc8b69b26fb0303b60d4; Expires=%s; Max-Age=172800; Path=/; Secure; HttpOnly", + time.Now().Add(5*time.Hour).Format("Mon, 02-Jan-06 15:04:05 MST"), + ) - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", expectedCookie) - return md - } + localMetadata := metadata.Pairs("set-cookie", expectedCookie) - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) + assistant.ProcessResponseMetadata(localMetadata) + assistantMetadata := assistant.RealMetadata() + cookieInfo := assistantMetadata.Get("cookie") - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != expectedCookie { - t.Fatalf("The parsed cookie is different than the expected cookie") + if len(cookieInfo) > 0 { + cookie := cookieInfo[0] + if cookie != expectedCookie { + t.Fatalf("The parsed cookie is different than the expected cookie") + } + } else { + t.Fatalf("The cookie was not parsed") } } func TestTestnetKubernetesLoadBalancedCookieAssistantRemovesExpiredCookie(t *testing.T) { assistant := TestnetKubernetesCookieAssistant() tt := time.Now() - closeExpirationTime := tt.Add(30 * time.Second) + closeExpirationTime := tt.Add(-30 * time.Second) - soonToExpireCookie := fmt.Sprintf( + expiredCookie := fmt.Sprintf( "grpc-cookie=d97c7a00bcb7bc8b69b26fb0303b60d4; Expires=%s; Max-Age=172800; Path=/; Secure; HttpOnly", closeExpirationTime.Format("Mon, 02-Jan-06 15:04:05 MST"), ) - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", soonToExpireCookie) - return md - } - - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) - - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } + localMetadata := metadata.Pairs("set-cookie", expiredCookie) - if cookie != soonToExpireCookie { - t.Fatalf("The parsed cookie is different than the expected cookie") - } + assistant.ProcessResponseMetadata(localMetadata) + cookieInfo := assistant.RealMetadata() - nextExpirationTime := tt.Add(5 * time.Minute) - secondCookie := fmt.Sprintf( - "grpc-cookie=d97c7a00bcb7bc8b69b26fb0303b60d4; Expires=%s; Max-Age=172800; Path=/; Secure; HttpOnly", - nextExpirationTime.Format("Mon, 02-Jan-06 15:04:05 MST"), - ) - - providerFunc = func() metadata.MD { - md := metadata.Pairs("set-cookie", secondCookie) - return md - } - - provider = NewMetadataProvider(providerFunc) - cookie, err = assistant.Metadata(provider) - - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != secondCookie { + if len(cookieInfo) > 0 { t.Fatalf("The expired cookie was not removed") } - farFutureTime := tt.Add(5 * time.Hour) - notRequiredCookie := fmt.Sprintf( - "grpc-cookie=d97c7a00bcb7bc8b69b26fb0303b60d4; Expires=%s; Max-Age=172800; Path=/; Secure; HttpOnly", - farFutureTime.Format("Mon, 02-Jan-06 15:04:05 MST"), - ) - - providerFunc = func() metadata.MD { - md := metadata.Pairs("set-cookie", notRequiredCookie) - return md - } - - provider = NewMetadataProvider(providerFunc) - cookie, err = assistant.Metadata(provider) - - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != secondCookie { - t.Fatalf("The cookie assistant removed a cookie that was not expired") - } - } func TestBareMetalLoadBalancedCookieAssistant(t *testing.T) { assistant := BareMetalLoadBalancedCookieAssistant{} expectedCookie := "lb=706c9476f31159d415afe3e9172972618b8ab99455c2daa799199540e6d31a1a; Path=/" - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", expectedCookie) - return md - } + localMetadata := metadata.Pairs("set-cookie", expectedCookie) - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) + assistant.ProcessResponseMetadata(localMetadata) + assistantMetadata := assistant.RealMetadata() + cookieInfo := assistantMetadata.Get("cookie") - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } - - if cookie != expectedCookie { - t.Fatalf("The parsed cookie is different than the expected cookie") + if len(cookieInfo) > 0 { + cookie := cookieInfo[0] + if cookie != expectedCookie { + t.Fatalf("The parsed cookie is different than the expected cookie") + } + } else { + t.Fatalf("The cookie was not parsed") } } func TestDisabledCookieAssistant(t *testing.T) { assistant := DisabledCookieAssistant{} providedCookie := "lb=706c9476f31159d415afe3e9172972618b8ab99455c2daa799199540e6d31a1a; Path=/" - providerFunc := func() metadata.MD { - md := metadata.Pairs("set-cookie", providedCookie) - return md - } - provider := NewMetadataProvider(providerFunc) - cookie, err := assistant.Metadata(provider) + localMetadata := metadata.Pairs("set-cookie", providedCookie) - if err != nil { - t.Errorf("Error parsing the cookie string %v", err) - } + assistant.ProcessResponseMetadata(localMetadata) + assistantMetadata := assistant.RealMetadata() + cookieInfo := assistantMetadata.Get("cookie") - if cookie != "" { - t.Fatalf("The parsed cookie is different than the expected cookie") + if len(cookieInfo) > 0 { + t.Fatalf("The disabled cookie assistant should not return any cookie") } } diff --git a/client/exchange/exchange.go b/client/exchange/exchange.go index 17577000..107e9f5e 100644 --- a/client/exchange/exchange.go +++ b/client/exchange/exchange.go @@ -3,22 +3,17 @@ package exchange import ( "context" "fmt" - "time" - "google.golang.org/grpc/credentials/insecure" "github.com/InjectiveLabs/sdk-go/client/common" accountPB "github.com/InjectiveLabs/sdk-go/exchange/accounts_rpc/pb" auctionPB "github.com/InjectiveLabs/sdk-go/exchange/auction_rpc/pb" derivativeExchangePB "github.com/InjectiveLabs/sdk-go/exchange/derivative_exchange_rpc/pb" - explorerPB "github.com/InjectiveLabs/sdk-go/exchange/explorer_rpc/pb" insurancePB "github.com/InjectiveLabs/sdk-go/exchange/insurance_rpc/pb" metaPB "github.com/InjectiveLabs/sdk-go/exchange/meta_rpc/pb" oraclePB "github.com/InjectiveLabs/sdk-go/exchange/oracle_rpc/pb" portfolioExchangePB "github.com/InjectiveLabs/sdk-go/exchange/portfolio_rpc/pb" spotExchangePB "github.com/InjectiveLabs/sdk-go/exchange/spot_exchange_rpc/pb" - "google.golang.org/grpc/metadata" - log "github.com/InjectiveLabs/suplog" "github.com/pkg/errors" "google.golang.org/grpc" @@ -131,7 +126,6 @@ func NewExchangeClient(network common.Network, options ...common.ClientOption) ( conn: conn, metaClient: metaPB.NewInjectiveMetaRPCClient(conn), - explorerClient: explorerPB.NewInjectiveExplorerRPCClient(conn), accountClient: accountPB.NewInjectiveAccountsRPCClient(conn), auctionClient: auctionPB.NewInjectiveAuctionRPCClient(conn), oracleClient: oraclePB.NewInjectiveOracleRPCClient(conn), @@ -156,7 +150,6 @@ type exchangeClient struct { logger log.Logger metaClient metaPB.InjectiveMetaRPCClient - explorerClient explorerPB.InjectiveExplorerRPCClient accountClient accountPB.InjectiveAccountsRPCClient auctionClient auctionPB.InjectiveAuctionRPCClient oracleClient oraclePB.InjectiveOracleRPCClient @@ -166,22 +159,6 @@ type exchangeClient struct { portfolioExchangeClient portfolioExchangePB.InjectivePortfolioRPCClient } -func (c *exchangeClient) requestCookie() metadata.MD { - var header metadata.MD - req := metaPB.InfoRequest{Timestamp: time.Now().UnixMilli()} - _, err := c.metaClient.Info(context.Background(), &req, grpc.Header(&header)) - if err != nil { - panic(err) - } - return header -} - -func (c *exchangeClient) getCookie(ctx context.Context) context.Context { - provider := common.NewMetadataProvider(c.requestCookie) - cookie, _ := c.network.ExchangeMetadata(provider) - return metadata.AppendToOutgoingContext(ctx, "cookie", cookie) -} - func (c *exchangeClient) QueryClient() *grpc.ClientConn { return c.conn } @@ -189,8 +166,7 @@ func (c *exchangeClient) QueryClient() *grpc.ClientConn { // Derivatives RPC func (c *exchangeClient) GetDerivativeOrders(ctx context.Context, req *derivativeExchangePB.OrdersRequest) (*derivativeExchangePB.OrdersResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.Orders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.Orders, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.OrdersResponse{}, err @@ -201,8 +177,7 @@ func (c *exchangeClient) GetDerivativeOrders(ctx context.Context, req *derivativ // Deprecated: Use GetDerivativePositionsV2 instead. func (c *exchangeClient) GetDerivativePositions(ctx context.Context, req *derivativeExchangePB.PositionsRequest) (*derivativeExchangePB.PositionsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.Positions(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.Positions, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.PositionsResponse{}, err @@ -212,8 +187,7 @@ func (c *exchangeClient) GetDerivativePositions(ctx context.Context, req *deriva } func (c *exchangeClient) GetDerivativePositionsV2(ctx context.Context, req *derivativeExchangePB.PositionsV2Request) (*derivativeExchangePB.PositionsV2Response, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.PositionsV2(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.PositionsV2, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.PositionsV2Response{}, err @@ -223,8 +197,7 @@ func (c *exchangeClient) GetDerivativePositionsV2(ctx context.Context, req *deri } func (c *exchangeClient) GetDerivativeLiquidablePositions(ctx context.Context, req *derivativeExchangePB.LiquidablePositionsRequest) (*derivativeExchangePB.LiquidablePositionsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.LiquidablePositions(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.LiquidablePositions, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.LiquidablePositionsResponse{}, err @@ -238,8 +211,7 @@ func (c *exchangeClient) GetDerivativeOrderbookV2(ctx context.Context, marketId MarketId: marketId, } - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.OrderbookV2(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.OrderbookV2, &req) if err != nil { fmt.Println(err) return &derivativeExchangePB.OrderbookV2Response{}, err @@ -253,8 +225,7 @@ func (c *exchangeClient) GetDerivativeOrderbooksV2(ctx context.Context, marketId MarketIds: marketIds, } - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.OrderbooksV2(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.OrderbooksV2, &req) if err != nil { fmt.Println(err) return &derivativeExchangePB.OrderbooksV2Response{}, err @@ -268,8 +239,8 @@ func (c *exchangeClient) StreamDerivativeOrderbookV2(ctx context.Context, market MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamOrderbookV2(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamOrderbookV2, &req) + if err != nil { fmt.Println(err) return nil, err @@ -283,8 +254,8 @@ func (c *exchangeClient) StreamDerivativeOrderbookUpdate(ctx context.Context, ma MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamOrderbookUpdate(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamOrderbookUpdate, &req) + if err != nil { fmt.Println(err) return nil, err @@ -294,8 +265,7 @@ func (c *exchangeClient) StreamDerivativeOrderbookUpdate(ctx context.Context, ma } func (c *exchangeClient) GetDerivativeMarkets(ctx context.Context, req *derivativeExchangePB.MarketsRequest) (*derivativeExchangePB.MarketsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.Markets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.Markets, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.MarketsResponse{}, err @@ -309,8 +279,7 @@ func (c *exchangeClient) GetDerivativeMarket(ctx context.Context, marketId strin MarketId: marketId, } - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.Market(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.Market, &req) if err != nil { fmt.Println(err) return &derivativeExchangePB.MarketResponse{}, err @@ -324,8 +293,8 @@ func (c *exchangeClient) StreamDerivativeMarket(ctx context.Context, marketIds [ MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamMarket(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamMarket, &req) + if err != nil { fmt.Println(err) return nil, err @@ -335,8 +304,8 @@ func (c *exchangeClient) StreamDerivativeMarket(ctx context.Context, marketIds [ } func (c *exchangeClient) StreamDerivativePositions(ctx context.Context, req *derivativeExchangePB.StreamPositionsRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamPositionsClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamPositions(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamPositions, req) + if err != nil { fmt.Println(err) return nil, err @@ -346,8 +315,8 @@ func (c *exchangeClient) StreamDerivativePositions(ctx context.Context, req *der } func (c *exchangeClient) StreamDerivativeOrders(ctx context.Context, req *derivativeExchangePB.StreamOrdersRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrdersClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamOrders(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamOrders, req) + if err != nil { fmt.Println(err) return nil, err @@ -357,8 +326,7 @@ func (c *exchangeClient) StreamDerivativeOrders(ctx context.Context, req *deriva } func (c *exchangeClient) GetDerivativeTrades(ctx context.Context, req *derivativeExchangePB.TradesRequest) (*derivativeExchangePB.TradesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.Trades(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.Trades, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.TradesResponse{}, err @@ -368,8 +336,7 @@ func (c *exchangeClient) GetDerivativeTrades(ctx context.Context, req *derivativ } func (c *exchangeClient) GetDerivativeTradesV2(ctx context.Context, req *derivativeExchangePB.TradesV2Request) (*derivativeExchangePB.TradesV2Response, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.TradesV2(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.TradesV2, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.TradesV2Response{}, err @@ -379,8 +346,8 @@ func (c *exchangeClient) GetDerivativeTradesV2(ctx context.Context, req *derivat } func (c *exchangeClient) StreamDerivativeTrades(ctx context.Context, req *derivativeExchangePB.StreamTradesRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamTradesClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamTrades(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamTrades, req) + if err != nil { fmt.Println(err) return nil, err @@ -390,8 +357,8 @@ func (c *exchangeClient) StreamDerivativeTrades(ctx context.Context, req *deriva } func (c *exchangeClient) StreamDerivativeV2Trades(ctx context.Context, req *derivativeExchangePB.StreamTradesV2Request) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamTradesV2Client, error) { - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamTradesV2(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamTradesV2, req) + if err != nil { fmt.Println(err) return nil, err @@ -401,8 +368,8 @@ func (c *exchangeClient) StreamDerivativeV2Trades(ctx context.Context, req *deri } func (c *exchangeClient) GetSubaccountDerivativeOrdersList(ctx context.Context, req *derivativeExchangePB.SubaccountOrdersListRequest) (*derivativeExchangePB.SubaccountOrdersListResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.SubaccountOrdersList(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.SubaccountOrdersList, req) + if err != nil { fmt.Println(err) return &derivativeExchangePB.SubaccountOrdersListResponse{}, err @@ -412,8 +379,8 @@ func (c *exchangeClient) GetSubaccountDerivativeOrdersList(ctx context.Context, } func (c *exchangeClient) GetSubaccountDerivativeTradesList(ctx context.Context, req *derivativeExchangePB.SubaccountTradesListRequest) (*derivativeExchangePB.SubaccountTradesListResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.SubaccountTradesList(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.SubaccountTradesList, req) + if err != nil { fmt.Println(err) return &derivativeExchangePB.SubaccountTradesListResponse{}, err @@ -423,8 +390,7 @@ func (c *exchangeClient) GetSubaccountDerivativeTradesList(ctx context.Context, } func (c *exchangeClient) GetHistoricalDerivativeOrders(ctx context.Context, req *derivativeExchangePB.OrdersHistoryRequest) (*derivativeExchangePB.OrdersHistoryResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.OrdersHistory(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.OrdersHistory, req) if err != nil { return &derivativeExchangePB.OrdersHistoryResponse{}, err } @@ -433,8 +399,8 @@ func (c *exchangeClient) GetHistoricalDerivativeOrders(ctx context.Context, req } func (c *exchangeClient) StreamHistoricalDerivativeOrders(ctx context.Context, req *derivativeExchangePB.StreamOrdersHistoryRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrdersHistoryClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.derivativeExchangeClient.StreamOrdersHistory(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.StreamOrdersHistory, req) + if err != nil { fmt.Println(err) return nil, err @@ -444,8 +410,7 @@ func (c *exchangeClient) StreamHistoricalDerivativeOrders(ctx context.Context, r } func (c *exchangeClient) GetDerivativeFundingPayments(ctx context.Context, req *derivativeExchangePB.FundingPaymentsRequest) (*derivativeExchangePB.FundingPaymentsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.FundingPayments(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.FundingPayments, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.FundingPaymentsResponse{}, err @@ -455,8 +420,7 @@ func (c *exchangeClient) GetDerivativeFundingPayments(ctx context.Context, req * } func (c *exchangeClient) GetDerivativeFundingRates(ctx context.Context, req *derivativeExchangePB.FundingRatesRequest) (*derivativeExchangePB.FundingRatesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.derivativeExchangeClient.FundingRates(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.derivativeExchangeClient.FundingRates, req) if err != nil { fmt.Println(err) return &derivativeExchangePB.FundingRatesResponse{}, err @@ -475,8 +439,8 @@ func (c *exchangeClient) GetPrice(ctx context.Context, baseSymbol string, quoteS OracleScaleFactor: oracleScaleFactor, } - ctx = c.getCookie(ctx) - res, err := c.oracleClient.Price(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.oracleClient.Price, &req) + if err != nil { fmt.Println(err) return &oraclePB.PriceResponse{}, err @@ -488,8 +452,7 @@ func (c *exchangeClient) GetPrice(ctx context.Context, baseSymbol string, quoteS func (c *exchangeClient) GetOracleList(ctx context.Context) (*oraclePB.OracleListResponse, error) { req := oraclePB.OracleListRequest{} - ctx = c.getCookie(ctx) - res, err := c.oracleClient.OracleList(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.oracleClient.OracleList, &req) if err != nil { fmt.Println(err) return &oraclePB.OracleListResponse{}, err @@ -505,8 +468,8 @@ func (c *exchangeClient) StreamPrices(ctx context.Context, baseSymbol string, qu OracleType: oracleType, } - ctx = c.getCookie(ctx) - stream, err := c.oracleClient.StreamPrices(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.oracleClient.StreamPrices, &req) + if err != nil { fmt.Println(err) return nil, err @@ -522,8 +485,7 @@ func (c *exchangeClient) GetAuction(ctx context.Context, round int64) (*auctionP Round: round, } - ctx = c.getCookie(ctx) - res, err := c.auctionClient.AuctionEndpoint(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.auctionClient.AuctionEndpoint, &req) if err != nil { fmt.Println(err) return &auctionPB.AuctionEndpointResponse{}, err @@ -535,8 +497,7 @@ func (c *exchangeClient) GetAuction(ctx context.Context, round int64) (*auctionP func (c *exchangeClient) GetAuctions(ctx context.Context) (*auctionPB.AuctionsResponse, error) { req := auctionPB.AuctionsRequest{} - ctx = c.getCookie(ctx) - res, err := c.auctionClient.Auctions(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.auctionClient.Auctions, &req) if err != nil { fmt.Println(err) return &auctionPB.AuctionsResponse{}, err @@ -548,8 +509,8 @@ func (c *exchangeClient) GetAuctions(ctx context.Context) (*auctionPB.AuctionsRe func (c *exchangeClient) StreamBids(ctx context.Context) (auctionPB.InjectiveAuctionRPC_StreamBidsClient, error) { req := auctionPB.StreamBidsRequest{} - ctx = c.getCookie(ctx) - stream, err := c.auctionClient.StreamBids(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.auctionClient.StreamBids, &req) + if err != nil { fmt.Println(err) return nil, err @@ -565,8 +526,8 @@ func (c *exchangeClient) GetSubaccountsList(ctx context.Context, accountAddress AccountAddress: accountAddress, } - ctx = c.getCookie(ctx) - res, err := c.accountClient.SubaccountsList(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.SubaccountsList, &req) + if err != nil { fmt.Println(err) return &accountPB.SubaccountsListResponse{}, err @@ -581,8 +542,8 @@ func (c *exchangeClient) GetSubaccountBalance(ctx context.Context, subaccountId Denom: denom, } - ctx = c.getCookie(ctx) - res, err := c.accountClient.SubaccountBalanceEndpoint(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.SubaccountBalanceEndpoint, &req) + if err != nil { fmt.Println(err) return &accountPB.SubaccountBalanceEndpointResponse{}, err @@ -596,8 +557,8 @@ func (c *exchangeClient) StreamSubaccountBalance(ctx context.Context, subaccount SubaccountId: subaccountId, } - ctx = c.getCookie(ctx) - stream, err := c.accountClient.StreamSubaccountBalance(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.StreamSubaccountBalance, &req) + if err != nil { fmt.Println(err) return nil, err @@ -611,8 +572,8 @@ func (c *exchangeClient) GetSubaccountBalancesList(ctx context.Context, subaccou SubaccountId: subaccountId, } - ctx = c.getCookie(ctx) - res, err := c.accountClient.SubaccountBalancesList(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.SubaccountBalancesList, &req) + if err != nil { fmt.Println(err) return &accountPB.SubaccountBalancesListResponse{}, err @@ -622,8 +583,8 @@ func (c *exchangeClient) GetSubaccountBalancesList(ctx context.Context, subaccou } func (c *exchangeClient) GetSubaccountHistory(ctx context.Context, req *accountPB.SubaccountHistoryRequest) (*accountPB.SubaccountHistoryResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.accountClient.SubaccountHistory(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.SubaccountHistory, req) + if err != nil { fmt.Println(err) return &accountPB.SubaccountHistoryResponse{}, err @@ -633,8 +594,8 @@ func (c *exchangeClient) GetSubaccountHistory(ctx context.Context, req *accountP } func (c *exchangeClient) GetSubaccountOrderSummary(ctx context.Context, req *accountPB.SubaccountOrderSummaryRequest) (*accountPB.SubaccountOrderSummaryResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.accountClient.SubaccountOrderSummary(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.SubaccountOrderSummary, req) + if err != nil { fmt.Println(err) return &accountPB.SubaccountOrderSummaryResponse{}, err @@ -644,8 +605,7 @@ func (c *exchangeClient) GetSubaccountOrderSummary(ctx context.Context, req *acc } func (c *exchangeClient) GetOrderStates(ctx context.Context, req *accountPB.OrderStatesRequest) (*accountPB.OrderStatesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.accountClient.OrderStates(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.OrderStates, req) if err != nil { fmt.Println(err) return &accountPB.OrderStatesResponse{}, err @@ -659,8 +619,8 @@ func (c *exchangeClient) GetPortfolio(ctx context.Context, accountAddress string AccountAddress: accountAddress, } - ctx = c.getCookie(ctx) - res, err := c.accountClient.Portfolio(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.Portfolio, &req) + if err != nil { fmt.Println(err) return &accountPB.PortfolioResponse{}, err @@ -670,8 +630,8 @@ func (c *exchangeClient) GetPortfolio(ctx context.Context, accountAddress string } func (c *exchangeClient) GetRewards(ctx context.Context, req *accountPB.RewardsRequest) (*accountPB.RewardsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.accountClient.Rewards(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.accountClient.Rewards, req) + if err != nil { fmt.Println(err) return &accountPB.RewardsResponse{}, err @@ -683,8 +643,8 @@ func (c *exchangeClient) GetRewards(ctx context.Context, req *accountPB.RewardsR // Spot RPC func (c *exchangeClient) GetSpotOrders(ctx context.Context, req *spotExchangePB.OrdersRequest) (*spotExchangePB.OrdersResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.Orders(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.Orders, req) + if err != nil { fmt.Println(err) return &spotExchangePB.OrdersResponse{}, err @@ -698,8 +658,8 @@ func (c *exchangeClient) GetSpotOrderbookV2(ctx context.Context, marketId string MarketId: marketId, } - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.OrderbookV2(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.OrderbookV2, &req) + if err != nil { fmt.Println(err) return &spotExchangePB.OrderbookV2Response{}, err @@ -713,8 +673,8 @@ func (c *exchangeClient) GetSpotOrderbooksV2(ctx context.Context, marketIds []st MarketIds: marketIds, } - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.OrderbooksV2(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.OrderbooksV2, &req) + if err != nil { fmt.Println(err) return &spotExchangePB.OrderbooksV2Response{}, err @@ -728,8 +688,8 @@ func (c *exchangeClient) StreamSpotOrderbookUpdate(ctx context.Context, marketId MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamOrderbookUpdate(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamOrderbookUpdate, &req) + if err != nil { fmt.Println(err) return nil, err @@ -743,8 +703,8 @@ func (c *exchangeClient) StreamSpotOrderbookV2(ctx context.Context, marketIds [] MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamOrderbookV2(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamOrderbookV2, &req) + if err != nil { fmt.Println(err) return nil, err @@ -754,8 +714,8 @@ func (c *exchangeClient) StreamSpotOrderbookV2(ctx context.Context, marketIds [] } func (c *exchangeClient) GetSpotMarkets(ctx context.Context, req *spotExchangePB.MarketsRequest) (*spotExchangePB.MarketsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.Markets(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.Markets, req) + if err != nil { fmt.Println(err) return &spotExchangePB.MarketsResponse{}, err @@ -769,8 +729,8 @@ func (c *exchangeClient) GetSpotMarket(ctx context.Context, marketId string) (*s MarketId: marketId, } - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.Market(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.Market, &req) + if err != nil { fmt.Println(err) return &spotExchangePB.MarketResponse{}, err @@ -784,8 +744,8 @@ func (c *exchangeClient) StreamSpotMarket(ctx context.Context, marketIds []strin MarketIds: marketIds, } - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamMarkets(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamMarkets, &req) + if err != nil { fmt.Println(err) return nil, err @@ -795,8 +755,8 @@ func (c *exchangeClient) StreamSpotMarket(ctx context.Context, marketIds []strin } func (c *exchangeClient) StreamSpotOrders(ctx context.Context, req *spotExchangePB.StreamOrdersRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrdersClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamOrders(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamOrders, req) + if err != nil { fmt.Println(err) return nil, err @@ -806,8 +766,8 @@ func (c *exchangeClient) StreamSpotOrders(ctx context.Context, req *spotExchange } func (c *exchangeClient) GetSpotTrades(ctx context.Context, req *spotExchangePB.TradesRequest) (*spotExchangePB.TradesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.Trades(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.Trades, req) + if err != nil { fmt.Println(err) return &spotExchangePB.TradesResponse{}, err @@ -817,8 +777,8 @@ func (c *exchangeClient) GetSpotTrades(ctx context.Context, req *spotExchangePB. } func (c *exchangeClient) GetSpotTradesV2(ctx context.Context, req *spotExchangePB.TradesV2Request) (*spotExchangePB.TradesV2Response, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.TradesV2(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.TradesV2, req) + if err != nil { fmt.Println(err) return &spotExchangePB.TradesV2Response{}, err @@ -828,8 +788,8 @@ func (c *exchangeClient) GetSpotTradesV2(ctx context.Context, req *spotExchangeP } func (c *exchangeClient) StreamSpotTrades(ctx context.Context, req *spotExchangePB.StreamTradesRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamTradesClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamTrades(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamTrades, req) + if err != nil { fmt.Println(err) return nil, err @@ -839,8 +799,8 @@ func (c *exchangeClient) StreamSpotTrades(ctx context.Context, req *spotExchange } func (c *exchangeClient) StreamSpotTradesV2(ctx context.Context, req *spotExchangePB.StreamTradesV2Request) (spotExchangePB.InjectiveSpotExchangeRPC_StreamTradesV2Client, error) { - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamTradesV2(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamTradesV2, req) + if err != nil { fmt.Println(err) return nil, err @@ -850,8 +810,8 @@ func (c *exchangeClient) StreamSpotTradesV2(ctx context.Context, req *spotExchan } func (c *exchangeClient) GetSubaccountSpotOrdersList(ctx context.Context, req *spotExchangePB.SubaccountOrdersListRequest) (*spotExchangePB.SubaccountOrdersListResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.SubaccountOrdersList(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.SubaccountOrdersList, req) + if err != nil { fmt.Println(err) return &spotExchangePB.SubaccountOrdersListResponse{}, err @@ -861,8 +821,8 @@ func (c *exchangeClient) GetSubaccountSpotOrdersList(ctx context.Context, req *s } func (c *exchangeClient) GetSubaccountSpotTradesList(ctx context.Context, req *spotExchangePB.SubaccountTradesListRequest) (*spotExchangePB.SubaccountTradesListResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.SubaccountTradesList(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.SubaccountTradesList, req) + if err != nil { fmt.Println(err) return &spotExchangePB.SubaccountTradesListResponse{}, err @@ -872,8 +832,7 @@ func (c *exchangeClient) GetSubaccountSpotTradesList(ctx context.Context, req *s } func (c *exchangeClient) GetHistoricalSpotOrders(ctx context.Context, req *spotExchangePB.OrdersHistoryRequest) (*spotExchangePB.OrdersHistoryResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.spotExchangeClient.OrdersHistory(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.OrdersHistory, req) if err != nil { return &spotExchangePB.OrdersHistoryResponse{}, err } @@ -882,8 +841,8 @@ func (c *exchangeClient) GetHistoricalSpotOrders(ctx context.Context, req *spotE } func (c *exchangeClient) StreamHistoricalSpotOrders(ctx context.Context, req *spotExchangePB.StreamOrdersHistoryRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrdersHistoryClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.spotExchangeClient.StreamOrdersHistory(ctx, req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.spotExchangeClient.StreamOrdersHistory, req) + if err != nil { fmt.Println(err) return nil, err @@ -893,8 +852,7 @@ func (c *exchangeClient) StreamHistoricalSpotOrders(ctx context.Context, req *sp } func (c *exchangeClient) GetInsuranceFunds(ctx context.Context, req *insurancePB.FundsRequest) (*insurancePB.FundsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.insuranceClient.Funds(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.insuranceClient.Funds, req) if err != nil { fmt.Println(err) return &insurancePB.FundsResponse{}, err @@ -904,8 +862,8 @@ func (c *exchangeClient) GetInsuranceFunds(ctx context.Context, req *insurancePB } func (c *exchangeClient) GetRedemptions(ctx context.Context, req *insurancePB.RedemptionsRequest) (*insurancePB.RedemptionsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.insuranceClient.Redemptions(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.insuranceClient.Redemptions, req) + if err != nil { fmt.Println(err) return &insurancePB.RedemptionsResponse{}, err @@ -915,8 +873,8 @@ func (c *exchangeClient) GetRedemptions(ctx context.Context, req *insurancePB.Re } func (c *exchangeClient) Ping(ctx context.Context, req *metaPB.PingRequest) (*metaPB.PingResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.metaClient.Ping(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.metaClient.Ping, req) + if err != nil { fmt.Println(err) return &metaPB.PingResponse{}, err @@ -926,8 +884,8 @@ func (c *exchangeClient) Ping(ctx context.Context, req *metaPB.PingRequest) (*me } func (c *exchangeClient) GetVersion(ctx context.Context, req *metaPB.VersionRequest) (*metaPB.VersionResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.metaClient.Version(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.metaClient.Version, req) + if err != nil { fmt.Println(err) return &metaPB.VersionResponse{}, err @@ -937,8 +895,7 @@ func (c *exchangeClient) GetVersion(ctx context.Context, req *metaPB.VersionRequ } func (c *exchangeClient) GetInfo(ctx context.Context, req *metaPB.InfoRequest) (*metaPB.InfoResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.metaClient.Info(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.metaClient.Info, req) if err != nil { fmt.Println(err) return &metaPB.InfoResponse{}, err @@ -950,8 +907,8 @@ func (c *exchangeClient) GetInfo(ctx context.Context, req *metaPB.InfoRequest) ( func (c *exchangeClient) StreamKeepalive(ctx context.Context) (metaPB.InjectiveMetaRPC_StreamKeepaliveClient, error) { req := metaPB.StreamKeepaliveRequest{} - ctx = c.getCookie(ctx) - stream, err := c.metaClient.StreamKeepalive(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.metaClient.StreamKeepalive, &req) + if err != nil { fmt.Println(err) return nil, err @@ -962,10 +919,10 @@ func (c *exchangeClient) StreamKeepalive(ctx context.Context) (metaPB.InjectiveM // Deprecated: Use GetAccountPortfolioBalances instead. func (c *exchangeClient) GetAccountPortfolio(ctx context.Context, accountAddress string) (*portfolioExchangePB.AccountPortfolioResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.portfolioExchangeClient.AccountPortfolio(ctx, &portfolioExchangePB.AccountPortfolioRequest{ + req := &portfolioExchangePB.AccountPortfolioRequest{ AccountAddress: accountAddress, - }) + } + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.portfolioExchangeClient.AccountPortfolio, req) if err != nil { fmt.Println(err) return &portfolioExchangePB.AccountPortfolioResponse{}, err @@ -975,10 +932,10 @@ func (c *exchangeClient) GetAccountPortfolio(ctx context.Context, accountAddress } func (c *exchangeClient) GetAccountPortfolioBalances(ctx context.Context, accountAddress string) (*portfolioExchangePB.AccountPortfolioBalancesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.portfolioExchangeClient.AccountPortfolioBalances(ctx, &portfolioExchangePB.AccountPortfolioBalancesRequest{ + req := &portfolioExchangePB.AccountPortfolioBalancesRequest{ AccountAddress: accountAddress, - }) + } + res, err := common.ExecuteCall(ctx, c.network.ExchangeCookieAssistant, c.portfolioExchangeClient.AccountPortfolioBalances, req) if err != nil { fmt.Println(err) return &portfolioExchangePB.AccountPortfolioBalancesResponse{}, err @@ -988,12 +945,13 @@ func (c *exchangeClient) GetAccountPortfolioBalances(ctx context.Context, accoun } func (c *exchangeClient) StreamAccountPortfolio(ctx context.Context, accountAddress string, subaccountId, balanceType string) (portfolioExchangePB.InjectivePortfolioRPC_StreamAccountPortfolioClient, error) { - ctx = c.getCookie(ctx) - stream, err := c.portfolioExchangeClient.StreamAccountPortfolio(ctx, &portfolioExchangePB.StreamAccountPortfolioRequest{ + req := &portfolioExchangePB.StreamAccountPortfolioRequest{ AccountAddress: accountAddress, SubaccountId: subaccountId, Type: balanceType, - }) + } + stream, err := common.ExecuteStreamCall(ctx, c.network.ExchangeCookieAssistant, c.portfolioExchangeClient.StreamAccountPortfolio, req) + if err != nil { fmt.Println(err) return nil, err diff --git a/client/explorer/explorer.go b/client/explorer/explorer.go index 00c76fc6..02b2290a 100644 --- a/client/explorer/explorer.go +++ b/client/explorer/explorer.go @@ -8,8 +8,6 @@ import ( "github.com/InjectiveLabs/sdk-go/client/common" explorerPB "github.com/InjectiveLabs/sdk-go/exchange/explorer_rpc/pb" - "google.golang.org/grpc/metadata" - log "github.com/InjectiveLabs/suplog" "github.com/pkg/errors" "google.golang.org/grpc" @@ -86,22 +84,6 @@ type explorerClient struct { explorerClient explorerPB.InjectiveExplorerRPCClient } -func (c *explorerClient) requestCookie() metadata.MD { - var header metadata.MD - req := explorerPB.GetTxsRequest{} - _, err := c.explorerClient.GetTxs(context.Background(), &req, grpc.Header(&header)) - if err != nil { - panic(err) - } - return header -} - -func (c *explorerClient) getCookie(ctx context.Context) context.Context { - provider := common.NewMetadataProvider(c.requestCookie) - cookie, _ := c.network.ExplorerMetadata(provider) - return metadata.AppendToOutgoingContext(ctx, "cookie", cookie) -} - func (c *explorerClient) QueryClient() *grpc.ClientConn { return c.conn } @@ -111,8 +93,8 @@ func (c *explorerClient) GetTxByTxHash(ctx context.Context, hash string) (*explo Hash: hash, } - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetTxByTxHash(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetTxByTxHash, &req) + if err != nil { fmt.Println(err) return &explorerPB.GetTxByTxHashResponse{}, err @@ -122,8 +104,8 @@ func (c *explorerClient) GetTxByTxHash(ctx context.Context, hash string) (*explo } func (c *explorerClient) GetAccountTxs(ctx context.Context, req *explorerPB.GetAccountTxsRequest) (*explorerPB.GetAccountTxsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetAccountTxs(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetAccountTxs, req) + if err != nil { fmt.Println(err) return &explorerPB.GetAccountTxsResponse{}, err @@ -135,8 +117,8 @@ func (c *explorerClient) GetAccountTxs(ctx context.Context, req *explorerPB.GetA func (c *explorerClient) GetBlocks(ctx context.Context) (*explorerPB.GetBlocksResponse, error) { req := explorerPB.GetBlocksRequest{} - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetBlocks(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetBlocks, &req) + if err != nil { fmt.Println(err) return &explorerPB.GetBlocksResponse{}, err @@ -150,8 +132,8 @@ func (c *explorerClient) GetBlock(ctx context.Context, blockHeight string) (*exp Id: blockHeight, } - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetBlock(ctx, &req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetBlock, &req) + if err != nil { fmt.Println(err) return &explorerPB.GetBlockResponse{}, err @@ -161,8 +143,8 @@ func (c *explorerClient) GetBlock(ctx context.Context, blockHeight string) (*exp } func (c *explorerClient) GetTxs(ctx context.Context, req *explorerPB.GetTxsRequest) (*explorerPB.GetTxsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetTxs(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetTxs, req) + if err != nil { fmt.Println(err) return &explorerPB.GetTxsResponse{}, err @@ -172,8 +154,8 @@ func (c *explorerClient) GetTxs(ctx context.Context, req *explorerPB.GetTxsReque } func (c *explorerClient) GetPeggyDeposits(ctx context.Context, req *explorerPB.GetPeggyDepositTxsRequest) (*explorerPB.GetPeggyDepositTxsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetPeggyDepositTxs(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetPeggyDepositTxs, req) + if err != nil { fmt.Println(err) return &explorerPB.GetPeggyDepositTxsResponse{}, err @@ -183,8 +165,8 @@ func (c *explorerClient) GetPeggyDeposits(ctx context.Context, req *explorerPB.G } func (c *explorerClient) GetPeggyWithdrawals(ctx context.Context, req *explorerPB.GetPeggyWithdrawalTxsRequest) (*explorerPB.GetPeggyWithdrawalTxsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetPeggyWithdrawalTxs(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetPeggyWithdrawalTxs, req) + if err != nil { fmt.Println(err) return &explorerPB.GetPeggyWithdrawalTxsResponse{}, err @@ -194,8 +176,8 @@ func (c *explorerClient) GetPeggyWithdrawals(ctx context.Context, req *explorerP } func (c *explorerClient) GetIBCTransfers(ctx context.Context, req *explorerPB.GetIBCTransferTxsRequest) (*explorerPB.GetIBCTransferTxsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetIBCTransferTxs(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetIBCTransferTxs, req) + if err != nil { fmt.Println(err) return &explorerPB.GetIBCTransferTxsResponse{}, err @@ -207,8 +189,8 @@ func (c *explorerClient) GetIBCTransfers(ctx context.Context, req *explorerPB.Ge func (c *explorerClient) StreamTxs(ctx context.Context) (explorerPB.InjectiveExplorerRPC_StreamTxsClient, error) { req := explorerPB.StreamTxsRequest{} - ctx = c.getCookie(ctx) - stream, err := c.explorerClient.StreamTxs(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.StreamTxs, &req) + if err != nil { fmt.Println(err) return nil, err @@ -220,8 +202,8 @@ func (c *explorerClient) StreamTxs(ctx context.Context) (explorerPB.InjectiveExp func (c *explorerClient) StreamBlocks(ctx context.Context) (explorerPB.InjectiveExplorerRPC_StreamBlocksClient, error) { req := explorerPB.StreamBlocksRequest{} - ctx = c.getCookie(ctx) - stream, err := c.explorerClient.StreamBlocks(ctx, &req) + stream, err := common.ExecuteStreamCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.StreamBlocks, &req) + if err != nil { fmt.Println(err) return nil, err @@ -231,8 +213,8 @@ func (c *explorerClient) StreamBlocks(ctx context.Context) (explorerPB.Injective } func (c *explorerClient) GetWasmCodes(ctx context.Context, req *explorerPB.GetWasmCodesRequest) (*explorerPB.GetWasmCodesResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetWasmCodes(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetWasmCodes, req) + if err != nil { fmt.Println(err) return &explorerPB.GetWasmCodesResponse{}, err @@ -242,8 +224,8 @@ func (c *explorerClient) GetWasmCodes(ctx context.Context, req *explorerPB.GetWa } func (c *explorerClient) GetWasmCodeByID(ctx context.Context, req *explorerPB.GetWasmCodeByIDRequest) (*explorerPB.GetWasmCodeByIDResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetWasmCodeByID(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetWasmCodeByID, req) + if err != nil { fmt.Println(err) return &explorerPB.GetWasmCodeByIDResponse{}, err @@ -253,8 +235,8 @@ func (c *explorerClient) GetWasmCodeByID(ctx context.Context, req *explorerPB.Ge } func (c *explorerClient) GetWasmContracts(ctx context.Context, req *explorerPB.GetWasmContractsRequest) (*explorerPB.GetWasmContractsResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetWasmContracts(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetWasmContracts, req) + if err != nil { fmt.Println(err) return &explorerPB.GetWasmContractsResponse{}, err @@ -264,8 +246,8 @@ func (c *explorerClient) GetWasmContracts(ctx context.Context, req *explorerPB.G } func (c *explorerClient) GetWasmContractByAddress(ctx context.Context, req *explorerPB.GetWasmContractByAddressRequest) (*explorerPB.GetWasmContractByAddressResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetWasmContractByAddress(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetWasmContractByAddress, req) + if err != nil { fmt.Println(err) return &explorerPB.GetWasmContractByAddressResponse{}, err @@ -275,8 +257,8 @@ func (c *explorerClient) GetWasmContractByAddress(ctx context.Context, req *expl } func (c *explorerClient) GetCW20Balance(ctx context.Context, req *explorerPB.GetCw20BalanceRequest) (*explorerPB.GetCw20BalanceResponse, error) { - ctx = c.getCookie(ctx) - res, err := c.explorerClient.GetCw20Balance(ctx, req) + res, err := common.ExecuteCall(ctx, c.network.ExplorerCookieAssistant, c.explorerClient.GetCw20Balance, req) + if err != nil { fmt.Println(err) return &explorerPB.GetCw20BalanceResponse{}, err From 7ac3f58e2ace0fdbd28f24b5879fe4fc1eebad7e Mon Sep 17 00:00:00 2001 From: abel Date: Tue, 9 Apr 2024 16:02:55 -0300 Subject: [PATCH 2/2] (fix) Fix pre-commit issues --- client/common/api_request_assistant.go | 1 + client/exchange/exchange.go | 1 + 2 files changed, 2 insertions(+) diff --git a/client/common/api_request_assistant.go b/client/common/api_request_assistant.go index e5956792..eaafb110 100644 --- a/client/common/api_request_assistant.go +++ b/client/common/api_request_assistant.go @@ -2,6 +2,7 @@ package common import ( "context" + "google.golang.org/grpc" "google.golang.org/grpc/metadata" ) diff --git a/client/exchange/exchange.go b/client/exchange/exchange.go index 107e9f5e..f0ec7892 100644 --- a/client/exchange/exchange.go +++ b/client/exchange/exchange.go @@ -3,6 +3,7 @@ package exchange import ( "context" "fmt" + "google.golang.org/grpc/credentials/insecure" "github.com/InjectiveLabs/sdk-go/client/common"