github.com/MetalBlockchain/metalgo@v1.11.9/wallet/subnet/primary/examples/remove-subnet-validator/main.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package main 5 6 import ( 7 "context" 8 "log" 9 "time" 10 11 "github.com/MetalBlockchain/metalgo/genesis" 12 "github.com/MetalBlockchain/metalgo/ids" 13 "github.com/MetalBlockchain/metalgo/utils/set" 14 "github.com/MetalBlockchain/metalgo/vms/secp256k1fx" 15 "github.com/MetalBlockchain/metalgo/wallet/subnet/primary" 16 ) 17 18 func main() { 19 key := genesis.EWOQKey 20 uri := primary.LocalAPIURI 21 kc := secp256k1fx.NewKeychain(key) 22 subnetIDStr := "29uVeLPJB1eQJkzRemU8g8wZDw5uJRqpab5U2mX9euieVwiEbL" 23 nodeIDStr := "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg" 24 25 subnetID, err := ids.FromString(subnetIDStr) 26 if err != nil { 27 log.Fatalf("failed to parse subnet ID: %s\n", err) 28 } 29 30 nodeID, err := ids.NodeIDFromString(nodeIDStr) 31 if err != nil { 32 log.Fatalf("failed to parse node ID: %s\n", err) 33 } 34 35 ctx := context.Background() 36 37 // MakeWallet fetches the available UTXOs owned by [kc] on the network that 38 // [uri] is hosting and registers [subnetID]. 39 walletSyncStartTime := time.Now() 40 wallet, err := primary.MakeWallet(ctx, &primary.WalletConfig{ 41 URI: uri, 42 AVAXKeychain: kc, 43 EthKeychain: kc, 44 PChainTxsToFetch: set.Of(subnetID), 45 }) 46 if err != nil { 47 log.Fatalf("failed to initialize wallet: %s\n", err) 48 } 49 log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime)) 50 51 // Get the P-chain wallet 52 pWallet := wallet.P() 53 54 removeValidatorStartTime := time.Now() 55 removeValidatorTx, err := pWallet.IssueRemoveSubnetValidatorTx( 56 nodeID, 57 subnetID, 58 ) 59 if err != nil { 60 log.Fatalf("failed to issue remove subnet validator transaction: %s\n", err) 61 } 62 log.Printf("removed subnet validator %s from %s with %s in %s\n", nodeID, subnetID, removeValidatorTx.ID(), time.Since(removeValidatorStartTime)) 63 }