diff --git a/client/rpc/dex_client.go b/client/rpc/dex_client.go index b990247f..770e9b51 100644 --- a/client/rpc/dex_client.go +++ b/client/rpc/dex_client.go @@ -966,6 +966,26 @@ func (c *HTTP) Claim(chainId sdk.IbcChainID, sequence uint64, payload []byte, sy return c.Broadcast(claimMsg, syncType, options...) } +func (c *HTTP) GetLastTotalPower() (power *int64, err error) { + key := []byte{0x12} + bz, err := c.QueryStore(key, StakeStoreKey) + if err != nil { + return + } + err = c.cdc.UnmarshalBinaryLengthPrefixed(bz, &power) + return +} + +func (c *HTTP) GetOracleRelayers() (relayers []msg.OracleRelayer, err error) { + key := []byte{0x03} + bz, err := c.QueryStore(key, StakeStoreKey) + if err != nil { + return + } + err = c.cdc.UnmarshalBinaryLengthPrefixed(bz, &relayers) + return +} + func (c *HTTP) GetProphecy(chainId sdk.IbcChainID, sequence int64) (*msg.Prophecy, error) { key := []byte(msg.GetClaimId(chainId, msg.OracleChannelId, sequence)) bz, err := c.QueryStore(key, OracleStoreName) diff --git a/client/rpc/staking_client.go b/client/rpc/staking_client.go index 2250d7ff..e54f31f7 100644 --- a/client/rpc/staking_client.go +++ b/client/rpc/staking_client.go @@ -28,6 +28,26 @@ var ( ) type StakingClient interface { + CreateValidatorOpen(delegation types.Coin, description msg.Description, commission types.CommissionMsg, sideConsAddr []byte, sideFeeAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + EditValidator(description msg.Description, commissionRate *types.Dec, sideFeeAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + Delegate(valAddr types.ValAddress, delegation types.Coin, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + Redelegate(valSrcAddr types.ValAddress, valDstAddr types.ValAddress, amount types.Coin, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + Undelegate(valAddr types.ValAddress, amount types.Coin, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + Unjail(valAddr types.ValAddress, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) + + QueryValidator(valAddr types.ValAddress) (*types.Validator, error) + QueryTopValidators(top int) ([]types.Validator, error) + QueryDelegation(delAddr types.AccAddress, valAddr types.ValAddress) (*types.DelegationResponse, error) + QueryDelegations(delAddr types.AccAddress) ([]types.DelegationResponse, error) + QueryRedelegation(delAddr types.AccAddress, valSrcAddr types.ValAddress, valDstAddr types.ValAddress) (*types.Redelegation, error) + QueryRedelegations(delAddr types.AccAddress) ([]types.Redelegation, error) + QueryUnbondingDelegation(valAddr types.ValAddress, delAddr types.AccAddress) (*types.UnbondingDelegation, error) + QueryUnbondingDelegations(delAddr types.AccAddress) ([]types.UnbondingDelegation, error) + GetUnBondingDelegationsByValidator(valAddr types.ValAddress) ([]types.UnbondingDelegation, error) + GetRedelegationsByValidator(valAddr types.ValAddress) ([]types.Redelegation, error) + GetPool() (*types.Pool, error) + GetAllValidatorsCount(jailInvolved bool) (int, error) + CreateSideChainValidator(delegation types.Coin, description msg.Description, commission types.CommissionMsg, sideChainId string, sideConsAddr []byte, sideFeeAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) EditSideChainValidator(sideChainId string, description msg.Description, commissionRate *types.Dec, sideFeeAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) SideChainDelegate(sideChainId string, valAddr types.ValAddress, delegation types.Coin, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) @@ -72,6 +92,44 @@ type bechValidator struct { SideChainId string `json:"side_chain_id,omitempty"` // side chain id to distinguish different side chains SideConsAddr string `json:"side_cons_addr,omitempty"` // consensus address of the side chain validator, this replaces the `ConsPubKey` SideFeeAddr string `json:"side_fee_addr,omitempty"` // fee address on the side chain + + StakeSnapshots []types.Dec `json:"stake_snapshots"` // staked tokens snapshot over a period of time, e.g. 30 days + AccumulatedStake types.Dec `json:"accumulated_stake"` // accumulated stake, sum of StakeSnapshots +} + +func (bv *bechValidator) toValidator() (*types.Validator, error) { + validator := types.Validator{ + FeeAddr: bv.FeeAddr, + OperatorAddr: bv.OperatorAddr, + ConsPubKey: bv.ConsPubKey, + Jailed: bv.Jailed, + Status: bv.Status, + Tokens: bv.Tokens, + DelegatorShares: bv.DelegatorShares, + Description: bv.Description, + BondHeight: bv.BondHeight, + BondIntraTxCounter: bv.BondIntraTxCounter, + UnbondingHeight: bv.UnbondingHeight, + UnbondingMinTime: bv.UnbondingMinTime, + Commission: bv.Commission, + DistributionAddr: bv.DistributionAddr, + StakeSnapshots: bv.StakeSnapshots, + AccumulatedStake: bv.AccumulatedStake, + } + if len(bv.SideChainId) != 0 { + validator.SideChainId = bv.SideChainId + if sideConsAddr, err := decodeSideChainAddress(bv.SideConsAddr); err != nil { + return nil, err + } else { + validator.SideConsAddr = sideConsAddr + } + if sideFeeAddr, err := decodeSideChainAddress(bv.SideFeeAddr); err != nil { + return nil, err + } else { + validator.SideFeeAddr = sideFeeAddr + } + } + return &validator, nil } func (c *HTTP) CreateSideChainValidator(delegation types.Coin, description msg.Description, commission types.CommissionMsg, @@ -88,14 +146,14 @@ func (c *HTTP) CreateSideChainValidator(delegation types.Coin, description msg.D } func (c *HTTP) EditSideChainValidator(sideChainId string, description msg.Description, commissionRate *types.Dec, - sideFeeAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + sideFeeAddr, sideConsAddr []byte, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { if c.key == nil { return nil, KeyMissingError } valOpAddr := types.ValAddress(c.key.GetAddr()) - m := msg.NewEditSideChainValidatorMsg(sideChainId, valOpAddr, description, commissionRate, sideFeeAddr) + m := msg.NewEditSideChainValidatorMsg(sideChainId, valOpAddr, description, commissionRate, sideFeeAddr, sideConsAddr) return c.Broadcast(m, syncType, options...) } @@ -143,6 +201,16 @@ func (c *HTTP) SideChainUnbond(sideChainId string, valAddr types.ValAddress, amo return c.Broadcast(m, syncType, options...) } +func (c *HTTP) Unjail(valAddr types.ValAddress, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + m := msg.MsgUnjail{ValidatorAddr: valAddr} + + return c.Broadcast(m, syncType, options...) +} + func (c *HTTP) SideChainUnjail(sideChainId string, valAddr types.ValAddress, syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { if c.key == nil { return nil, KeyMissingError @@ -631,3 +699,328 @@ func decodeSideChainAddress(addr string) ([]byte, error) { return hex.DecodeString(addr) } } + +func (c *HTTP) CreateValidatorOpen(delegation types.Coin, description msg.Description, commission types.CommissionMsg, pubkey string, + syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + delegatorAddr := c.key.GetAddr() + validatorAddr := types.ValAddress(c.key.GetAddr()) + + m := msg.MsgCreateValidatorOpen{ + Description: description, + Commission: commission, + Delegation: delegation, + PubKey: pubkey, + DelegatorAddr: delegatorAddr, + ValidatorAddr: validatorAddr, + } + + return c.Broadcast(m, syncType, options...) +} + +func (c *HTTP) EditValidator(description msg.Description, commissionRate *types.Dec, pubkey string, + syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + valOpAddr := types.ValAddress(c.key.GetAddr()) + + m := msg.MsgEditValidator{ + Description: description, + CommissionRate: commissionRate, + PubKey: pubkey, + ValidatorAddr: valOpAddr, + } + return c.Broadcast(m, syncType, options...) +} + +func (c *HTTP) Delegate(valAddr types.ValAddress, delegation types.Coin, syncType SyncType, + options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + delAddr := c.key.GetAddr() + + m := msg.MsgDelegate{ + DelegatorAddr: delAddr, + ValidatorAddr: valAddr, + Delegation: delegation, + } + + return c.Broadcast(m, syncType, options...) +} + +func (c *HTTP) Redelegate(valSrcAddr types.ValAddress, valDstAddr types.ValAddress, amount types.Coin, + syncType SyncType, options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + if bytes.Equal(valSrcAddr, valDstAddr) { + return nil, fmt.Errorf("cannot redelegate to the same validator") + } + + delAddr := c.key.GetAddr() + + m := msg.MsgRedelegate{ + DelegatorAddr: delAddr, + ValidatorSrcAddr: valSrcAddr, + ValidatorDstAddr: valDstAddr, + Amount: amount, + } + + return c.Broadcast(m, syncType, options...) +} + +func (c *HTTP) Undelegate(valAddr types.ValAddress, amount types.Coin, syncType SyncType, + options ...tx.Option) (*coretypes.ResultBroadcastTx, error) { + if c.key == nil { + return nil, KeyMissingError + } + + delAddr := c.key.GetAddr() + + m := msg.MsgUndelegate{ + DelegatorAddr: delAddr, + ValidatorAddr: valAddr, + Amount: amount, + } + + return c.Broadcast(m, syncType, options...) +} + +func (c *HTTP) QueryValidator(valAddr types.ValAddress) (*types.Validator, error) { + params := types.QueryValidatorParams{ + ValidatorAddr: valAddr, + } + + bz, err := json.Marshal(params) + + if err != nil { + return nil, err + } + + res, err := c.QueryWithData("custom/stake/validator", bz) + if err != nil { + return nil, err + } + + if len(res) == 0 { + return nil, nil + } + + var bv bechValidator + if err = c.cdc.UnmarshalJSON(res, &bv); err != nil { + return nil, err + } + validator, err := bv.toValidator() + if err != nil { + return nil, err + } + return validator, nil +} + +func (c *HTTP) QueryTopValidators(top int) ([]types.Validator, error) { + if top > 50 || top < 1 { + return nil, fmt.Errorf("top must be between 1 and 50") + } + + params := types.QueryTopValidatorsParams{ + Top: top, + } + + bz, err := json.Marshal(params) + + if err != nil { + return nil, err + } + + res, err := c.QueryWithData("custom/stake/topValidators", bz) + if err != nil { + return nil, err + } + + var validators = make([]types.Validator, 0) + + if len(res) == 0 { + return validators, nil + } + + var bvs []bechValidator + if err = c.cdc.UnmarshalJSON(res, &bvs); err != nil { + return nil, err + } + + for _, v := range bvs { + validator, err := v.toValidator() + if err != nil { + return nil, err + } + validators = append(validators, *validator) + } + + return validators, nil +} + +func (c *HTTP) QueryDelegation(delAddr types.AccAddress, valAddr types.ValAddress) (*types.DelegationResponse, error) { + return c.QuerySideChainDelegation("", delAddr, valAddr) +} + +func (c *HTTP) QueryDelegations(delAddr types.AccAddress) ([]types.DelegationResponse, error) { + return c.QuerySideChainDelegations("", delAddr) +} + +func (c *HTTP) QueryRedelegation(delAddr types.AccAddress, valSrcAddr types.ValAddress, + valDstAddr types.ValAddress) (*types.Redelegation, error) { + params := types.QueryRedelegationParams{ + DelegatorAddr: delAddr, + ValSrcAddr: valSrcAddr, + ValDstAddr: valDstAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/redelegation", bz) + if err != nil { + return nil, err + } + var red types.Redelegation + err = c.cdc.UnmarshalJSON(res, &red) + return &red, err +} + +//Query all redelegations records for one delegator +func (c *HTTP) QueryRedelegations(delAddr types.AccAddress) ([]types.Redelegation, error) { + params := types.QueryDelegatorParams{ + DelegatorAddr: delAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/delegatorRedelegations", bz) + if err != nil { + return nil, err + } + var reds []types.Redelegation + err = c.cdc.UnmarshalJSON(res, &reds) + return reds, err +} + +//Query an unbonding-delegation record based on delegator and validator address +func (c *HTTP) QueryUnbondingDelegation(valAddr types.ValAddress, delAddr types.AccAddress) (*types.UnbondingDelegation, error) { + params := types.QueryBondsParams{ + DelegatorAddr: delAddr, + ValidatorAddr: valAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/unbondingDelegation", bz) + if err != nil { + return nil, err + } + var ub types.UnbondingDelegation + err = c.cdc.UnmarshalJSON(res, &ub) + return &ub, err +} + +//Query all unbonding-delegations records for one delegator +func (c *HTTP) QueryUnbondingDelegations(delAddr types.AccAddress) ([]types.UnbondingDelegation, error) { + params := types.QueryDelegatorParams{ + DelegatorAddr: delAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/delegatorUnbondingDelegations", bz) + if err != nil { + return nil, err + } + var ubds []types.UnbondingDelegation + err = c.cdc.UnmarshalJSON(res, &ubds) + return ubds, err +} + +func (c *HTTP) GetUnBondingDelegationsByValidator(valAddr types.ValAddress) ([]types.UnbondingDelegation, error) { + params := types.QueryValidatorParams{ + ValidatorAddr: valAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/validatorUnbondingDelegations", bz) + if err != nil { + return nil, err + } + var ubds []types.UnbondingDelegation + err = c.cdc.UnmarshalJSON(res, &ubds) + return ubds, err +} + +func (c *HTTP) GetRedelegationsByValidator(valAddr types.ValAddress) ([]types.Redelegation, error) { + params := types.QueryValidatorParams{ + ValidatorAddr: valAddr, + } + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + res, err := c.QueryWithData("custom/stake/validatorRedelegations", bz) + if err != nil { + return nil, err + } + var reds []types.Redelegation + err = c.cdc.UnmarshalJSON(res, &reds) + return reds, err +} + +func (c *HTTP) GetPool() (*types.Pool, error) { + params := types.NewBaseParams("") + + bz, err := json.Marshal(params) + if err != nil { + return nil, err + } + path := "custom/stake/pool" + response, err := c.QueryWithData(path, bz) + + if err != nil { + return nil, err + } + var pool types.Pool + err = c.cdc.UnmarshalJSON(response, &pool) + return &pool, err +} + +func (c *HTTP) GetAllValidatorsCount(jailInvolved bool) (int, error) { + params := types.NewBaseParams("") + + bz, err := json.Marshal(params) + if err != nil { + return 0, err + } + + path := "custom/stake/allUnJailValidatorsCount" + if jailInvolved { + path = "custom/stake/allValidatorsCount" + } + response, err := c.QueryWithData(path, bz) + + if err != nil { + return 0, err + } + + count := strings.ReplaceAll(string(response), "\"", "") + + return strconv.Atoi(count) +} diff --git a/common/types/address.go b/common/types/address.go index b595402c..33d39592 100644 --- a/common/types/address.go +++ b/common/types/address.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" "github.com/tendermint/tendermint/crypto" @@ -149,3 +150,17 @@ func MustBech32ifyConsPub(pub crypto.PubKey) string { func Bech32ifyConsPub(pub crypto.PubKey) (string, error) { return bech32.ConvertAndEncode(bech32PrefixConsPub, pub.Bytes()) } + +func GetConsPubKeyBech32(pubkey string) (pk crypto.PubKey, err error) { + bz, err := GetFromBech32(pubkey, bech32PrefixConsPub) + if err != nil { + return nil, err + } + + pk, err = cryptoAmino.PubKeyFromBytes(bz) + if err != nil { + return nil, err + } + + return pk, nil +} diff --git a/common/types/coins.go b/common/types/coins.go index 95cac864..3a525f97 100644 --- a/common/types/coins.go +++ b/common/types/coins.go @@ -39,6 +39,10 @@ func (coin Coin) String() string { return fmt.Sprintf("%v%v", coin.Amount, coin.Denom) } +func (coin Coin) IsEqual(other Coin) bool { + return coin.Denom == other.Denom && coin.Amount == other.Amount +} + // Coins def type Coins []Coin diff --git a/common/types/dec.go b/common/types/dec.go index 1113f699..50f039e6 100644 --- a/common/types/dec.go +++ b/common/types/dec.go @@ -131,6 +131,10 @@ func NewDecWithPrec(i, prec int64) Dec { return Dec{c} } +func NewDec(i int64) Dec { + return NewDecWithPrec(i, Precision) +} + // get the precision multiplier, do not mutate result func precisionMultiplier(prec int64) int64 { if prec > Precision { diff --git a/common/types/delegation.go b/common/types/delegation.go index c2c98240..293678cf 100644 --- a/common/types/delegation.go +++ b/common/types/delegation.go @@ -80,4 +80,11 @@ type DelegationResponse struct { type QueryDelegatorParams struct { BaseParams DelegatorAddr AccAddress -} \ No newline at end of file +} + +type QueryRedelegationParams struct { + BaseParams + DelegatorAddr AccAddress + ValSrcAddr ValAddress + ValDstAddr ValAddress +} diff --git a/common/types/stake.go b/common/types/stake.go index a7015d83..bb8ac074 100644 --- a/common/types/stake.go +++ b/common/types/stake.go @@ -147,9 +147,12 @@ type Validator struct { Commission Commission `json:"commission"` // commission parameters DistributionAddr AccAddress `json:"distribution_addr"` // the address receives rewards from the side address, and distribute rewards to delegators. It's auto generated - SideChainId string `json:"side_chain_id"` // side chain id to distinguish different side chains - SideConsAddr []byte `json:"side_cons_addr"` // consensus address of the side chain validator, this replaces the `ConsPubKey` - SideFeeAddr []byte `json:"side_fee_addr"` // fee address on the side chain + SideChainId string `json:"side_chain_id"` // side chain id to distinguish different side chains + SideConsAddr []byte `json:"side_cons_addr"` // consensus address of the side chain validator, this replaces the `ConsPubKey` + SideFeeAddr []byte `json:"side_fee_addr"` // fee address on the side chain + + StakeSnapshots []Dec `json:"stake_snapshots"` // staked tokens snapshot over a period of time, e.g. 30 days + AccumulatedStake Dec `json:"accumulated_stake"` // accumulated stake, sum of StakeSnapshots } type UnbondingDelegation struct { @@ -327,9 +330,8 @@ func (ca ConsAddress) Format(s fmt.State, verb rune) { } } - func NewBaseParams(sideChainId string) BaseParams { - return BaseParams{SideChainId:sideChainId} + return BaseParams{SideChainId: sideChainId} } type QueryTopValidatorsParams struct { @@ -351,4 +353,4 @@ type QueryValidatorParams struct { type Pool struct { LooseTokens Dec `json:"loose_tokens"` // tokens which are not bonded in a validator BondedTokens Dec `json:"bonded_tokens"` // reserve of bonded tokens -} \ No newline at end of file +} diff --git a/go.mod b/go.mod index 4b9e8955..ba870928 100644 --- a/go.mod +++ b/go.mod @@ -1,32 +1,57 @@ module github.com/binance-chain/go-sdk +go 1.17 + require ( github.com/binance-chain/ledger-cosmos-go v0.9.9-binance.1 github.com/btcsuite/btcd v0.20.1-beta github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d - github.com/go-kit/kit v0.8.0 // indirect github.com/gorilla/websocket v1.4.1-0.20190629185528-ae1634f6a989 - github.com/kr/pretty v0.1.0 // indirect github.com/pkg/errors v0.8.1 - github.com/prometheus/client_golang v0.9.2 // indirect - github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect github.com/stretchr/testify v1.4.0 - github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d // indirect github.com/tendermint/btcd v0.0.0-20180816174608-e5840949ff4f github.com/tendermint/go-amino v0.14.1 github.com/tendermint/tendermint v0.32.3 + golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 + gopkg.in/resty.v1 v1.10.3 +) + +require ( + github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/etcd-io/bbolt v1.3.3 // indirect + github.com/go-kit/kit v0.8.0 // indirect + github.com/go-logfmt/logfmt v0.3.0 // indirect + github.com/gogo/protobuf v1.2.1 // indirect + github.com/golang/protobuf v1.3.2 // indirect + github.com/golang/snappy v0.0.1 // indirect + github.com/jmhodges/levigo v1.0.0 // indirect + github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect + github.com/kr/pretty v0.1.0 // indirect + github.com/libp2p/go-buffer-pool v0.0.1 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_golang v0.9.2 // indirect + github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect + github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 // indirect + github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a // indirect + github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect + github.com/rs/cors v1.6.0 // indirect + github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d // indirect + github.com/tendermint/tm-db v0.1.1 // indirect github.com/zondax/hid v0.9.0 // indirect github.com/zondax/ledger-go v0.9.0 // indirect - golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 + golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect golang.org/x/text v0.3.2 // indirect + google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2 // indirect + google.golang.org/grpc v1.22.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/resty.v1 v1.10.3 + gopkg.in/yaml.v2 v2.2.2 // indirect ) -replace github.com/tendermint/go-amino => github.com/binance-chain/bnc-go-amino v0.14.1-binance.1 - -replace github.com/zondax/ledger-go => github.com/binance-chain/ledger-go v0.9.1 - -go 1.13 +replace ( + github.com/tendermint/go-amino => github.com/binance-chain/bnc-go-amino v0.14.1-binance.1 + github.com/zondax/ledger-go => github.com/binance-chain/ledger-go v0.9.1 +) diff --git a/go.sum b/go.sum index e430e3b7..9ada1c88 100644 --- a/go.sum +++ b/go.sum @@ -15,7 +15,6 @@ github.com/btcsuite/btcd v0.0.0-20190115013929-ed77733ec07d/go.mod h1:d3C0AkH6BR github.com/btcsuite/btcd v0.20.1-beta h1:Ik4hyJqN8Jfyv3S4AGBOmyouMsYE3EdYODkMbQjwPGw= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= -github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a h1:RQMUrEILyYJEoAT34XS/kLu40vC0+po/UfxrBBA4qZE= github.com/btcsuite/btcutil v0.0.0-20180706230648-ab6388e0c60a/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d h1:yJzD/yFppdVCf6ApMkVy8cUxV0XrxdP9rVf6D87/Mng= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= @@ -35,7 +34,6 @@ github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM= github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw= github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q= github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-kit/kit v0.6.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0= @@ -49,7 +47,6 @@ github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zV github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -120,13 +117,10 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 h1:1oFLiOyVl+W7bnBzGhf7BbIv9loSFQcieWWYIjLqcAw= github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d h1:gZZadD8H+fF+n9CmNhYL1Y0dJB+kLOmKd7FbPJLeGHs= github.com/syndtr/goleveldb v1.0.1-0.20190923125748-758128399b1d/go.mod h1:9OrXJhf154huy1nPWmuSrkgjPUtUNhA+Zmy+6AESzuA= @@ -149,7 +143,6 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -159,11 +152,9 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI= golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -172,13 +163,11 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2 h1:67iHsV9djwGdZpdZNbLuQj6FOzCaZe3w+vhLjn5AcFA= google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.22.0 h1:J0UbZOIrCAl+fpTOf8YLs4dJo8L/owV4LYVtAXQoPkw= google.golang.org/grpc v1.22.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -188,7 +177,6 @@ gopkg.in/resty.v1 v1.10.3 h1:w8FjChB7PWrvE5z6JX/gfFzVwTDj38qiAQJKgdWDGvA= gopkg.in/resty.v1 v1.10.3/go.mod h1:nrgQYbPhkRfn2BfT32NNTLfq3K9NuHRB0MsAcA9weWY= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/types/msg/msg-sidechain-stake.go b/types/msg/msg-sidechain-stake.go index 2d18fbd6..a31ab282 100644 --- a/types/msg/msg-sidechain-stake.go +++ b/types/msg/msg-sidechain-stake.go @@ -131,17 +131,19 @@ type EditSideChainValidatorMsg struct { CommissionRate *types.Dec `json:"commission_rate"` - SideChainId string `json:"side_chain_id"` - SideFeeAddr []byte `json:"side_fee_addr"` + SideChainId string `json:"side_chain_id"` + SideFeeAddr []byte `json:"side_fee_addr"` + SideConsAddr []byte `json:"side_cons_addr,omitempty"` } -func NewEditSideChainValidatorMsg(sideChainId string, validatorAddr types.ValAddress, description Description, commissionRate *types.Dec, sideFeeAddr []byte) EditSideChainValidatorMsg { +func NewEditSideChainValidatorMsg(sideChainId string, validatorAddr types.ValAddress, description Description, commissionRate *types.Dec, sideFeeAddr, sideConsAddr []byte) EditSideChainValidatorMsg { return EditSideChainValidatorMsg{ Description: description, ValidatorAddr: validatorAddr, CommissionRate: commissionRate, SideChainId: sideChainId, SideFeeAddr: sideFeeAddr, + SideConsAddr: sideConsAddr, } } @@ -184,9 +186,16 @@ func (msg EditSideChainValidatorMsg) ValidateBasic() error { return fmt.Errorf("side chain id must be included and max length is %d bytes", MaxSideChainIdLength) } - //sideFeeAddr length should between 16 - 64 - if err := checkSideChainAddr("SideFeeAddr", msg.SideFeeAddr); err != nil { - return err + if len(msg.SideFeeAddr) != 0 { + if err := checkSideChainAddr("SideFeeAddr", msg.SideFeeAddr); err != nil { + return err + } + } + + if len(msg.SideConsAddr) != 0 { + if err := checkSideChainAddr("SideConsAddr", msg.SideConsAddr); err != nil { + return err + } } return nil diff --git a/types/msg/msg-unjail.go b/types/msg/msg-unjail.go new file mode 100644 index 00000000..769463d4 --- /dev/null +++ b/types/msg/msg-unjail.go @@ -0,0 +1,52 @@ +package msg + +import ( + "fmt" + sdk "github.com/binance-chain/go-sdk/common/types" +) + +// name to identify transaction types +const ( + TypeMsgUnjail = "unjail" + SlashMsgRoute = "slashing" +) + +// MsgUnjail - struct for unjailing jailed validator +type MsgUnjail struct { + ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator operator +} + +func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail { + return MsgUnjail{ + ValidatorAddr: validatorAddr, + } +} + +//nolint +func (msg MsgUnjail) Route() string { return SlashMsgRoute } +func (msg MsgUnjail) Type() string { return TypeMsgUnjail } +func (msg MsgUnjail) GetSigners() []sdk.AccAddress { + res := []sdk.AccAddress{sdk.AccAddress(msg.ValidatorAddr)} + fmt.Printf("MsgUnjail.GetSigners: %+v\n", res) + return res +} + +// get the bytes for the message signer to sign on +func (msg MsgUnjail) GetSignBytes() []byte { + b := MsgCdc.MustMarshalJSON(msg) + res := MustSortJSON(b) + fmt.Printf("MsgUnjail.GetSignBytes: %X\n", res) + return res +} + +// quick validity check +func (msg MsgUnjail) ValidateBasic() error { + if len(msg.ValidatorAddr) != sdk.AddrLen { + return fmt.Errorf("validator does not exist for that address") + } + return nil +} + +func (msg MsgUnjail) GetInvolvedAddresses() []sdk.AccAddress { + return msg.GetSigners() +} diff --git a/types/msg/msg-validator.go b/types/msg/msg-validator.go index 88ec5da4..1bc05d14 100644 --- a/types/msg/msg-validator.go +++ b/types/msg/msg-validator.go @@ -5,7 +5,6 @@ import ( "fmt" "github.com/binance-chain/go-sdk/common/types" - "github.com/tendermint/tendermint/crypto" ) // Description - description fields for a validator @@ -34,26 +33,20 @@ func (d Description) EnsureLength() (Description, error) { return d, nil } -// MsgCreateValidator - struct for bonding transactions -type MsgCreateValidator struct { - Description Description - Commission types.CommissionMsg - DelegatorAddr types.AccAddress `json:"delegator_address"` - ValidatorAddr types.ValAddress `json:"validator_address"` - PubKey crypto.PubKey `json:"pubkey"` - Delegation types.Coin `json:"delegation"` -} - -type MsgCreateValidatorProposal struct { - MsgCreateValidator - ProposalId int64 `json:"proposal_id"` +type MsgCreateValidatorOpen struct { + Description Description `json:"description"` + Commission types.CommissionMsg `json:"commission"` + DelegatorAddr types.AccAddress `json:"delegator_address"` + ValidatorAddr types.ValAddress `json:"validator_address"` + PubKey string `json:"pubkey"` + Delegation types.Coin `json:"delegation"` } -func (msg MsgCreateValidator) Route() string { return MsgRoute } -func (msg MsgCreateValidator) Type() string { return "create_validator" } +func (msg MsgCreateValidatorOpen) Route() string { return MsgRoute } +func (msg MsgCreateValidatorOpen) Type() string { return "create_validator_open" } // Return address(es) that must sign over msg.GetSignBytes() -func (msg MsgCreateValidator) GetSigners() []types.AccAddress { +func (msg MsgCreateValidatorOpen) GetSigners() []types.AccAddress { // delegator is first signer so delegator pays fees addrs := []types.AccAddress{msg.DelegatorAddr} @@ -66,39 +59,25 @@ func (msg MsgCreateValidator) GetSigners() []types.AccAddress { } // get the bytes for the message signer to sign on -func (msg MsgCreateValidator) GetSignBytes() []byte { - b, err := MsgCdc.MarshalJSON(struct { - Description - DelegatorAddr types.AccAddress `json:"delegator_address"` - ValidatorAddr types.ValAddress `json:"validator_address"` - PubKey string `json:"pubkey"` - Delegation types.Coin `json:"delegation"` - }{ - Description: msg.Description, - ValidatorAddr: msg.ValidatorAddr, - PubKey: types.MustBech32ifyConsPub(msg.PubKey), - Delegation: msg.Delegation, - }) - if err != nil { - panic(err) - } +func (msg MsgCreateValidatorOpen) GetSignBytes() []byte { + b := MsgCdc.MustMarshalJSON(msg) return MustSortJSON(b) } -func (msg MsgCreateValidator) GetInvolvedAddresses() []types.AccAddress { +func (msg MsgCreateValidatorOpen) GetInvolvedAddresses() []types.AccAddress { return msg.GetSigners() } // quick validity check -func (msg MsgCreateValidator) ValidateBasic() error { +func (msg MsgCreateValidatorOpen) ValidateBasic() error { if len(msg.DelegatorAddr) != types.AddrLen { return fmt.Errorf("Expected delegator address length is %d, actual length is %d", types.AddrLen, len(msg.DelegatorAddr)) } if len(msg.ValidatorAddr) != types.AddrLen { return fmt.Errorf("Expected validator address length is %d, actual length is %d", types.AddrLen, len(msg.ValidatorAddr)) } - if !(msg.Delegation.Amount > 0) { - return fmt.Errorf("DelegationAmount %d is invalid", msg.Delegation.Amount) + if msg.Delegation.Amount < 1e8 { + return fmt.Errorf("self delegation must not be less than 1e8") } if msg.Description == (Description{}) { return fmt.Errorf("description must be included") @@ -177,3 +156,169 @@ func (msg MsgRemoveValidator) ValidateBasic() error { func (msg MsgRemoveValidator) GetInvolvedAddresses() []types.AccAddress { return []types.AccAddress{msg.LauncherAddr} } + +// MsgEditValidator - struct for editing a validator +type MsgEditValidator struct { + Description Description `json:"description"` + ValidatorAddr types.ValAddress `json:"address"` + // We pass a reference to the new commission rate as it's not mandatory to + // update. If not updated, the deserialized rate will be zero with no way to + // distinguish if an update was intended. + CommissionRate *types.Dec `json:"commission_rate"` + PubKey string `json:"pubkey"` +} + +//nolint +func (msg MsgEditValidator) Route() string { return MsgRoute } +func (msg MsgEditValidator) Type() string { return "edit_validator" } +func (msg MsgEditValidator) GetSigners() []types.AccAddress { + return []types.AccAddress{types.AccAddress(msg.ValidatorAddr)} +} + +// get the bytes for the message signer to sign on +func (msg MsgEditValidator) GetSignBytes() []byte { + bz := MsgCdc.MustMarshalJSON(msg) + return MustSortJSON(bz) +} + +// quick validity check +func (msg MsgEditValidator) ValidateBasic() error { + if msg.ValidatorAddr == nil { + return fmt.Errorf("nil validator address") + } + + if msg.Description == (Description{}) { + return fmt.Errorf("transaction must include some information to modify") + } + + if msg.PubKey != "" { + if _, err := types.GetConsPubKeyBech32(msg.PubKey); err != nil { + return fmt.Errorf("invalid PubKey: %v", err) + } + } + + return nil +} + +func (msg MsgEditValidator) GetInvolvedAddresses() []types.AccAddress { + return msg.GetSigners() +} + +//______________________________________________________________________ + +// MsgDelegate - struct for bonding transactions +type MsgDelegate struct { + DelegatorAddr types.AccAddress `json:"delegator_addr"` + ValidatorAddr types.ValAddress `json:"validator_addr"` + Delegation types.Coin `json:"delegation"` +} + +//nolint +func (msg MsgDelegate) Route() string { return MsgRoute } +func (msg MsgDelegate) Type() string { return "delegate" } +func (msg MsgDelegate) GetSigners() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr} +} + +// get the bytes for the message signer to sign on +func (msg MsgDelegate) GetSignBytes() []byte { + bz := MsgCdc.MustMarshalJSON(msg) + return MustSortJSON(bz) +} + +// quick validity check +func (msg MsgDelegate) ValidateBasic() error { + if msg.DelegatorAddr == nil { + return fmt.Errorf("delegator address is nil") + } + if msg.ValidatorAddr == nil { + return fmt.Errorf("validator address is nil") + } + if msg.Delegation.Amount < 1e8 { + return fmt.Errorf("delegation amount should not be less than 1e8") + } + return nil +} + +func (msg MsgDelegate) GetInvolvedAddresses() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr, types.AccAddress(msg.ValidatorAddr)} +} + +// MsgDelegate - struct for bonding transactions +type MsgRedelegate struct { + DelegatorAddr types.AccAddress `json:"delegator_addr"` + ValidatorSrcAddr types.ValAddress `json:"validator_src_addr"` + ValidatorDstAddr types.ValAddress `json:"validator_dst_addr"` + Amount types.Coin `json:"amount"` +} + +//nolint +func (msg MsgRedelegate) Route() string { return MsgRoute } +func (msg MsgRedelegate) Type() string { return "redelegate" } +func (msg MsgRedelegate) GetSigners() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr} +} + +// get the bytes for the message signer to sign on +func (msg MsgRedelegate) GetSignBytes() []byte { + bz := MsgCdc.MustMarshalJSON(msg) + return MustSortJSON(bz) +} + +func (msg MsgRedelegate) GetInvolvedAddresses() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr, types.AccAddress(msg.ValidatorSrcAddr), types.AccAddress(msg.DelegatorAddr)} +} + +// ValidateBasic is used to quickly disqualify obviously invalid messages quickly +func (msg MsgRedelegate) ValidateBasic() error { + if len(msg.DelegatorAddr) != types.AddrLen { + return fmt.Errorf("Expected delegator address length is %d, actual length is %d", types.AddrLen, len(msg.DelegatorAddr)) + } + if len(msg.ValidatorSrcAddr) != types.AddrLen { + return fmt.Errorf("Expected validator source address length is %d, actual length is %d", types.AddrLen, len(msg.ValidatorSrcAddr)) + } + if len(msg.ValidatorDstAddr) != types.AddrLen { + return fmt.Errorf("Expected validator destination address length is %d, actual length is %d", types.AddrLen, len(msg.ValidatorDstAddr)) + } + if msg.Amount.Amount <= 0 { + return fmt.Errorf("Expected positive amount, actual amount is %v", msg.Amount.Amount) + } + return nil +} + +type MsgUndelegate struct { + DelegatorAddr types.AccAddress `json:"delegator_addr"` + ValidatorAddr types.ValAddress `json:"validator_addr"` + Amount types.Coin `json:"amount"` +} + +//nolint +func (msg MsgUndelegate) Route() string { return MsgRoute } +func (msg MsgUndelegate) Type() string { return "undelegate" } +func (msg MsgUndelegate) GetSigners() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr} +} + +// get the bytes for the message signer to sign on +func (msg MsgUndelegate) GetSignBytes() []byte { + bz := MsgCdc.MustMarshalJSON(msg) + return MustSortJSON(bz) +} + +// quick validity check +func (msg MsgUndelegate) ValidateBasic() error { + if len(msg.DelegatorAddr) != types.AddrLen { + return fmt.Errorf("Expected delegator address length is %d, actual length is %d", types.AddrLen, len(msg.DelegatorAddr)) + } + if len(msg.ValidatorAddr) != types.AddrLen { + return fmt.Errorf("Expected validator address length is %d, actual length is %d", types.AddrLen, len(msg.ValidatorAddr)) + } + if msg.Amount.Amount <= 0 { + return fmt.Errorf("undelegation amount must be positive: %d", msg.Amount.Amount) + } + return nil +} + +func (msg MsgUndelegate) GetInvolvedAddresses() []types.AccAddress { + return []types.AccAddress{msg.DelegatorAddr, types.AccAddress(msg.ValidatorAddr)} +} diff --git a/types/msg/msg.go b/types/msg/msg.go index 09df69fa..e04c4852 100644 --- a/types/msg/msg.go +++ b/types/msg/msg.go @@ -242,6 +242,11 @@ func (dbProphecy DBProphecy) DeserializeFromDB() (Prophecy, error) { }, nil } +type OracleRelayer struct { + Address types.ValAddress `json:"address"` + Power int64 `json:"power"` +} + //Validate and check if it's mini token func IsValidMiniTokenSymbol(symbol string) bool { return ValidateMiniTokenSymbol(symbol) == nil diff --git a/types/msg/wire.go b/types/msg/wire.go index e12a3d08..822e63e1 100644 --- a/types/msg/wire.go +++ b/types/msg/wire.go @@ -49,9 +49,12 @@ func RegisterCodec(cdc *amino.Codec) { cdc.RegisterConcrete(SetAccountFlagsMsg{}, "scripts/SetAccountFlagsMsg", nil) - cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil) + cdc.RegisterConcrete(MsgCreateValidatorOpen{}, "cosmos-sdk/MsgCreateValidatorOpen", nil) cdc.RegisterConcrete(MsgRemoveValidator{}, "cosmos-sdk/MsgRemoveValidator", nil) - cdc.RegisterConcrete(MsgCreateValidatorProposal{}, "cosmos-sdk/MsgCreateValidatorProposal", nil) + cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil) + cdc.RegisterConcrete(MsgDelegate{}, "cosmos-sdk/MsgDelegate", nil) + cdc.RegisterConcrete(MsgRedelegate{}, "cosmos-sdk/MsgRedelegate", nil) + cdc.RegisterConcrete(MsgUndelegate{}, "cosmos-sdk/MsgUndelegate", nil) cdc.RegisterConcrete(CreateSideChainValidatorMsg{}, "cosmos-sdk/MsgCreateSideChainValidator", nil) cdc.RegisterConcrete(EditSideChainValidatorMsg{}, "cosmos-sdk/MsgEditSideChainValidator", nil) @@ -59,6 +62,7 @@ func RegisterCodec(cdc *amino.Codec) { cdc.RegisterConcrete(SideChainRedelegateMsg{}, "cosmos-sdk/MsgSideChainRedelegate", nil) cdc.RegisterConcrete(SideChainUndelegateMsg{}, "cosmos-sdk/MsgSideChainUndelegate", nil) cdc.RegisterConcrete(MsgSideChainUnjail{}, "cosmos-sdk/MsgSideChainUnjail", nil) + cdc.RegisterConcrete(MsgUnjail{}, "cosmos-sdk/MsgUnjail", nil) cdc.RegisterConcrete(BindMsg{}, "bridge/BindMsg", nil) cdc.RegisterConcrete(TransferOutMsg{}, "bridge/TransferOutMsg", nil)