Skip to content
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
8 changes: 3 additions & 5 deletions proto/bitsong/fantoken/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ option go_package = "github.com/bitsongofficial/chainmodules/x/fantoken/types";
service Query {
// FanToken returns fantoken with fantoken name
rpc FanToken(QueryFanTokenRequest) returns (QueryFanTokenResponse) {
option (google.api.http).get = "/bitsong/fantoken/v1beta1/tokens/{denom}";
option (google.api.http).get = "/bitsong/fantoken/v1beta1/denom/{denom}";
}
// FanTokens returns the fantoken list
rpc FanTokens(QueryFanTokensRequest) returns (QueryFanTokensResponse) {
option (google.api.http).get = "/bitsong/fantoken/v1beta1/tokens";
option (google.api.http).get = "/bitsong/fantoken/v1beta1/fantokens";
}
// Params queries the fantoken parameters
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
Expand Down Expand Up @@ -58,11 +58,9 @@ message QueryParamsRequest {}
// QueryParametersResponse is response type for the Query/Parameters RPC method
message QueryParamsResponse {
bitsong.fantoken.v1beta1.Params params = 1 [ (gogoproto.nullable) = false ];

cosmos.base.query.v1beta1.PageResponse res = 2;
}

// QueryFanTokenRequest is request type for the Query/TotalBurn RPC method
// QueryTotalBurnRequest is request type for the Query/TotalBurn RPC method
message QueryTotalBurnRequest {}

// QueryTotalBurnResponse is response type for the Query/TotalBurn RPC method
Expand Down
4 changes: 2 additions & 2 deletions proto/bitsong/fantoken/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ message MsgIssueFanTokenResponse {}

// MsgTransferFanTokenOwner defines an SDK message for transferring the token owner
message MsgTransferFanTokenOwner {
string symbol = 1;
string denom = 1;
string src_owner = 2 [ (gogoproto.moretags) = "yaml:\"src_owner\"" ];
string dst_owner = 3 [ (gogoproto.moretags) = "yaml:\"dst_owner\"" ];
}
Expand All @@ -57,7 +57,7 @@ message MsgTransferFanTokenOwnerResponse {}

// MsgEditFanToken defines an SDK message for editing a fan token
message MsgEditFanToken {
string symbol = 1;
string denom = 1;
bool mintable = 2;
string owner = 3;
}
Expand Down
12 changes: 5 additions & 7 deletions x/fantoken/client/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/tidwall/gjson"

"github.com/tendermint/tendermint/crypto"

Expand Down Expand Up @@ -57,8 +56,8 @@ func (s *IntegrationTestSuite) TestToken() {

from := val.Address
symbol := "kitty"
denom := "ukitty"
name := "Kitty Token"
denom := tokentypes.GetFantokenDenom(from, symbol, name)
maxSupply := sdk.NewInt(200000000)
mintable := true
issueFee := "1000000ubtsg"
Expand All @@ -84,7 +83,6 @@ func (s *IntegrationTestSuite) TestToken() {
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType), bz.String())
txResp := respType.(*sdk.TxResponse)
s.Require().Equal(expectedCode, txResp.Code)
tokenSymbol := gjson.Get(txResp.RawLog, "0.events.0.attributes.0.value").String()

//------test GetCmdQueryFanTokens()-------------
tokens := &[]tokentypes.FanToken{}
Expand All @@ -96,7 +94,7 @@ func (s *IntegrationTestSuite) TestToken() {
//------test GetCmdQueryFanToken()-------------
var token *tokentypes.FanToken
respType = proto.Message(&tokentypes.FanToken{})
bz, err = tokentestutil.QueryFanTokenExec(clientCtx, tokenSymbol)
bz, err = tokentestutil.QueryFanTokenExec(clientCtx, denom)
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType))
token = respType.(*tokentypes.FanToken)
Expand Down Expand Up @@ -183,7 +181,7 @@ func (s *IntegrationTestSuite) TestToken() {
}

respType = proto.Message(&sdk.TxResponse{})
bz, err = tokentestutil.EditFanTokenExec(clientCtx, from.String(), symbol, args...)
bz, err = tokentestutil.EditFanTokenExec(clientCtx, from.String(), denom, args...)

s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType), bz.String())
Expand All @@ -192,7 +190,7 @@ func (s *IntegrationTestSuite) TestToken() {

var token2 *tokentypes.FanToken
respType = proto.Message(&tokentypes.FanToken{})
bz, err = tokentestutil.QueryFanTokenExec(clientCtx, tokenSymbol)
bz, err = tokentestutil.QueryFanTokenExec(clientCtx, denom)
s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType))
token2 = respType.(*tokentypes.FanToken)
Expand All @@ -209,7 +207,7 @@ func (s *IntegrationTestSuite) TestToken() {
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(s.cfg.BondDenom, sdk.NewInt(10))).String()),
}
respType = proto.Message(&sdk.TxResponse{})
bz, err = tokentestutil.TransferFanTokenOwnerExec(clientCtx, from.String(), symbol, args...)
bz, err = tokentestutil.TransferFanTokenOwnerExec(clientCtx, from.String(), denom, args...)

s.Require().NoError(err)
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType), bz.String())
Expand Down
20 changes: 10 additions & 10 deletions x/fantoken/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func GetQueryCmd() *cobra.Command {
return queryCmd
}

// GetCmdQueryToken implements the query token command.
// GetCmdQueryFanToken implements the query fantoken command.
func GetCmdQueryFanToken() *cobra.Command {
cmd := &cobra.Command{
Use: "token [denom]",
Long: "Query a token by symbol or denom.",
Example: fmt.Sprintf("$ %s query token token <denom>", version.AppName),
Use: "denom [denom]",
Long: "Query a fantoken by denom.",
Example: fmt.Sprintf("$ %s query fantoken denom <denom>", version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand All @@ -46,7 +46,7 @@ func GetCmdQueryFanToken() *cobra.Command {
return err
}

if err := types.ValidateSymbol(args[0]); err != nil {
if err := types.ValidateDenom(args[0]); err != nil {
return err
}

Expand All @@ -71,9 +71,9 @@ func GetCmdQueryFanToken() *cobra.Command {
// GetCmdQueryTokens implements the query tokens command.
func GetCmdQueryFanTokens() *cobra.Command {
cmd := &cobra.Command{
Use: "tokens [owner]",
Long: "Query token by the owner.",
Example: fmt.Sprintf("$ %s query token tokens <owner>", version.AppName),
Use: "owner [owner]",
Long: "Query fantokens by the owner.",
Example: fmt.Sprintf("$ %s query fantoken owner <owner>", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand Down Expand Up @@ -118,7 +118,7 @@ func GetCmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Long: "Query values set as token parameters.",
Example: fmt.Sprintf("$ %s query token params", version.AppName),
Example: fmt.Sprintf("$ %s query fantoken params", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand All @@ -144,7 +144,7 @@ func GetCmdQueryTotalBurn() *cobra.Command {
cmd := &cobra.Command{
Use: "total-burn",
Long: "Query the total amount of all burned tokens.",
Example: fmt.Sprintf("$ %s query token params", version.AppName),
Example: fmt.Sprintf("$ %s query fantoken total-burn", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions x/fantoken/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ func NewTxCmd() *cobra.Command {
func GetCmdIssueFanToken() *cobra.Command {
cmd := &cobra.Command{
Use: "issue",
Long: "Issue a new fan token.",
Long: "Issue a new fantoken.",
Example: fmt.Sprintf(
"$ %s tx token issue "+
"$ %s tx fantoken issue "+
"--name=\"Kitty Token\" "+
"--symbol=\"kitty\" "+
"--max-supply=\"1000000000000\" "+
Expand Down Expand Up @@ -125,7 +125,7 @@ func GetCmdIssueFanToken() *cobra.Command {
func GetCmdEditFanToken() *cobra.Command {
cmd := &cobra.Command{
Use: "edit [denom]",
Long: "Edit an existing fan token mintable.",
Long: "Edit an existing fantoken.",
Example: fmt.Sprintf(
"$ %s tx fantoken edit <denom> "+
"--mintable=true "+
Expand Down Expand Up @@ -170,9 +170,9 @@ func GetCmdEditFanToken() *cobra.Command {
func GetCmdMintFanToken() *cobra.Command {
cmd := &cobra.Command{
Use: "mint [denom]",
Long: "Mint tokens to a specified address.",
Long: "Mint fantokens to a specified address.",
Example: fmt.Sprintf(
"$ %s tx token mint <denom> "+
"$ %s tx fantoken mint <denom> "+
"--recipient=<recipient>"+
"--amount=<amount> "+
"--from=<key-name> "+
Expand Down Expand Up @@ -231,9 +231,9 @@ func GetCmdMintFanToken() *cobra.Command {
func GetCmdBurnFanToken() *cobra.Command {
cmd := &cobra.Command{
Use: "burn [denom]",
Long: "Burn fan tokens.",
Long: "Burn fantoken.",
Example: fmt.Sprintf(
"$ %s tx token burn <denom> "+
"$ %s tx fantoken burn <denom> "+
"--amount=<amount> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
Expand Down Expand Up @@ -291,10 +291,10 @@ func GetCmdBurnFanToken() *cobra.Command {
// GetCmdTransferFanTokenOwner implements the transfer fan token owner command
func GetCmdTransferFanTokenOwner() *cobra.Command {
cmd := &cobra.Command{
Use: "transfer [symbol]",
Use: "transfer [denom]",
Long: "Transfer the owner of a fantoken to a new owner.",
Example: fmt.Sprintf(
"$ %s tx fantoken transfer <symbol> "+
"$ %s tx fantoken transfer <denom> "+
"--recipient=<recipient> "+
"--from=<key-name> "+
"--chain-id=<chain-id> "+
Expand Down
7 changes: 3 additions & 4 deletions x/fantoken/client/rest/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/tidwall/gjson"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/testutil/network"
Expand Down Expand Up @@ -62,6 +61,7 @@ func (s *IntegrationTestSuite) TestToken() {
issueFee := "1000000ubtsg"
description := "Kitty Token"
baseURL := val.APIAddress
denom := tokentypes.GetFantokenDenom(from, symbol, name)

//------test GetCmdIssueFanToken()-------------
args := []string{
Expand All @@ -84,10 +84,9 @@ func (s *IntegrationTestSuite) TestToken() {
s.Require().NoError(clientCtx.JSONMarshaler.UnmarshalJSON(bz.Bytes(), respType), bz.String())
txResp := respType.(*sdk.TxResponse)
s.Require().Equal(expectedCode, txResp.Code)
tokenSymbol := gjson.Get(txResp.RawLog, "0.events.0.attributes.0.value").String()

//------test GetCmdQueryFanTokens()-------------
url := fmt.Sprintf("%s/bitsong/fantoken/v1beta1/tokens", baseURL)
url := fmt.Sprintf("%s/bitsong/fantoken/v1beta1/fantokens", baseURL)
resp, err := rest.GetRequest(url)
respType = proto.Message(&tokentypes.QueryFanTokensResponse{})
s.Require().NoError(err)
Expand All @@ -96,7 +95,7 @@ func (s *IntegrationTestSuite) TestToken() {
s.Require().Equal(1, len(tokensResp.Tokens))

//------test GetCmdQueryFanToken()-------------
url = fmt.Sprintf("%s/bitsong/fantoken/v1beta1/tokens/%s", baseURL, tokenSymbol)
url = fmt.Sprintf("%s/bitsong/fantoken/v1beta1/denom/%s", baseURL, denom)
resp, err = rest.GetRequest(url)
respType = proto.Message(&tokentypes.QueryFanTokenResponse{})
var token tokentypes.FanTokenI
Expand Down
6 changes: 3 additions & 3 deletions x/fantoken/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
)

func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {
// Query the token by symbol or denom
r.HandleFunc(fmt.Sprintf("/%s/tokens/{%s}", types.ModuleName, RestParamDenom), queryFanTokenHandlerFn(cliCtx)).Methods("GET")
// Query the token by denom
r.HandleFunc(fmt.Sprintf("/%s/denom/{%s}", types.ModuleName, RestParamDenom), queryFanTokenHandlerFn(cliCtx)).Methods("GET")
// Query tokens by owner
r.HandleFunc(fmt.Sprintf("/%s/tokens", types.ModuleName), queryFanTokensHandlerFn(cliCtx)).Methods("GET")
r.HandleFunc(fmt.Sprintf("/%s/fantokens", types.ModuleName), queryFanTokensHandlerFn(cliCtx)).Methods("GET")
// Query token params
r.HandleFunc(fmt.Sprintf("/%s/params", types.ModuleName), queryFanTokenParamsHandlerFn(cliCtx)).Methods("GET")
// Query the total amount of all burned tokens
Expand Down
5 changes: 2 additions & 3 deletions x/fantoken/client/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import (
// Rest variable names
// nolint
const (
RestParamDenom = "denom"
RestParamSymbol = "symbol"
RestParamOwner = "owner"
RestParamDenom = "denom"
RestParamOwner = "owner"
)

// RegisterHandlers registers token-related REST handlers to a router
Expand Down
18 changes: 9 additions & 9 deletions x/fantoken/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import (

func registerTxRoutes(cliCtx client.Context, r *mux.Router) {
// issue a token
r.HandleFunc(fmt.Sprintf("/%s/tokens", tokentypes.ModuleName), issueTokenHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/denom", tokentypes.ModuleName), issueTokenHandlerFn(cliCtx)).Methods("POST")
// edit a token
r.HandleFunc(fmt.Sprintf("/%s/tokens/{%s}", tokentypes.ModuleName, RestParamSymbol), editFanTokenHandlerFn(cliCtx)).Methods("PUT")
r.HandleFunc(fmt.Sprintf("/%s/denom/{%s}", tokentypes.ModuleName, RestParamDenom), editFanTokenHandlerFn(cliCtx)).Methods("PUT")
// transfer owner
r.HandleFunc(fmt.Sprintf("/%s/tokens/{%s}/transfer", tokentypes.ModuleName, RestParamSymbol), transferOwnerHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/denom/{%s}/transfer", tokentypes.ModuleName, RestParamDenom), transferOwnerHandlerFn(cliCtx)).Methods("POST")
// mint token
r.HandleFunc(fmt.Sprintf("/%s/tokens/{%s}/mint", tokentypes.ModuleName, RestParamDenom), mintFanTokenHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/denom/{%s}/mint", tokentypes.ModuleName, RestParamDenom), mintFanTokenHandlerFn(cliCtx)).Methods("POST")
// burn token
r.HandleFunc(fmt.Sprintf("/%s/tokens/{%s}/burn", tokentypes.ModuleName, RestParamDenom), burnFanTokenHandlerFn(cliCtx)).Methods("POST")
r.HandleFunc(fmt.Sprintf("/%s/denom/{%s}/burn", tokentypes.ModuleName, RestParamDenom), burnFanTokenHandlerFn(cliCtx)).Methods("POST")
}

func issueTokenHandlerFn(cliCtx client.Context) http.HandlerFunc {
Expand Down Expand Up @@ -73,7 +73,7 @@ func issueTokenHandlerFn(cliCtx client.Context) http.HandlerFunc {
func editFanTokenHandlerFn(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
symbol := vars[RestParamSymbol]
denom := vars[RestParamDenom]

var req editFanTokenReq
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
Expand All @@ -88,7 +88,7 @@ func editFanTokenHandlerFn(cliCtx client.Context) http.HandlerFunc {
mintable := req.Mintable

// create the MsgEditToken message
msg := tokentypes.NewMsgEditFanToken(symbol, mintable, req.Owner)
msg := tokentypes.NewMsgEditFanToken(denom, mintable, req.Owner)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand All @@ -101,7 +101,7 @@ func editFanTokenHandlerFn(cliCtx client.Context) http.HandlerFunc {
func transferOwnerHandlerFn(cliCtx client.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
symbol := vars[RestParamSymbol]
denom := vars[RestParamDenom]

var req transferFanTokenOwnerReq
if !rest.ReadRESTReq(w, r, cliCtx.LegacyAmino, &req) {
Expand All @@ -114,7 +114,7 @@ func transferOwnerHandlerFn(cliCtx client.Context) http.HandlerFunc {
}

// create the MsgTransferTokenOwner message
msg := tokentypes.NewMsgTransferFanTokenOwner(symbol, req.SrcOwner, req.DstOwner)
msg := tokentypes.NewMsgTransferFanTokenOwner(denom, req.SrcOwner, req.DstOwner)
if err := msg.ValidateBasic(); err != nil {
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
return
Expand Down
16 changes: 8 additions & 8 deletions x/fantoken/client/testutil/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@ func IssueFanTokenExec(clientCtx client.Context, from string, extraArgs ...strin
return clitestutil.ExecTestCLICmd(clientCtx, tokencli.GetCmdIssueFanToken(), args)
}

func EditFanTokenExec(clientCtx client.Context, from string, symbol string, extraArgs ...string) (testutil.BufferWriter, error) {
func EditFanTokenExec(clientCtx client.Context, from string, denom string, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{
symbol,
denom,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}
args = append(args, extraArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, tokencli.GetCmdEditFanToken(), args)
}

func MintFanTokenExec(clientCtx client.Context, from string, symbol string, extraArgs ...string) (testutil.BufferWriter, error) {
func MintFanTokenExec(clientCtx client.Context, from string, denom string, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{
symbol,
denom,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}
args = append(args, extraArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, tokencli.GetCmdMintFanToken(), args)
}

func BurnFanTokenExec(clientCtx client.Context, from string, symbol string, extraArgs ...string) (testutil.BufferWriter, error) {
func BurnFanTokenExec(clientCtx client.Context, from string, denom string, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{
symbol,
denom,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}
args = append(args, extraArgs...)

return clitestutil.ExecTestCLICmd(clientCtx, tokencli.GetCmdBurnFanToken(), args)
}

func TransferFanTokenOwnerExec(clientCtx client.Context, from string, symbol string, extraArgs ...string) (testutil.BufferWriter, error) {
func TransferFanTokenOwnerExec(clientCtx client.Context, from string, denom string, extraArgs ...string) (testutil.BufferWriter, error) {
args := []string{
symbol,
denom,
fmt.Sprintf("--%s=%s", flags.FlagFrom, from),
}
args = append(args, extraArgs...)
Expand Down
Loading