-
Notifications
You must be signed in to change notification settings - Fork 714
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
Allow P-chain wallet to be used by the platformvm #3314
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package p | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ava-labs/avalanchego/vms/platformvm" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/txs" | ||
"github.com/ava-labs/avalanchego/wallet/chain/p/wallet" | ||
Check failure on line 11 in wallet/chain/p/client.go GitHub Actions / Unit (macos-12)
Check failure on line 11 in wallet/chain/p/client.go GitHub Actions / Unit (ubuntu-20.04)
Check failure on line 11 in wallet/chain/p/client.go GitHub Actions / Unit (ubuntu-22.04)
Check failure on line 11 in wallet/chain/p/client.go GitHub Actions / Unit (custom-arm64-focal)
|
||
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common" | ||
) | ||
|
||
var ( | ||
ErrNotCommitted = errors.New("not committed") | ||
|
||
_ wallet.Client = (*client)(nil) | ||
) | ||
|
||
func NewClient( | ||
c platformvm.Client, | ||
b wallet.Backend, | ||
) wallet.Client { | ||
return &client{ | ||
client: c, | ||
backend: b, | ||
} | ||
} | ||
|
||
type client struct { | ||
client platformvm.Client | ||
backend wallet.Backend | ||
} | ||
|
||
func (c *client) IssueTx( | ||
tx *txs.Tx, | ||
options ...common.Option, | ||
) error { | ||
ops := common.NewOptions(options) | ||
ctx := ops.Context() | ||
txID, err := c.client.IssueTx(ctx, tx.Bytes()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if f := ops.PostIssuanceFunc(); f != nil { | ||
f(txID) | ||
} | ||
|
||
if ops.AssumeDecided() { | ||
return c.backend.AcceptTx(ctx, tx) | ||
} | ||
|
||
if err := platformvm.AwaitTxAccepted(c.client, ctx, txID, ops.PollFrequency()); err != nil { | ||
return err | ||
} | ||
|
||
return c.backend.AcceptTx(ctx, tx) | ||
} |
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.
I am wondering if it is not simpler to just export these fields? The constructor doesn't do anything special so i think it might make sense to skip it altogether and just initialize the instance with its fields (exported) directly.
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.
The wrapping function is nice to enforce that they are provided imo (as the struct is not useful without populating them).
If this signature looks weird I'd be down to unexport the
Client
type entirely to avoid invalid use.