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

Non-segwit inputs are not serialized in PSBTs #1171

Open
Jossec101 opened this issue May 8, 2023 · 4 comments
Open

Non-segwit inputs are not serialized in PSBTs #1171

Jossec101 opened this issue May 8, 2023 · 4 comments

Comments

@Jossec101
Copy link

Jossec101 commented May 8, 2023

It looks like that after getting the base64 string of a PSBT the non-witness UTXO fields are not serialised hence empty/null after deserialising back to the PSBT object.

Looks like orphanTxOut is not used much

internal TxOut? orphanTxOut = null; // When this input is not segwit, but we don't have the previous tx

If I retrieve a PSBTInput object, named input an do input.GetCoin().TxOutis filled if the PSBT was generated programatically from code (.i.e. PSBT Builder), this is because the orphanTxOut is filled.
image

However, after deserialising back from a base64 PSBT, orphanTxOut is no longer present and therefore I cannot get the Coin of a non-segwit input. This is happening in the picture below.

image

Hope I explained well enough 👯

@Jossec101
Copy link
Author

Jossec101 commented May 8, 2023

I managed to make it work by adding the NonWitnessUtxo by hand using Nbxplorer

foreach (var item1Input in result.Item1.Inputs)
          {
              item1Input.NonWitnessUtxo =                (await  _nbXplorerService.GetTransactionAsync(item1Input.PrevOut.Hash, default)).Transaction;

          }

@NicolasDorier
Copy link
Collaborator

@Jossec101 if you are using NBXplorer, this endpoint https://github.com/dgarage/NBXplorer/blob/master/docs/API.md#create-partially-signed-bitcoin-transaction has alwaysIncludeNonWitnessUTXO.

Else, you are correct, the TransactionBuilder's PSBT doesn't include the NonWitnessUtxo, because it has no knowledge about it. (The Coin abstraction can't have any transaction attached to it)

@Jossec101
Copy link
Author

I guess an improvement to the builder should programatically allow to add the NonWitnessUtxo for serialisation, it serialised to base64 well after adding it manually.

@NicolasDorier
Copy link
Collaborator

The problem is that it doesn't have this information. There is no way to feed the previous transactions to the builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants