Skip to content

Commit

Permalink
rename tx
Browse files Browse the repository at this point in the history
  • Loading branch information
hansol-medi committed Apr 20, 2022
1 parent b988841 commit fcab598
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 146 deletions.
12 changes: 6 additions & 6 deletions proto/panacea/datapool/v2/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ service Msg {
// SellData defines a method for selling data
rpc SellData(MsgSellData) returns (MsgSellDataResponse);

// BuyDataAccessNFT defines a method for buying data access NFT
rpc BuyDataAccessNFT(MsgBuyDataAccessNFT) returns (MsgBuyDataAccessNFTResponse);
// BuyDataPass defines a method for buying data access NFT
rpc BuyDataPass(MsgBuyDataPass) returns (MsgBuyDataPassResponse);

// RedeemDataAccessNFT defines a method for redeeming data access NFT to get data
rpc RedeemDataAccessNFT(MsgRedeemDataAccessNFT) returns (MsgRedeemDataAccessNFTResponse);
Expand Down Expand Up @@ -75,16 +75,16 @@ message MsgSellDataResponse {
cosmos.base.v1beta1.Coin accum_pool_share_token = 1; // denom: DP-{pood-id}
}

// MsgBuyDataAccessNFT defines the Msg/BuyDataAccessNFT request type.
message MsgBuyDataAccessNFT {
// MsgBuyDataPass defines the Msg/BuyDataPass request type.
message MsgBuyDataPass {
uint64 pool_id = 1;
uint64 round = 2;
cosmos.base.v1beta1.Coin payment = 3;
string buyer = 4; // 'panacea1' address of buyer
}

// MsgBuyDataAccessNFTResponse defines the Msg/BuyDataAccessNFT response type.
message MsgBuyDataAccessNFTResponse {
// MsgBuyDataPassResponse defines the Msg/BuyDataAccessNFT response type.
message MsgBuyDataPassResponse {
uint64 pool_id = 1;
uint64 round = 2;
uint64 nft_id = 3;
Expand Down
2 changes: 1 addition & 1 deletion x/datapool/client/cli/txPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func CmdBuyDataAccessNFT() *cobra.Command {
return err
}

msg := &types.MsgBuyDataAccessNFT{
msg := &types.MsgBuyDataPass{
PoolId: poolID,
Round: round,
Payment: &payment,
Expand Down
4 changes: 2 additions & 2 deletions x/datapool/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgCreatePool:
res, err := msgServer.CreatePool(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgBuyDataAccessNFT:
res, err := msgServer.BuyDataAccessNFT(sdk.WrapSDKContext(ctx), msg)
case *types.MsgBuyDataPass:
res, err := msgServer.BuyDataPass(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgSellData:
res, err := msgServer.SellData(sdk.WrapSDKContext(ctx), msg)
Expand Down
6 changes: 3 additions & 3 deletions x/datapool/keeper/msg_server_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ func (m msgServer) SellData(goCtx context.Context, msg *types.MsgSellData) (*typ
}, nil
}

func (m msgServer) BuyDataAccessNFT(goCtx context.Context, msg *types.MsgBuyDataAccessNFT) (*types.MsgBuyDataAccessNFTResponse, error) {
func (m msgServer) BuyDataPass(goCtx context.Context, msg *types.MsgBuyDataPass) (*types.MsgBuyDataPassResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

buyer, err := sdk.AccAddressFromBech32(msg.Buyer)
if err != nil {
return nil, err
}

err = m.Keeper.BuyDataAccessNFT(ctx, buyer, msg.PoolId, msg.Round, *msg.Payment)
err = m.Keeper.BuyDataPass(ctx, buyer, msg.PoolId, msg.Round, *msg.Payment)
if err != nil {
return nil, err
}

return &types.MsgBuyDataAccessNFTResponse{PoolId: msg.PoolId, Round: msg.Round}, nil
return &types.MsgBuyDataPassResponse{PoolId: msg.PoolId, Round: msg.Round}, nil
}

func (m msgServer) RedeemDataAccessNFT(goCtx context.Context, msg *types.MsgRedeemDataAccessNFT) (*types.MsgRedeemDataAccessNFTResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion x/datapool/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (k Keeper) GetDataValidationCertificate(ctx sdk.Context, poolID, round uint
return cert, nil
}

func (k Keeper) BuyDataAccessNFT(ctx sdk.Context, buyer sdk.AccAddress, poolID, round uint64, payment sdk.Coin) error {
func (k Keeper) BuyDataPass(ctx sdk.Context, buyer sdk.AccAddress, poolID, round uint64, payment sdk.Coin) error {
pool, err := k.GetPool(ctx, poolID)
if err != nil {
return sdkerrors.Wrapf(types.ErrBuyDataPass, err.Error())
Expand Down
14 changes: 7 additions & 7 deletions x/datapool/keeper/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (suite poolTestSuite) TestBuyDataAccessNFTPending() {
err := suite.BankKeeper.AddCoins(suite.Ctx, buyerAddr, fundForBuyer)
suite.Require().NoError(err)

err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
suite.Require().NoError(err)

pool, err := suite.DataPoolKeeper.GetPool(suite.Ctx, poolID)
Expand All @@ -312,7 +312,7 @@ func (suite poolTestSuite) TestBuyDataAccessNFTPoolNotFound() {
suite.Require().NoError(err)

// buy NFT other data pool
err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, 2, 1, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, 2, 1, NFTPrice)
suite.Require().Error(err, types.ErrPoolNotFound)
}

Expand All @@ -324,11 +324,11 @@ func (suite poolTestSuite) TestBuyDataAccessNFTSoldOut() {
suite.Require().NoError(err)

// buy 1 NFT
err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
suite.Require().NoError(err)

// buy 1 NFT more
err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
suite.Require().Error(err, types.ErrNFTAllIssued)
}

Expand All @@ -340,7 +340,7 @@ func (suite poolTestSuite) TestBuyDataAccessNFTRoundNotMatched() {
suite.Require().NoError(err)

// different round
err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 2, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 2, NFTPrice)
suite.Require().Error(err, types.ErrRoundNotMatched)
}

Expand All @@ -352,7 +352,7 @@ func (suite poolTestSuite) TestBuyDataAccessNFTPaymentNotMatched() {
suite.Require().NoError(err)

// buy NFT with different payment
err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 1, sdk.NewCoin(assets.MicroMedDenom, sdk.NewInt(5000000)))
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 1, sdk.NewCoin(assets.MicroMedDenom, sdk.NewInt(5000000)))
suite.Require().Error(err, types.ErrPaymentNotMatched)
}

Expand All @@ -364,7 +364,7 @@ func (suite poolTestSuite) TestBuyDataAccessNFTInsufficientBalance() {
err := suite.BankKeeper.AddCoins(suite.Ctx, buyerAddr, sdk.NewCoins(sdk.NewCoin(assets.MicroMedDenom, sdk.NewInt(1000))))
suite.Require().NoError(err)

err = suite.DataPoolKeeper.BuyDataAccessNFT(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
err = suite.DataPoolKeeper.BuyDataPass(suite.Ctx, buyerAddr, poolID, 1, NFTPrice)
suite.Require().Error(err, sdkerrors.ErrInsufficientFunds)
}

Expand Down
4 changes: 2 additions & 2 deletions x/datapool/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgUpdateDataValidator{}, "datapool/UpdateDataValidator", nil)
cdc.RegisterConcrete(&MsgCreatePool{}, "datapool/CreatePool", nil)
cdc.RegisterConcrete(&MsgSellData{}, "datapool/SellData", nil)
cdc.RegisterConcrete(&MsgBuyDataAccessNFT{}, "datapool/BuyDataAccessNFT", nil)
cdc.RegisterConcrete(&MsgBuyDataPass{}, "datapool/BuyDataPass", nil)
cdc.RegisterConcrete(&MsgRedeemDataAccessNFT{}, "datapool/RedeemDataAccessNFT", nil)
}

Expand All @@ -24,7 +24,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgUpdateDataValidator{},
&MsgCreatePool{},
&MsgSellData{},
&MsgBuyDataAccessNFT{},
&MsgBuyDataPass{},
&MsgRedeemDataAccessNFT{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
14 changes: 7 additions & 7 deletions x/datapool/types/message_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ func (msg *MsgSellData) GetSigners() []sdk.AccAddress {
return []sdk.AccAddress{seller}
}

var _ sdk.Msg = &MsgBuyDataAccessNFT{}
var _ sdk.Msg = &MsgBuyDataPass{}

func (msg *MsgBuyDataAccessNFT) Route() string {
func (msg *MsgBuyDataPass) Route() string {
return RouterKey
}

func (msg *MsgBuyDataAccessNFT) Type() string {
return "BuyDataAccessNFT"
func (msg *MsgBuyDataPass) Type() string {
return "BuyDataPass"
}

func (msg *MsgBuyDataAccessNFT) ValidateBasic() error {
func (msg *MsgBuyDataPass) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Buyer)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid buyer address (%s)", err)
Expand All @@ -236,12 +236,12 @@ func (msg *MsgBuyDataAccessNFT) ValidateBasic() error {
return nil
}

func (msg *MsgBuyDataAccessNFT) GetSignBytes() []byte {
func (msg *MsgBuyDataPass) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(msg)
return sdk.MustSortJSON(bz)
}

func (msg *MsgBuyDataAccessNFT) GetSigners() []sdk.AccAddress {
func (msg *MsgBuyDataPass) GetSigners() []sdk.AccAddress {
buyer, err := sdk.AccAddressFromBech32(msg.Buyer)
if err != nil {
panic(err)
Expand Down
Loading

0 comments on commit fcab598

Please sign in to comment.