Merge pull request #5854 from LN-Zap/upstream/RPCTransaction
Adds helper function lnrpc.RPCTransaction to create a single lnrpc.Transaction and refactors lnrpc.RPCTransactionDetails
This commit is contained in:
3 files changed
+20
-37
No files matched your search
@@ -40,9 +40,13 @@
|
|||||||
exposed](https://github.com/lightningnetwork/lnd/pull/5971) inside
|
exposed](https://github.com/lightningnetwork/lnd/pull/5971) inside
|
||||||
WaitingCloseResp from calling `PendingChannels`.
|
WaitingCloseResp from calling `PendingChannels`.
|
||||||
|
|
||||||
|
* [Fix missing label on streamed
|
||||||
|
transactions](https://github.com/lightningnetwork/lnd/pull/5854).
|
||||||
|
|
||||||
# Contributors (Alphabetical Order)
|
# Contributors (Alphabetical Order)
|
||||||
|
|
||||||
* Andras Banki-Horvath
|
* Andras Banki-Horvath
|
||||||
|
* Bjarne Magnussen
|
||||||
* Harsha Goli
|
* Harsha Goli
|
||||||
* Martin Habovštiak
|
* Martin Habovštiak
|
||||||
* Naveen Srinivasan
|
* Naveen Srinivasan
|
||||||
|
|||||||
+14
-10
@@ -16,26 +16,20 @@ const (
|
|||||||
RegisterRPCMiddlewareURI = "/lnrpc.Lightning/RegisterRPCMiddleware"
|
RegisterRPCMiddlewareURI = "/lnrpc.Lightning/RegisterRPCMiddleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RPCTransactionDetails returns a set of rpc transaction details.
|
// RPCTransaction returns a rpc transaction.
|
||||||
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetails {
|
func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
||||||
txDetails := &TransactionDetails{
|
|
||||||
Transactions: make([]*Transaction, len(txns)),
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, tx := range txns {
|
|
||||||
var destAddresses []string
|
var destAddresses []string
|
||||||
for _, destAddress := range tx.DestAddresses {
|
for _, destAddress := range tx.DestAddresses {
|
||||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||||
}
|
}
|
||||||
|
|
||||||
// We also get unconfirmed transactions, so BlockHash can be
|
// We also get unconfirmed transactions, so BlockHash can be nil.
|
||||||
// nil.
|
|
||||||
blockHash := ""
|
blockHash := ""
|
||||||
if tx.BlockHash != nil {
|
if tx.BlockHash != nil {
|
||||||
blockHash = tx.BlockHash.String()
|
blockHash = tx.BlockHash.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
txDetails.Transactions[i] = &Transaction{
|
return &Transaction{
|
||||||
TxHash: tx.Hash.String(),
|
TxHash: tx.Hash.String(),
|
||||||
Amount: int64(tx.Value),
|
Amount: int64(tx.Value),
|
||||||
NumConfirmations: tx.NumConfirmations,
|
NumConfirmations: tx.NumConfirmations,
|
||||||
@@ -49,6 +43,16 @@ func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetai
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RPCTransactionDetails returns a set of rpc transaction details.
|
||||||
|
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetails {
|
||||||
|
txDetails := &TransactionDetails{
|
||||||
|
Transactions: make([]*Transaction, len(txns)),
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tx := range txns {
|
||||||
|
txDetails.Transactions[i] = RPCTransaction(tx)
|
||||||
|
}
|
||||||
|
|
||||||
// Sort transactions by number of confirmations rather than height so
|
// Sort transactions by number of confirmations rather than height so
|
||||||
// that unconfirmed transactions (height =0; confirmations =-1) will
|
// that unconfirmed transactions (height =0; confirmations =-1) will
|
||||||
// follow the most recently set of confirmed transactions. If we sort
|
// follow the most recently set of confirmed transactions. If we sort
|
||||||
|
|||||||
+2
-27
@@ -5314,38 +5314,13 @@ func (r *rpcServer) SubscribeTransactions(req *lnrpc.GetTransactionsRequest,
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case tx := <-txClient.ConfirmedTransactions():
|
case tx := <-txClient.ConfirmedTransactions():
|
||||||
destAddresses := make([]string, 0, len(tx.DestAddresses))
|
detail := lnrpc.RPCTransaction(tx)
|
||||||
for _, destAddress := range tx.DestAddresses {
|
|
||||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
|
||||||
}
|
|
||||||
detail := &lnrpc.Transaction{
|
|
||||||
TxHash: tx.Hash.String(),
|
|
||||||
Amount: int64(tx.Value),
|
|
||||||
NumConfirmations: tx.NumConfirmations,
|
|
||||||
BlockHash: tx.BlockHash.String(),
|
|
||||||
BlockHeight: tx.BlockHeight,
|
|
||||||
TimeStamp: tx.Timestamp,
|
|
||||||
TotalFees: tx.TotalFees,
|
|
||||||
DestAddresses: destAddresses,
|
|
||||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
|
||||||
}
|
|
||||||
if err := updateStream.Send(detail); err != nil {
|
if err := updateStream.Send(detail); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
case tx := <-txClient.UnconfirmedTransactions():
|
case tx := <-txClient.UnconfirmedTransactions():
|
||||||
var destAddresses []string
|
detail := lnrpc.RPCTransaction(tx)
|
||||||
for _, destAddress := range tx.DestAddresses {
|
|
||||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
|
||||||
}
|
|
||||||
detail := &lnrpc.Transaction{
|
|
||||||
TxHash: tx.Hash.String(),
|
|
||||||
Amount: int64(tx.Value),
|
|
||||||
TimeStamp: tx.Timestamp,
|
|
||||||
TotalFees: tx.TotalFees,
|
|
||||||
DestAddresses: destAddresses,
|
|
||||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
|
||||||
}
|
|
||||||
if err := updateStream.Send(detail); err != nil {
|
if err := updateStream.Send(detail); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user