-
Notifications
You must be signed in to change notification settings - Fork 664
/
context.go
82 lines (71 loc) · 2.45 KB
/
context.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
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package builder
import (
"context"
"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/avm"
)
const Alias = "P"
type Context struct {
NetworkID uint32
AVAXAssetID ids.ID
BaseTxFee uint64
CreateSubnetTxFee uint64
TransformSubnetTxFee uint64
CreateBlockchainTxFee uint64
AddPrimaryNetworkValidatorFee uint64
AddPrimaryNetworkDelegatorFee uint64
AddSubnetValidatorFee uint64
AddSubnetDelegatorFee uint64
}
func NewContextFromURI(ctx context.Context, uri string) (*Context, error) {
infoClient := info.NewClient(uri)
xChainClient := avm.NewClient(uri, "X")
return NewContextFromClients(ctx, infoClient, xChainClient)
}
func NewContextFromClients(
ctx context.Context,
infoClient info.Client,
xChainClient avm.Client,
) (*Context, error) {
networkID, err := infoClient.GetNetworkID(ctx)
if err != nil {
return nil, err
}
asset, err := xChainClient.GetAssetDescription(ctx, "AVAX")
if err != nil {
return nil, err
}
txFees, err := infoClient.GetTxFee(ctx)
if err != nil {
return nil, err
}
return &Context{
NetworkID: networkID,
AVAXAssetID: asset.AssetID,
BaseTxFee: uint64(txFees.TxFee),
CreateSubnetTxFee: uint64(txFees.CreateSubnetTxFee),
TransformSubnetTxFee: uint64(txFees.TransformSubnetTxFee),
CreateBlockchainTxFee: uint64(txFees.CreateBlockchainTxFee),
AddPrimaryNetworkValidatorFee: uint64(txFees.AddPrimaryNetworkValidatorFee),
AddPrimaryNetworkDelegatorFee: uint64(txFees.AddPrimaryNetworkDelegatorFee),
AddSubnetValidatorFee: uint64(txFees.AddSubnetValidatorFee),
AddSubnetDelegatorFee: uint64(txFees.AddSubnetDelegatorFee),
}, nil
}
func NewSnowContext(networkID uint32, avaxAssetID ids.ID) (*snow.Context, error) {
lookup := ids.NewAliaser()
return &snow.Context{
NetworkID: networkID,
SubnetID: constants.PrimaryNetworkID,
ChainID: constants.PlatformChainID,
AVAXAssetID: avaxAssetID,
Log: logging.NoLog{},
BCLookup: lookup,
}, lookup.Alias(constants.PlatformChainID, Alias)
}