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

Update PSBT test #627

Closed

Conversation

joemphilips
Copy link
Contributor

@joemphilips joemphilips commented Dec 30, 2018

  • implement walletcreatefundedpsbt rpc
  • implement getaddressinfo rpc (by biproduct)
  • fix subtle bug in multisig script finalization.
  • enable finalization only in a NBitcoin-aware type of script. (Currently only for regular multisig)

* Finalization for multisig was counting `OP_0` as real signature, so fix.
* In v0.17 of bitcoin core, `importmulti` does not recognize witness script, so ignore for now.
* Rename `GetSigPushes` to more Generic `GetPushItems`
* throw error when tried to finalize PSBT Input with unknown type of script.
@joemphilips
Copy link
Contributor Author

FWIW, segwit support for importmulti is merged in this pr
It seems bitcoin core is heading towards to the trend for using the word "redeemscript" exclusively for p2sh script, btw.

* Run ScriptVerify before setting final_script*
* Capture Errors in `TryFinalize`
@NicolasDorier
Copy link
Collaborator

Thanks, reviewing. Next time can you make several PRs instead of one big? it is faster to review.

@@ -311,10 +311,19 @@ private void DeconstructTxIn(TxIn txin)

internal void AddCoin(ICoin coin, TxIn txin = null)
{
if (coin is ScriptCoin && !IsFinalized() && txin != null)
var scriptCoin = coin as ScriptCoin;
if (scriptCoin != null && !IsFinalized() && txin != null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave it like this, but protip to simplify:

- var scriptCoin = coin as ScriptCoin;
- if (scriptCoin != null && !IsFinalized() && txin != null)
+ if (coin is ScriptCoin scriptCoin && !IsFinalized() && txin != null)

@@ -1404,8 +1406,8 @@ public void ShouldWalletProcessPSBTAndExtractMempoolAcceptableTX()
result = client.WalletProcessPSBT(psbtUnFinalized, false, type, bip32derivs: true);
Assert.False(result.Complete);
Assert.False(result.PSBT.CanExtractTX());
result.PSBT.TryFinalize(out bool isFinalized2);
Assert.False(isFinalized2);
result.PSBT.TryFinalize(out var errors2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should still Assert.False this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the TryFinalize API to take out InvalidOperationException[] instead of out bool so that the user can see why (and which input) is failing to finalize (breaking change). So Assert.NotEmpty below is equal to previous Assert.False
Sorry that I have put too many changes in one PR, I will split.

// with 2 difference.
// 1. one user (David) do not use bitcoin core (only NBitcoin)
// 2. 4-of-4 instead of 2-of-3
// 3. In version 0.17, `importmulti` can not handle witness script so only p2sh are considered here. TODO: fix
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed in 0.17.1 ? :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried but its not fixed :(

Copy link
Contributor Author

@joemphilips joemphilips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next time can you make several PRs instead of one big? it is faster to review.

I will split this one. It is my bad habit that creating too big PR :(

@@ -1404,8 +1406,8 @@ public void ShouldWalletProcessPSBTAndExtractMempoolAcceptableTX()
result = client.WalletProcessPSBT(psbtUnFinalized, false, type, bip32derivs: true);
Assert.False(result.Complete);
Assert.False(result.PSBT.CanExtractTX());
result.PSBT.TryFinalize(out bool isFinalized2);
Assert.False(isFinalized2);
result.PSBT.TryFinalize(out var errors2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the TryFinalize API to take out InvalidOperationException[] instead of out bool so that the user can see why (and which input) is failing to finalize (breaking change). So Assert.NotEmpty below is equal to previous Assert.False
Sorry that I have put too many changes in one PR, I will split.

// with 2 difference.
// 1. one user (David) do not use bitcoin core (only NBitcoin)
// 2. 4-of-4 instead of 2-of-3
// 3. In version 0.17, `importmulti` can not handle witness script so only p2sh are considered here. TODO: fix
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried but its not fixed :(

@joemphilips
Copy link
Contributor Author

closing in favor of #630 #631 #632

@joemphilips joemphilips closed this Jan 4, 2019
@joemphilips joemphilips deleted the psbt.walletcreatefundedpsbt branch January 5, 2019 12:39
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

Successfully merging this pull request may close these issues.

None yet

2 participants