mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 06:34:27 +01:00
htlcswitch: remove lnrpc dependency
This commits removes an unwanted dependency that prevents moving parts of rpcserver to a sub server.
This commit is contained in:
66
rpcserver.go
66
rpcserver.go
@@ -1419,7 +1419,7 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||
chanPoint, force)
|
||||
|
||||
var (
|
||||
updateChan chan *lnrpc.CloseStatusUpdate
|
||||
updateChan chan interface{}
|
||||
errChan chan error
|
||||
)
|
||||
|
||||
@@ -1472,13 +1472,9 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||
|
||||
// With the transaction broadcast, we send our first update to
|
||||
// the client.
|
||||
updateChan = make(chan *lnrpc.CloseStatusUpdate, 2)
|
||||
updateChan <- &lnrpc.CloseStatusUpdate{
|
||||
Update: &lnrpc.CloseStatusUpdate_ClosePending{
|
||||
ClosePending: &lnrpc.PendingUpdate{
|
||||
Txid: closingTxid[:],
|
||||
},
|
||||
},
|
||||
updateChan = make(chan interface{}, 2)
|
||||
updateChan <- &pendingUpdate{
|
||||
Txid: closingTxid[:],
|
||||
}
|
||||
|
||||
errChan = make(chan error, 1)
|
||||
@@ -1487,13 +1483,9 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
||||
&closingTxid, closingTx.TxOut[0].PkScript, func() {
|
||||
// Respond to the local subsystem which
|
||||
// requested the channel closure.
|
||||
updateChan <- &lnrpc.CloseStatusUpdate{
|
||||
Update: &lnrpc.CloseStatusUpdate_ChanClose{
|
||||
ChanClose: &lnrpc.ChannelCloseUpdate{
|
||||
ClosingTxid: closingTxid[:],
|
||||
Success: true,
|
||||
},
|
||||
},
|
||||
updateChan <- &channelCloseUpdate{
|
||||
ClosingTxid: closingTxid[:],
|
||||
Success: true,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -1544,18 +1536,26 @@ out:
|
||||
"ChannelPoint(%v): %v", chanPoint, err)
|
||||
return err
|
||||
case closingUpdate := <-updateChan:
|
||||
rpcClosingUpdate, err := createRPCCloseUpdate(
|
||||
closingUpdate,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rpcsLog.Tracef("[closechannel] sending update: %v",
|
||||
closingUpdate)
|
||||
if err := updateStream.Send(closingUpdate); err != nil {
|
||||
rpcClosingUpdate)
|
||||
|
||||
if err := updateStream.Send(rpcClosingUpdate); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If a final channel closing updates is being sent,
|
||||
// then we can break out of our dispatch loop as we no
|
||||
// longer need to process any further updates.
|
||||
switch closeUpdate := closingUpdate.Update.(type) {
|
||||
case *lnrpc.CloseStatusUpdate_ChanClose:
|
||||
h, _ := chainhash.NewHash(closeUpdate.ChanClose.ClosingTxid)
|
||||
switch closeUpdate := closingUpdate.(type) {
|
||||
case *channelCloseUpdate:
|
||||
h, _ := chainhash.NewHash(closeUpdate.ClosingTxid)
|
||||
rpcsLog.Infof("[closechannel] close completed: "+
|
||||
"txid(%v)", h)
|
||||
break out
|
||||
@@ -1568,6 +1568,32 @@ out:
|
||||
return nil
|
||||
}
|
||||
|
||||
func createRPCCloseUpdate(update interface{}) (
|
||||
*lnrpc.CloseStatusUpdate, error) {
|
||||
|
||||
switch u := update.(type) {
|
||||
case *channelCloseUpdate:
|
||||
return &lnrpc.CloseStatusUpdate{
|
||||
Update: &lnrpc.CloseStatusUpdate_ChanClose{
|
||||
ChanClose: &lnrpc.ChannelCloseUpdate{
|
||||
ClosingTxid: u.ClosingTxid,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
case *pendingUpdate:
|
||||
return &lnrpc.CloseStatusUpdate{
|
||||
Update: &lnrpc.CloseStatusUpdate_ClosePending{
|
||||
ClosePending: &lnrpc.PendingUpdate{
|
||||
Txid: u.Txid,
|
||||
OutputIndex: u.OutputIndex,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return nil, errors.New("unknown close status update")
|
||||
}
|
||||
|
||||
// AbandonChannel removes all channel state from the database except for a
|
||||
// close summary. This method can be used to get rid of permanently unusable
|
||||
// channels due to bugs fixed in newer versions of lnd.
|
||||
|
||||
Reference in New Issue
Block a user