From 5782a143716b7a86a02f1bd8ca79a9bb996fa2b9 Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 19 Mar 2024 18:07:07 +0100 Subject: [PATCH] fixed merge --- vms/avm/service_backend.go | 26 +++++++++++++++----------- vms/avm/tx_builders.go | 29 +++++++++++++++++------------ vms/avm/wallet_service_backend.go | 26 +++++++++++++++----------- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/vms/avm/service_backend.go b/vms/avm/service_backend.go index 158dc01d2dc1..0b0f7b382f26 100644 --- a/vms/avm/service_backend.go +++ b/vms/avm/service_backend.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/vms/avm/config" "github.com/ava-labs/avalanchego/vms/avm/state" "github.com/ava-labs/avalanchego/vms/components/avax" - "github.com/ava-labs/avalanchego/wallet/chain/x/backends" + "github.com/ava-labs/avalanchego/wallet/chain/x/builder" ) var _ txBuilderBackend = (*serviceBackend)(nil) @@ -26,15 +26,16 @@ func newServiceBackend( state state.State, atomicUTXOsMan avax.AtomicUTXOManager, ) *serviceBackend { - backendCtx := backends.NewContext( - ctx.NetworkID, - ctx.XChainID, - feeAssetID, - cfg.TxFee, - cfg.CreateAssetTxFee, - ) + backendCtx := &builder.Context{ + NetworkID: ctx.NetworkID, + BlockchainID: ctx.XChainID, + AVAXAssetID: feeAssetID, + BaseTxFee: cfg.TxFee, + CreateAssetTxFee: cfg.CreateAssetTxFee, + } + return &serviceBackend{ - Context: backendCtx, + ctx: backendCtx, xchainID: ctx.XChainID, cfg: cfg, state: state, @@ -43,8 +44,7 @@ func newServiceBackend( } type serviceBackend struct { - backends.Context - + ctx *builder.Context xchainID ids.ID cfg *config.Config addrs set.Set[ids.ShortID] @@ -52,6 +52,10 @@ type serviceBackend struct { atomicUTXOsMan avax.AtomicUTXOManager } +func (b *serviceBackend) Context() *builder.Context { + return b.ctx +} + func (b *serviceBackend) ResetAddresses(addrs set.Set[ids.ShortID]) { b.addrs = addrs } diff --git a/vms/avm/tx_builders.go b/vms/avm/tx_builders.go index 9606af6069f5..dc07c7ea9593 100644 --- a/vms/avm/tx_builders.go +++ b/vms/avm/tx_builders.go @@ -13,13 +13,17 @@ import ( "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/verify" "github.com/ava-labs/avalanchego/vms/secp256k1fx" - "github.com/ava-labs/avalanchego/wallet/chain/x/backends" + "github.com/ava-labs/avalanchego/wallet/chain/x/signer" "github.com/ava-labs/avalanchego/wallet/subnet/primary/common" + + walletbuilder "github.com/ava-labs/avalanchego/wallet/chain/x/builder" ) type txBuilderBackend interface { - backends.Backend + walletbuilder.Backend + signer.Backend + Context() *walletbuilder.Context ResetAddresses(addrs set.Set[ids.ShortID]) } @@ -44,7 +48,7 @@ func buildCreateAssetTx( return nil, ids.ShortEmpty, fmt.Errorf("failed building base tx: %w", err) } - tx, err := backends.SignUnsigned(context.Background(), pSigner, utx) + tx, err := signer.SignUnsigned(context.Background(), pSigner, utx) if err != nil { return nil, ids.ShortEmpty, err } @@ -69,7 +73,7 @@ func buildBaseTx( return nil, ids.ShortEmpty, fmt.Errorf("failed building base tx: %w", err) } - tx, err := backends.SignUnsigned(context.Background(), pSigner, utx) + tx, err := signer.SignUnsigned(context.Background(), pSigner, utx) if err != nil { return nil, ids.ShortEmpty, err } @@ -97,7 +101,7 @@ func mintNFT( return nil, fmt.Errorf("failed minting NFTs: %w", err) } - return backends.SignUnsigned(context.Background(), pSigner, utx) + return signer.SignUnsigned(context.Background(), pSigner, utx) } func mintFTs( @@ -116,7 +120,7 @@ func mintFTs( return nil, fmt.Errorf("failed minting FTs: %w", err) } - return backends.SignUnsigned(context.Background(), pSigner, utx) + return signer.SignUnsigned(context.Background(), pSigner, utx) } func buildOperation( @@ -135,7 +139,7 @@ func buildOperation( return nil, fmt.Errorf("failed building operation tx: %w", err) } - return backends.SignUnsigned(context.Background(), pSigner, utx) + return signer.SignUnsigned(context.Background(), pSigner, utx) } func buildImportTx( @@ -160,7 +164,7 @@ func buildImportTx( return nil, fmt.Errorf("failed building import tx: %w", err) } - return backends.SignUnsigned(context.Background(), pSigner, utx) + return signer.SignUnsigned(context.Background(), pSigner, utx) } func buildExportTx( @@ -195,19 +199,20 @@ func buildExportTx( return nil, ids.ShortEmpty, fmt.Errorf("failed building export tx: %w", err) } - tx, err := backends.SignUnsigned(context.Background(), pSigner, utx) + tx, err := signer.SignUnsigned(context.Background(), pSigner, utx) if err != nil { return nil, ids.ShortEmpty, err } return tx, changeAddr, nil } -func builders(backend txBuilderBackend, kc *secp256k1fx.Keychain) (backends.Builder, backends.Signer) { +func builders(backend txBuilderBackend, kc *secp256k1fx.Keychain) (walletbuilder.Builder, signer.Signer) { var ( addrs = kc.Addresses() - builder = backends.NewBuilder(addrs, backend) - signer = backends.NewSigner(kc, backend) + builder = walletbuilder.New(addrs, backend.Context(), backend) + signer = signer.New(kc, backend) ) + backend.ResetAddresses(addrs) return builder, signer diff --git a/vms/avm/wallet_service_backend.go b/vms/avm/wallet_service_backend.go index 8c9eb6e55a3d..babf8d02da6d 100644 --- a/vms/avm/wallet_service_backend.go +++ b/vms/avm/wallet_service_backend.go @@ -14,21 +14,22 @@ import ( "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/avm/txs" "github.com/ava-labs/avalanchego/vms/components/avax" - "github.com/ava-labs/avalanchego/wallet/chain/x/backends" + "github.com/ava-labs/avalanchego/wallet/chain/x/builder" ) var _ txBuilderBackend = (*walletServiceBackend)(nil) func NewWalletServiceBackend(vm *VM) *walletServiceBackend { - backendCtx := backends.NewContext( - vm.ctx.NetworkID, - vm.ctx.XChainID, - vm.feeAssetID, - vm.Config.TxFee, - vm.Config.CreateAssetTxFee, - ) + backendCtx := &builder.Context{ + NetworkID: vm.ctx.NetworkID, + BlockchainID: vm.ctx.XChainID, + AVAXAssetID: vm.feeAssetID, + BaseTxFee: vm.Config.TxFee, + CreateAssetTxFee: vm.Config.CreateAssetTxFee, + } + return &walletServiceBackend{ - Context: backendCtx, + ctx: backendCtx, vm: vm, pendingTxs: linkedhashmap.New[ids.ID, *txs.Tx](), utxos: make([]*avax.UTXO, 0), @@ -36,8 +37,7 @@ func NewWalletServiceBackend(vm *VM) *walletServiceBackend { } type walletServiceBackend struct { - backends.Context - + ctx *builder.Context vm *VM pendingTxs linkedhashmap.LinkedHashmap[ids.ID, *txs.Tx] utxos []*avax.UTXO @@ -45,6 +45,10 @@ type walletServiceBackend struct { addrs set.Set[ids.ShortID] } +func (b *walletServiceBackend) Context() *builder.Context { + return b.ctx +} + func (b *walletServiceBackend) ResetAddresses(addrs set.Set[ids.ShortID]) { b.addrs = addrs }