Skip to content

Commit

Permalink
merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mj850 committed Nov 12, 2024
2 parents b1beadf + b6ed1a7 commit c1388bf
Show file tree
Hide file tree
Showing 14 changed files with 1,537 additions and 210 deletions.
17 changes: 17 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import (
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/utils/metrics"
"github.com/sei-protocol/sei-chain/wasmbinding"
ctmodule "github.com/sei-protocol/sei-chain/x/confidentialtransfers"
ctkeeper "github.com/sei-protocol/sei-chain/x/confidentialtransfers/keeper"
cttypes "github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
epochmodule "github.com/sei-protocol/sei-chain/x/epoch"
Expand Down Expand Up @@ -209,6 +210,7 @@ var (
wasm.AppModuleBasic{},
epochmodule.AppModuleBasic{},
tokenfactorymodule.AppModuleBasic{},
ctmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand All @@ -226,9 +228,13 @@ var (
wasm.ModuleName: {authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
<<<<<<< HEAD

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

expected operand, found '<<' (typecheck)

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (13)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (10)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (19)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected <<, expected expression

Check failure on line 231 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected <<, expected expression
// Confidential Transfers module is not live yet, but we add the permissions for testing
cttypes.ModuleName: nil,

=======
cttypes.ModuleName: {},
>>>>>>> feature/ct_types

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (13)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (10)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (19)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected >>, expected expression

Check failure on line 237 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected >>, expected expression
// this line is used by starport scaffolding # stargate/app/maccPerms
}

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or ) (typecheck)

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (14)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (13)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (17)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (11)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (16)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (05)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (07)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (06)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (10)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (15)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (08)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (19)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 239 in app/app.go

View workflow job for this annotation

GitHub Actions / tests (12)

syntax error: unexpected } in grouped declaration; possibly missing semicolon or newline or )

Expand Down Expand Up @@ -558,6 +564,12 @@ func New(
tokenFactoryConfig,
)

app.ConfidentialTransfersKeeper = ctkeeper.NewKeeper(
appCodec,
app.keys[(cttypes.StoreKey)],
app.GetSubspace(cttypes.ModuleName),
app.AccountKeeper)

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "iterator,staking,stargate,sei"
Expand Down Expand Up @@ -760,6 +772,7 @@ func New(
epochModule,
tokenfactorymodule.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ctmodule.NewAppModule(app.ConfidentialTransfersKeeper),
// this line is used by starport scaffolding # stargate/app/appModule
)

Expand Down Expand Up @@ -791,6 +804,7 @@ func New(
evmtypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
cttypes.ModuleName,
acltypes.ModuleName,
)

Expand Down Expand Up @@ -822,6 +836,7 @@ func New(
evmtypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
cttypes.ModuleName,
acltypes.ModuleName,
)

