Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable building transaction from any given ScriptPubKey #159

Closed
thunderbiscuit opened this issue Jun 10, 2022 · 1 comment · Fixed by #192
Closed

Enable building transaction from any given ScriptPubKey #159

thunderbiscuit opened this issue Jun 10, 2022 · 1 comment · Fixed by #192
Assignees
Labels
ldk-compatibility Compatibility with the Lightning Dev Kit

Comments

@thunderbiscuit
Copy link
Member

This feature is required to make the language bindings interop with LDK.

The LDK workflow is the following:

  1. LDK gives you an output script in raw bytes which you must use to build a ready-to-be-broadcast transaction (the funding transaction)
  2. You must give this tx in its raw form back to LDK, which will then broadcast it (potentially using BDK as well, see Provide a way to broadcast raw transaction for LDK compatibility #157)

I have recreated what is required in Rust in this small cli tool. Of this workflow, I believe only a few lines would be "new" APIs for the bindings, namely:

// 1. transform the LDK output script from raw bytes into a Script type using either one of:
// let script: Script = Script::from_hex(&output_script_hex).unwrap();
let script: Script = Script::from(output_script_raw);

// 2. extract the tx from the psbt
let funding_tx: Transaction = psbt.extract_tx();

// 3. serialize the tx to give it back to LDK
let funding_tx_encoded = funding_tx.serialize();
@thunderbiscuit thunderbiscuit changed the title Enable building transactions from any given output script Enable building transaction from any given output script Jun 10, 2022
@thunderbiscuit thunderbiscuit self-assigned this Jun 10, 2022
@thunderbiscuit thunderbiscuit added the ldk-compatibility Compatibility with the Lightning Dev Kit label Jun 10, 2022
@thunderbiscuit thunderbiscuit changed the title Enable building transaction from any given output script Enable building transaction from any given ScriptPubKey Aug 2, 2022
@thunderbiscuit
Copy link
Member Author

thunderbiscuit commented Aug 29, 2022

One of the first issues that need to be fixed for this to work is that our add_recipient() method on the TxBuilder only accepts addresses:

for (address, amount) in &self.recipients {
    tx_builder.add_recipient(to_script_pubkey(address)?, *amount);
}

We'll need to enable it to take arbitrary scripts.

The second part of this is to expose the ability to extract and serialize the transaction once it has been signed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ldk-compatibility Compatibility with the Lightning Dev Kit
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants