Skip to content

Commit

Permalink
Merge pull request #493 from oasisprotocol/andrew7234/evmtokens-api
Browse files Browse the repository at this point in the history
Andrew7234/evmtokens api
  • Loading branch information
Andrew7234 committed Jul 31, 2023
2 parents 406e905 + ee368f6 commit 82c10f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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)
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

0 comments on commit 82c10f7

Please sign in to comment.