From aba158320681971e780d9fb9bfd2f24885d28ad6 Mon Sep 17 00:00:00 2001 From: Mikhail Kornilov Date: Wed, 21 Oct 2020 18:31:37 +0300 Subject: [PATCH 1/4] [Release v0.7] [DFI-908,DFI-910] Cosmos SDK version fix, Swagger update (#227) * [DFI-908,DFI-910] Cosmos SDK version fix, Swagger update * go mod tidy * Switched CSDK to v0.39.1-0.2 which has no appHash changes --- cmd/dncli/docs/swagger.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmd/dncli/docs/swagger.go b/cmd/dncli/docs/swagger.go index 36a3aec0..c3b820cb 100644 --- a/cmd/dncli/docs/swagger.go +++ b/cmd/dncli/docs/swagger.go @@ -761,6 +761,26 @@ definitions: voter: type: string type: object + auth.StdFee: + $ref: '#/definitions/types.StdFee' + auth.StdSignature: + $ref: '#/definitions/types.StdSignature' + auth.StdTx: + $ref: '#/definitions/types.StdTx' + bytes.HexBytes: + items: + type: integer + type: array + ccstorage.Currencies: + $ref: '#/definitions/types.Currencies' + ccstorage.Currency: + $ref: '#/definitions/types.Currency' + crypto.Address: + $ref: '#/definitions/bytes.HexBytes' + markets.MarketExtended: + $ref: '#/definitions/types.MarketExtended' + msmodule.MsMsg: + type: object rest.BaseReq: properties: account_number: @@ -1577,6 +1597,8 @@ definitions: items: type: integer type: array + types.Address: + $ref: '#/definitions/crypto.Address' types.Asset: properties: active: @@ -2059,6 +2081,15 @@ definitions: items: $ref: '#/definitions/types.Order' type: array + types.PartSetHeader: + properties: + hash: + items: + type: integer + type: array + total: + type: integer + type: object types.Pool: properties: bonded_tokens: From 24ebb57b3a644719b4f4e751eae58db8975a4a53 Mon Sep 17 00:00:00 2001 From: Sergey Kruglov Date: Fri, 16 Oct 2020 18:02:48 +0300 Subject: [PATCH 2/4] [DFI-796] Add option to add ERC20 contract address to ccstorage currency --- x/ccstorage/client/cli/genesis.go | 20 +++++++++--- x/ccstorage/internal/types/currency.go | 16 +++++++--- x/ccstorage/internal/types/events.go | 8 +++-- x/ccstorage/internal/types/genesis.go | 32 ++++++++++++------- x/ccstorage/internal/types/genesis_test.go | 4 +-- x/currencies/client/cli/tx.go | 15 +++++++-- .../internal/types/gov_add_proposal.go | 5 ++- 7 files changed, 69 insertions(+), 31 deletions(-) diff --git a/x/ccstorage/client/cli/genesis.go b/x/ccstorage/client/cli/genesis.go index 6de4f3e1..52313654 100644 --- a/x/ccstorage/client/cli/genesis.go +++ b/x/ccstorage/client/cli/genesis.go @@ -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.ExactArgs(3), RunE: func(_ *cobra.Command, args []string) error { // setup viper config config := ctx.Config @@ -36,6 +36,14 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo return err } + 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) @@ -48,8 +56,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) @@ -85,6 +94,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 diff --git a/x/ccstorage/internal/types/currency.go b/x/ccstorage/internal/types/currency.go index bc15a052..d3d3ff82 100644 --- a/x/ccstorage/internal/types/currency.go +++ b/x/ccstorage/internal/types/currency.go @@ -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. @@ -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(), ) } @@ -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, }) } @@ -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, } } diff --git a/x/ccstorage/internal/types/events.go b/x/ccstorage/internal/types/events.go index c737f692..3e269eca 100644 --- a/x/ccstorage/internal/types/events.go +++ b/x/ccstorage/internal/types/events.go @@ -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. @@ -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), ) } diff --git a/x/ccstorage/internal/types/genesis.go b/x/ccstorage/internal/types/genesis.go index 9737f607..944a611e 100644 --- a/x/ccstorage/internal/types/genesis.go +++ b/x/ccstorage/internal/types/genesis.go @@ -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. @@ -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: "", }, }, } diff --git a/x/ccstorage/internal/types/genesis_test.go b/x/ccstorage/internal/types/genesis_test.go index 105f05ee..badca3c7 100644 --- a/x/ccstorage/internal/types/genesis_test.go +++ b/x/ccstorage/internal/types/genesis_test.go @@ -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()) } } diff --git a/x/currencies/client/cli/tx.go b/x/currencies/client/cli/tx.go index d1224047..130964d1 100644 --- a/x/currencies/client/cli/tx.go +++ b/x/currencies/client/cli/tx.go @@ -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]", + Use: "add-currency-proposal [denom] [decimals] [vmBalancePathHex] [vmInfoPathHex] [ERC20ContractAddress]", Args: cobra.ExactArgs(4), - Short: "Submit currency add proposal, creating non-token currency", + 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()) @@ -96,8 +96,16 @@ func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command { return err } + 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 } @@ -116,6 +124,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 diff --git a/x/currencies/internal/types/gov_add_proposal.go b/x/currencies/internal/types/gov_add_proposal.go index b0e5852a..d1a982e4 100644 --- a/x/currencies/internal/types/gov_add_proposal.go +++ b/x/currencies/internal/types/gov_add_proposal.go @@ -24,6 +24,7 @@ type AddCurrencyProposal struct { Decimals uint8 VmBalancePathHex string VmInfoPathHex string + ContractAddress string } func (p AddCurrencyProposal) GetTitle() string { return "Add currency" } @@ -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, } From 4116803613a1947a292e33a6b024f896d3337abb Mon Sep 17 00:00:00 2001 From: Sergey Kruglov Date: Mon, 19 Oct 2020 12:40:16 +0300 Subject: [PATCH 3/4] [DFI-796] Add option to add ERC20 contract address to ccstorage currency --- x/currencies/client/cli/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/currencies/client/cli/tx.go b/x/currencies/client/cli/tx.go index 130964d1..a41cc5e4 100644 --- a/x/currencies/client/cli/tx.go +++ b/x/currencies/client/cli/tx.go @@ -59,7 +59,7 @@ func PostWithdrawCurrency(cdc *codec.Codec) *cobra.Command { func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "add-currency-proposal [denom] [decimals] [vmBalancePathHex] [vmInfoPathHex] [ERC20ContractAddress]", - Args: cobra.ExactArgs(4), + Args: cobra.ExactArgs(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 { From 042474629904a3c9f0c2e70345baf14dc017958a Mon Sep 17 00:00:00 2001 From: Sergey Kruglov Date: Mon, 19 Oct 2020 13:36:24 +0300 Subject: [PATCH 4/4] [DFI-796] Add option to add ERC20 contract address to ccstorage currency --- x/ccstorage/client/cli/genesis.go | 15 +++++++++------ x/currencies/client/cli/tx.go | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/x/ccstorage/client/cli/genesis.go b/x/ccstorage/client/cli/genesis.go index 52313654..17317b6a 100644 --- a/x/ccstorage/client/cli/genesis.go +++ b/x/ccstorage/client/cli/genesis.go @@ -19,7 +19,7 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo cmd := &cobra.Command{ Use: "set-currency [denom] [decimals] [ERC20ContractAddress]", Short: "Set currency to genesis state", - Args: cobra.ExactArgs(3), + Args: cobra.RangeArgs(2, 3), RunE: func(_ *cobra.Command, args []string) error { // setup viper config config := ctx.Config @@ -36,11 +36,14 @@ func AddGenesisCurrencyInfo(ctx *server.Context, cdc *codec.Codec, defaultNodeHo return err } - contractAddress := args[2] - if contractAddress != "" { - _, err := helpers.ParseEthereumAddressParam("ERC20ContractAddress", contractAddress, helpers.ParamTypeCliArg) - if err != nil { - 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 + } } } diff --git a/x/currencies/client/cli/tx.go b/x/currencies/client/cli/tx.go index a41cc5e4..a634c05b 100644 --- a/x/currencies/client/cli/tx.go +++ b/x/currencies/client/cli/tx.go @@ -59,7 +59,7 @@ func PostWithdrawCurrency(cdc *codec.Codec) *cobra.Command { func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "add-currency-proposal [denom] [decimals] [vmBalancePathHex] [vmInfoPathHex] [ERC20ContractAddress]", - Args: cobra.ExactArgs(5), + 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 { @@ -96,11 +96,14 @@ func AddCurrencyProposal(cdc *codec.Codec) *cobra.Command { return err } - contractAddress := args[4] - if contractAddress != "" { - _, err := helpers.ParseEthereumAddressParam("ERC20ContractAddress", contractAddress, helpers.ParamTypeCliArg) - if err != nil { - 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 + } } }