diff --git a/client/client.go b/client/client.go index c65bae4..5c221d3 100644 --- a/client/client.go +++ b/client/client.go @@ -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" ) @@ -14,6 +15,7 @@ type Client struct { sdk.BaseClient NFTClient nft.IClient + MTClient mt.IClient } func NewClient(cfg sdk.ClientConfig) (Client, error) { @@ -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 } diff --git a/integration_test/mt_test.go b/integration_test/mt_test.go new file mode 100644 index 0000000..c82eb26 --- /dev/null +++ b/integration_test/mt_test.go @@ -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) +} diff --git a/integration_test/nft_test.go b/integration_test/nft_test.go index 8a1012b..39269df 100644 --- a/integration_test/nft_test.go +++ b/integration_test/nft_test.go @@ -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) +} diff --git a/mt/abci_query.go b/mt/abci_query.go index abb7afd..8edc525 100644 --- a/mt/abci_query.go +++ b/mt/abci_query.go @@ -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) { @@ -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") diff --git a/mt/client.go b/mt/client.go index 49d5b72..5259d6d 100644 --- a/mt/client.go +++ b/mt/client.go @@ -1,7 +1,7 @@ package mt import ( - context "context" + "context" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/types" @@ -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( @@ -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( diff --git a/mt/exported.go b/mt/exported.go index 61d5390..9620352 100644 --- a/mt/exported.go +++ b/mt/exported.go @@ -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) } diff --git a/nft/client.go b/nft/client.go index cd19c11..1110409 100644 --- a/nft/client.go +++ b/nft/client.go @@ -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, @@ -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{