/
genesis.go
executable file
·61 lines (51 loc) · 1.53 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package types
import (
"errors"
"fmt"
ethcmn "github.com/ethereum/go-ethereum/common"
treasurenet "github.com/maoaixiao1314/treasureapp/types"
)
// Validate performs a basic validation of a GenesisAccount fields.
func (ga GenesisAccount) Validate() error {
if err := treasurenet.ValidateAddress(ga.Address); err != nil {
return err
}
if len(ethcmn.Hex2Bytes(ga.Code)) == 0 {
return errors.New("code cannot be empty")
}
return ga.Storage.Validate()
}
// DefaultGenesisState sets default evm genesis state with empty accounts and default params and
// chain config values.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Accounts: []GenesisAccount{},
TxsLogs: []TransactionLogs{},
Params: DefaultParams(),
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
seenAccounts := make(map[string]bool)
seenTxs := make(map[string]bool)
for _, acc := range gs.Accounts {
if seenAccounts[acc.Address] {
return fmt.Errorf("duplicated genesis account %s", acc.Address)
}
if err := acc.Validate(); err != nil {
return fmt.Errorf("invalid genesis account %s: %w", acc.Address, err)
}
seenAccounts[acc.Address] = true
}
for _, tx := range gs.TxsLogs {
if seenTxs[tx.Hash] {
return fmt.Errorf("duplicated logs from transaction %s", tx.Hash)
}
if err := tx.Validate(); err != nil {
return fmt.Errorf("invalid logs from transaction %s: %w", tx.Hash, err)
}
seenTxs[tx.Hash] = true
}
return gs.Params.Validate()
}