lntest: add new Unlock method to allow unlock of fresh node
In this commit, we convert the Unlock method to accept the `lnrpc.UnlockWalletRequest`. This makes things a bit more generic as we no longer need to continue to add params to the method each time a new field is added to the Unlock method.
This commit is contained in:
1 file changed
+22
-8
+22
-8
@@ -117,7 +117,8 @@ type nodeConfig struct {
|
|||||||
ReadMacPath string
|
ReadMacPath string
|
||||||
InvoiceMacPath string
|
InvoiceMacPath string
|
||||||
|
|
||||||
HasSeed bool
|
HasSeed bool
|
||||||
|
Password []byte
|
||||||
|
|
||||||
P2PPort int
|
P2PPort int
|
||||||
RPCPort int
|
RPCPort int
|
||||||
@@ -412,11 +413,11 @@ func (hn *HarnessNode) initClientWhenReady() error {
|
|||||||
conn *grpc.ClientConn
|
conn *grpc.ClientConn
|
||||||
connErr error
|
connErr error
|
||||||
)
|
)
|
||||||
if err := WaitPredicate(func() bool {
|
if err := WaitNoError(func() error {
|
||||||
conn, connErr = hn.ConnectRPC(true)
|
conn, connErr = hn.ConnectRPC(true)
|
||||||
return connErr == nil
|
|
||||||
}, 5*time.Second); err != nil {
|
|
||||||
return connErr
|
return connErr
|
||||||
|
}, 5*time.Second); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return hn.initLightningClient(conn)
|
return hn.initLightningClient(conn)
|
||||||
@@ -430,8 +431,7 @@ func (hn *HarnessNode) initClientWhenReady() error {
|
|||||||
func (hn *HarnessNode) Init(ctx context.Context,
|
func (hn *HarnessNode) Init(ctx context.Context,
|
||||||
initReq *lnrpc.InitWalletRequest) error {
|
initReq *lnrpc.InitWalletRequest) error {
|
||||||
|
|
||||||
timeout := time.Duration(time.Second * 15)
|
ctxt, _ := context.WithTimeout(ctx, DefaultTimeout)
|
||||||
ctxt, _ := context.WithTimeout(ctx, timeout)
|
|
||||||
_, err := hn.InitWallet(ctxt, initReq)
|
_, err := hn.InitWallet(ctxt, initReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -439,13 +439,27 @@ func (hn *HarnessNode) Init(ctx context.Context,
|
|||||||
|
|
||||||
// Wait for the wallet to finish unlocking, such that we can connect to
|
// Wait for the wallet to finish unlocking, such that we can connect to
|
||||||
// it via a macaroon-authenticated rpc connection.
|
// it via a macaroon-authenticated rpc connection.
|
||||||
}, 5*time.Second); err != nil {
|
|
||||||
return hn.initClientWhenReady()
|
return hn.initClientWhenReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unlock attempts to unlock the wallet of the target HarnessNode. This method
|
||||||
|
// should be called after the restart of a HarnessNode that was created with a
|
||||||
|
// seed+password. Once this method returns, the HarnessNode will be ready to
|
||||||
|
// accept normal gRPC requests and harness command.
|
||||||
|
func (hn *HarnessNode) Unlock(ctx context.Context,
|
||||||
|
unlockReq *lnrpc.UnlockWalletRequest) error {
|
||||||
|
|
||||||
|
ctxt, _ := context.WithTimeout(ctx, DefaultTimeout)
|
||||||
|
|
||||||
|
// Otherwise, we'll need to unlock the node before it's able to start
|
||||||
|
// up properly.
|
||||||
|
if _, err := hn.UnlockWallet(ctxt, unlockReq); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return hn.initLightningClient(conn)
|
// Now that the wallet has been unlocked, we'll wait for the RPC client
|
||||||
|
// to be ready, then establish the normal gRPC connection.
|
||||||
|
return hn.initClientWhenReady()
|
||||||
}
|
}
|
||||||
|
|
||||||
// initLightningClient constructs the grpc LightningClient from the given client
|
// initLightningClient constructs the grpc LightningClient from the given client
|
||||||
|
|||||||
Reference in new issue
Block a user