-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feat(bank/v2): port tokenfactory into bank/v2 #22264
Changes from 11 commits
f7c5def
a7c45d4
e3794b2
1ed5ce2
78fa7d0
d2fc65f
dbdae75
638b1a0
edfcd67
b20efbe
007d595
d95d5fb
0d1ceaf
13878ff
498208a
767299a
4ec773c
9ae0291
3d937ca
0bfe528
73eaed3
67489ff
f7c130c
b295e39
3c33c55
f391ffe
03b0438
23a2703
3d8967e
a325394
081f723
737463c
a18b33d
1ce441e
880b20a
7b2bbcb
ede3f22
989643f
710a95a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
package cosmos.bank.v2; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "cosmos/base/v1beta1/coin.proto"; | ||
Comment on lines
+1
to
+5
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. 💡 Codebase verification Import The import 🔗 Analysis chainVerify the The import of Run the following script to check for the presence of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for the presence of gogoproto in the project
# Test 1: Search for gogoproto in go.mod
echo "Searching for gogoproto in go.mod:"
rg 'github.com/gogo/protobuf' go.mod
# Test 2: Search for other imports of gogoproto
echo "Searching for other imports of gogoproto:"
rg --type proto 'import "gogoproto/gogo.proto"'
# Test 3: Check if protoc-gen-gogo is installed
echo "Checking if protoc-gen-gogo is installed:"
which protoc-gen-gogo || echo "protoc-gen-gogo not found in PATH"
Length of output: 601 Script: #!/bin/bash
# Description: Verify the existence of gogoproto/gogo.proto in the repository
echo "Searching for gogoproto/gogo.proto in the repository:"
fd 'gogoproto/gogo.proto' . --case-sensitive
Length of output: 161 🧰 Tools🪛 buf
|
||
|
||
option go_package = "cosmossdk.io/x/bank/v2/types"; | ||
|
||
// DenomAuthorityMetadata specifies metadata for addresses that have specific | ||
// capabilities over a token factory denom. Right now there is only one Admin | ||
// permission, but is planned to be extended to the future. | ||
message DenomAuthorityMetadata { | ||
option (gogoproto.equal) = true; | ||
|
||
// Can be empty for no admin, or a valid osmosis address | ||
string admin = 1 [(gogoproto.moretags) = "yaml:\"admin\""]; | ||
} | ||
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. 🛠️ Refactor suggestion Consider adding a validation rule for the admin address The Example: string admin = 1 [
(gogoproto.moretags) = "yaml:\"admin\"",
(validate.rules).string = {
pattern: "^$|^osmo[a-zA-Z0-9]{39}$"
}
]; This regex pattern allows either an empty string or a valid osmosis address. Would you like me to provide more information on implementing this validation? |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,65 @@ | ||||||||||||||||||||
syntax = "proto3"; | ||||||||||||||||||||
package cosmos.bank.v2; | ||||||||||||||||||||
|
||||||||||||||||||||
import "gogoproto/gogo.proto"; | ||||||||||||||||||||
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. Fix missing import: "gogoproto/gogo.proto" The imported file 🧰 Tools🪛 buf
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. Fix the import path for 'gogoproto/gogo.proto' The import statement at line 4 refers to a file that does not exist, as indicated by the static analysis tool. Please verify that the import path is correct and that all necessary dependencies are included. 🧰 Tools🪛 buf
|
||||||||||||||||||||
import "cosmos_proto/cosmos.proto"; | ||||||||||||||||||||
import "cosmos/base/v1beta1/coin.proto"; | ||||||||||||||||||||
|
||||||||||||||||||||
option go_package = "cosmossdk.io/x/bank/v2/types"; | ||||||||||||||||||||
|
||||||||||||||||||||
// Params defines the parameters for the bank/v2 module. | ||||||||||||||||||||
message Params {} | ||||||||||||||||||||
message Params { | ||||||||||||||||||||
// DenomCreationFee defines the fee to be charged on the creation of a new | ||||||||||||||||||||
// denom. The fee is drawn from the MsgCreateDenom's sender account, and | ||||||||||||||||||||
// transferred to the community pool. | ||||||||||||||||||||
repeated cosmos.base.v1beta1.Coin denom_creation_fee = 1 [ | ||||||||||||||||||||
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", | ||||||||||||||||||||
(gogoproto.moretags) = "yaml:\"denom_creation_fee\"", | ||||||||||||||||||||
(gogoproto.nullable) = false | ||||||||||||||||||||
Comment on lines
+15
to
+19
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. Review the use of 'nullable' option with repeated fields In the Apply the following diff to remove the unnecessary repeated cosmos.base.v1beta1.Coin denom_creation_fee = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.moretags) = "yaml:\"denom_creation_fee\"",
- (gogoproto.nullable) = false
]; 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
]; | ||||||||||||||||||||
|
||||||||||||||||||||
// DenomCreationGasConsume defines the gas cost for creating a new denom. | ||||||||||||||||||||
// This is intended as a spam deterrence mechanism. | ||||||||||||||||||||
// | ||||||||||||||||||||
// See: https://github.com/CosmWasm/token-factory/issues/11 | ||||||||||||||||||||
uint64 denom_creation_gas_consume = 2 | ||||||||||||||||||||
[(gogoproto.moretags) = "yaml:\"denom_creation_gas_consume\"", (gogoproto.nullable) = true]; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// DenomUnit represents a struct that describes a given | ||||||||||||||||||||
// denomination unit of the basic token. | ||||||||||||||||||||
message DenomUnit { | ||||||||||||||||||||
// denom represents the string name of the given denom unit (e.g uatom). | ||||||||||||||||||||
string denom = 1; | ||||||||||||||||||||
// exponent represents power of 10 exponent that one must | ||||||||||||||||||||
// raise the base_denom to in order to equal the given DenomUnit's denom | ||||||||||||||||||||
// 1 denom = 10^exponent base_denom | ||||||||||||||||||||
// (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with | ||||||||||||||||||||
// exponent = 6, thus: 1 atom = 10^6 uatom). | ||||||||||||||||||||
uint32 exponent = 2; | ||||||||||||||||||||
// aliases is a list of string aliases for the given denom | ||||||||||||||||||||
repeated string aliases = 3; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// Metadata represents a struct that describes | ||||||||||||||||||||
// a basic token. | ||||||||||||||||||||
message Metadata { | ||||||||||||||||||||
string description = 1; | ||||||||||||||||||||
// denom_units represents the list of DenomUnit's for a given coin | ||||||||||||||||||||
repeated DenomUnit denom_units = 2; | ||||||||||||||||||||
// base represents the base denom (should be the DenomUnit with exponent = 0). | ||||||||||||||||||||
string base = 3; | ||||||||||||||||||||
// display indicates the suggested denom that should be | ||||||||||||||||||||
// displayed in clients. | ||||||||||||||||||||
string display = 4; | ||||||||||||||||||||
// name defines the name of the token (eg: Cosmos Atom) | ||||||||||||||||||||
string name = 5 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.43"]; | ||||||||||||||||||||
// symbol is the token symbol usually shown on exchanges (eg: ATOM). This can | ||||||||||||||||||||
// be the same as the display. | ||||||||||||||||||||
string symbol = 6 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.43"]; | ||||||||||||||||||||
// URI to a document (on or off-chain) that contains additional information. Optional. | ||||||||||||||||||||
string uri = 7 [(gogoproto.customname) = "URI", (cosmos_proto.field_added_in) = "cosmos-sdk 0.46"]; | ||||||||||||||||||||
// URIHash is a sha256 hash of a document pointed by URI. It's used to verify that | ||||||||||||||||||||
// the document didn't change. Optional. | ||||||||||||||||||||
string uri_hash = 8 [(gogoproto.customname) = "URIHash", (cosmos_proto.field_added_in) = "cosmos-sdk 0.46"]; | ||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -44,6 +44,33 @@ message MsgSend { | |||||||||||||||||||||||||||||||||||||||||||||||||
// MsgSendResponse defines the response structure for executing a MsgSend message. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgSendResponse {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// MsgCreateDenom represents a message to create new denom. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgCreateDenom { | ||||||||||||||||||||||||||||||||||||||||||||||||||
option (cosmos.msg.v1.signer) = "sender"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
option (amino.name) = "cosmos-sdk/x/bank/v2/MsgCreateDenom"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
string subdenom = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+54
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. Add validation rules for the subdenom field To prevent malicious denom creation and ensure consistency, consider adding validation rules for the Apply this addition to the subdenom field: - string subdenom = 2;
+ string subdenom = 2 [(gogoproto.moretags) = "validate:\"subdenom\""]; This will enforce the standard Cosmos SDK denomination format rules.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// MsgCreateDenomResponse defines the response structure for executing a MsgCreateDenom message. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgCreateDenomResponse { | ||||||||||||||||||||||||||||||||||||||||||||||||||
string new_token_denom = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
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. 🛠️ Refactor suggestion Add annotation to 'new_token_denom' field. Consider adding the 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. 🛠️ Refactor suggestion Provide a comment for the response field Please add a documentation comment for the |
||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// MsgChangeAdmin represents a message to change admin of denom. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgChangeAdmin { | ||||||||||||||||||||||||||||||||||||||||||||||||||
option (cosmos.msg.v1.signer) = "sender"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
option (amino.name) = "cosmos-sdk/x/bank/v2/MsgChangeAdmin"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
string denom = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+66
to
+67
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. 🛠️ Refactor suggestion Add validation annotation to the 'denom' field. To ensure proper validation and serialization of the |
||||||||||||||||||||||||||||||||||||||||||||||||||
string new_admin = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+66
to
+69
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. 🛠️ Refactor suggestion Document the fields in For better code documentation and consistency, consider adding comments explaining the
Comment on lines
+61
to
+69
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. Add validation and event documentation Two improvements needed:
Apply these changes: // MsgChangeAdmin represents a message to change admin of denom.
+// Events emitted:
+// - EventType: "change_admin"
+// Attributes:
+// - "denom": the denomination being modified
+// - "old_admin": the previous admin address
+// - "new_admin": the new admin address
message MsgChangeAdmin {
option (cosmos.msg.v1.signer) = "sender";
option (amino.name) = "cosmos-sdk/x/bank/v2/MsgChangeAdmin";
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
- string denom = 2;
+ string denom = 2 [(cosmos_proto.scalar) = "cosmos.DenomString"];
string new_admin = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// MsgChangeAdminResponse defines the response structure for executing a MsgChangeAdmin message. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgChangeAdminResponse {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// MsgMint is the Msg/Mint request type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
message MsgMint { | ||||||||||||||||||||||||||||||||||||||||||||||||||
option (cosmos.msg.v1.signer) = "authority"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||||||||||||||||||||||||||||||||||||
package keeper | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
"cosmossdk.io/x/bank/v2/types" | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// GetAuthorityMetadata returns the authority metadata for a specific denom | ||||||||||||||||||||||||||||||||||||||
func (k Keeper) GetAuthorityMetadata(ctx context.Context, denom string) (types.DenomAuthorityMetadata, error) { | ||||||||||||||||||||||||||||||||||||||
authority, err := k.denomAuthority.Get(ctx, denom) | ||||||||||||||||||||||||||||||||||||||
return authority, err | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+10
to
+13
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. 🛠️ Refactor suggestion Use consistent variable naming for clarity In the Apply this diff to rename the variable: func (k Keeper) GetAuthorityMetadata(ctx context.Context, denom string) (types.DenomAuthorityMetadata, error) {
- authority, err := k.denomAuthority.Get(ctx, denom)
- return authority, err
+ metadata, err := k.denomAuthority.Get(ctx, denom)
+ return metadata, err
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
// setAuthorityMetadata stores authority metadata for a specific denom | ||||||||||||||||||||||||||||||||||||||
func (k Keeper) setAuthorityMetadata(ctx context.Context, denom string, metadata types.DenomAuthorityMetadata) error { | ||||||||||||||||||||||||||||||||||||||
err := metadata.Validate() | ||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
hieuvubk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return k.denomAuthority.Set(ctx, denom, metadata) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+15
to
+23
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. 🛠️ Refactor suggestion Improve error handling by wrapping validation errors In the Apply this diff to wrap the error: func (k Keeper) setAuthorityMetadata(ctx context.Context, denom string, metadata types.DenomAuthorityMetadata) error {
err := metadata.Validate()
if err != nil {
- return err
+ return fmt.Errorf("failed to validate metadata for denom %s: %w", denom, err)
}
return k.denomAuthority.Set(ctx, denom, metadata)
} Ensure you have imported the import (
"context"
+ "fmt"
"cosmossdk.io/x/bank/v2/types"
) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
func (k Keeper) setAdmin(ctx context.Context, denom, admin string) error { | ||||||||||||||||||||||||||||||||||||||
metadata, err := k.GetAuthorityMetadata(ctx, denom) | ||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
hieuvubk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
metadata.Admin = admin | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return k.setAuthorityMetadata(ctx, denom, metadata) | ||||||||||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,111 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
package keeper | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"cosmossdk.io/x/bank/v2/types" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"github.com/cosmos/cosmos-sdk/types/address" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// ConvertToBaseToken converts a fee amount in a whitelisted fee token to the base fee token amount | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Incorrect function comment for The comment on line 13 describes Apply this diff to correct the comment: -// ConvertToBaseToken converts a fee amount in a whitelisted fee token to the base fee token amount
+// CreateDenom handles the creation of a new denomination, including validation and fee charging. 📝 Committable suggestion
Suggested change
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. Update the function comment to match The comment at line 13 refers to Apply this diff to fix the comment: -// ConvertToBaseToken converts a fee amount in a whitelisted fee token to the base fee token amount
+// CreateDenom creates a new token denomination after validation and fee charges. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (k Keeper) CreateDenom(ctx context.Context, creatorAddr, subdenom string) (newTokenDenom string, err error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
denom, err := k.validateCreateDenom(ctx, creatorAddr, subdenom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "", err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.chargeForCreateDenom(ctx, creatorAddr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "", err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.createDenomAfterValidation(ctx, creatorAddr, denom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return denom, err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Runs CreateDenom logic after the charge and all denom validation has been handled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Made into a second function for genesis initialization. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (k Keeper) createDenomAfterValidation(ctx context.Context, creatorAddr, denom string) (err error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, exists := k.GetDenomMetaData(ctx, denom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !exists { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
denomMetaData := types.Metadata{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DenomUnits: []*types.DenomUnit{{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Denom: denom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exponent: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Base: denom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Name: denom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Symbol: denom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Display: denom, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Would it make sense to let the caller define other metadata as well? I understand that there must be a trade-off between supported functionality and fraud prevention. Some code comment would be helpful, when this is limited for some reason. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err := k.SetDenomMetaData(ctx, denomMetaData) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+49
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. Avoid shadowing the The declaration Apply this diff to fix the variable shadowing: - err := k.SetDenomMetaData(ctx, denomMetaData)
+ err = k.SetDenomMetaData(ctx, denomMetaData) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
authorityMetadata := types.DenomAuthorityMetadata{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Admin: creatorAddr, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.setAuthorityMetadata(ctx, denom, authorityMetadata) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: do we need map creator => denom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// k.addDenomFromCreator(ctx, creatorAddr, denom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Are you going to do this in this PR? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. 🛠️ Refactor suggestion Avoid unnecessary named return parameters In the Apply this diff to remove the named return parameter: -func (k Keeper) createDenomAfterValidation(ctx context.Context, creatorAddr, denom string) (err error) {
+func (k Keeper) createDenomAfterValidation(ctx context.Context, creatorAddr, denom string) error { Update the return statements accordingly: - return err
+ return err Note: Ensure all 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (k Keeper) validateCreateDenom(ctx context.Context, creatorAddr, subdenom string) (newTokenDenom string, err error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Temporary check until IBC bug is sorted out | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if k.HasSupply(ctx, subdenom) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "", fmt.Errorf("temporary error until IBC bug is sorted out, " + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"can't create subdenoms that are the same as a native denom") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+90
to
+92
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. Simplify and clarify the error message The error message includes phrases like "temporary error until IBC bug is sorted out," which may not be appropriate for end-users. Consider rephrasing the error message to be concise and user-friendly. Apply this diff to improve the error message: -return "", fmt.Errorf("temporary error until IBC bug is sorted out, " +
- "can't create subdenoms that are the same as a native denom")
+return "", fmt.Errorf("cannot create a subdenom that matches an existing native denomination") 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
denom, err := types.GetTokenDenom(creatorAddr, subdenom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "", err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_, found := k.GetDenomMetaData(ctx, denom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if found { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return "", types.ErrDenomExists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return denom, nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+87
to
+106
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. 🛠️ Refactor suggestion Avoid unnecessary named return parameters In the Apply this diff to simplify the function signature: -func (k Keeper) validateCreateDenom(ctx context.Context, creatorAddr, subdenom string) (newTokenDenom string, err error) {
+func (k Keeper) validateCreateDenom(ctx context.Context, creatorAddr, subdenom string) (string, error) { Ensure all return statements are updated accordingly to match the new signature. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
func (k Keeper) chargeForCreateDenom(ctx context.Context, creatorAddr string) (err error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params := k.GetParams(ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if DenomCreationFee is non-zero, transfer the tokens from the creator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// account to community pool | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if params.DenomCreationFee != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
accAddr, err := sdk.AccAddressFromBech32(creatorAddr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
communityPoolAddr := address.Module("protocolpool") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. 💡 Codebase verification Incorrect Module Name for Community Pool Address The module name
🔗 Analysis chainVerify the module name for the community pool address At line 95, the module name Run the following script to check the module names in the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: List all module account names used in the codebase.
rg --type go 'Module\("(\w+)"\)' -o -r '$1' | sort | uniq
Length of output: 417 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err := k.SendCoins(ctx, accAddr, communityPoolAddr, params.DenomCreationFee); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// if DenomCreationGasConsume is non-zero, consume the gas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if params.DenomCreationGasConsume != 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.Environment.GasService.GasMeter(ctx).Consume(params.DenomCreationGasConsume, "consume denom creation gas") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. 🛠️ Refactor suggestion Simplify function signature by removing named return parameter The Apply this diff to modify the function: -func (k Keeper) chargeForCreateDenom(ctx context.Context, creatorAddr string) (err error) {
+func (k Keeper) chargeForCreateDenom(ctx context.Context, creatorAddr string) error { Adjust any assignments or return statements as needed to reflect this change. 📝 Committable suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package keeper | ||
|
||
// import ( | ||
// storetypes "cosmossdk.io/store/types" | ||
// sdk "github.com/cosmos/cosmos-sdk/types" | ||
// ) | ||
|
||
// func (k Keeper) addDenomFromCreator(ctx sdk.Context, creator, denom string) { | ||
// store := k.GetCreatorPrefixStore(ctx, creator) | ||
// store.Set([]byte(denom), []byte(denom)) | ||
// } | ||
|
||
// func (k Keeper) getDenomsFromCreator(ctx sdk.Context, creator string) []string { | ||
// store := k.GetCreatorPrefixStore(ctx, creator) | ||
|
||
// iterator := store.Iterator(nil, nil) | ||
// defer iterator.Close() | ||
|
||
// denoms := []string{} | ||
// for ; iterator.Valid(); iterator.Next() { | ||
// denoms = append(denoms, string(iterator.Key())) | ||
// } | ||
// return denoms | ||
// } | ||
|
||
// func (k Keeper) GetAllDenomsIterator(ctx sdk.Context) storetypes.Iterator { | ||
// return k.GetCreatorsPrefixStore(ctx).Iterator(nil, nil) | ||
// } |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -44,6 +44,28 @@ func (k *Keeper) InitGenesis(ctx context.Context, state *types.GenesisState) err | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
k.setSupply(ctx, supply) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, meta := range state.DenomMetadata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err := k.SetDenomMetaData(ctx, meta) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+52
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. Add context to error handling when setting denomination metadata Currently, if Consider modifying the error handling as follows: for _, meta := range state.DenomMetadata {
err := k.SetDenomMetaData(ctx, meta)
if err != nil {
- return err
+ return fmt.Errorf("failed to set metadata for denom %s: %w", meta.Base, err)
}
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for _, genDenom := range state.GetFactoryDenoms() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
creator, _, err := types.DeconstructDenom(genDenom.GetDenom()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.createDenomAfterValidation(ctx, creator, genDenom.GetDenom()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
err = k.setAuthorityMetadata(ctx, genDenom.GetDenom(), genDenom.GetAuthorityMetadata()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+54
to
+67
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. 🛠️ Refactor suggestion Error handling and validation in factory denom initialization The code introduces initialization for factory denoms by iterating over
Apply this diff to improve error messages: for _, genDenom := range state.GetFactoryDenoms() {
creator, _, err := types.DeconstructDenom(genDenom.GetDenom())
if err != nil {
- return err
+ return fmt.Errorf("failed to deconstruct denom %s: %w", genDenom.GetDenom(), err)
}
err = k.createDenomAfterValidation(ctx, creator, genDenom.GetDenom())
if err != nil {
- return err
+ return fmt.Errorf("failed to create denom %s: %w", genDenom.GetDenom(), err)
}
err = k.setAuthorityMetadata(ctx, genDenom.GetDenom(), genDenom.GetAuthorityMetadata())
if err != nil {
- return err
+ return fmt.Errorf("failed to set authority metadata for denom %s: %w", genDenom.GetDenom(), err)
}
} 📝 Committable suggestion
Suggested change
💡 Codebase verification Issues Found: Instances of 🔗 Analysis chainVerify consistency of denom creation across the codebase Ensure that all usages and initializations of factory denoms are consistent with the new initialization logic introduced here. There might be other places in the codebase where denoms are created or initialized that need to be updated. Run the following script to search for other instances of denom creation: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find instances where denoms are created or initialized outside InitGenesis
# Search for calls to createDenomAfterValidation excluding InitGenesis method
rg --type go 'createDenomAfterValidation\(' -g '!x/bank/v2/keeper/genesis.go' -A 5 -B 5
Length of output: 1203 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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.
💡 Codebase verification
Missing
gogoproto
DependencyThe
gogoproto/gogo.proto
import is present in multiple.proto
files, but thegogoproto
directory andgogo.proto
file are not found in the repository. This indicates that the necessarygogoproto
dependency is missing and needs to be properly installed or included in the project.gogoproto
is added to your project's dependency management system.🔗 Analysis chain
Verify the existence of the gogoproto import
The static analysis tool indicates that the file
gogoproto/gogo.proto
does not exist. Please ensure that this import is correctly set up in your project. If it's a third-party dependency, make sure it's properly installed.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 246
Script:
Length of output: 3176
🧰 Tools
🪛 buf