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

fix: sdk error #24

Open
wants to merge 3 commits into
base: sheldon/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/irisnet/core-sdk-go/client"
sdk "github.com/irisnet/core-sdk-go/types"
"github.com/irisnet/irismod-sdk-go/mt"
"github.com/irisnet/irismod-sdk-go/nft"
"github.com/tendermint/tendermint/libs/log"
)
Expand All @@ -14,6 +15,7 @@ type Client struct {
sdk.BaseClient

NFTClient nft.IClient
MTClient mt.IClient
}

func NewClient(cfg sdk.ClientConfig) (Client, error) {
Expand All @@ -28,13 +30,19 @@ func NewClient(cfg sdk.ClientConfig) (Client, error) {
return Client{}, err
}

mtClient, err := mt.NewClient(baseClient)
if err != nil {
return Client{}, err
}

cli := Client{
BaseClient: baseClient,
moduleManager: make(map[string]sdk.Module),
encodingConfig: encodingConfig,
NFTClient: nftClient,
MTClient: mtClient,
}
cli.RegisterModule(nftClient)
cli.RegisterModule(nftClient, mtClient)
return cli, nil
}

Expand Down
37 changes: 37 additions & 0 deletions integration_test/mt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package integration_test

func (s *ClientTestSuite) TestMtABCIQueryClass() {
classId := "c02a799c8fee067a7f9b944554d8431ee539847234441833e45a3a2d3123fd99"
height := int64(15530227)

resp, err := s.MTClient.ABCIQueryClass(classId, height)
s.Require().NoError(err)
s.T().Log(resp)
}

func (s *ClientTestSuite) TestMtABCIQueryClass2() {
classId := "c02a799c8fee067a7f9b944554d8431ee539847234441833e45a3a2d3123fd99"
height := int64(20000000)

resp, err := s.MTClient.ABCIQueryClass2(classId, height)
s.Require().NoError(err)
s.T().Log(resp)
}

func (s *ClientTestSuite) TestMtIQueryClass() {
classId := "c02a799c8fee067a7f9b944554d8431ee539847234441833e45a3a2d3123fd99"

resp, err := s.MTClient.QueryClass(classId)
s.Require().NoError(err)
s.T().Log(resp)
}

func (s *ClientTestSuite) TestMtABCIQueryMT() {
classId := "c02a799c8fee067a7f9b944554d8431ee539847234441833e45a3a2d3123fd99"
tokenId := "ff6e57b41cb52ae7d58d854b2123da2c5657fd15d525821a13fe7da1b9cebd80"
height := int64(26606801)

resp, err := s.MTClient.ABCIQueryMT(classId, tokenId, height)
s.Require().NoError(err)
s.T().Log(resp)
}
9 changes: 9 additions & 0 deletions integration_test/nft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ func (s *ClientTestSuite) TestNFT() {
s.Require().NoError(err)
s.T().Log(resp)
}

func (s *ClientTestSuite) TestNftABCIQueryClass() {
classId := "testticket"
height := int64(2554487)

resp, err := s.NFTClient.ABCIQueryClass(classId, height)
s.Require().NoError(err)
s.T().Log(resp)
}
59 changes: 57 additions & 2 deletions mt/abci_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
)

const (
FunctionPathQueryDenom = "/irismod.mt.Query/Denom"
FunctionPathQueryMT = "/irismod.mt.Query/MT"
FunctionPathQueryDenom = "/irismod.mt.Query/Denom"
FunctionPathQueryDenoms = "/irismod.mt.Query/Denoms"
FunctionPathQueryMT = "/irismod.mt.Query/MT"
)

func (cli *Client) ABCIQueryClass(classId string, height int64) (*QueryClassResp, error) {
Expand Down Expand Up @@ -63,6 +64,60 @@ func (cli *Client) ABCIQueryClass(classId string, height int64) (*QueryClassResp
return &resp, nil
}

func (cli *Client) ABCIQueryClass2(classId string, height int64) (*QueryClassResp, error) {
var resp QueryClassResp

if len(classId) == 0 {
return nil, sdkerrors.Wrapf(ErrInvalidClassId, "class id is required")
}

if height < 0 {
return nil, sdkerrors.Wrapf(ErrInvalidHeight, "height must be not less than 0")
}

grpcReq := &QueryDenomsRequest{}

reqBz, err := cli.Marshaler().Marshal(grpcReq)
if err != nil {
return nil, err
}

opts := rpcclient.ABCIQueryOptions{
Height: height,
Prove: false,
}

result, err := cli.ABCIQueryWithOptions(context.Background(),
FunctionPathQueryDenoms, reqBz, opts)
if err != nil {
return nil, err
}

if !result.Response.IsOK() {
return nil, errors.New(fmt.Sprint(result.Response.Log))
}

var grpcResp QueryDenomsResponse
err = cli.Marshaler().Unmarshal(result.Response.Value, &grpcResp)
if err != nil {
return nil, err
}

for _, denom := range grpcResp.Denoms {
if denom.Id == classId {
resp = QueryClassResp{
ID: denom.Id,
Name: denom.Name,
Data: denom.Data,
Owner: denom.Owner,
}
break
}
}

return &resp, nil
}

func (cli *Client) ABCIQueryMT(classId, tokenId string, height int64) (*QueryMTResp, error) {
if len(classId) == 0 {
return nil, sdkerrors.Wrapf(ErrInvalidClassId, "class id is required")
Expand Down
11 changes: 6 additions & 5 deletions mt/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mt

import (
context "context"
"context"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -165,8 +165,9 @@ func (cli *Client) QuerySupply(denomID, creator string) (uint64, sdk.Error) {
if len(denomID) == 0 {
return 0, sdk.Wrapf("denomID is required")
}
if _, err := types.ValAddressFromBech32(creator); err != nil {
return 0, sdk.Wrap(err)

if _, err := types.AccAddressFromBech32(creator); err != nil {
return 0, sdk.Wrapf("invalid sender address (%s)", err)
}

res, err := cli.queryCli.Supply(
Expand Down Expand Up @@ -320,8 +321,8 @@ func (cli *Client) QueryBalances(denomID, owner string, pagination *query.PageRe
return nil, sdk.Wrapf("denomID is required")
}

if _, err := types.ValAddressFromBech32(owner); err != nil {
return nil, sdk.Wrap(err)
if _, err := types.AccAddressFromBech32(owner); err != nil {
return nil, sdk.Wrapf("invalid sender address (%s)", err)
}

res, err := cli.queryCli.Balances(
Expand Down
1 change: 1 addition & 0 deletions mt/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type IABIClient interface {
ABCIQueryClass(classId string, height int64) (*QueryClassResp, error)
ABCIQueryClass2(classId string, height int64) (*QueryClassResp, error)
ABCIQueryMT(classId, tokenId string, height int64) (*QueryMTResp, error)
}

Expand Down
4 changes: 2 additions & 2 deletions nft/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (cli *Client) QueryCollection(classId string, pagination PaginationRequest)
Description: result.Collection.Denom.Description,
}
nfts := make([]QueryNFTResp, 0, len(result.Collection.NFTs))
for index, value := range result.Collection.NFTs {
for _, value := range result.Collection.NFTs {
nft := QueryNFTResp{
ID: value.Id,
Name: value.Name,
Expand All @@ -282,7 +282,7 @@ func (cli *Client) QueryCollection(classId string, pagination PaginationRequest)
URI: value.URI,
URIHash: value.UriHash,
}
nfts[index] = nft
nfts = append(nfts, nft)
}

response := &QueryCollectionResp{
Expand Down