mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-21 14:14:28 +01:00
Add functions for LND subscription (#4062)
This commit is contained in:
parent
e2b9c458e4
commit
44373f8449
2 changed files with 51 additions and 1 deletions
|
@ -56,6 +56,7 @@ import scala.util.{Failure, Success, Try}
|
|||
class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
||||
implicit system: ActorSystem)
|
||||
extends NativeProcessFactory
|
||||
with LndUtils
|
||||
with StartStopAsync[LndRpcClient]
|
||||
with Logging {
|
||||
instance match {
|
||||
|
@ -248,6 +249,28 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
|||
lnd.subscribeInvoices(InvoiceSubscription())
|
||||
}
|
||||
|
||||
def subscribeTransactions(): Source[TxDetails, NotUsed] = {
|
||||
lnd
|
||||
.subscribeTransactions(GetTransactionsRequest())
|
||||
.map(LndTransactionToTxDetails)
|
||||
}
|
||||
|
||||
def subscribeChannelEvents(): Source[ChannelEventUpdate, NotUsed] = {
|
||||
lnd.subscribeChannelEvents(ChannelEventSubscription())
|
||||
}
|
||||
|
||||
def subscribePeerEvents(): Source[PeerEvent, NotUsed] = {
|
||||
lnd.subscribePeerEvents(PeerEventSubscription())
|
||||
}
|
||||
|
||||
def subscribeChannelGraph(): Source[GraphTopologyUpdate, NotUsed] = {
|
||||
lnd.subscribeChannelGraph(GraphTopologySubscription())
|
||||
}
|
||||
|
||||
def subscribeChannelBackups(): Source[ChanBackupSnapshot, NotUsed] = {
|
||||
lnd.subscribeChannelBackups(ChannelBackupSubscription())
|
||||
}
|
||||
|
||||
def getNewAddress: Future[BitcoinAddress] = {
|
||||
logger.trace("lnd calling newaddress")
|
||||
|
||||
|
|
|
@ -3,8 +3,10 @@ package org.bitcoins.lnd.rpc
|
|||
import com.google.protobuf.ByteString
|
||||
import lnrpc.ChannelPoint
|
||||
import lnrpc.ChannelPoint.FundingTxid.FundingTxidBytes
|
||||
import org.bitcoins.commons.jsonmodels.lnd.TxDetails
|
||||
import org.bitcoins.core.currency.Satoshis
|
||||
import org.bitcoins.core.number.UInt32
|
||||
import org.bitcoins.core.protocol.BitcoinAddress
|
||||
import org.bitcoins.core.protocol.script.ScriptPubKey
|
||||
import org.bitcoins.core.protocol.transaction._
|
||||
import org.bitcoins.crypto._
|
||||
|
@ -13,7 +15,7 @@ import signrpc.TxOut
|
|||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
object LndUtils {
|
||||
trait LndUtils {
|
||||
|
||||
implicit def byteVecToByteString(byteVector: ByteVector): ByteString =
|
||||
ByteString.copyFrom(byteVector.toArray)
|
||||
|
@ -50,4 +52,29 @@ object LndUtils {
|
|||
val txId = FundingTxidBytes(outPoint.txId.bytes)
|
||||
ChannelPoint(txId, outPoint.vout.toInt)
|
||||
}
|
||||
|
||||
implicit def LndTransactionToTxDetails(
|
||||
details: lnrpc.Transaction): TxDetails = {
|
||||
val blockHashOpt = if (details.blockHash.isEmpty) {
|
||||
None
|
||||
} else Some(DoubleSha256DigestBE(details.blockHash))
|
||||
|
||||
val addrs =
|
||||
details.destAddresses.map(BitcoinAddress.fromString).toVector
|
||||
|
||||
TxDetails(
|
||||
txId = DoubleSha256DigestBE(details.txHash),
|
||||
amount = Satoshis(details.amount),
|
||||
numConfirmations = details.numConfirmations,
|
||||
blockHashOpt = blockHashOpt,
|
||||
blockHeight = details.blockHeight,
|
||||
timeStamp = details.timeStamp,
|
||||
totalFees = Satoshis(details.totalFees),
|
||||
destAddresses = addrs,
|
||||
tx = Transaction(details.rawTxHex),
|
||||
label = details.label
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object LndUtils extends LndUtils
|
||||
|
|
Loading…
Add table
Reference in a new issue