-
Notifications
You must be signed in to change notification settings - Fork 815
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 confidential transfer queries to seid #1931
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
977e0a6
update codec
mj850 e9897b5
cleanup and queryies
mj850 51ec944
enable in module
mj850 586e7d7
add other query
mj850 ec489c8
Merge branch 'feature/ct_types' into mj/ctMod3
mj850 27bdfea
fix bug
mj850 50fd8dc
fix lint
mj850 d405a5c
add decryption query
mj850 7e726d1
cleanup
mj850 e889bae
validate address
mj850 a306f8c
comments
mj850 8de9292
rectify test failures
mj850 22c0faa
speed up withdraw test
mj850 6614143
make other tests slightly faster
mj850 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
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" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// GetQueryCmd returns the cli query commands for the minting module. | ||
func GetQueryCmd() *cobra.Command { | ||
confidentialTransfersQueryCmd := &cobra.Command{ | ||
Use: types.ModuleName, | ||
Short: "Querying commands for the confidential transfer module", | ||
DisableFlagParsing: true, | ||
SuggestionsMinimumDistance: 2, | ||
RunE: client.ValidateCmd, | ||
} | ||
|
||
confidentialTransfersQueryCmd.AddCommand( | ||
GetCmdQueryAccount(), | ||
GetCmdQueryAllAccount(), | ||
) | ||
|
||
return confidentialTransfersQueryCmd | ||
} | ||
|
||
// GetCmdQueryAccount implements a command to return an account asssociated with the address and denom | ||
func GetCmdQueryAccount() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "account [denom] [address] [flags]", | ||
Short: "Query the account state", | ||
Long: "Queries the account state associated with the address and denom." + | ||
"Pass the --from flag to decrypt the account." + | ||
"Pass the --decryptAvailableBalance flag to attempt to decrypt the available balance.", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think we were moving those functions to separate methods in tx. Might make our code consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to separate functions for both |
||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
denom := args[0] | ||
mj850 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
address := args[1] | ||
// Validate address | ||
_, err = sdk.AccAddressFromBech32(address) | ||
if err != nil { | ||
return fmt.Errorf("invalid address: %v", err) | ||
} | ||
|
||
from, err := cmd.Flags().GetString(flags.FlagFrom) | ||
dssei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
fromAddr, _, _, err := client.GetFromFields(clientCtx, clientCtx.Keyring, from) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, err := queryClient.GetCtAccount(cmd.Context(), &types.GetCtAccountRequest{ | ||
|
||
Address: address, | ||
mj850 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Denom: denom, | ||
}) | ||
|
||
if fromAddr.String() == args[0] { | ||
account, err := res.Account.FromProto() | ||
if err != nil { | ||
return err | ||
} | ||
privateKey, err := getPrivateKey(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
aesKey, err := encryption.GetAESKey(*privateKey, denom) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
decryptor := elgamal.NewTwistedElgamal() | ||
keyPair, err := decryptor.KeyGen(*privateKey, denom) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
decryptAvailableBalance, err := cmd.Flags().GetBool("decryptAvailableBalance") | ||
mj850 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
decryptedAccount, err := account.Decrypt(decryptor, keyPair, aesKey, decryptAvailableBalance) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(decryptedAccount) | ||
|
||
} else { | ||
return clientCtx.PrintProto(res.Account) | ||
} | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
cmd.Flags().String(flags.FlagFrom, "", "Name or address of private key to decrypt the account") | ||
cmd.Flags().Bool("decryptAvailableBalance", false, "Set this to attempt to decrypt the available balance") | ||
return cmd | ||
} | ||
|
||
// GetCmdQueryAccount implements a command to return an account asssociated with the address and denom | ||
func GetCmdQueryAllAccount() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "accounts [address]", | ||
Short: "Query all the confidential token accounts associated with the address", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
address := args[0] | ||
// Validate address | ||
_, err = sdk.AccAddressFromBech32(address) | ||
if err != nil { | ||
return fmt.Errorf("invalid address: %v", err) | ||
} | ||
|
||
res, err := queryClient.GetAllCtAccounts(cmd.Context(), &types.GetAllCtAccountsRequest{ | ||
Address: args[0], | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for i := range res.Accounts { | ||
clientCtx.PrintString("\n") | ||
err = clientCtx.PrintProto(&res.Accounts[i]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually multi word flags I think are concatenated with
-
e.g.--decrypt-available-balance
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to --decrypt-available-balance