Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add msg_server methods #1923

Merged
merged 24 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ var (
wasm.ModuleName: {authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
// TODO: Add confidential transfers module here when we enable it
// confidentialtransferstypes.ModuleName: nil,

// this line is used by starport scaffolding # stargate/app/maccPerms
}

Expand Down
18 changes: 10 additions & 8 deletions proto/confidentialtransfers/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ service Msg {
rpc Transfer(MsgTransfer) returns (MsgTransferResponse);

// InitializeAccount defines a method for creating a new confidential transfers account for some denom.
rpc InitializeAccount(MsgInitializeAccount) returns (MsgInitializeAccount);
rpc InitializeAccount(MsgInitializeAccount) returns (MsgInitializeAccountResponse);

// Deposit defines a method for depositing funds into a confidential transfers account.
rpc Deposit(MsgDeposit) returns (MsgDeposit);
rpc Deposit(MsgDeposit) returns (MsgDepositResponse);

// Withdraw defines a method for withdrawing funds from a confidential transfers account.
rpc Withdraw(MsgWithdraw) returns (MsgWithdraw);
rpc Withdraw(MsgWithdraw) returns (MsgWithdrawResponse);

// ApplyPendingBalance defines a method for applying pending balance to an account.
rpc ApplyPendingBalance(MsgApplyPendingBalance) returns (MsgApplyPendingBalanceResponse);

// CloseAccount defines a method for closing an account.
rpc CloseAccount(MsgCloseAccount) returns (MsgCloseAccountResponse);

}

// MsgTransfer represents a message to send coins from one account to another.
Expand Down Expand Up @@ -70,7 +69,10 @@ message MsgInitializeAccount {
string denom = 2 [(gogoproto.moretags) = "yaml:\"denom\""];
bytes public_key = 3 [(gogoproto.moretags) = "yaml:\"public_key\""];
string decryptable_balance = 4 [(gogoproto.moretags) = "yaml:\"decryptable_balance\""];
InitializeAccountMsgProofs proofs = 5 [(gogoproto.moretags) = "yaml:\"proofs\""];
Ciphertext pending_balance_lo = 5 [(gogoproto.moretags) = "yaml:\"pending_balance_lo\""];
Ciphertext pending_balance_hi = 6 [(gogoproto.moretags) = "yaml:\"pending_balance_hi\""];
Ciphertext available_balance = 7 [(gogoproto.moretags) = "yaml:\"available_balance\""];
InitializeAccountMsgProofs proofs = 8 [(gogoproto.moretags) = "yaml:\"proofs\""];
}

// MsgInitializeAccountResponse defines the Msg/Send response type.
Expand Down Expand Up @@ -110,9 +112,9 @@ message MsgApplyPendingBalance {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string address = 1;
string denom = 2;
string new_decryptable_available_balance = 3;
string address = 1 [(gogoproto.moretags) = "yaml:\"address\""];
string denom = 2 [(gogoproto.moretags) = "yaml:\"denom\""];
string new_decryptable_available_balance = 3 [(gogoproto.moretags) = "yaml:\"new_decryptable_available_balance\""];
}

message MsgApplyPendingBalanceResponse {}
Expand Down
3 changes: 3 additions & 0 deletions proto/confidentialtransfers/zk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ message TransferMsgProofs {

message InitializeAccountMsgProofs {
PubkeyValidityProof pubkey_validity_proof = 1;
ZeroBalanceProof zero_pending_balance_lo_proof = 2;
ZeroBalanceProof zero_pending_balance_hi_proof = 3;
ZeroBalanceProof zero_available_balance_proof = 4;
}

message WithdrawMsgProofs {
Expand Down
14 changes: 14 additions & 0 deletions x/confidentialtransfers/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
)

func (k *Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) {
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName)
k.accountKeeper.SetModuleAccount(ctx, moduleAcc)

// TODO: Fill in more genesis stuff here
}
35 changes: 26 additions & 9 deletions x/confidentialtransfers/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
import (
"bytes"
"context"
"fmt"

Check failure on line 6 in x/confidentialtransfers/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"github.com/cosmos/cosmos-sdk/store/prefix"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"

"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

// TODO: This is just scaffolding. To be implemented.
Expand All @@ -22,8 +21,8 @@

cdc codec.Codec

// TODO: Add any required keepers here
// accountKeeper types.AccountKeeper
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
}
)

Expand All @@ -36,11 +35,14 @@
func NewKeeper(
codec codec.Codec,
storeKey sdk.StoreKey,
paramSpace paramtypes.Subspace,
ak types.AccountKeeper,
bk types.BankKeeper,
) Keeper {
return Keeper{
cdc: codec,
storeKey: storeKey,
cdc: codec,
storeKey: storeKey,
accountKeeper: ak,
bankKeeper: bk,
}
}

Expand All @@ -61,14 +63,20 @@
return *account, true
}

func (k Keeper) SetAccount(ctx sdk.Context, address sdk.AccAddress, denom string, account types.Account) {
func (k Keeper) SetAccount(ctx sdk.Context, address sdk.AccAddress, denom string, account *types.Account) {
store := ctx.KVStore(k.storeKey)
key := types.GetAccountKey(address, denom)
ctAccount := account.ToProto()
ctAccount := types.NewCtAccount(account)
bz := k.cdc.MustMarshal(ctAccount) // Marshal the Account object into bytes
store.Set(key, bz) // Store the serialized account under the key
}

func (k Keeper) DeleteAccount(ctx sdk.Context, address sdk.AccAddress, denom string) {
store := ctx.KVStore(k.storeKey)
key := types.GetAccountKey(address, denom)
store.Delete(key) // Store the serialized account under the key
}

// Logger returns a logger for the x/confidentialtransfers module
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName))
Expand Down Expand Up @@ -103,3 +111,12 @@

return accounts, nil
}

// CreateModuleAccount creates the module account for confidentialtransfers
func (k Keeper) CreateModuleAccount(ctx sdk.Context) {
account := k.accountKeeper.GetModuleAccount(ctx, types.ModuleName)
if account == nil {
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName)
k.accountKeeper.SetModuleAccount(ctx, moduleAcc)
}
}
Loading
Loading