Skip to content

invoice: Getter for fallbacks as Address'es #882

Closed

Description

@sgeisler

The fallback() method returns some custom address payload implementation. A regular fallback_addresses or so that is just a Vec<Address> would be great.

Or an Into<Address> for Fallback.

Activity

  1. futurepaul commented on Feb 7, 2023

    @futurepaul
    Contributor

    is there any good way right now to convert a Fallback into an Address? just ran into this and not sure the best strat.

  2. added this to the 0.0.115 milestone on Feb 7, 2023
  3. TheBlueMatt commented on Feb 7, 2023

    @TheBlueMatt
    Collaborator

    Sadly only pretty manually, we should fix this!

  4. futurepaul commented on Feb 7, 2023

    @futurepaul
    Contributor

    I'll make an Into<Address> based on this logic:

        match fallback {
            Fallback::SegWitProgram { version, program } => {
                let version = WitnessVersion::from_u5(version).unwrap();
                let script = Script::new_witness_program(version, program.as_slice());
                Address::from_script(&script, Network::Bitcoin)
            }
            Fallback::PubKeyHash(pkh) => {
                let pkh = PubkeyHash::from_slice(&pkh).unwrap();
                let script = Script::new_p2pkh(&pkh);
                Address::from_script(&script, Network::Bitcoin)
            }
            Fallback::ScriptHash(sh) => {
                let sh = ScriptHash::from_slice(&sh).unwrap();
                let script = Script::new_p2sh(&sh);
                Address::from_script(&script, Network::Bitcoin)
            }
        }
  5. assigned and unassigned on Feb 8, 2023
  6. jkczyz commented on Feb 8, 2023

    @jkczyz
    Contributor

    Currently, the builder has a method that takes a Fallback, which are then exposed via an accessor returning Vec<&Fallback>. So an Into<Address> would require a clone since self is taken by value.

    We have a few options that I can imagine:

    • use the Into approach and live with users needing to clone
    • hide Fallback by having separate builder methods for each variant and have the accessor return Vec<Address> like BOLT 12 invoices do
    • have an inconsistent interface where the builder remains as it is and the accessor returns Vec<Address>
    • add an additional accessor that returns Vec<Address> similar to private_route / route_hints, which would essentially hide the clone from the user

    I'm sorta leaning towards the last option to avoid too much change in the interface, but I'm open to other options.

  7. futurepaul commented on Feb 8, 2023

    @futurepaul
    Contributor

    sorry I saw this comment after writing this code so thought I'd throw it up here and if it's helpful can iterate, otherwise feel free to close

  8. jkczyz commented on Feb 8, 2023

    @jkczyz
    Contributor

    sorry I saw this comment after writing this code so thought I'd throw it up here and if it's helpful can iterate, otherwise feel free to close

    Nah, we'll need that or something like that somewhere, regardless. Just need to figure out which interface.

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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions