Skip to content

Commit

Permalink
Add RemoveSubnetValidatorTx wallet example (ava-labs#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 16, 2023
1 parent eb265ae commit 459759d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions wallet/subnet/primary/examples/remove-subnet-validator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (C) 2019-2022, 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)
subnetIDStr := "29uVeLPJB1eQJkzRemU8g8wZDw5uJRqpab5U2mX9euieVwiEbL"
nodeIDStr := "NodeID-7Xhw2mDxuDS44j42TCB6U5579esbSt3Lg"

subnetID, err := ids.FromString(subnetIDStr)
if err != nil {
log.Fatalf("failed to parse subnet ID: %s\n", err)
}

nodeID, err := ids.NodeIDFromString(nodeIDStr)
if err != nil {
log.Fatalf("failed to parse node ID: %s\n", err)
}

ctx := context.Background()

// NewWalletWithTxs fetches the available UTXOs owned by [kc] on the network
// that [uri] is hosting and registers [subnetID].
walletSyncStartTime := time.Now()
wallet, err := primary.NewWalletWithTxs(ctx, uri, kc, subnetID)
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()

removeValidatorStartTime := time.Now()
removeValidatorTxID, err := pWallet.IssueRemoveSubnetValidatorTx(
nodeID,
subnetID,
)
if err != nil {
log.Fatalf("failed to issue remove subnet validator transaction: %s\n", err)
}
log.Printf("removed subnet validator %s from %s with %s in %s\n", nodeID, subnetID, removeValidatorTxID, time.Since(removeValidatorStartTime))
}

0 comments on commit 459759d

Please sign in to comment.