mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 18:47:38 +01:00
Allow creating invoices with description hash (#3966)
This commit is contained in:
parent
eeeecb00c5
commit
3ba8fb6dd4
2 changed files with 40 additions and 0 deletions
|
@ -5,6 +5,7 @@ import org.bitcoins.core.currency.Satoshis
|
|||
import org.bitcoins.core.protocol.ln.LnInvoice
|
||||
import org.bitcoins.core.protocol.ln.currency._
|
||||
import org.bitcoins.core.protocol.script.P2WPKHWitnessSPKV0
|
||||
import org.bitcoins.crypto.CryptoUtil
|
||||
import org.bitcoins.testkit.fixtures.LndFixture
|
||||
|
||||
import scala.concurrent.Future
|
||||
|
@ -31,6 +32,21 @@ class LndRpcClientTest extends LndFixture {
|
|||
}
|
||||
}
|
||||
|
||||
it must "create an invoice using a description hash" in { lnd =>
|
||||
val memo = "this is my memo"
|
||||
val hash = CryptoUtil.sha256(memo)
|
||||
val amount = Satoshis(1000)
|
||||
|
||||
for {
|
||||
invoiceResult <- lnd.addInvoice(hash, amount, 1000)
|
||||
} yield {
|
||||
val invoice = invoiceResult.invoice
|
||||
|
||||
assert(invoice.lnTags.descriptionHash.exists(_.hash == hash))
|
||||
assert(invoice.amount.map(_.toSatoshis).contains(amount))
|
||||
}
|
||||
}
|
||||
|
||||
it must "create an invoice using msats" in { lnd =>
|
||||
val memo = "this is my memo"
|
||||
val amount = MilliSatoshis(1000)
|
||||
|
|
|
@ -195,6 +195,18 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
|||
addInvoice(invoice)
|
||||
}
|
||||
|
||||
def addInvoice(
|
||||
descriptionHash: Sha256Digest,
|
||||
value: Satoshis,
|
||||
expiry: Long): Future[AddInvoiceResult] = {
|
||||
val invoice: Invoice =
|
||||
Invoice(value = value.toLong,
|
||||
expiry = expiry,
|
||||
descriptionHash = descriptionHash.bytes)
|
||||
|
||||
addInvoice(invoice)
|
||||
}
|
||||
|
||||
def addInvoice(
|
||||
memo: String,
|
||||
value: MilliSatoshis,
|
||||
|
@ -205,6 +217,18 @@ class LndRpcClient(val instance: LndInstance, binaryOpt: Option[File] = None)(
|
|||
addInvoice(invoice)
|
||||
}
|
||||
|
||||
def addInvoice(
|
||||
descriptionHash: Sha256Digest,
|
||||
value: MilliSatoshis,
|
||||
expiry: Long): Future[AddInvoiceResult] = {
|
||||
val invoice: Invoice =
|
||||
Invoice(valueMsat = value.toLong,
|
||||
expiry = expiry,
|
||||
descriptionHash = descriptionHash.bytes)
|
||||
|
||||
addInvoice(invoice)
|
||||
}
|
||||
|
||||
def addInvoice(invoice: Invoice): Future[AddInvoiceResult] = {
|
||||
logger.trace("lnd calling addinvoice")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue