Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api] return evm address instead of oasis addr in RuntimeEvmBalance #492

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Andrew7234 marked this conversation as resolved.
Show resolved Hide resolved
JOIN chain.evm_tokens AS tokens USING (runtime, token_address)
WHERE runtime = $1 AND
balances.account_address = $2::text AND
Expand Down