Skip to content

Commit

Permalink
add class id & tokeninfo querier (#143)
Browse files Browse the repository at this point in the history
* add class id & tokeninfo querier

* change class id rpc path

* swagger

* token id length check
  • Loading branch information
sh-cha authored Jan 15, 2025
1 parent f82cee0 commit 0ac1947
Show file tree
Hide file tree
Showing 12 changed files with 1,824 additions and 137 deletions.
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

196 changes: 169 additions & 27 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37493,10 +37493,10 @@ paths:
description: The target chain type.
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
submission_interval:
type: string
description: >-
Expand Down Expand Up @@ -39667,6 +39667,114 @@ paths:
type: string
tags:
- Query
/minievm/evm/v1/erc721/class_id/{contract_addr}:
get:
summary: ERC721ClassIdByContractAddr gets the class id by contract address.
operationId: ERC721ClassIdByContractAddr
responses:
'200':
description: A successful response.
schema:
type: object
properties:
class_id:
type: string
title: >-
QueryERC721ClassIdsByContractAddrResponse is the response type for
the Query/ERC721ClassIdsByContractAddr RPC

method
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: contract_addr
in: path
required: true
type: string
tags:
- Query
/minievm/evm/v1/erc721/origin_token_infos/{class_id}:
get:
summary: >-
ERC721OriginTokenInfos gets the origin token infos by class id and token
ids.
operationId: ERC721OriginTokenInfos
responses:
'200':
description: A successful response.
schema:
type: object
properties:
token_infos:
type: array
items:
type: object
properties:
token_origin_id:
type: string
token_uri:
type: string
title: >-
QueryERC721OriginTokenInfosResponse is the response type for the
Query/ERC721OriginTokenInfos RPC

method
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
parameters:
- name: class_id
in: path
required: true
type: string
- name: token_ids
in: query
required: false
type: array
items:
type: string
collectionFormat: multi
tags:
- Query
/minievm/evm/v1/params:
get:
summary: Params queries all parameters.
Expand Down Expand Up @@ -67991,10 +68099,10 @@ definitions:
description: The target chain type.
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
submission_interval:
type: string
description: >-
Expand Down Expand Up @@ -68124,10 +68232,10 @@ definitions:
description: The target chain type.
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
submission_interval:
type: string
description: >-
Expand Down Expand Up @@ -68864,24 +68972,24 @@ definitions:
description: The target chain type.
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
description: BatchInfo defines the set of batch information.
opinit.ophost.v1.BatchInfo.ChainType:
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
description: |-
ChainType defines the type of chain.

- CHAIN_TYPE_UNSPECIFIED: Unspecified chain type.
- CHAIN_TYPE_INITIA: The chain type of the initia chain.
- CHAIN_TYPE_CELESTIA: The chain type of the celestia chain.
- UNSPECIFIED: Unspecified chain type.
- INITIA: The chain type of the initia chain.
- CELESTIA: The chain type of the celestia chain.
opinit.ophost.v1.BridgeConfig:
type: object
properties:
Expand All @@ -68902,10 +69010,10 @@ definitions:
description: The target chain type.
type: string
enum:
- CHAIN_TYPE_UNSPECIFIED
- CHAIN_TYPE_INITIA
- CHAIN_TYPE_CELESTIA
default: CHAIN_TYPE_UNSPECIFIED
- UNSPECIFIED
- INITIA
- CELESTIA
default: UNSPECIFIED
submission_interval:
type: string
description: >-
Expand All @@ -68930,6 +69038,13 @@ definitions:
format: byte
description: Normally it is IBC channelID for permissioned IBC relayer.
description: BridgeConfig defines the set of bridge config.
minievm.evm.v1.ERC721OriginTokenInfo:
type: object
properties:
token_origin_id:
type: string
token_uri:
type: string
minievm.evm.v1.Log:
type: object
properties:
Expand Down Expand Up @@ -69110,6 +69225,33 @@ definitions:
QueryERC20WrapperResponse is the response type for the Query/ERC20Wrapper
RPC

method
minievm.evm.v1.QueryERC721ClassIdByContractAddrResponse:
type: object
properties:
class_id:
type: string
title: >-
QueryERC721ClassIdsByContractAddrResponse is the response type for the
Query/ERC721ClassIdsByContractAddr RPC

method
minievm.evm.v1.QueryERC721OriginTokenInfosResponse:
type: object
properties:
token_infos:
type: array
items:
type: object
properties:
token_origin_id:
type: string
token_uri:
type: string
title: >-
QueryERC721OriginTokenInfosResponse is the response type for the
Query/ERC721OriginTokenInfos RPC

method
minievm.evm.v1.QueryParamsResponse:
type: object
Expand Down
35 changes: 35 additions & 0 deletions proto/minievm/evm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ service Query {
option (google.api.http).get = "/minievm/evm/v1/contracts/by_denom";
}

// ERC721ClassIdByContractAddr gets the class id by contract address.
rpc ERC721ClassIdByContractAddr(QueryERC721ClassIdByContractAddrRequest) returns (QueryERC721ClassIdByContractAddrResponse) {
option (google.api.http).get = "/minievm/evm/v1/erc721/class_id/{contract_addr}";
}

// ERC721OriginTokenInfos gets the origin token infos by class id and token ids.
rpc ERC721OriginTokenInfos(QueryERC721OriginTokenInfosRequest) returns (QueryERC721OriginTokenInfosResponse) {
option (google.api.http).get = "/minievm/evm/v1/erc721/origin_token_infos/{class_id=**}";
}

// Denom gets the denom of the given contract address.
rpc Denom(QueryDenomRequest) returns (QueryDenomResponse) {
option (google.api.http).get = "/minievm/evm/v1/denoms/{contract_addr}";
Expand Down Expand Up @@ -185,6 +195,31 @@ message QueryCallResponse {
string error = 5;
}

// QueryERC721ClassIdsByContractAddrRequest is the request type for the Query/ERC721ClassIdsByContractAddr RPC
// method
message QueryERC721ClassIdByContractAddrRequest {
string contract_addr = 1;
}

// QueryERC721ClassIdsByContractAddrResponse is the response type for the Query/ERC721ClassIdsByContractAddr RPC
// method
message QueryERC721ClassIdByContractAddrResponse {
string class_id = 1;
}

// QueryERC721OriginTokenInfosRequest is the request type for the Query/ERC721OriginTokenInfos RPC
// method
message QueryERC721OriginTokenInfosRequest {
string class_id = 1;
repeated string token_ids = 2;
}

// QueryERC721OriginTokenInfosResponse is the response type for the Query/ERC721OriginTokenInfos RPC
// method
message QueryERC721OriginTokenInfosResponse {
repeated ERC721OriginTokenInfo token_infos = 1;
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

Expand Down
5 changes: 5 additions & 0 deletions proto/minievm/evm/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ message AccessTuple {
// These keys represent specific storage slots in the contract's storage that are accessed or modified.
repeated string storage_keys = 2;
}

message ERC721OriginTokenInfo {
string token_origin_id = 1;
string token_uri = 2;
}
48 changes: 48 additions & 0 deletions x/evm/keeper/erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,30 @@ func (k ERC721Keeper) GetTokenInfos(ctx context.Context, classId string, tokenId
return tokenUris, make([]string, len(tokenIds)), err
}

func (k ERC721Keeper) GetOriginTokenInfos(ctx context.Context, classId string, tokenIds []*big.Int) (tokenOriginIds, tokenUris []string, err error) {
contractAddr, err := types.ContractAddressFromClassId(ctx, k, classId)
if err != nil {
return nil, nil, err
}

tokenOriginIds = make([]string, len(tokenIds))
tokenUris = make([]string, len(tokenIds))
for i, tokenId := range tokenIds {
tokenUri, err := k.tokenURI(ctx, tokenId, contractAddr)
if err != nil {
return nil, nil, err
}
tokenUris[i] = tokenUri

tokenOriginId, err := k.tokenOriginId(ctx, tokenId, contractAddr)
if err != nil {
return nil, nil, err
}
tokenOriginIds[i] = tokenOriginId
}
return tokenOriginIds, tokenUris, err
}

func (k ERC721Keeper) balanceOf(ctx context.Context, addr, contractAddr common.Address) (math.Int, error) {
inputBz, err := k.ABI.Pack("balanceOf", addr)
if err != nil {
Expand Down Expand Up @@ -405,3 +429,27 @@ func (k ERC721Keeper) tokenURI(ctx context.Context, tokenId *big.Int, contractAd

return tokenUri, nil
}

func (k ERC721Keeper) tokenOriginId(ctx context.Context, tokenId *big.Int, contractAddr common.Address) (string, error) {
inputBz, err := k.ABI.Pack("tokenOriginId", tokenId)
if err != nil {
return "", types.ErrFailedToPackABI.Wrap(err.Error())
}

retBz, err := k.EVMStaticCall(ctx, types.NullAddress, contractAddr, inputBz, nil)
if err != nil {
return "", err
}

res, err := k.ABI.Unpack("tokenOriginId", retBz)
if err != nil {
return "", types.ErrFailedToUnpackABI.Wrap(err.Error())
}

tokenOriginId, ok := res[0].(string)
if !ok {
return tokenOriginId, types.ErrFailedToDecodeOutput
}

return tokenOriginId, nil
}
Loading

0 comments on commit 0ac1947

Please sign in to comment.