input+wallet: extract musig2 session management into new module

In this commit, we extract the musig2 session management into a new
module. This allows us to re-use the session logic elsewhere in unit
tests so we don't need to instantiate the entire wallet.
This commit is contained in:
Olaoluwa Osuntokun
2023-01-18 19:29:41 -08:00
parent 4733da5ccb
commit 9a65806c09
13 changed files with 402 additions and 371 deletions

View File

@@ -104,8 +104,7 @@ type BtcWallet struct {
blockCache *blockcache.BlockCache
musig2Sessions map[input.MuSig2SessionID]*muSig2State
musig2SessionsMtx sync.Mutex
*input.MusigSessionManager
}
// A compile time check to ensure that BtcWallet implements the
@@ -167,16 +166,21 @@ func New(cfg Config, blockCache *blockcache.BlockCache) (*BtcWallet, error) {
}
}
return &BtcWallet{
cfg: &cfg,
wallet: wallet,
db: wallet.Database(),
chain: cfg.ChainSource,
netParams: cfg.NetParams,
chainKeyScope: chainKeyScope,
blockCache: blockCache,
musig2Sessions: make(map[input.MuSig2SessionID]*muSig2State),
}, nil
finalWallet := &BtcWallet{
cfg: &cfg,
wallet: wallet,
db: wallet.Database(),
chain: cfg.ChainSource,
netParams: cfg.NetParams,
chainKeyScope: chainKeyScope,
blockCache: blockCache,
}
finalWallet.MusigSessionManager = input.NewMusigSessionManager(
finalWallet.fetchPrivKey,
)
return finalWallet, nil
}
// loaderCfg holds optional wallet loader configuration.