Skip to content

Commit

Permalink
Merge pull request #492 from oasisprotocol/andrew7234/runtime-account…
Browse files Browse the repository at this point in the history
…-evm-balance

[api] return evm address instead of oasis addr in RuntimeEvmBalance
  • Loading branch information
Andrew7234 committed Jul 31, 2023
2 parents c787db9 + f578b38 commit 406e905
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1740,15 +1740,19 @@ components:
RuntimeEvmBalance:
description: Balance of an account for a specific runtime and EVM token.
type: object
required: [balance, token_contract_addr, token_decimals, token_type]
required: [balance, token_contract_addr, token_contract_addr_eth, token_decimals, token_type]
properties:
balance:
<<: *BigIntType
description: Number of tokens held, in base units.
token_contract_addr:
type: string
description: The EVM address of this token's contract. Encoded as a lowercase hex string.
example: 'dc19a122e268128b5ee20366299fc7b5b199c8e3'
description: The oasis address of this token's contract.
example: 'oasis1qzk5pr2x8ah04lgjee3lv06fmyvqvz45egjv4ps0'
token_contract_addr_eth:
type: string
description: The EVM address of this token's contract.
example: '0xF8E3DE55D24D13607A12628E0A113B66BA578bDC'
token_symbol:
type: string
description: The token ticker symbol. Not guaranteed to be unique across distinct EVM tokens.
Expand Down
3 changes: 3 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,16 +1393,19 @@ 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,
&b.TokenDecimals,
); err != nil {
return nil, wrapError(err)
}
b.TokenContractAddrEth = ethCommon.BytesToAddress(addrPreimage).String()
a.EvmBalances = append(a.EvmBalances, b)
}

Expand Down
2 changes: 2 additions & 0 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ const (
SELECT
balances.balance AS balance,
balances.token_address AS token_address,
preimages.address_data AS token_address_eth,
tokens.symbol AS token_symbol,
tokens.token_name AS token_name,
CASE -- NOTE: There are three queries that use this CASE via copy-paste; edit both if changing.
Expand All @@ -534,6 +535,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
Expand Down

0 comments on commit 406e905

Please sign in to comment.