Skip to content

Commit

Permalink
chore: refactor MsgMakeSwapProposal -> MsgSetSwap
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed May 9, 2024
1 parent 3ab8739 commit c40e8e5
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 454 deletions.
34 changes: 9 additions & 25 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,6 @@
- [EventSwapCoins](#lbm.fswap.v1.EventSwapCoins)

- [lbm/fswap/v1/fswap.proto](#lbm/fswap/v1/fswap.proto)
- [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal)
- [Swap](#lbm.fswap.v1.Swap)
- [SwapStats](#lbm.fswap.v1.SwapStats)
- [Swapped](#lbm.fswap.v1.Swapped)
Expand All @@ -973,8 +972,8 @@
- [Query](#lbm.fswap.v1.Query)

- [lbm/fswap/v1/tx.proto](#lbm/fswap/v1/tx.proto)
- [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal)
- [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse)
- [MsgSetSwap](#lbm.fswap.v1.MsgSetSwap)
- [MsgSetSwapResponse](#lbm.fswap.v1.MsgSetSwapResponse)
- [MsgSwap](#lbm.fswap.v1.MsgSwap)
- [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll)
- [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse)
Expand Down Expand Up @@ -14162,22 +14161,6 @@ Msg defines the foundation Msg service.



<a name="lbm.fswap.v1.MakeSwapProposal"></a>

### MakeSwapProposal



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swap` | [Swap](#lbm.fswap.v1.Swap) | | |
| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | |






<a name="lbm.fswap.v1.Swap"></a>

### Swap
Expand Down Expand Up @@ -14398,25 +14381,26 @@ GenesisState defines the fswap module's genesis state.



<a name="lbm.fswap.v1.MsgMakeSwapProposal"></a>
<a name="lbm.fswap.v1.MsgSetSwap"></a>

### MsgMakeSwapProposal
### MsgSetSwap



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | authority is the address of the privileged account. |
| `proposal` | [MakeSwapProposal](#lbm.fswap.v1.MakeSwapProposal) | | |
| `swap` | [Swap](#lbm.fswap.v1.Swap) | | |
| `to_denom_metadata` | [cosmos.bank.v1beta1.Metadata](#cosmos.bank.v1beta1.Metadata) | | |






<a name="lbm.fswap.v1.MsgMakeSwapProposalResponse"></a>
<a name="lbm.fswap.v1.MsgSetSwapResponse"></a>

### MsgMakeSwapProposalResponse
### MsgSetSwapResponse



Expand Down Expand Up @@ -14493,7 +14477,7 @@ GenesisState defines the fswap module's genesis state.
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Swap` | [MsgSwap](#lbm.fswap.v1.MsgSwap) | [MsgSwapResponse](#lbm.fswap.v1.MsgSwapResponse) | | |
| `SwapAll` | [MsgSwapAll](#lbm.fswap.v1.MsgSwapAll) | [MsgSwapAllResponse](#lbm.fswap.v1.MsgSwapAllResponse) | | |
| `MakeSwapProposal` | [MsgMakeSwapProposal](#lbm.fswap.v1.MsgMakeSwapProposal) | [MsgMakeSwapProposalResponse](#lbm.fswap.v1.MsgMakeSwapProposalResponse) | | |
| `SetSwap` | [MsgSetSwap](#lbm.fswap.v1.MsgSetSwap) | [MsgSetSwapResponse](#lbm.fswap.v1.MsgSetSwapResponse) | | |

<!-- end services -->

Expand Down
9 changes: 0 additions & 9 deletions proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/bank/v1beta1/bank.proto";

message Swap {
option (gogoproto.equal) = true;
Expand All @@ -26,14 +25,6 @@ message SwapStats {
int32 swap_count = 1;
}

message MakeSwapProposal {
option (gogoproto.goproto_stringer) = false;

Swap swap = 1 [(gogoproto.nullable) = false];
cosmos.bank.v1beta1.Metadata to_denom_metadata = 2
[(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false];
}

message Swapped {
option (gogoproto.goproto_stringer) = false;
cosmos.base.v1beta1.Coin from_coin_amount = 1
Expand Down
15 changes: 10 additions & 5 deletions proto/lbm/fswap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ option go_package = "github.com/Finschia/finschia-sdk/x/fswap/types";

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "lbm/fswap/v1/fswap.proto";

service Msg {
rpc Swap(MsgSwap) returns (MsgSwapResponse);
rpc SwapAll(MsgSwapAll) returns (MsgSwapAllResponse);
rpc MakeSwapProposal(MsgMakeSwapProposal) returns (MsgMakeSwapProposalResponse);
rpc SetSwap(MsgSetSwap) returns (MsgSetSwapResponse);
}

message MsgSwap {
Expand All @@ -33,10 +34,14 @@ message MsgSwapAll {

message MsgSwapAllResponse {}

message MsgMakeSwapProposal {
message MsgSetSwap {
option (gogoproto.goproto_stringer) = false;

// authority is the address of the privileged account.
string authority = 1;
MakeSwapProposal proposal = 2;
string authority = 1;
Swap swap = 2 [(gogoproto.nullable) = false];
cosmos.bank.v1beta1.Metadata to_denom_metadata = 3
[(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false];
}

message MsgMakeSwapProposalResponse {}
message MsgSetSwapResponse {}
10 changes: 4 additions & 6 deletions x/fswap/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,10 @@ Example of the content of metadata-json:
return err
}

msg := types.MsgMakeSwapProposal{
Authority: authority,
Proposal: &types.MakeSwapProposalTmp{
Swap: swap,
ToDenomMetadata: toDenomMetadata,
},
msg := types.MsgSetSwap{
Authority: authority,
Swap: swap,
ToDenomMetadata: toDenomMetadata,
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &msg)
Expand Down
1 change: 0 additions & 1 deletion x/fswap/codec/codec.go

This file was deleted.

6 changes: 3 additions & 3 deletions x/fswap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ func (s MsgServer) SwapAll(ctx context.Context, req *types.MsgSwapAll) (*types.M
return &types.MsgSwapAllResponse{}, nil
}

func (s MsgServer) MakeSwapProposal(ctx context.Context, req *types.MsgMakeSwapProposal) (*types.MsgMakeSwapProposalResponse, error) {
func (s MsgServer) SetSwap(ctx context.Context, req *types.MsgSetSwap) (*types.MsgSetSwapResponse, error) {
c := sdk.UnwrapSDKContext(ctx)

Check warning on line 65 in x/fswap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/msg_server.go#L64-L65

Added lines #L64 - L65 were not covered by tests

if err := s.keeper.validateAuthority(req.Authority); err != nil {
return nil, err

Check warning on line 68 in x/fswap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/msg_server.go#L67-L68

Added lines #L67 - L68 were not covered by tests
}

if err := s.keeper.MakeSwap(c, req.GetProposal().GetSwap(), req.GetProposal().GetToDenomMetadata()); err != nil {
if err := s.keeper.MakeSwap(c, req.GetSwap(), req.GetToDenomMetadata()); err != nil {
return nil, err

Check warning on line 72 in x/fswap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/msg_server.go#L71-L72

Added lines #L71 - L72 were not covered by tests
}

return &types.MsgMakeSwapProposalResponse{}, nil
return &types.MsgSetSwapResponse{}, nil

Check warning on line 75 in x/fswap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/keeper/msg_server.go#L75

Added line #L75 was not covered by tests
}
4 changes: 2 additions & 2 deletions x/fswap/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func init() {
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
legacy.RegisterAminoMsg(cdc, &MsgSwap{}, "lbm-sdk/MsgSwap")
legacy.RegisterAminoMsg(cdc, &MsgSwapAll{}, "lbm-sdk/MsgSwapAll")
legacy.RegisterAminoMsg(cdc, &MsgMakeSwapProposal{}, "lbm-sdk/MsgMakeSwapProposal")
legacy.RegisterAminoMsg(cdc, &MsgSetSwap{}, "lbm-sdk/MsgSetSwap")
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations((*sdk.Msg)(nil),
&MsgSwap{},
&MsgSwapAll{},
&MsgMakeSwapProposal{},
&MsgSetSwap{},

Check warning on line 38 in x/fswap/types/codec.go

View check run for this annotation

Codecov / codecov/patch

x/fswap/types/codec.go#L38

Added line #L38 was not covered by tests
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
19 changes: 0 additions & 19 deletions x/fswap/types/fswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,3 @@ func (s *Swapped) String() string {
out, _ := yaml.Marshal(s)
return string(out)
}

func (s *MakeSwapProposalTmp) ValidateBasic() error {
if err := s.Swap.ValidateBasic(); err != nil {
return err
}
if err := s.ToDenomMetadata.Validate(); err != nil {
return err
}
if s.Swap.ToDenom != s.ToDenomMetadata.Base {
return sdkerrors.ErrInvalidRequest.Wrapf("denomination does not match %s != %s", s.Swap.ToDenom, s.ToDenomMetadata.Base)
}

return nil
}

func (s *MakeSwapProposalTmp) String() string {
out, _ := yaml.Marshal(s)
return string(out)
}
Loading

0 comments on commit c40e8e5

Please sign in to comment.