From 0e1ee16f3f3be6574c3b3d20e51b445b541d6310 Mon Sep 17 00:00:00 2001 From: Andrew Low Date: Wed, 19 Jul 2023 23:05:09 -0400 Subject: [PATCH] [api] return evm address instead of oasis addr in RuntimeEvmBalance --- storage/client/client.go | 4 +++- storage/client/queries/queries.go | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/storage/client/client.go b/storage/client/client.go index 76807810e..d21a4b57f 100644 --- a/storage/client/client.go +++ b/storage/client/client.go @@ -1393,9 +1393,10 @@ func (c *StorageClient) RuntimeAccount(ctx context.Context, address staking.Addr for runtimeEvmRows.Next() { b := RuntimeEvmBalance{} + var addrPreimage []byte if err = runtimeEvmRows.Scan( &b.Balance, - &b.TokenContractAddr, + &addrPreimage, &b.TokenSymbol, &b.TokenName, &b.TokenType, @@ -1403,6 +1404,7 @@ func (c *StorageClient) RuntimeAccount(ctx context.Context, address staking.Addr ); err != nil { return nil, wrapError(err) } + b.TokenContractAddr = ethCommon.BytesToAddress(addrPreimage).String() a.EvmBalances = append(a.EvmBalances, b) } diff --git a/storage/client/queries/queries.go b/storage/client/queries/queries.go index 38f490603..c6c629672 100644 --- a/storage/client/queries/queries.go +++ b/storage/client/queries/queries.go @@ -521,7 +521,7 @@ const ( AccountRuntimeEvmBalances = ` SELECT balances.balance AS balance, - balances.token_address AS token_address, + preimages.address_data AS token_address, tokens.symbol AS token_symbol, tokens.token_name AS token_name, CASE -- NOTE: There are two queries that use this CASE via copy-paste; edit both if changing. @@ -531,6 +531,7 @@ const ( END AS token_type, tokens.decimals AS token_decimals FROM chain.evm_token_balances AS balances + JOIN chain.address_preimages AS preimages ON (preimages.address = balances.token_address AND preimages.context_identifier = 'oasis-runtime-sdk/address: secp256k1eth' AND preimages.context_version = 0) JOIN chain.evm_tokens AS tokens USING (runtime, token_address) WHERE runtime = $1 AND balances.account_address = $2::text AND