-
Notifications
You must be signed in to change notification settings - Fork 16
/
gen_genesis.go
46 lines (41 loc) · 1.08 KB
/
gen_genesis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Code generated by qitmeer/tools/ngen. DO NOT EDIT.
package types
import (
"encoding/json"
"errors"
)
var _ = (*genesisJSON)(nil)
// MarshalJSON marshals as JSON
func (g Genesis) MarshalJSON() ([]byte, error) {
type Genesis struct {
Config *Config `json:"config" required:"true"`
Nonce UInt64 `json:"nonce" required:"true" min:"1"`
}
var enc Genesis
enc.Config = g.Config
enc.Nonce = UInt64(g.Nonce)
return json.Marshal(&enc)
}
// UnmarshalJSON unmarshals from JSON
func (g *Genesis) UnmarshalJSON(input []byte) error {
type Genesis struct {
Config *Config `json:"config" required:"true"`
Nonce *UInt64 `json:"nonce" required:"true" min:"1"`
}
var dec Genesis
if err := json.Unmarshal(input, &dec); err != nil {
return err
}
if dec.Config == nil {
return errors.New("missing required field 'config' for Genesis")
}
g.Config = dec.Config
if dec.Nonce == nil {
return errors.New("missing required field 'nonce' for Genesis")
}
g.Nonce = uint64(*dec.Nonce)
if g.Nonce < 1 {
return errors.New("error field 'nonce' for Genesis, minimal is 1")
}
return nil
}