feat: execute Podcasting-2.0 value-for-value (V4V) Lightning splits

Adds payment execution to the V4V value blocks that were previously
display-only. A "Send value" button on the value card opens the account's
zap-amount picker; choosing an amount fans the weighted shares out to every
recipient, mirroring how a NIP-57 zap-split is paid.

quartz (pure, tested):
- PodcastValue.computeShares() — splits a total across recipients by relative
  weight, honoring `fee` recipients that take their split as a percent off the
  top. Returns PodcastValueShare (recipient + millisats).
- PodcastBoostagram — the satoshis.stream keysend metadata blob carried in TLV
  record 7629169, with the registered field names and unset fields omitted.
- PODCAST_TLV_RECORD / TYPE_NODE / TYPE_LNADDRESS constants.

amethyst:
- V4VPaymentHandler — the execution engine. lnaddress recipients resolve to a
  BOLT-11 via LNURL-pay and pay through the user's default source (NWC, CLINK
  debit, or external wallet intent), same rails as a zap. node recipients pay
  by NWC keysend (pay_keysend) carrying the boostagram TLV plus any per-recipient
  custom TLV; keysend is NWC-only, so node recipients are skipped with a clear
  error when no NWC wallet is configured.
- AccountViewModel.payV4V() wrapper + the "Send value" amount picker on the
  value card, wired for both episode and show value blocks.

V4V recipients are raw Lightning destinations, not Nostr users, so there is no
zap request and no zap receipt — just the payment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JGa1EM5KWyDo1o5Yr6sS18
This commit is contained in:
Claude
2026-06-28 15:43:22 +00:00
parent 5984d20042
commit a71ba61370
10 changed files with 699 additions and 6 deletions
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.podcasts
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class PodcastBoostagramTest {
@Test
fun `uses satoshis-stream field names and omits unset fields`() {
val json =
PodcastBoostagram(
podcast = "My Show",
episode = "Ep 1",
action = PodcastBoostagram.ACTION_BOOST,
appName = "Amethyst",
valueMsatTotal = 21_000_000L,
).toJson()
assertTrue(json.contains("\"podcast\":\"My Show\""))
assertTrue(json.contains("\"app_name\":\"Amethyst\""))
assertTrue(json.contains("\"value_msat_total\":21000000"))
assertTrue(json.contains("\"action\":\"boost\""))
// Unset optionals (message, sender_name) must not appear.
assertFalse(json.contains("message"))
assertFalse(json.contains("sender_name"))
}
@Test
fun `round-trips through json`() {
val original =
PodcastBoostagram(
podcast = "Show",
action = PodcastBoostagram.ACTION_STREAM,
valueMsatTotal = 1000L,
senderName = "alice",
)
val parsed = JsonMapper.fromJson<PodcastBoostagram>(original.toJson())
assertEquals("Show", parsed.podcast)
assertEquals(PodcastBoostagram.ACTION_STREAM, parsed.action)
assertEquals(1000L, parsed.valueMsatTotal)
assertEquals("alice", parsed.senderName)
}
}
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2025 Vitor Pamplona
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.vitorpamplona.quartz.podcasts
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class PodcastValueShareTest {
private fun node(
name: String,
split: Int,
fee: Boolean? = null,
) = PodcastValueRecipient(name = name, type = PodcastValue.TYPE_NODE, address = "node-$name", split = split, fee = fee)
@Test
fun `weighted split with no fees divides by relative weight`() {
val value =
PodcastValue(
recipients = listOf(node("host", 90), node("producer", 10)),
)
// 100k sats total in millisats.
val shares = value.computeShares(100_000_000L).associate { it.recipient.name to it.amountMilliSats }
assertEquals(90_000_000L, shares["host"])
assertEquals(10_000_000L, shares["producer"])
}
@Test
fun `fee recipient takes its split as a percent off the top, remainder split by weight`() {
val value =
PodcastValue(
recipients =
listOf(
node("app", 5, fee = true), // 5% fee off the top
node("host", 80),
node("cohost", 20),
),
)
val shares = value.computeShares(1_000_000L).associate { it.recipient.name to it.amountMilliSats }
// 5% of 1,000,000 = 50,000 fee. Remainder 950,000 split 80/20.
assertEquals(50_000L, shares["app"])
assertEquals(760_000L, shares["host"])
assertEquals(190_000L, shares["cohost"])
// No more than the total is ever allocated.
assertTrue(shares.values.sum() <= 1_000_000L)
}
@Test
fun `recipients without an address or with non-positive split are ignored`() {
val value =
PodcastValue(
recipients =
listOf(
node("host", 100),
PodcastValueRecipient(name = "noaddr", type = PodcastValue.TYPE_NODE, address = null, split = 50),
node("zero", 0),
),
)
val shares = value.computeShares(10_000L)
assertEquals(1, shares.size)
assertEquals("host", shares.single().recipient.name)
assertEquals(10_000L, shares.single().amountMilliSats)
}
@Test
fun `non-positive total or empty recipients yields no shares`() {
val value = PodcastValue(recipients = listOf(node("host", 100)))
assertTrue(value.computeShares(0L).isEmpty())
assertTrue(value.computeShares(-5L).isEmpty())
assertTrue(PodcastValue(recipients = emptyList()).computeShares(1_000L).isEmpty())
}
}