-
Notifications
You must be signed in to change notification settings - Fork 659
/
genesis.go
43 lines (38 loc) · 1.12 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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package genesis
import (
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
)
// UTXO adds messages to UTXOs
type UTXO struct {
avax.UTXO `serialize:"true"`
Message []byte `serialize:"true" json:"message"`
}
// Genesis represents a genesis state of the platform chain
type Genesis struct {
UTXOs []*UTXO `serialize:"true"`
Validators []*txs.Tx `serialize:"true"`
Chains []*txs.Tx `serialize:"true"`
Timestamp uint64 `serialize:"true"`
InitialSupply uint64 `serialize:"true"`
Message string `serialize:"true"`
}
func Parse(genesisBytes []byte) (*Genesis, error) {
gen := &Genesis{}
if _, err := Codec.Unmarshal(genesisBytes, gen); err != nil {
return nil, err
}
for _, tx := range gen.Validators {
if err := tx.Initialize(txs.GenesisCodec); err != nil {
return nil, err
}
}
for _, tx := range gen.Chains {
if err := tx.Initialize(txs.GenesisCodec); err != nil {
return nil, err
}
}
return gen, nil
}