Skip to content

Commit

Permalink
chore: change old/new to from/to
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeseung-bae committed Apr 30, 2024
1 parent 9b26d2f commit 547c5d6
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 262 deletions.
32 changes: 16 additions & 16 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,8 @@
- [lbm/fswap/v1/query.proto](#lbm/fswap/v1/query.proto)
- [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest)
- [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse)
- [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest)
- [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse)
- [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest)
- [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse)

- [Query](#lbm.fswap.v1.Query)

Expand Down Expand Up @@ -12726,8 +12726,8 @@ Msg defines the foundation Msg service.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | holder's address |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the old currency |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of the new currency |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount |
| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | to-coin amount |



Expand Down Expand Up @@ -12793,8 +12793,8 @@ From cosmos-sdk 0.46.0 they deprecated this way, but currently finschia-sdk base

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand Down Expand Up @@ -12867,33 +12867,33 @@ GenesisState defines the fswap module's genesis state.

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `old_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `new_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `from_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `to_coin_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |






<a name="lbm.fswap.v1.QueryTotalSwappableAmountRequest"></a>
<a name="lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest"></a>

### QueryTotalSwappableAmountRequest
### QueryTotalSwappableToCoinAmountRequest







<a name="lbm.fswap.v1.QueryTotalSwappableAmountResponse"></a>
<a name="lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse"></a>

### QueryTotalSwappableAmountResponse
### QueryTotalSwappableToCoinAmountResponse



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `swappable_new_coin` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |
| `swappable_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | |



Expand All @@ -12913,8 +12913,8 @@ GenesisState defines the fswap module's genesis state.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | Swapped queries the current swapped status that includes a burnt amount of old coin and a minted amount of new coin. | GET|/lbm/fswap/v1/swapped|
| `TotalSwappableAmount` | [QueryTotalSwappableAmountRequest](#lbm.fswap.v1.QueryTotalSwappableAmountRequest) | [QueryTotalSwappableAmountResponse](#lbm.fswap.v1.QueryTotalSwappableAmountResponse) | TotalSwappableAmount queries the current swappable amount for new coin. | GET|/lbm/fswap/v1/swappable_new_coin_amount|
| `Swapped` | [QuerySwappedRequest](#lbm.fswap.v1.QuerySwappedRequest) | [QuerySwappedResponse](#lbm.fswap.v1.QuerySwappedResponse) | Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of to-coin. | GET|/lbm/fswap/v1/swapped|
| `TotalSwappableToCoinAmount` | [QueryTotalSwappableToCoinAmountRequest](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountRequest) | [QueryTotalSwappableToCoinAmountResponse](#lbm.fswap.v1.QueryTotalSwappableToCoinAmountResponse) | TotalSwappableToCoinAmount queries the current swappable amount for to-coin. | GET|/lbm/fswap/v1/swappable_new_coin_amount|

<!-- end services -->

Expand Down Expand Up @@ -12961,7 +12961,7 @@ GenesisState defines the fswap module's genesis state.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `from_address` | [string](#string) | | holder's address |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | amount of old currency |
| `amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | from-coin amount |



Expand Down
8 changes: 4 additions & 4 deletions proto/lbm/fswap/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import "cosmos/base/v1beta1/coin.proto";
message EventSwapCoins {
// holder's address
string address = 1;
// amount of the old currency
cosmos.base.v1beta1.Coin old_coin_amount = 2
// from-coin amount
cosmos.base.v1beta1.Coin from_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
// amount of the new currency
cosmos.base.v1beta1.Coin new_coin_amount = 3
// to-coin amount
cosmos.base.v1beta1.Coin to_coin_amount = 3
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
6 changes: 3 additions & 3 deletions proto/lbm/fswap/v1/fswap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ message SwapInitProposal {
}

message Swapped {
option (gogoproto.goproto_stringer) = false;
cosmos.base.v1beta1.Coin old_coin_amount = 1
option (gogoproto.goproto_stringer) = false;
cosmos.base.v1beta1.Coin from_coin_amount = 1
[(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false];
cosmos.base.v1beta1.Coin new_coin_amount = 2
cosmos.base.v1beta1.Coin to_coin_amount = 2
[(gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin", (gogoproto.nullable) = false];
}
19 changes: 10 additions & 9 deletions proto/lbm/fswap/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@ import "cosmos/base/v1beta1/coin.proto";
import "lbm/fswap/v1/fswap.proto";

service Query {
// Swapped queries the current swapped status that includes a burnt amount of old coin and a minted amount of new
// coin.
// Swapped queries the current swapped status that includes a burnt amount of from-coin and a minted amount of
// to-coin.
rpc Swapped(QuerySwappedRequest) returns (QuerySwappedResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swapped";
}
// TotalSwappableAmount queries the current swappable amount for new coin.
rpc TotalSwappableAmount(QueryTotalSwappableAmountRequest) returns (QueryTotalSwappableAmountResponse) {
// TotalSwappableToCoinAmount queries the current swappable amount for to-coin.
rpc TotalSwappableToCoinAmount(QueryTotalSwappableToCoinAmountRequest)
returns (QueryTotalSwappableToCoinAmountResponse) {
option (google.api.http).get = "/lbm/fswap/v1/swappable_new_coin_amount";
}
}

message QuerySwappedRequest {}
message QuerySwappedResponse {
cosmos.base.v1beta1.Coin old_coin_amount = 1
cosmos.base.v1beta1.Coin from_coin_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
cosmos.base.v1beta1.Coin new_coin_amount = 2
cosmos.base.v1beta1.Coin to_coin_amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}

message QueryTotalSwappableAmountRequest {}
message QueryTotalSwappableAmountResponse {
cosmos.base.v1beta1.Coin swappable_new_coin = 1
message QueryTotalSwappableToCoinAmountRequest {}
message QueryTotalSwappableToCoinAmountResponse {
cosmos.base.v1beta1.Coin swappable_amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
2 changes: 1 addition & 1 deletion proto/lbm/fswap/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ service Msg {
message MsgSwapRequest {
// holder's address
string from_address = 1;
// amount of old currency
// from-coin amount
cosmos.base.v1beta1.Coin amount = 2
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/Finschia/finschia-sdk/types.Coin"];
}
Expand Down
2 changes: 1 addition & 1 deletion x/fswap/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func CmdQueryTotalSwappableAmount() *cobra.Command {
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.TotalSwappableAmount(cmd.Context(), &types.QueryTotalSwappableAmountRequest{})
res, err := queryClient.TotalSwappableToCoinAmount(cmd.Context(), &types.QueryTotalSwappableToCoinAmountRequest{})
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions x/fswap/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ func (s QueryServer) Swapped(ctx context.Context, _ *types.QuerySwappedRequest)
return nil, err
}
return &types.QuerySwappedResponse{
OldCoinAmount: swapped.GetOldCoinAmount(),
NewCoinAmount: swapped.GetNewCoinAmount(),
FromCoinAmount: swapped.GetFromCoinAmount(),
ToCoinAmount: swapped.GetToCoinAmount(),
}, nil
}

func (s QueryServer) TotalSwappableAmount(ctx context.Context, _ *types.QueryTotalSwappableAmountRequest) (*types.QueryTotalSwappableAmountResponse, error) {
func (s QueryServer) TotalSwappableToCoinAmount(ctx context.Context, _ *types.QueryTotalSwappableToCoinAmountRequest) (*types.QueryTotalSwappableToCoinAmountResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
amount, err := s.Keeper.getSwappableNewCoinAmount(c)
if err != nil {
return &types.QueryTotalSwappableAmountResponse{}, err
return &types.QueryTotalSwappableToCoinAmountResponse{}, err
}
return &types.QueryTotalSwappableAmountResponse{
SwappableNewCoin: amount,
return &types.QueryTotalSwappableToCoinAmountResponse{
SwappableAmount: amount,
}, nil
}
20 changes: 10 additions & 10 deletions x/fswap/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (k Keeper) SwapInit(ctx sdk.Context, swapInit types.SwapInit) error {
return err
}
swapped := types.Swapped{
OldCoinAmount: sdk.Coin{
FromCoinAmount: sdk.Coin{
Denom: swapInit.GetFromDenom(),
Amount: sdk.ZeroInt(),
},
NewCoinAmount: sdk.Coin{
ToCoinAmount: sdk.Coin{
Denom: swapInit.GetToDenom(),
Amount: sdk.ZeroInt(),
},
Expand Down Expand Up @@ -110,9 +110,9 @@ func (k Keeper) Swap(ctx sdk.Context, addr sdk.AccAddress, oldCoinAmount sdk.Coi
}

if err := ctx.EventManager().EmitTypedEvent(&types.EventSwapCoins{
Address: addr.String(),
OldCoinAmount: oldCoinAmount,
NewCoinAmount: newCoinAmount,
Address: addr.String(),
FromCoinAmount: oldCoinAmount,
ToCoinAmount: newCoinAmount,
}); err != nil {
return err
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func (k Keeper) getSwapped(ctx sdk.Context) (types.Swapped, error) {

func (k Keeper) setSwapped(ctx sdk.Context, swapped types.Swapped) error {
store := ctx.KVStore(k.storeKey)
key := swappedKey(swapped.NewCoinAmount.Denom)
key := swappedKey(swapped.ToCoinAmount.Denom)
bz, err := k.cdc.Marshal(&swapped)
if err != nil {
return err
Expand Down Expand Up @@ -238,7 +238,7 @@ func (k Keeper) getSwappableNewCoinAmount(ctx sdk.Context) (sdk.Coin, error) {
return sdk.Coin{}, err
}

remainingAmount := swapCap.Sub(swapped.GetNewCoinAmount().Amount)
remainingAmount := swapCap.Sub(swapped.GetToCoinAmount().Amount)
return sdk.NewCoin(denom, remainingAmount), nil
}

Expand Down Expand Up @@ -304,8 +304,8 @@ func (k Keeper) updateSwapped(ctx sdk.Context, oldAmount, newAmount sdk.Coin) er
return err
}
updatedSwapped := &types.Swapped{
OldCoinAmount: oldAmount.Add(prevSwapped.OldCoinAmount),
NewCoinAmount: newAmount.Add(prevSwapped.NewCoinAmount),
FromCoinAmount: oldAmount.Add(prevSwapped.FromCoinAmount),
ToCoinAmount: newAmount.Add(prevSwapped.ToCoinAmount),
}

store := ctx.KVStore(k.storeKey)
Expand All @@ -328,7 +328,7 @@ func (k Keeper) checkSwapCap(ctx sdk.Context, newCoinAmount sdk.Coin) error {
return err
}

if swapCap.LT(swapped.NewCoinAmount.Add(newCoinAmount).Amount) {
if swapCap.LT(swapped.ToCoinAmount.Add(newCoinAmount).Amount) {
return fmt.Errorf("cann't swap more because of swapCap limit, amount=%s", newCoinAmount.String())
}

Expand Down
Loading

0 comments on commit 547c5d6

Please sign in to comment.