-
Notifications
You must be signed in to change notification settings - Fork 2
Convert Tx #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Convert Tx #179
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8a822fe
convert
sukantoraymond 9fd50ac
convert
sukantoraymond 56dd05a
convert subnet
sukantoraymond f469dd8
Merge branch 'create-chain' into convert-example
sukantoraymond 385bc79
register validator
sukantoraymond 2f13422
lint
sukantoraymond 6161d9a
Merge branch 'create-chain' into convert-example
sukantoraymond 4d79244
merge chain tx
sukantoraymond 4addd50
merge chain tx
sukantoraymond e3b52b2
merge chain tx
sukantoraymond 34d91b7
merge chain tx
sukantoraymond 1b4381d
lint
sukantoraymond c1b083e
lint
sukantoraymond 5e9270f
lint
sukantoraymond 029eef2
remove base params
sukantoraymond File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| //go:build convert_subnet | ||
| // +build convert_subnet | ||
|
|
||
| // Copyright (C) 2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/ava-labs/avalanche-tooling-sdk-go/network" | ||
| "github.com/ava-labs/avalanche-tooling-sdk-go/utils" | ||
| "github.com/ava-labs/avalanche-tooling-sdk-go/wallet/local" | ||
| "github.com/ava-labs/avalanche-tooling-sdk-go/wallet/types" | ||
|
|
||
| pchainTxs "github.com/ava-labs/avalanche-tooling-sdk-go/wallet/txs/p-chain" | ||
| avagoTxs "github.com/ava-labs/avalanchego/vms/platformvm/txs" | ||
| ) | ||
|
|
||
| func ConvertSubnet(subnetID, chainID string) error { | ||
| ctx, cancel := utils.GetTimedContext(120 * time.Second) | ||
| defer cancel() | ||
| network := network.FujiNetwork() | ||
|
|
||
| localWallet, err := local.NewLocalWallet() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create wallet: %w", err) | ||
| } | ||
|
|
||
| existingAccount, err := localWallet.ImportAccount("EXISTING_KEY_PATH") | ||
| if err != nil { | ||
| return fmt.Errorf("failed to ImportAccount: %w", err) | ||
| } | ||
|
|
||
| // Validator information | ||
| nodeIDStr := "NodeID-xxxxx" | ||
| BLSPublicKey := "0x....,." // Replace with actual BLS public key | ||
| BLSProofOfPossession := "0x....." // Replace with actual BLS proof of possession | ||
| ChangeOwnerAddr := "P-fujixxxx" | ||
| ValidatorManagerAddress := "0x0FEEDC0DE0000000000000000000000000000000" // default validator manager address | ||
| Weight := 100 // Validator weight | ||
| Balance := 1000000000 // Validator balance in nAVAX | ||
|
|
||
| bootstrapValidators := []*pchainTxs.ConvertSubnetToL1Validator{} | ||
| bootstrapValidator := &pchainTxs.ConvertSubnetToL1Validator{ | ||
| NodeID: nodeIDStr, | ||
| Weight: uint64(Weight), | ||
| Balance: uint64(Balance), | ||
| BLSPublicKey: BLSPublicKey, | ||
| BLSProofOfPossession: BLSProofOfPossession, | ||
| RemainingBalanceOwner: ChangeOwnerAddr, | ||
| } | ||
| bootstrapValidators = append(bootstrapValidators, bootstrapValidator) | ||
|
|
||
| convertSubnetParams := &pchainTxs.ConvertSubnetToL1TxParams{ | ||
| SubnetAuthKeys: []string{"P-fujixxxxxx"}, | ||
| SubnetID: subnetID, | ||
| // ChainID is Blockchain ID of the L1 where the validator manager contract is deployed. | ||
| ChainID: chainID, | ||
| // Validators are the initial set of L1 validators after the conversion. | ||
| Validators: bootstrapValidators, | ||
| Address: ValidatorManagerAddress, | ||
| } | ||
| buildTxParams := types.BuildTxParams{ | ||
| BaseParams: types.BaseParams{ | ||
| Account: *existingAccount, | ||
| Network: network, | ||
| }, | ||
| BuildTxInput: convertSubnetParams, | ||
| } | ||
| buildTxResult, err := localWallet.BuildTx(ctx, buildTxParams) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to BuildTx: %w", err) | ||
| } | ||
|
|
||
| signTxParams := types.SignTxParams{ | ||
| BaseParams: types.BaseParams{ | ||
| Account: *existingAccount, | ||
| Network: network, | ||
| }, | ||
| BuildTxResult: &buildTxResult, | ||
| } | ||
| signTxResult, err := localWallet.SignTx(ctx, signTxParams) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to signTx: %w", err) | ||
| } | ||
|
|
||
| sendTxParams := types.SendTxParams{ | ||
| BaseParams: types.BaseParams{ | ||
| Account: *existingAccount, | ||
| Network: network, | ||
| }, | ||
| SignTxResult: &signTxResult, | ||
| } | ||
| sendTxResult, err := localWallet.SendTx(ctx, sendTxParams) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to sendTx: %w", err) | ||
| } | ||
| if tx := sendTxResult.GetTx(); tx != nil { | ||
| if pChainTx, ok := tx.(*avagoTxs.Tx); ok { | ||
| fmt.Printf("sendTxResult %s \n", pChainTx.ID()) | ||
| } else { | ||
| fmt.Printf("sendTxResult %s transaction \n", sendTxResult.GetChainType()) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func main() { | ||
| // Use a hardcoded subnet ID & chain ID for this example | ||
| // In a real scenario, you would get this from creating a subnet & creating a blockchain first | ||
| subnetID := "SUBNET_ID" | ||
| chainID := "CHAIN_ID" | ||
| if err := ConvertSubnet(subnetID, chainID); err != nil { | ||
| fmt.Println(err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove BaseParams