2020-03-05 14:48:30 +00:00
|
|
|
package result
|
|
|
|
|
|
|
|
import (
|
2022-07-01 09:34:43 +00:00
|
|
|
"encoding/json"
|
|
|
|
|
2020-03-05 14:48:30 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
)
|
|
|
|
|
2022-07-01 09:34:43 +00:00
|
|
|
// Validator is used for the representation of consensus node data in the JSON-RPC
|
|
|
|
// protocol.
|
2020-03-05 14:48:30 +00:00
|
|
|
type Validator struct {
|
2022-07-01 09:34:43 +00:00
|
|
|
PublicKey keys.PublicKey `json:"publickey"`
|
|
|
|
Votes int64 `json:"votes"`
|
|
|
|
}
|
|
|
|
|
2022-07-01 13:02:03 +00:00
|
|
|
// Candidate represents a node participating in the governance elections, it's
|
|
|
|
// active when it's a validator (consensus node).
|
|
|
|
type Candidate struct {
|
|
|
|
PublicKey keys.PublicKey `json:"publickey"`
|
|
|
|
Votes int64 `json:"votes,string"`
|
|
|
|
Active bool `json:"active"`
|
|
|
|
}
|
|
|
|
|
2022-07-01 09:34:43 +00:00
|
|
|
type newValidator struct {
|
|
|
|
PublicKey keys.PublicKey `json:"publickey"`
|
|
|
|
Votes int64 `json:"votes"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type oldValidator struct {
|
2020-03-05 14:48:30 +00:00
|
|
|
PublicKey keys.PublicKey `json:"publickey"`
|
2020-04-26 17:04:16 +00:00
|
|
|
Votes int64 `json:"votes,string"`
|
2022-07-01 09:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
|
|
|
func (v *Validator) UnmarshalJSON(data []byte) error {
|
|
|
|
var nv = new(newValidator)
|
|
|
|
err := json.Unmarshal(data, nv)
|
|
|
|
if err != nil {
|
|
|
|
var ov = new(oldValidator)
|
|
|
|
err := json.Unmarshal(data, ov)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
v.PublicKey = ov.PublicKey
|
|
|
|
v.Votes = ov.Votes
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
v.PublicKey = nv.PublicKey
|
|
|
|
v.Votes = nv.Votes
|
|
|
|
return nil
|
2020-03-05 14:48:30 +00:00
|
|
|
}
|