add StakeMsg interface to deep copy

pull/1841/head
Chao Ma 5 years ago
parent 2586f16899
commit 4a185825a5
  1. 65
      staking/types/messages.go
  2. 4
      staking/types/transaction.go

@ -14,6 +14,12 @@ import (
// Directive says what kind of payload follows // Directive says what kind of payload follows
type Directive byte type Directive byte
// StakeMsg defines the interface of Stake Message
type StakeMsg interface {
Type() Directive
Copy() StakeMsg
}
const ( const (
// DirectiveCreateValidator ... // DirectiveCreateValidator ...
DirectiveCreateValidator Directive = iota DirectiveCreateValidator Directive = iota
@ -86,3 +92,62 @@ type Undelegate struct {
type CollectRewards struct { type CollectRewards struct {
DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"` DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"`
} }
// Type of CreateValidator
func (v CreateValidator) Type() Directive {
return DirectiveCreateValidator
}
// Type of EditValidator
func (v EditValidator) Type() Directive {
return DirectiveEditValidator
}
// Type of Delegate
func (v Delegate) Type() Directive {
return DirectiveCreateValidator
}
// Type of Undelegate
func (v Undelegate) Type() Directive {
return DirectiveUndelegate
}
// Type of CollectRewards
func (v CollectRewards) Type() Directive {
return DirectiveCollectRewards
}
// Copy deep copy of the interface
func (v CreateValidator) Copy() StakeMsg {
v1 := v
desc := *v.Description
v1.Description = &desc
return v1
}
// Copy deep copy of the interface
func (v EditValidator) Copy() StakeMsg {
v1 := v
desc := *v.Description
v1.Description = &desc
return v1
}
// Copy deep copy of the interface
func (v Delegate) Copy() StakeMsg {
v1 := v
return v1
}
// Copy deep copy of the interface
func (v Undelegate) Copy() StakeMsg {
v1 := v
return v1
}
// Copy deep copy of the interface
func (v CollectRewards) Copy() StakeMsg {
v1 := v
return v1
}

@ -30,11 +30,11 @@ type txdata struct {
} }
func (d *txdata) CopyFrom(d2 *txdata) { func (d *txdata) CopyFrom(d2 *txdata) {
d.Directive = d2.Directive
d.AccountNonce = d2.AccountNonce d.AccountNonce = d2.AccountNonce
d.Price = new(big.Int).Set(d2.Price) d.Price = new(big.Int).Set(d2.Price)
d.GasLimit = d2.GasLimit d.GasLimit = d2.GasLimit
d.StakeMsg = d2.StakeMsg // TODO: add code to protect crashing
d.StakeMsg = d2.StakeMsg.(StakeMsg).Copy()
d.V = new(big.Int).Set(d2.V) d.V = new(big.Int).Set(d2.V)
d.R = new(big.Int).Set(d2.R) d.R = new(big.Int).Set(d2.R)
d.S = new(big.Int).Set(d2.S) d.S = new(big.Int).Set(d2.S)

Loading…
Cancel
Save