lnrpc: refactor populating lnrpc.Transaction inside SubscribeTransaction
This commit is contained in:
2 files changed
+30
-51
No files matched your search
+28
-24
@@ -16,6 +16,33 @@ const (
|
||||
RegisterRPCMiddlewareURI = "/lnrpc.Lightning/RegisterRPCMiddleware"
|
||||
)
|
||||
|
||||
// RPCTransaction returns a rpc transaction.
|
||||
func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
|
||||
var destAddresses []string
|
||||
for _, destAddress := range tx.DestAddresses {
|
||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||
}
|
||||
|
||||
// We also get unconfirmed transactions, so BlockHash can be nil.
|
||||
blockHash := ""
|
||||
if tx.BlockHash != nil {
|
||||
blockHash = tx.BlockHash.String()
|
||||
}
|
||||
|
||||
return &Transaction{
|
||||
TxHash: tx.Hash.String(),
|
||||
Amount: int64(tx.Value),
|
||||
NumConfirmations: tx.NumConfirmations,
|
||||
BlockHash: blockHash,
|
||||
BlockHeight: tx.BlockHeight,
|
||||
TimeStamp: tx.Timestamp,
|
||||
TotalFees: tx.TotalFees,
|
||||
DestAddresses: destAddresses,
|
||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||
Label: tx.Label,
|
||||
}
|
||||
}
|
||||
|
||||
// RPCTransactionDetails returns a set of rpc transaction details.
|
||||
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetails {
|
||||
txDetails := &TransactionDetails{
|
||||
@@ -23,30 +50,7 @@ func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetai
|
||||
}
|
||||
|
||||
for i, tx := range txns {
|
||||
var destAddresses []string
|
||||
for _, destAddress := range tx.DestAddresses {
|
||||
destAddresses = append(destAddresses, destAddress.EncodeAddress())
|
||||
}
|
||||
|
||||
// We also get unconfirmed transactions, so BlockHash can be
|
||||
// nil.
|
||||
blockHash := ""
|
||||
if tx.BlockHash != nil {
|
||||
blockHash = tx.BlockHash.String()
|
||||
}
|
||||
|
||||
txDetails.Transactions[i] = &Transaction{
|
||||
TxHash: tx.Hash.String(),
|
||||
Amount: int64(tx.Value),
|
||||
NumConfirmations: tx.NumConfirmations,
|
||||
BlockHash: blockHash,
|
||||
BlockHeight: tx.BlockHeight,
|
||||
TimeStamp: tx.Timestamp,
|
||||
TotalFees: tx.TotalFees,
|
||||
DestAddresses: destAddresses,
|
||||
RawTxHex: hex.EncodeToString(tx.RawTx),
|
||||
Label: tx.Label,
|
||||
}
|
||||
txDetails.Transactions[i] = RPCTransaction(tx)
|
||||
}
|
||||
|
||||
// Sort transactions by number of confirmations rather than height so
|
||||
|
||||
Reference in new issue
Block a user