wallet是整个btcwallet的核心
// Loader implements the creating of new and opening of existing wallets, while
// providing a callback system for other subsystems to handle the loading of a
// wallet. This is primarily intended for use by the RPC servers, to enable
// methods and services which require the wallet when the wallet is loaded by
// another subsystem.
//
// Loader is safe for concurrent access.
type Loader struct {
callbacks []func(*Wallet)
chainParams *chaincfg.Params
dbDirPath string
recoveryWindow uint32
wallet *Wallet
db walletdb.DB
mu sync.Mutex
}
Loader主要负责创建打开钱包Wallet
,他会提供一些callback方法,让钱包打开以后自动调用这些callback.
主要是onLoaded
和RunAfterLoad
rpc接口简单封装以后,最后都是直接走到Wallet进行处理.Wallet内容非常丰富.
这里找一个简单rpc例子来介绍.
"walletpassphrase": {handler: walletPassphrase},
func walletPassphrase(icmd interface{}, w *wallet.Wallet) (interface{}, error)
,func (w *Wallet) Unlock(passphrase []byte, lock <-chan time.Time) error
进入Wallet特别注意: 这里的timeout的用法, for,select组合的时候,一开始timeout完全没有准备好,只是在需要的时候准备好,用完了再次置为nil即可.
主要是处理createTxRequest,在指定账户上,根据需要输出的金额一起其他要求,选择合适的UTXO,然后形成未签名的Tx