github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/txstest/builder.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package txstest
     5  
     6  import (
     7  	"github.com/MetalBlockchain/metalgo/snow"
     8  	"github.com/MetalBlockchain/metalgo/utils/crypto/secp256k1"
     9  	"github.com/MetalBlockchain/metalgo/vms/platformvm/config"
    10  	"github.com/MetalBlockchain/metalgo/vms/platformvm/state"
    11  	"github.com/MetalBlockchain/metalgo/vms/secp256k1fx"
    12  	"github.com/MetalBlockchain/metalgo/wallet/chain/p/builder"
    13  	"github.com/MetalBlockchain/metalgo/wallet/chain/p/signer"
    14  )
    15  
    16  func NewWalletFactory(
    17  	ctx *snow.Context,
    18  	cfg *config.Config,
    19  	state state.State,
    20  ) *WalletFactory {
    21  	return &WalletFactory{
    22  		ctx:   ctx,
    23  		cfg:   cfg,
    24  		state: state,
    25  	}
    26  }
    27  
    28  type WalletFactory struct {
    29  	ctx   *snow.Context
    30  	cfg   *config.Config
    31  	state state.State
    32  }
    33  
    34  func (w *WalletFactory) NewWallet(keys ...*secp256k1.PrivateKey) (builder.Builder, signer.Signer) {
    35  	var (
    36  		kc      = secp256k1fx.NewKeychain(keys...)
    37  		addrs   = kc.Addresses()
    38  		backend = newBackend(addrs, w.state, w.ctx.SharedMemory)
    39  		context = newContext(w.ctx, w.cfg, w.state.GetTimestamp())
    40  	)
    41  
    42  	return builder.New(addrs, context, backend), signer.New(kc, backend)
    43  }