-
Notifications
You must be signed in to change notification settings - Fork 646
/
main.go
51 lines (42 loc) · 1.33 KB
/
main.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
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"context"
"log"
"time"
"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
)
func main() {
key := genesis.EWOQKey
uri := primary.LocalAPIURI
kc := secp256k1fx.NewKeychain(key)
subnetOwner := key.Address()
ctx := context.Background()
// NewWalletFromURI fetches the available UTXOs owned by [kc] on the network
// that [uri] is hosting.
walletSyncStartTime := time.Now()
wallet, err := primary.NewWalletFromURI(ctx, uri, kc)
if err != nil {
log.Fatalf("failed to initialize wallet: %s\n", err)
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))
// Get the P-chain wallet
pWallet := wallet.P()
// Pull out useful constants to use when issuing transactions.
owner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
subnetOwner,
},
}
createSubnetStartTime := time.Now()
createSubnetTxID, err := pWallet.IssueCreateSubnetTx(owner)
if err != nil {
log.Fatalf("failed to issue create subnet transaction: %s\n", err)
}
log.Printf("created new subnet %s in %s\n", createSubnetTxID, time.Since(createSubnetStartTime))
}