Additional bond commands (#4)

* Add commands to get bonds by id and owner

* Add commands to get bond module params and balances

* Add commands to refill, withdraw and cancel bond

* Add implementations for bond tx commands

* Use indexed map to implement command for getting bond by owner

* Use collections for bond module params

* Clean up
This commit is contained in:
prathamesh0
2024-02-08 18:53:20 +05:30
committed by GitHub
parent e511051f3e
commit 4da8dd8d7b
22 changed files with 11740 additions and 262 deletions
-2
View File
@@ -10,6 +10,4 @@ message Module {
option (cosmos.app.v1alpha1.module) = {
go_import : "git.vdb.to/cerc-io/laconic2d/x/bond"
};
// TODO: Setup any config required
}
+68 -2
View File
@@ -8,15 +8,45 @@ import "gogoproto/gogo.proto";
import "cerc/bond/v1/bond.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "cosmos/base/v1beta1/coin.proto";
// import "cosmos/query/v1/query.proto";
// Query defines the gRPC querier service for bond module
service Query {
// Bonds queries bonds list.
// Params queries bonds module params.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cerc/bond/v1/params";
}
// Bonds queries bonds list
rpc Bonds(QueryGetBondsRequest) returns (QueryGetBondsResponse) {
// option (cosmos.query.v1.module_query_safe) = true; // Add?
// Mark query as module_query_safe?
// option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cerc/bond/v1/bonds";
}
// GetBondById
rpc GetBondById(QueryGetBondByIdRequest) returns (QueryGetBondByIdResponse) {
option (google.api.http).get = "/cerc/bond/v1/bonds/{id}";
}
// Get Bonds list by Owner
rpc GetBondsByOwner(QueryGetBondsByOwnerRequest) returns (QueryGetBondsByOwnerResponse) {
option (google.api.http).get = "/cerc/bond/v1/by-owner/{owner}";
}
// Get Bond module balance
rpc GetBondsModuleBalance(QueryGetBondModuleBalanceRequest) returns (QueryGetBondModuleBalanceResponse) {
option (google.api.http).get = "/cerc/bond/v1/balance";
}
}
// QueryParamsRequest is request for query the bond module params
message QueryParamsRequest {}
// QueryParamsResponse returns response type of bond module params
message QueryParamsResponse {
Params params = 1 [(gogoproto.moretags) = "json:\"params\" yaml:\"params\""];
}
// QueryGetBondById queries a bonds.
@@ -33,3 +63,39 @@ message QueryGetBondsResponse {
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondById
message QueryGetBondByIdRequest {
string id = 1 [(gogoproto.moretags) = "json:\"id\" yaml:\"id\""];
}
// QueryGetBondByIdResponse returns QueryGetBondById query response
message QueryGetBondByIdResponse {
Bond bond = 1 [(gogoproto.moretags) = "json:\"bond\" yaml:\"bond\""];
}
// QueryGetBondsByOwnerRequest is request type for Query/GetBondsByOwner RPC Method
message QueryGetBondsByOwnerRequest {
string owner = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondsByOwnerResponse is response type for Query/GetBondsByOwner RPC Method
message QueryGetBondsByOwnerResponse {
repeated Bond bonds = 1 [(gogoproto.nullable) = false, (gogoproto.moretags) = "json:\"bonds\" yaml:\"bonds\""];
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
// QueryGetBondModuleBalanceRequest is request type for bond module balance rpc method
message QueryGetBondModuleBalanceRequest {}
// QueryGetBondModuleBalanceResponse is the response type for bond module balance rpc method
message QueryGetBondModuleBalanceResponse {
repeated cosmos.base.v1beta1.Coin balance = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}
+57 -2
View File
@@ -9,8 +9,6 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
// TODO: Add remaining messages
// Msg defines the bond Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
@@ -20,6 +18,20 @@ service Msg {
option (google.api.http).post = "/cerc/bond/v1/create_bond";
};
// RefillBond defines a method for refilling amount for bond.
rpc RefillBond(MsgRefillBond) returns (MsgRefillBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/refill_bond";
};
// WithdrawBond defines a method for withdrawing amount from bond.
rpc WithdrawBond(MsgWithdrawBond) returns (MsgWithdrawBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/withdraw_bond";
};
// CancelBond defines a method for cancelling a bond.
rpc CancelBond(MsgCancelBond) returns (MsgCancelBondResponse) {
option (google.api.http).post = "/cerc/bond/v1/cancel_bond";
};
}
// MsgCreateBond defines a SDK message for creating a new bond.
@@ -38,3 +50,46 @@ message MsgCreateBond {
message MsgCreateBondResponse {
string id = 1;
}
// MsgRefillBond defines a SDK message for refill the amount for bond.
message MsgRefillBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
repeated cosmos.base.v1beta1.Coin coins = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}
// MsgRefillBondResponse defines the Msg/RefillBond response type.
message MsgRefillBondResponse {}
// MsgWithdrawBond defines a SDK message for withdrawing amount from bond.
message MsgWithdrawBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
repeated cosmos.base.v1beta1.Coin coins = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "json:\"coins\" yaml:\"coins\""
];
}
// MsgWithdrawBondResponse defines the Msg/WithdrawBond response type.
message MsgWithdrawBondResponse {}
// MsgCancelBond defines a SDK message for the cancel the bond.
message MsgCancelBond {
option (cosmos.msg.v1.signer) = "signer";
string id = 1;
string signer = 2;
}
// MsgCancelBondResponse defines the Msg/CancelBond response type.
message MsgCancelBondResponse {}