Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/dncli/docs/swagger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions x/ccstorage/client/cli/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
// AddGenesisCurrencyInfo return genesis cmd which adds currency into node genesis state.
func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "set-currency [denom] [decimals]",
Short: "Set currency to genesis state (non-token)",
Args: cobra.ExactArgs(2),
Use: "set-currency [denom] [decimals] [ERC20ContractAddress]",
Short: "Set currency to genesis state",
Args: cobra.RangeArgs(2, 3),
RunE: func(_ *cobra.Command, args []string) error {
// setup viper config
config := ctx.Config
Expand All @@ -36,6 +36,17 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo
return err
}

var contractAddress string
if len(args) > 2 {
contractAddress = args[2]
if contractAddress != "" {
_, err := helpers.ParseEthereumAddressParam("ERC20ContractAddress", contractAddress, helpers.ParamTypeCliArg)
if err != nil {
return err
}
}
}

// retrieve the app state
genFile := config.GenesisFile()
appState, genDoc, err := genutil.GenesisStateFromGenFile(cdc, genFile)
Expand All @@ -48,8 +59,9 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo

// update the state
params := types.CurrencyParams{
Denom: denom,
Decimals: decimals,
Denom: denom,
Decimals: decimals,
ContractAddress: contractAddress,
}
if err := params.Validate(); err != nil {
return fmt.Errorf("invalid params: %w", err)
Expand Down Expand Up @@ -85,6 +97,7 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo
helpers.BuildCmdHelp(cmd, []string{
"currency denomination symbol",
"currency decimals count",
"ERC20 contract address",
})

return cmd
Expand Down
16 changes: 11 additions & 5 deletions x/ccstorage/internal/types/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Currency struct {
Decimals uint8 `json:"decimals" yaml:"decimals" example:"0"`
// Total amount of currency coins in Bank
Supply sdk.Int `json:"supply" yaml:"supply" swaggertype:"string" example:"100"`
// ERC20 contract address
ContractAddress string `json:"contract_address" yaml:"contract_address"`
}

// Valid checks that Currency is valid.
Expand Down Expand Up @@ -75,9 +77,11 @@ func (c Currency) String() string {
return fmt.Sprintf("Currency:\n"+
" Denom: %s\n"+
" Decimals: %d\n"+
" Contract Address: %s\n"+
" Supply: %s",
c.Denom,
c.Decimals,
c.ContractAddress,
c.Supply.String(),
)
}
Expand All @@ -90,8 +94,9 @@ func (list Currencies) ToParams() CurrenciesParams {
var params CurrenciesParams
for _, currency := range list {
params = append(params, CurrencyParams{
Denom: currency.Denom,
Decimals: currency.Decimals,
Denom: currency.Denom,
Decimals: currency.Decimals,
ContractAddress: currency.ContractAddress,
})
}

Expand All @@ -101,8 +106,9 @@ func (list Currencies) ToParams() CurrenciesParams {
// NewCurrency creates a new Currency object.
func NewCurrency(params CurrencyParams, supply sdk.Int) Currency {
return Currency{
Denom: params.Denom,
Decimals: params.Decimals,
Supply: supply,
Denom: params.Denom,
Decimals: params.Decimals,
Supply: supply,
ContractAddress: params.ContractAddress,
}
}
8 changes: 5 additions & 3 deletions x/ccstorage/internal/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
const (
EventTypesCreate = ModuleName + ".create"
//
AttributeDenom = "denom"
AttributeDecimals = "decimals"
AttributeInfoPath = "info_path"
AttributeDenom = "denom"
AttributeDecimals = "decimals"
AttributeInfoPath = "info_path"
AttributeContractAddress = "contract_address"
)

// NewCCCreatedEvent creates an Event on currency creation.
Expand All @@ -21,5 +22,6 @@ func NewCCCreatedEvent(currency Currency) sdk.Event {
sdk.NewAttribute(AttributeDenom, currency.Denom),
sdk.NewAttribute(AttributeDecimals, strconv.FormatUint(uint64(currency.Decimals), 10)),
sdk.NewAttribute(AttributeInfoPath, currency.InfoPathHex()),
sdk.NewAttribute(AttributeContractAddress, currency.ContractAddress),
)
}
32 changes: 20 additions & 12 deletions x/ccstorage/internal/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type CurrencyParams struct {
Denom string `json:"denom" yaml:"denom"`
// Currency decimals count
Decimals uint8 `json:"decimals" yaml:"decimals"`
// ERC20 contract address
ContractAddress string `json:"contract_address" yaml:"contract_address"`
}

// Validate check that params are valid.
Expand All @@ -53,28 +55,34 @@ func DefaultGenesisState() GenesisState {
state := GenesisState{
CurrenciesParams: CurrenciesParams{
{
Denom: "xfi",
Decimals: 18,
Denom: "xfi",
Decimals: 18,
ContractAddress: "",
},
{
Denom: "sxfi",
Decimals: 18,
Denom: "sxfi",
Decimals: 18,
ContractAddress: "",
},
{
Denom: "eth",
Decimals: 18,
Denom: "eth",
Decimals: 18,
ContractAddress: "",
},
{
Denom: "usdt",
Decimals: 6,
Denom: "usdt",
Decimals: 6,
ContractAddress: "",
},
{
Denom: "btc",
Decimals: 8,
Denom: "btc",
Decimals: 8,
ContractAddress: "",
},
{
Denom: "lpt",
Decimals: 18,
Denom: "lpt",
Decimals: 18,
ContractAddress: "",
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions x/ccstorage/internal/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ func TestCCS_GenesisParams_Validate(t *testing.T) {

// ok
{
param := CurrencyParams{"xfi", 0}
param := CurrencyParams{"xfi", 0, ""}
require.NoError(t, param.Validate())
}

// fail: invalid denom
{
param1 := CurrencyParams{"xfi1", 0}
param1 := CurrencyParams{"xfi1", 0, ""}
require.Error(t, param1.Validate())
}
}
Expand Down
20 changes: 16 additions & 4 deletions x/currencies/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func PostWithdrawCurrency(cdc *codec.Codec) *cobra.Command {
// Send governance add currency proposal.
func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "add-currency-proposal [denom] [decimals] [vmBalancePathHex] [vmInfoPathHex]",
Args: cobra.ExactArgs(4),
Short: "Submit currency add proposal, creating non-token currency",
Use: "add-currency-proposal [denom] [decimals] [vmBalancePathHex] [vmInfoPathHex] [ERC20ContractAddress]",
Args: cobra.RangeArgs(4, 5),
Short: "Submit currency add proposal, creating currency",
Example: "add-currency-proposal xfi 18 {balancePath} {infoPath} --deposit 100xfi --fees 1xfi",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, txBuilder := helpers.GetTxCmdCtx(cdc, cmd.InOrStdin())
Expand Down Expand Up @@ -96,8 +96,19 @@ func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command {
return err
}

var contractAddress string
if len(args) > 4 {
contractAddress = args[4]
if contractAddress != "" {
_, err := helpers.ParseEthereumAddressParam("ERC20ContractAddress", contractAddress, helpers.ParamTypeCliArg)
if err != nil {
return err
}
}
}

// prepare and send message
content := types.NewAddCurrencyProposal(denom, decimals, balancePath, infoPath)
content := types.NewAddCurrencyProposal(denom, decimals, balancePath, infoPath, contractAddress)
if err := content.ValidateBasic(); err != nil {
return err
}
Expand All @@ -116,6 +127,7 @@ func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command {
"new currency number of decimals",
"DVM path for balance resources [HEX string]",
"DVM path for currencyInfo resource [HEX string]",
"ERC20 contract address",
})

return cmd
Expand Down
5 changes: 4 additions & 1 deletion x/currencies/internal/types/gov_add_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type AddCurrencyProposal struct {
Decimals uint8
VmBalancePathHex string
VmInfoPathHex string
ContractAddress string
}

func (p AddCurrencyProposal) GetTitle() string { return "Add currency" }
Expand Down Expand Up @@ -58,15 +59,17 @@ func (p AddCurrencyProposal) String() string {
b.WriteString(fmt.Sprintf(" Decimals: %d\n", p.Decimals))
b.WriteString(fmt.Sprintf(" VmBalancePathHex: 0x%s\n", p.VmBalancePathHex))
b.WriteString(fmt.Sprintf(" VmInfoPathHex: %s", p.VmInfoPathHex))
b.WriteString(fmt.Sprintf(" ContractAddress: %s", p.ContractAddress))

return b.String()
}

// NewAddCurrencyProposal creates a AddCurrencyProposal object.
func NewAddCurrencyProposal(denom string, decimals uint8, balancePath, infoPath string) AddCurrencyProposal {
func NewAddCurrencyProposal(denom string, decimals uint8, balancePath, infoPath string, contractAddress string) AddCurrencyProposal {
return AddCurrencyProposal{
Denom: denom,
Decimals: decimals,
ContractAddress: contractAddress,
VmBalancePathHex: balancePath,
VmInfoPathHex: infoPath,
}
Expand Down