Expand Down Expand Up @@ -851,6 +866,7 @@ func New(
feegrant.ModuleName,
oracletypes.ModuleName,
tokenfactorytypes.ModuleName,
cttypes.ModuleName,
epochmoduletypes.ModuleName,
wasm.ModuleName,
evmtypes.ModuleName,
Expand Down Expand Up @@ -882,6 +898,7 @@ func New(
transferModule,
epochModule,
tokenfactorymodule.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
ctmodule.NewAppModule(app.ConfidentialTransfersKeeper),
// this line is used by starport scaffolding # stargate/app/appModule
)
app.sm.RegisterStoreDecoders()
Expand Down
5 changes: 5 additions & 0 deletions proto/confidentialtransfers/confidential.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ message CtAccount {
uint32 pending_balance_credit_counter = 4;
Ciphertext available_balance = 5; // elgamal encoded balance
string decryptable_available_balance = 6; // aes encoded balance
}

message CtAccountWithDenom {
string denom = 1;
CtAccount account = 2 [(gogoproto.nullable) = false];
}
42 changes: 32 additions & 10 deletions proto/confidentialtransfers/query.proto
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
syntax = "proto3";
package seiprotocol.seichain.confidentialtransfers;

import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "confidentialtransfers/confidential.proto";

option go_package = "github.com/sei-protocol/sei-chain/x/confidentialtransfers/types";

// TODO: Define any query messages here
// Query defines the gRPC querier service.
service Query {
// TODO: This is a mock method. Remove when we add real queries
rpc TestQuery (TestQueryRequest) returns (TestQueryResponse) {
rpc GetCtAccount (GetCtAccountRequest) returns (GetCtAccountResponse) {
option (google.api.http) = {
get: "/seichain/confidentialtransfers/test_query"
get: "/seichain/confidentialtransfers/account/{address}/{denom}"
};
}

rpc GetAllCtAccounts (GetAllCtAccountsRequest) returns (GetAllCtAccountsResponse) {
option (google.api.http) = {
get: "/seichain/confidentialtransfers/account/{address}"
};
}
}

message GetCtAccountRequest {
string address = 1;
string denom = 2;
}

// TODO: This is a mock method. Remove when we add real queries
message TestQueryRequest {
string test_field = 1;
message GetCtAccountResponse {
CtAccount account = 1;
}

// TODO: This is a mock method. Remove when we add real queries
message TestQueryResponse {
string test_field = 1;
message GetAllCtAccountsRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string address = 1;

// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}

message GetAllCtAccountsResponse {
repeated CtAccountWithDenom accounts = 1 [(gogoproto.nullable) = false];

// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}
12 changes: 5 additions & 7 deletions x/confidentialtransfers/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"

"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/cosmos/cosmos-sdk/types/query"
)

func (k BaseKeeper) InitGenesis(ctx sdk.Context, gs *types.GenesisState) {
moduleAcc := authtypes.NewEmptyModuleAccount(types.ModuleName)
k.accountKeeper.SetModuleAccount(ctx, moduleAcc)
k.SetParams(ctx, gs.Params)
store := k.getAccountStore(ctx)
for i := range gs.Accounts {
genesisCtAccount := gs.Accounts[i]
store := ctx.KVStore(k.storeKey)

bz := k.cdc.MustMarshal(&genesisCtAccount.Account) // Marshal the Account object into bytes
store.Set(genesisCtAccount.Key, bz)
}
Expand All @@ -34,11 +33,10 @@ func (k BaseKeeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
}

func (k BaseKeeper) GetPaginatedAccounts(ctx sdk.Context, pagination *query.PageRequest) ([]types.GenesisCtAccount, *query.PageResponse, error) {
store := ctx.KVStore(k.storeKey)
supplyStore := prefix.NewStore(store, types.AccountsKey)
store := k.getAccountStore(ctx)

genesisAccounts := make([]types.GenesisCtAccount, 0)
pageRes, err := query.Paginate(supplyStore, pagination, func(key, value []byte) error {
pageRes, err := query.Paginate(store, pagination, func(key, value []byte) error {
var ctAccount types.CtAccount
err := ctAccount.Unmarshal(value)
if err != nil {
Expand Down
65 changes: 65 additions & 0 deletions x/confidentialtransfers/keeper/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package keeper_test

import (
"crypto/ecdsa"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
"github.com/sei-protocol/sei-cryptography/pkg/encryption"
"github.com/sei-protocol/sei-cryptography/pkg/encryption/elgamal"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

Expand All @@ -16,3 +21,63 @@ func (suite *KeeperTestSuite) TestDefaultGenesisState() {
suite.Require().NotNil(exportedGenesis)
suite.Require().Equal(genesisState, exportedGenesis)
}

func (suite *KeeperTestSuite) TestGenesisExportImportState() {
pk1, _ := encryption.GenerateKey()
pk2, _ := encryption.GenerateKey()
addr1 := sdk.AccAddress("addr1")
addr2 := sdk.AccAddress("addr2")
testDenom1 := fmt.Sprintf("factory/%s/TEST1", addr1.String())
testDenom2 := fmt.Sprintf("factory/%s/TEST2", addr2.String())

ctAcc1 := generateCtAccount(pk1, testDenom1, 1000)
ctAcc2 := generateCtAccount(pk2, testDenom2, 2000)

accounts := []types.GenesisCtAccount{
{
Key: []byte(addr1.String() + testDenom1),
Account: ctAcc1,
},
{
Key: []byte(addr2.String() + testDenom2),
Account: ctAcc2,
},
}
genesisState := types.NewGenesisState(types.DefaultParams(), accounts)
app := suite.App
suite.Ctx = app.BaseApp.NewContext(false, tmproto.Header{})

suite.App.ConfidentialTransfersKeeper.InitGenesis(suite.Ctx, genesisState)

exportedGenesis := suite.App.ConfidentialTransfersKeeper.ExportGenesis(suite.Ctx)
suite.Require().NotNil(exportedGenesis)
suite.Require().Equal(genesisState, exportedGenesis)
}

func generateCtAccount(pk *ecdsa.PrivateKey, testDenom string, balance uint64) types.CtAccount {
eg := elgamal.NewTwistedElgamal()
keyPair, _ := eg.KeyGen(*pk, testDenom)

aesPK1, _ := encryption.GetAESKey(*pk, testDenom)

amountLo := uint64(100)
amountHi := uint64(0)

decryptableBalance, _ := encryption.EncryptAESGCM(balance, aesPK1)

ciphertextLo, _, _ := eg.Encrypt(keyPair.PublicKey, amountLo)
ciphertextHi, _, _ := eg.Encrypt(keyPair.PublicKey, amountHi)

zeroCiphertextAvailable, _, _ := eg.Encrypt(keyPair.PublicKey, amountLo)

account := &types.Account{
PublicKey: keyPair.PublicKey,
PendingBalanceLo: ciphertextLo,
PendingBalanceHi: ciphertextHi,
PendingBalanceCreditCounter: 1,
AvailableBalance: zeroCiphertextAvailable,
DecryptableAvailableBalance: decryptableBalance,
}

return *types.NewCtAccount(account)
}
80 changes: 80 additions & 0 deletions x/confidentialtransfers/keeper/grpc_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package keeper

import (
"context"

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

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var _ types.QueryServer = BaseKeeper{}

func (k BaseKeeper) GetCtAccount(ctx context.Context, req *types.GetCtAccountRequest) (*types.GetCtAccountResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if req.Address == "" {
return nil, status.Error(codes.InvalidArgument, "address cannot be empty")
}

address, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
}

if req.Denom == "" {
return nil, status.Error(codes.InvalidArgument, "invalid denom")
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

ctAccount, found := k.getCtAccount(sdkCtx, address, req.Denom)
if !found {
return nil, status.Errorf(codes.NotFound, "account not found for account %s and denom %s",
req.Address, req.Denom)
}

return &types.GetCtAccountResponse{Account: &ctAccount}, nil
}

func (k BaseKeeper) GetAllCtAccounts(ctx context.Context, req *types.GetAllCtAccountsRequest) (*types.GetAllCtAccountsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if req.Address == "" {
return nil, status.Error(codes.InvalidArgument, "address cannot be empty")
}

address, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error())
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

store := k.getAccountStoreForAddress(sdkCtx, address)
accounts := make([]types.CtAccountWithDenom, 0)
pageRes, err := query.Paginate(store, req.Pagination, func(denom, value []byte) error {

var ctAccount types.CtAccount
err = k.cdc.Unmarshal(value, &ctAccount)
if err != nil {
return err
}
accounts = append(accounts, types.CtAccountWithDenom{Denom: string(denom), Account: ctAccount})
return nil
})

if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "paginate: %v", err)
}

return &types.GetAllCtAccountsResponse{Accounts: accounts, Pagination: pageRes}, nil

}
Loading

0 comments on commit c1388bf

Please sign in to comment.