Skip to content

Commit

Permalink
Add EvmToken.evm_contract_addr
Browse files Browse the repository at this point in the history
  • Loading branch information
mitjat committed Jan 25, 2023
1 parent d854819 commit c19dd29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 5 additions & 1 deletion api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1762,12 +1762,16 @@ components:

EvmToken:
type: object
required: [contract_addr, num_holders, type]
required: [contract_addr, evm_contract_addr, num_holders, type]
properties:
contract_addr:
type: string
description: The Oasis address of this token's contract.
example: 'oasis1qp2hssandc7dekjdr6ygmtzt783k3gn38uupdeys'
evm_contract_addr:
type: string
description: The EVM address of this token's contract. Encoded as a lowercase hex string.
example: 'dc19a122e268128b5ee20366299fc7b5b199c8e3'
name:
type: string
description: Name of the token, as provided by token contract's `name()` method.
Expand Down
1 change: 1 addition & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,7 @@ func (c *StorageClient) RuntimeTokens(ctx context.Context, p apiTypes.GetEmerald
var totalSupplyNum pgtype.Numeric
if err := rows.Scan(
&t.ContractAddr,
&t.EvmContractAddr,
&t.Name,
&t.Symbol,
&t.Decimals,
Expand Down
20 changes: 11 additions & 9 deletions storage/client/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,23 @@ func (qf QueryFactory) RuntimeTransactionsQuery() string {

func (qf QueryFactory) EvmTokensQuery() string {
return fmt.Sprintf(`
WITH token_holders AS (
WITH holders AS (
SELECT token_address, COUNT(*) AS cnt
FROM %[1]s.%[2]s_token_balances
GROUP BY token_address
)
SELECT
token_address AS contract_addr,
token_name AS name,
symbol,
decimals,
total_supply,
tokens.token_address AS contract_addr,
encode(preimages.address_data, 'hex') as eth_contract_addr,
tokens.token_name AS name,
tokens.symbol,
tokens.decimals,
tokens.total_supply,
'ERC20' AS type, -- TODO: fetch from the table once available
token_holders.cnt AS num_holders
FROM %[1]s.%[2]s_tokens
JOIN token_holders USING (token_address)
holders.cnt AS num_holders
FROM %[1]s.%[2]s_tokens AS tokens
JOIN %[1]s.address_preimages AS preimages ON (token_address = preimages.address)
JOIN holders USING (token_address)
ORDER BY num_holders DESC
LIMIT $1::bigint
OFFSET $2::bigint`, qf.chainID, qf.runtime)
Expand Down

0 comments on commit c19dd29

Please sign in to comment.