-
Notifications
You must be signed in to change notification settings - Fork 247
/
genesis.go
55 lines (47 loc) · 1.28 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
// Copyright (c) 2018 The VeChainThor developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package genesis
import (
"github.com/vechain/thor/abi"
"github.com/vechain/thor/block"
"github.com/vechain/thor/state"
"github.com/vechain/thor/thor"
"github.com/vechain/thor/tx"
)
// Genesis to build genesis block.
type Genesis struct {
builder *Builder
id thor.Bytes32
name string
}
// Build build the genesis block.
func (g *Genesis) Build(stater *state.Stater) (blk *block.Block, events tx.Events, transfers tx.Transfers, err error) {
block, events, transfers, err := g.builder.Build(stater)
if err != nil {
return nil, nil, nil, err
}
if block.Header().ID() != g.id {
panic("built genesis ID incorrect")
}
return block, events, transfers, nil
}
// ID returns genesis block ID.
func (g *Genesis) ID() thor.Bytes32 {
return g.id
}
// Name returns network name.
func (g *Genesis) Name() string {
return g.name
}
func mustEncodeInput(abi *abi.ABI, name string, args ...interface{}) []byte {
m, found := abi.MethodByName(name)
if !found {
panic("method not found")
}
data, err := m.EncodeInput(args...)
if err != nil {
panic(err)
}
return data
}