-
Notifications
You must be signed in to change notification settings - Fork 670
/
genesis.go
37 lines (31 loc) · 973 Bytes
/
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
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/hashing"
"github.com/ava-labs/avalanchego/vms/example/xsvm/block"
)
type Genesis struct {
Timestamp int64 `serialize:"true" json:"timestamp"`
Allocations []Allocation `serialize:"true" json:"allocations"`
}
type Allocation struct {
Address ids.ShortID `serialize:"true" json:"address"`
Balance uint64 `serialize:"true" json:"balance"`
}
func Parse(bytes []byte) (*Genesis, error) {
genesis := &Genesis{}
_, err := Codec.Unmarshal(bytes, genesis)
return genesis, err
}
func Block(genesis *Genesis) (*block.Stateless, error) {
bytes, err := Codec.Marshal(CodecVersion, genesis)
if err != nil {
return nil, err
}
return &block.Stateless{
ParentID: hashing.ComputeHash256Array(bytes),
Timestamp: genesis.Timestamp,
}, nil
}