Skip to content
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

Use BaseTx in P-chain wallet #2731

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions wallet/chain/p/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ type Builder interface {
options ...common.Option,
) (map[ids.ID]uint64, error)

// NewBaseTx creates a new simple value transfer. Because the P-chain
// doesn't intend for balance transfers to occur, this method is expensive
// and abuses the creation of subnets.
// NewBaseTx creates a new simple value transfer.
//
// - [outputs] specifies all the recipients and amounts that should be sent
// from this transaction.
NewBaseTx(
outputs []*avax.TransferableOutput,
options ...common.Option,
) (*txs.CreateSubnetTx, error)
) (*txs.BaseTx, error)

// NewAddValidatorTx creates a new validator of the primary network.
//
Expand Down Expand Up @@ -300,9 +298,9 @@ func (b *builder) GetImportableBalance(
func (b *builder) NewBaseTx(
outputs []*avax.TransferableOutput,
options ...common.Option,
) (*txs.CreateSubnetTx, error) {
) (*txs.BaseTx, error) {
toBurn := map[ids.ID]uint64{
b.backend.AVAXAssetID(): b.backend.CreateSubnetTxFee(),
b.backend.AVAXAssetID(): b.backend.BaseTxFee(),
}
for _, out := range outputs {
assetID := out.AssetID()
Expand All @@ -322,16 +320,13 @@ func (b *builder) NewBaseTx(
outputs = append(outputs, changeOutputs...)
avax.SortTransferableOutputs(outputs, txs.Codec) // sort the outputs

tx := &txs.CreateSubnetTx{
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
NetworkID: b.backend.NetworkID(),
BlockchainID: constants.PlatformChainID,
Ins: inputs,
Outs: outputs,
Memo: ops.Memo(),
}},
Owner: &secp256k1fx.OutputOwners{},
}
tx := &txs.BaseTx{BaseTx: avax.BaseTx{
NetworkID: b.backend.NetworkID(),
BlockchainID: constants.PlatformChainID,
Ins: inputs,
Outs: outputs,
Memo: ops.Memo(),
}}
return tx, b.initCtx(tx)
}

Expand Down
2 changes: 1 addition & 1 deletion wallet/chain/p/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestBaseTx(t *testing.T) {
require.Len(ins, 2)
require.Len(outs, 2)

expectedConsumed := testCtx.CreateSubnetTxFee() + outputsToMove[0].Out.Amount()
expectedConsumed := testCtx.BaseTxFee() + outputsToMove[0].Out.Amount()
consumed := ins[0].In.Amount() + ins[1].In.Amount() - outs[0].Out.Amount()
require.Equal(expectedConsumed, consumed)
require.Equal(outputsToMove[0], outs[1])
Expand Down
2 changes: 0 additions & 2 deletions wallet/chain/p/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type Wallet interface {
Signer() Signer

// IssueBaseTx creates, signs, and issues a new simple value transfer.
// Because the P-chain doesn't intend for balance transfers to occur, this
// method is expensive and abuses the creation of subnets.
//
// - [outputs] specifies all the recipients and amounts that should be sent
// from this transaction.
Expand Down
Loading