Skip to content

Commit

Permalink
api: glue code for EVM NFTs
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Sep 27, 2023
1 parent e00b761 commit d95cd32
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/v1/strict_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,11 @@ func (srv *StrictServerImpl) GetRuntimeEvmTokensAddressHolders(ctx context.Conte
}

func (srv *StrictServerImpl) GetRuntimeEvmNftsAddress(ctx context.Context, request apiTypes.GetRuntimeEvmNftsAddressRequestObject) (apiTypes.GetRuntimeEvmNftsAddressResponseObject, error) {
// TODO implement me
panic("implement me")
nfts, err := srv.dbClient.RuntimeEVMNFTs(ctx, request.Params, request.Address)
if err != nil {
return nil, err
}
return apiTypes.GetRuntimeEvmNftsAddress200JSONResponse(*nfts), nil
}

func (srv *StrictServerImpl) GetRuntimeTransactions(ctx context.Context, request apiTypes.GetRuntimeTransactionsRequestObject) (apiTypes.GetRuntimeTransactionsResponseObject, error) {
Expand Down
57 changes: 57 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"database/sql"
"fmt"
"math/big"
"time"
Expand Down Expand Up @@ -1531,6 +1532,62 @@ func (c *StorageClient) RuntimeTokenHolders(ctx context.Context, p apiTypes.GetR
return &hs, nil
}

func (c *StorageClient) RuntimeEVMNFTs(ctx context.Context, p apiTypes.GetRuntimeEvmNftsAddressParams, address staking.Address) (*EvmNftList, error) {
res, err := c.withTotalCount(
ctx,
"SELECT 1 FROM FALSE", // todo: queries.EvmNfts
runtimeFromCtx(ctx),
address,
p.Limit,
p.Offset,
)
if err != nil {
return nil, wrapError(err)
}
defer res.rows.Close()

nfts := EvmNftList{
EvmNfts: []EvmNft{},
TotalCount: res.totalCount,
IsTotalCountClipped: res.isTotalCountClipped,
}
for res.rows.Next() {
var nft EvmNft
var contractAddrContextIdentifier string
var contractAddrContextVersion int
var contractAddrData []byte
var metadataAccessedN sql.NullTime
if err2 := res.rows.Scan(
&nft.ContractAddr,
&contractAddrContextIdentifier,
&contractAddrContextVersion,
&contractAddrData,
&nft.TokenName,
&nft.TokenSymbol,
&nft.TokenType,
&nft.TokenTotalSupply,
&nft.Id,
&nft.MetadataUri,
&metadataAccessedN,
&nft.Name,
&nft.Description,
&nft.Image,
); err2 != nil {
return nil, wrapError(err2)
}
if contractEthAddr, err2 := EVMEthAddrFromPreimage(contractAddrContextIdentifier, contractAddrContextVersion, contractAddrData); err2 == nil {
contractECAddr := ethCommon.BytesToAddress(contractEthAddr)
nft.EthContractAddr = common.Ptr(contractECAddr.String())
}
if metadataAccessedN.Valid {
nft.MetadataAccessed = common.Ptr(metadataAccessedN.Time.String())
}
nfts.EvmNfts = append(nfts.EvmNfts, nft)
}

return &nfts, nil
}

// RuntimeStatus returns runtime status information.
func (c *StorageClient) RuntimeStatus(ctx context.Context) (*RuntimeStatus, error) {
runtimeName := runtimeFromCtx(ctx)
Expand Down
4 changes: 4 additions & 0 deletions storage/client/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type BareTokenHolder = api.BareTokenHolder

type TokenHolderList = api.TokenHolderList

type EvmNft = api.EvmNft

type EvmNftList = api.EvmNftList

// TxVolumeList is the storage response for GetVolumes.
type TxVolumeList = api.TxVolumeList

Expand Down

0 comments on commit d95cd32

Please sign in to comment.