Skip to content

Commit dc03622

Browse files
dhrubabasuabi87StephenButtolph
authored
Use BaseTx in P-chain wallet (#2731)
Co-authored-by: Alberto Benegiamo <alberto.benegiamo@gmail.com> Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
1 parent dc2c5d0 commit dc03622

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

wallet/chain/p/builder.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,14 @@ type Builder interface {
5151
options ...common.Option,
5252
) (map[ids.ID]uint64, error)
5353

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

6563
// NewAddValidatorTx creates a new validator of the primary network.
6664
//
@@ -300,9 +298,9 @@ func (b *builder) GetImportableBalance(
300298
func (b *builder) NewBaseTx(
301299
outputs []*avax.TransferableOutput,
302300
options ...common.Option,
303-
) (*txs.CreateSubnetTx, error) {
301+
) (*txs.BaseTx, error) {
304302
toBurn := map[ids.ID]uint64{
305-
b.backend.AVAXAssetID(): b.backend.CreateSubnetTxFee(),
303+
b.backend.AVAXAssetID(): b.backend.BaseTxFee(),
306304
}
307305
for _, out := range outputs {
308306
assetID := out.AssetID()
@@ -322,16 +320,13 @@ func (b *builder) NewBaseTx(
322320
outputs = append(outputs, changeOutputs...)
323321
avax.SortTransferableOutputs(outputs, txs.Codec) // sort the outputs
324322

325-
tx := &txs.CreateSubnetTx{
326-
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
327-
NetworkID: b.backend.NetworkID(),
328-
BlockchainID: constants.PlatformChainID,
329-
Ins: inputs,
330-
Outs: outputs,
331-
Memo: ops.Memo(),
332-
}},
333-
Owner: &secp256k1fx.OutputOwners{},
334-
}
323+
tx := &txs.BaseTx{BaseTx: avax.BaseTx{
324+
NetworkID: b.backend.NetworkID(),
325+
BlockchainID: constants.PlatformChainID,
326+
Ins: inputs,
327+
Outs: outputs,
328+
Memo: ops.Memo(),
329+
}}
335330
return tx, b.initCtx(tx)
336331
}
337332

wallet/chain/p/builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestBaseTx(t *testing.T) {
8787
require.Len(ins, 2)
8888
require.Len(outs, 2)
8989

90-
expectedConsumed := testCtx.CreateSubnetTxFee() + outputsToMove[0].Out.Amount()
90+
expectedConsumed := testCtx.BaseTxFee() + outputsToMove[0].Out.Amount()
9191
consumed := ins[0].In.Amount() + ins[1].In.Amount() - outs[0].Out.Amount()
9292
require.Equal(expectedConsumed, consumed)
9393
require.Equal(outputsToMove[0], outs[1])

wallet/chain/p/wallet.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ type Wallet interface {
3434
Signer() Signer
3535

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

0 commit comments

Comments
 (0)