Skip to content
14 changes: 13 additions & 1 deletion libs/cosmos-sdk/x/mint/client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package utils

import (
"fmt"
"io/ioutil"

"github.com/okx/okbchain/libs/cosmos-sdk/codec"
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
"github.com/okx/okbchain/libs/cosmos-sdk/x/mint/internal/types"
"io/ioutil"
"github.com/pkg/errors"
)

// ManageTreasuresProposalJSON defines a ManageTreasureProposal with a deposit used to parse
Expand All @@ -25,10 +28,19 @@ func ParseManageTreasuresProposalJSON(cdc *codec.Codec, proposalFilePath string)
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}

func parseRecover(contents []byte, err *error) {
if r := recover(); r != nil {
*err = errors.New(fmt.Sprintf("Please check the file:\n%s\nFailed to parse the proposal json:%s",
string(contents), r))
}
}

// ExtraProposalJSON defines a ExtraProposal with a deposit used to parse
// manage treasures proposals from a JSON file.
type ExtraProposalJSON struct {
Expand Down
7 changes: 6 additions & 1 deletion libs/cosmos-sdk/x/mint/internal/types/treasure.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"sort"
)

//Treasure is the struct which has address and proportion of mint reward.
// Treasure is the struct which has address and proportion of mint reward.
type Treasure struct {
//Treasure Address
Address sdk.AccAddress `json:"address" yaml:"address"`
Expand All @@ -28,6 +28,11 @@ func (t Treasure) ValidateBasic() error {
if t.Proportion.LTE(sdk.ZeroDec()) || t.Proportion.GT(sdk.OneDec()) {
return errors.New(fmt.Sprintf("treasure proportion should non-negative and less than one: %s", t.Proportion))
}

if t.Address.Empty() {
return errors.New(fmt.Sprintf("treasure address is nil"))
}

return nil
}

Expand Down
6 changes: 6 additions & 0 deletions libs/cosmos-sdk/x/mint/internal/types/treasure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestValidateBasic(t *testing.T) {
treasure1 := NewTreasure(sdk.AccAddress([]byte{0x01}), sdk.NewDecWithPrec(1, 2))
treasure2 := NewTreasure(sdk.AccAddress([]byte{0x02}), sdk.NewDecWithPrec(1, 2))
treasure3 := NewTreasure(sdk.AccAddress([]byte{0x03}), sdk.NewDecWithPrec(1, 2))
treasure4 := NewTreasure(nil, sdk.NewDecWithPrec(1, 2))

//success treasures
treasures := []Treasure{*treasure1, *treasure2, *treasure3}
Expand Down Expand Up @@ -65,6 +66,11 @@ func TestValidateBasic(t *testing.T) {
err = ValidateTreasures(treasures)
require.Error(t, err)
require.Contains(t, err.Error(), "the sum of treasure proportion should non-negative and less than one")

// err treasures has empty address
treasures = []Treasure{*treasure1, *treasure2, *treasure3, *treasure4}
err = ValidateTreasures(treasures)
require.Error(t, err)
}

func TestSortTreasures(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion x/evm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Where proposal.json contains:
{
"title":"Update system contract address",
"description":"Will change the system contract address",
"contract_addresses": "0x1033796B018B2bf0Fc9CB88c0793b2F275eDB624",
"contract_address": "0x1033796B018B2bf0Fc9CB88c0793b2F275eDB624",
"is_added":true,
"deposit": [
{
Expand Down
21 changes: 20 additions & 1 deletion x/evm/client/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package utils

import (
"github.com/okx/okbchain/x/evm/types"
"fmt"
"io/ioutil"

"github.com/okx/okbchain/libs/cosmos-sdk/codec"
sdk "github.com/okx/okbchain/libs/cosmos-sdk/types"
"github.com/okx/okbchain/x/evm/types"
"github.com/pkg/errors"
)

type (
Expand Down Expand Up @@ -75,6 +77,8 @@ func ParseManageContractDeploymentWhitelistProposalJSON(cdc *codec.Codec, propos
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}
Expand All @@ -87,6 +91,8 @@ func ParseManageContractBlockedListProposalJSON(cdc *codec.Codec, proposalFilePa
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}
Expand All @@ -99,6 +105,8 @@ func ParseManageContractMethodBlockedListProposalJSON(cdc *codec.Codec, proposal
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}
Expand All @@ -111,6 +119,8 @@ func ParseManageSysContractAddressProposalJSON(cdc *codec.Codec, proposalFilePat
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}
Expand All @@ -123,6 +133,15 @@ func ParseManageContractBytecodeProposalJSON(cdc *codec.Codec, proposalFilePath
return
}

defer parseRecover(contents, &err)

cdc.MustUnmarshalJSON(contents, &proposal)
return
}

func parseRecover(contents []byte, err *error) {
if r := recover(); r != nil {
*err = errors.New(fmt.Sprintf("Please check the file:\n%s\nFailed to parse the proposal json:%s",
string(contents), r))
}
}
3 changes: 3 additions & 0 deletions x/evm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ var (

// ErrGUFactor returns an error if gu_factor is negative
ErrGUFactor = sdkerrors.Register(ModuleName, 24, "gu_factor should non-negative")

// ErrEmptyAddr returns an error if the address is empty in address list
ErrEmptyAddr = sdkerrors.Register(ModuleName, 25, "Empty address in list")
)

const (
Expand Down
19 changes: 19 additions & 0 deletions x/evm/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ func (mp ManageContractDeploymentWhitelistProposal) ValidateBasic() sdk.Error {
return ErrDuplicatedAddr
}

if isEmptyAddr(mp.DistributorAddrs) {
return ErrEmptyAddr
}

return nil
}

Expand Down Expand Up @@ -156,6 +160,17 @@ func isAddrDuplicated(addrs []sdk.AccAddress) bool {
return false
}

func isEmptyAddr(addrs []sdk.AccAddress) bool {
lenAddrs := len(addrs)
for i := 0; i < lenAddrs; i++ {
if addrs[i].Empty() {
return true
}
}

return false
}

// ManageContractBlockedListProposal - structure for the proposal to add or delete a contract address from blocked list
type ManageContractBlockedListProposal struct {
Title string `json:"title" yaml:"title"`
Expand Down Expand Up @@ -229,6 +244,10 @@ func (mp ManageContractBlockedListProposal) ValidateBasic() sdk.Error {
return ErrDuplicatedAddr
}

if isEmptyAddr(mp.ContractAddrs) {
return ErrEmptyAddr
}

return nil
}

Expand Down