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