-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add pchain client wrapper with options #568
Draft
cam-schultz
wants to merge
1
commit into
main
Choose a base branch
from
fix-pclient-dial-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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 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 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 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,186 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package peers | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ava-labs/avalanchego/api" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/snow/validators" | ||
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1" | ||
"github.com/ava-labs/avalanchego/utils/rpc" | ||
"github.com/ava-labs/avalanchego/vms/components/gas" | ||
"github.com/ava-labs/avalanchego/vms/platformvm" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/status" | ||
"github.com/ava-labs/awm-relayer/config" | ||
"github.com/ava-labs/awm-relayer/peers/utils" | ||
|
||
platformapi "github.com/ava-labs/avalanchego/vms/platformvm/api" | ||
) | ||
|
||
// PChainAPI is a wrapper around the platformvm.Client, | ||
// and provides additional options for the API | ||
// passed in the config. | ||
type PChainAPI struct { | ||
client platformvm.Client | ||
options []rpc.Option | ||
} | ||
|
||
func NewPChainAPI(apiConfig *config.APIConfig) *PChainAPI { | ||
client := platformvm.NewClient(apiConfig.BaseURL) | ||
options := utils.InitializeOptions(apiConfig) | ||
return &PChainAPI{ | ||
client: client, | ||
options: options, | ||
} | ||
} | ||
|
||
func (p *PChainAPI) GetHeight(ctx context.Context) (uint64, error) { | ||
return p.client.GetHeight(ctx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetProposedHeight(ctx context.Context) (uint64, error) { | ||
return p.client.GetProposedHeight(ctx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) ExportKey(ctx context.Context, user api.UserPass, address ids.ShortID) (*secp256k1.PrivateKey, error) { | ||
return p.client.ExportKey(ctx, user, address, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetBalance(ctx context.Context, addrs []ids.ShortID) (*platformvm.GetBalanceResponse, error) { | ||
return p.client.GetBalance(ctx, addrs, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) ListAddresses(ctx context.Context, user api.UserPass) ([]ids.ShortID, error) { | ||
return p.client.ListAddresses(ctx, user, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetUTXOs( | ||
ctx context.Context, | ||
addrs []ids.ShortID, | ||
limit uint32, | ||
startAddress ids.ShortID, | ||
startUTXOID ids.ID, | ||
) ([][]byte, ids.ShortID, ids.ID, error) { | ||
return p.client.GetUTXOs(ctx, addrs, limit, startAddress, startUTXOID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetAtomicUTXOs( | ||
ctx context.Context, | ||
addrs []ids.ShortID, | ||
sourceChain string, | ||
limit uint32, | ||
startAddress ids.ShortID, | ||
startUTXOID ids.ID, | ||
) ([][]byte, ids.ShortID, ids.ID, error) { | ||
return p.client.GetAtomicUTXOs(ctx, addrs, sourceChain, limit, startAddress, startUTXOID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetSubnet(ctx context.Context, subnetID ids.ID) (platformvm.GetSubnetClientResponse, error) { | ||
return p.client.GetSubnet(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetSubnets(ctx context.Context, subnetIDs []ids.ID) ([]platformvm.ClientSubnet, error) { | ||
return p.client.GetSubnets(ctx, subnetIDs, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetStakingAssetID(ctx context.Context, subnetID ids.ID) (ids.ID, error) { | ||
return p.client.GetStakingAssetID(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetCurrentValidators(ctx context.Context, subnetID ids.ID, nodeIDs []ids.NodeID) ([]platformvm.ClientPermissionlessValidator, error) { | ||
return p.client.GetCurrentValidators(ctx, subnetID, nodeIDs, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetL1Validator(ctx context.Context, validationID ids.ID) (platformvm.L1Validator, uint64, error) { | ||
return p.client.GetL1Validator(ctx, validationID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetCurrentSupply(ctx context.Context, subnetID ids.ID) (uint64, uint64, error) { | ||
return p.client.GetCurrentSupply(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) SampleValidators(ctx context.Context, subnetID ids.ID, sampleSize uint16) ([]ids.NodeID, error) { | ||
return p.client.SampleValidators(ctx, subnetID, sampleSize, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetBlockchainStatus(ctx context.Context, blockchainID string) (status.BlockchainStatus, error) { | ||
return p.client.GetBlockchainStatus(ctx, blockchainID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) ValidatedBy(ctx context.Context, blockchainID ids.ID) (ids.ID, error) { | ||
return p.client.ValidatedBy(ctx, blockchainID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) Validates(ctx context.Context, subnetID ids.ID) ([]ids.ID, error) { | ||
return p.client.Validates(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetBlockchains(ctx context.Context) ([]platformvm.APIBlockchain, error) { | ||
return p.client.GetBlockchains(ctx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) IssueTx(ctx context.Context, tx []byte) (ids.ID, error) { | ||
return p.client.IssueTx(ctx, tx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetTx(ctx context.Context, txID ids.ID) ([]byte, error) { | ||
return p.client.GetTx(ctx, txID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetTxStatus(ctx context.Context, txID ids.ID) (*platformvm.GetTxStatusResponse, error) { | ||
return p.client.GetTxStatus(ctx, txID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetStake( | ||
ctx context.Context, | ||
addrs []ids.ShortID, | ||
validatorsOnly bool, | ||
|
||
) (map[ids.ID]uint64, [][]byte, error) { | ||
return p.client.GetStake(ctx, addrs, validatorsOnly, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetMinStake(ctx context.Context, subnetID ids.ID) (uint64, uint64, error) { | ||
return p.client.GetMinStake(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetTotalStake(ctx context.Context, subnetID ids.ID) (uint64, error) { | ||
return p.client.GetTotalStake(ctx, subnetID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetRewardUTXOs(ctx context.Context, args *api.GetTxArgs) ([][]byte, error) { | ||
return p.client.GetRewardUTXOs(ctx, args, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetTimestamp(ctx context.Context) (time.Time, error) { | ||
return p.client.GetTimestamp(ctx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetValidatorsAt( | ||
ctx context.Context, | ||
subnetID ids.ID, | ||
height platformapi.Height, | ||
|
||
) (map[ids.NodeID]*validators.GetValidatorOutput, error) { | ||
return p.client.GetValidatorsAt(ctx, subnetID, height, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetBlock(ctx context.Context, blockID ids.ID) ([]byte, error) { | ||
return p.client.GetBlock(ctx, blockID, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetBlockByHeight(ctx context.Context, height uint64) ([]byte, error) { | ||
return p.client.GetBlockByHeight(ctx, height, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetFeeConfig(ctx context.Context) (*gas.Config, error) { | ||
return p.client.GetFeeConfig(ctx, p.options...) | ||
} | ||
|
||
func (p *PChainAPI) GetFeeState(ctx context.Context) (gas.State, gas.Price, time.Time, error) { | ||
return p.client.GetFeeState(ctx, p.options...) | ||
} |
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.
🥇