-
Notifications
You must be signed in to change notification settings - Fork 175
/
execution_state.go
70 lines (56 loc) · 2.21 KB
/
execution_state.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
62
63
64
65
66
67
68
69
70
package unittest
import (
"encoding/hex"
"fmt"
"github.com/onflow/flow-go/crypto"
"github.com/onflow/flow-go/crypto/hash"
"github.com/onflow/cadence"
"github.com/onflow/flow-go/model/flow"
)
// Used below with random service key
// privateKey := flow.AccountPrivateKey{
// PrivateKey: rootKey,
// SignAlgo: crypto.ECDSAP256,
// HashAlgo: hash.SHA2_256,
// }
const ServiceAccountPrivateKeyHex = "8ae3d0461cfed6d6f49bfc25fa899351c39d1bd21fdba8c87595b6c49bb4cc43"
const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256
// Pre-calculated state commitment with root account with the above private key
const GenesisStateCommitmentHex = "48bc690ac7ebf7cdb41df24c6f8ba011b206408623b6d56b3723910664cdb5aa"
var GenesisStateCommitment flow.StateCommitment
var GenesisTokenSupply = func() cadence.UFix64 {
// value, err := cadence.NewUFix64("10000000000.0") // 10 billion
value, err := cadence.NewUFix64("1000000000.0") // 1 billion
if err != nil {
panic(fmt.Errorf("invalid genesis token supply: %w", err))
}
return value
}()
var ServiceAccountPrivateKey flow.AccountPrivateKey
var ServiceAccountPublicKey flow.AccountPublicKey
func init() {
var err error
GenesisStateCommitmentBytes, err := hex.DecodeString(GenesisStateCommitmentHex)
if err != nil {
panic("error while hex decoding hardcoded state commitment")
}
GenesisStateCommitment, err = flow.ToStateCommitment(GenesisStateCommitmentBytes)
if err != nil {
panic("genesis state commitment size is invalid")
}
serviceAccountPrivateKeyBytes, err := hex.DecodeString(ServiceAccountPrivateKeyHex)
if err != nil {
panic("error while hex decoding hardcoded root key")
}
ServiceAccountPrivateKey.SignAlgo = ServiceAccountPrivateKeySignAlgo
ServiceAccountPrivateKey.HashAlgo = ServiceAccountPrivateKeyHashAlgo
ServiceAccountPrivateKey.PrivateKey, err = crypto.DecodePrivateKey(
ServiceAccountPrivateKey.SignAlgo, serviceAccountPrivateKeyBytes)
if err != nil {
panic("error while decoding hardcoded root key bytes")
}
// Cannot import virtual machine, due to circular dependency. Just use the value of
// fvm.AccountKeyWeightThreshold here
ServiceAccountPublicKey = ServiceAccountPrivateKey.PublicKey(1000)
}