You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I receive a onchain payment it would be useful to know the address the payment way received to. This way I can attribute incoming unchain payments to specific users when I am building an account system on top of LDK Node.
It appears to me that the right way to do this is to add an address field to PaymentKind::Onchain.
This might not be as trivial, because many things could happen at the same time in a single transaction, i.e., also multiple (change) addresses could be in the mix. Our current model is that we classify transactions as 'inbound'/'outbound' based on whether they send more to foreign addresses than to wallet-owned addresses, which works decently well, but I'm not quite sure if there's currently a good way for us to access this information or expose it reasonably (short of listing out all details).
We hit this from a different angle and did some digging that might help unblock
the two doubts in the previous comment.
Use case. We're building a graduated-custody wallet on LDK Node (via
orange-sdk). Our Receive screen shows a BIP21 request and flips to a "paid"
state when the payment lands — we match Lightning receives on PaymentKind::Bolt11 { hash }, which works well. On-chain receives can't be
matched at all: PaymentKind::Onchain carries only txid, so we can't tell
whether the payment that just arrived is the request the user is looking at or
an unrelated deposit. There's no local workaround short of independently
querying a chain backend and re-deriving ownership, which duplicates work the
node already did and is backend-specific for us.
On "not sure there's currently a good way for us to access this
information": the data appears to already be in hand at the point the record
is built. Wallet::create_payment_from_tx (src/wallet/mod.rs:1444) receives
both the full tx: &Transaction and the locked_wallet, and onchain_payment_fields_locked right above it (:1417) already calls locked_wallet.sent_and_received(tx) (:1421) — which walks the outputs
against the keychain index to compute amount/direction. So the per-output
ownership determination is happening already; the script just isn't retained.
On "expose it reasonably (short of listing out all details)" + the
change-address concern:bdk_wallet exposes derivation_of_spk(spk) -> Option<(KeychainKind, u32)>, documented as only
returning Some(_) for spks the wallet has given out. Filtering on KeychainKind::External therefore excludes change outputs by construction,
which we think is exactly the distinction that makes this tractable — you'd
expose only the spks that were handed out, not "all details". Something like:
let received_spks:Vec<ScriptBuf> = tx.output.iter().filter(|o| locked_wallet.derivation_of_spk(o.script_pubkey.clone()).is_some_and(|(k, _)| k == KeychainKind::External)).map(|o| o.script_pubkey.clone()).collect();
A Vec also handles the "many things at once" case honestly rather than
pretending there's a single address.
Back-compat looks like it has an in-repo precedent: tx_type was added to
this same variant as an optional field, with the documented "records written
before it existed read back as None" behavior and a round-trip test
(known_onchain_tx_type_survives_unknown_update). The same shape should work
here.
We're aware this isn't free — PaymentKind is derive(uniffi::Enum), so a new
field lands in the Swift/Kotlin/Python bindings too and needs a representation
chosen for it.
Happy to write the PR if the shape above (external-only, Vec, optional field)
is the direction you'd want. Equally happy to be told a different shape is
preferred, or that this isn't worth the bindings churn.
Activity
tnull commentedon Nov 7, 2025
This might not be as trivial, because many things could happen at the same time in a single transaction, i.e., also multiple (change) addresses could be in the mix. Our current model is that we classify transactions as 'inbound'/'outbound' based on whether they send more to foreign addresses than to wallet-owned addresses, which works decently well, but I'm not quite sure if there's currently a good way for us to access this information or expose it reasonably (short of listing out all details).
hash-money commentedon Jul 24, 2026
We hit this from a different angle and did some digging that might help unblock
the two doubts in the previous comment.
Use case. We're building a graduated-custody wallet on LDK Node (via
orange-sdk). Our Receive screen shows a BIP21 request and flips to a "paid"
state when the payment lands — we match Lightning receives on
PaymentKind::Bolt11 { hash }, which works well. On-chain receives can't bematched at all:
PaymentKind::Onchaincarries onlytxid, so we can't tellwhether the payment that just arrived is the request the user is looking at or
an unrelated deposit. There's no local workaround short of independently
querying a chain backend and re-deriving ownership, which duplicates work the
node already did and is backend-specific for us.
On "not sure there's currently a good way for us to access this
information": the data appears to already be in hand at the point the record
is built.
Wallet::create_payment_from_tx(src/wallet/mod.rs:1444) receivesboth the full
tx: &Transactionand thelocked_wallet, andonchain_payment_fields_lockedright above it (:1417) already callslocked_wallet.sent_and_received(tx)(:1421) — which walks the outputsagainst the keychain index to compute amount/direction. So the per-output
ownership determination is happening already; the script just isn't retained.
On "expose it reasonably (short of listing out all details)" + the
change-address concern:
bdk_walletexposesderivation_of_spk(spk) -> Option<(KeychainKind, u32)>, documented as onlyreturning
Some(_)for spks the wallet has given out. Filtering onKeychainKind::Externaltherefore excludes change outputs by construction,which we think is exactly the distinction that makes this tractable — you'd
expose only the spks that were handed out, not "all details". Something like:
A
Vecalso handles the "many things at once" case honestly rather thanpretending there's a single address.
Back-compat looks like it has an in-repo precedent:
tx_typewas added tothis same variant as an optional field, with the documented "records written
before it existed read back as
None" behavior and a round-trip test(
known_onchain_tx_type_survives_unknown_update). The same shape should workhere.
We're aware this isn't free —
PaymentKindisderive(uniffi::Enum), so a newfield lands in the Swift/Kotlin/Python bindings too and needs a representation
chosen for it.
Happy to write the PR if the shape above (external-only,
Vec, optional field)is the direction you'd want. Equally happy to be told a different shape is
preferred, or that this isn't worth the bindings churn.