// Code generated by github.com/fjl/gencodec. DO NOT EDIT.

package core

import (
	"encoding/json"
	"errors"
	"math/big"

	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/common/math"
)

var _ = (*validatorInfoMarshaling)(nil)

// MarshalJSON marshals as JSON.
func (v ValidatorInfo) MarshalJSON() ([]byte, error) {
	type ValidatorInfo struct {
		Address          common.Address        `json:"address"         gencodec:"required"`
		Manager          common.Address        `json:"manager"         gencodec:"required"`
		Rate             *math.HexOrDecimal256 `json:"rate,omitempty"`
		AcceptDelegation bool                  `json:"acceptDelegation,omitempty"`
	}
	var enc ValidatorInfo
	enc.Address = v.Address
	enc.Manager = v.Manager
	enc.Rate = (*math.HexOrDecimal256)(v.Rate)
	enc.AcceptDelegation = v.AcceptDelegation
	return json.Marshal(&enc)
}

// UnmarshalJSON unmarshals from JSON.
func (v *ValidatorInfo) UnmarshalJSON(input []byte) error {
	type ValidatorInfo struct {
		Address          *common.Address       `json:"address"         gencodec:"required"`
		Manager          *common.Address       `json:"manager"         gencodec:"required"`
		Rate             *math.HexOrDecimal256 `json:"rate,omitempty"`
		AcceptDelegation *bool                 `json:"acceptDelegation,omitempty"`
	}
	var dec ValidatorInfo
	if err := json.Unmarshal(input, &dec); err != nil {
		return err
	}
	if dec.Address == nil {
		return errors.New("missing required field 'address' for ValidatorInfo")
	}
	v.Address = *dec.Address
	if dec.Manager == nil {
		return errors.New("missing required field 'manager' for ValidatorInfo")
	}
	v.Manager = *dec.Manager
	if dec.Rate != nil {
		v.Rate = (*big.Int)(dec.Rate)
	}
	if dec.AcceptDelegation != nil {
		v.AcceptDelegation = *dec.AcceptDelegation
	}
	return nil
}
