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

Andrew7234/evmtokens api #493

Merged
merged 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2496,7 +2496,7 @@ components:

EvmToken:
type: object
required: [contract_addr, num_holders, type]
required: [contract_addr, eth_contract_addr, num_holders, type, is_verified]
properties:
contract_addr:
type: string
Expand Down Expand Up @@ -2537,6 +2537,13 @@ components:
description: |
The number of addresses that have a nonzero balance of this token.
example: 123
is_verified:
type: boolean
description: |
Whether the contract has been successfully verified by Sourcify.
Additional information on verified contracts is available via
the `/{runtime}/accounts/{address}` endpoint.
example: false

AccountStats:
type: object
Expand Down
3 changes: 2 additions & 1 deletion storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1499,11 +1499,12 @@ func (c *StorageClient) RuntimeTokens(ctx context.Context, p apiTypes.GetRuntime
&t.TotalSupply,
&t.Type,
&t.NumHolders,
&t.IsVerified,
); err2 != nil {
return nil, wrapError(err2)
}

t.EthContractAddr = common.Ptr(ethCommon.BytesToAddress(addrPreimage).String())
t.EthContractAddr = ethCommon.BytesToAddress(addrPreimage).String()
ts.EvmTokens = append(ts.EvmTokens, t)
}

Expand Down
6 changes: 4 additions & 2 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,12 @@ const (
WHEN tokens.token_type = 721 THEN 'ERC721'
ELSE 'unexpected_other_type' -- Our openapi spec doesn't allow us to output this, but better this than a null value (which causes nil dereference)
END AS type,
holders.cnt AS num_holders
holders.cnt AS num_holders,
(contracts.verification_info_downloaded_at IS NOT NULL) AS is_verified
FROM chain.evm_tokens AS tokens
JOIN chain.address_preimages AS preimages ON (token_address = preimages.address)
JOIN chain.address_preimages AS preimages ON (token_address = preimages.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 holders USING (token_address)
LEFT JOIN chain.evm_contracts as contracts ON (tokens.runtime = contracts.runtime AND tokens.token_address = contracts.contract_address)
WHERE
(tokens.runtime = $1) AND
($2::oasis_addr IS NULL OR tokens.token_address = $2::oasis_addr) AND
Expand Down