Skip to content

Printing a PjUri drops non-payjoin recognized params #2050

Open

Description

@DanGould

check_pj_supported builds a new URI from the fields payjoin knows (address, amount, label, message, pj, pjos) instead of keeping the one it parsed, so a PjUri prints without everything else. Parse bitcoin:bc1q…?amount=0.01&lightning=lnbc…&pj=https://…, call check_pj_supported, and to_string() comes back without lightning=. Same for sp= or any unknown key. This is the payjoin crate half of payjoin/bitcoin_uri#10. bitcoin_uri 0.2 prints a parsed URI exactly as it came in, and a plain payjoin Uri does too since #1975, but a PjUri still doesn't.

check_pj_supported should keep the parsed bitcoin_uri::Uri. The catch is set_amount. A bitcoin_uri 0.2 Uri can't be edited, so setting an amount means rebuilding, and the builder is stricter than the parser, so some parsed URIs can't be rebuilt as written.

set_amount is a receiver urtility. It's public for v1 receivers, who call it after build_v1_pj_uri, as payjoin-cli does. v2 receivers already pass the amount up front with ReceiverBuilder::with_amount. The amount belongs on the receiver side, set before the URI exists, and a receiver should be able to set a label and message there too. Right now it can't set those at all.

The plan:

  1. check_pj_supported keeps the parsed URI, so a sender's PjUri prints what it parsed.
  2. Either receivers get a builder for amount, label and message, for v1 and v2, built on bitcoin_uri::UriBuilder, or they use bitcoin_uri::UriBuilder directly and payjoin hands out its pj and pjos params together as strings (I'm leaning toward the latter). To be discussed. Deprecate PjUri::set_amount and payjoin-ffi's set_amount_sats in favor of whichever we pick, and document that set_amount on a parsed URI drops non-payjoin params.
  3. Remove set_amount in 2.0.

1 and 2 are additive, so they can ship in 1.x.

Activity

  1. MayurK-cmd commented on Nov 12, 2026

    @MayurK-cmd

    hey can i work on this one?

  2. caarloshenriq commented on Nov 13, 2026

    @caarloshenriq
    Contributor

    I put step 1 in #1975 as a new commit since it changes code that PR adds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions