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

feat: add Wallet Descriptor Support for Transaction Indexing #407

Merged
merged 6 commits into from
Oct 23, 2023

Conversation

qustavo
Copy link
Contributor

@qustavo qustavo commented Sep 2, 2023

This introduces support for wallet descriptors.
Descriptors provide a compact and semi-standardized method for describing how scripts and addresses within a wallet are generated[1].

Chainhooks users that want to track addresses derived from an extended pubkey or a multisig-wallet for example, can now rely on this feature instead of defining one predicate per address.

For example if we wanted to track the first 3 addressed generated by the following descriptor:

wpkh(tprv8ZgxMBicQKsPePxn6j3TjvB2MBzQkuhGgc6oRh2WZancZQgxktcnjZJ44XdsRiw3jNkbVTK9JW6KFHvnRKgAMtSyuBevMJprSkZ4PTfmTgV/84'/1'/0'/0/*)

which reads: describe a P2WPKH output with the specified extended public key, and produces these BIP84 addresses:

bcrt1qzy2rdyvu8c57qd8exyyp0mw7dk5drsu9ewzdsu
bcrt1qsfsjnagr29m8h3a3vdand2s85cg4cefkcwk2fy
bcrt1qauewfytqe5mtr0xwp786r6fl39kmum2lr65kmj

we could use the following predicate:

...
  "networks": {
    "regtest": {
      "if_this": {
        "scope": "outputs",
        "descriptor": {
          "expression": "wpkh(tprv8ZgxMBicQKsPePxn6j3TjvB2MBzQkuhGgc6oRh2WZancZQgxktcnjZJ44XdsRiw3jNkbVTK9JW6KFHvnRKgAMtSyuBevMJprSkZ4PTfmTgV/84'/1'/0'/0/*)",
          "range": [0,3]
        }
      },
      "then_that": {
        "file_append": {
          "path": "txns.txt"
        }
      }
    }
  }
...

1: https://bitcoindevkit.org/descriptors/

@lgalabru
Copy link
Contributor

This is really cool, thank you @qustavo 🚀
Do you think we could have some tests for this PR?
Happy to set-up with you and @MicaiahReid, and onboard you with our testing framework if you think it can help!

@qustavo
Copy link
Contributor Author

qustavo commented Sep 13, 2023

This is really cool, thank you @qustavo 🚀 Do you think we could have some tests for this PR? Happy to set-up with you and @MicaiahReid, and onboard you with our testing framework if you think it can help!

Thanks for taking the time to review, and definitively yes, I'd like to get onboard with how you test this.

@lgalabru
Copy link
Contributor

@qustavo sounds great, could you shoot me a message - ludovic at hiro so?
I'll follow up with an invite!

@@ -42,6 +42,8 @@ dashmap = "5.4.0"
fxhash = "0.2.1"
lazy_static = "1.4.0"
regex = "1.9.3"
miniscript = "10.0.0"
bitcoin = "0.30.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

@qustavo we may not need this dep, can you confirm if we can remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@MicaiahReid
Copy link
Contributor

Could you add a test case to the it_handles_bitcoin_if_this_predicates function in components/chainhook-cli/src/service/tests/mod.rs, as well as some documentation on this? What you have in the PR description could work great for our docs.

@qustavo qustavo force-pushed the feat/wallet-descriptors branch from b094ac1 to edf4da0 Compare September 24, 2023 15:55
@qustavo qustavo force-pushed the feat/wallet-descriptors branch 3 times, most recently from 441e7a8 to bdb7914 Compare October 2, 2023 21:29
@qustavo qustavo marked this pull request as ready for review October 2, 2023 21:31
@qustavo qustavo requested a review from MicaiahReid October 2, 2023 21:32
@qustavo
Copy link
Contributor Author

qustavo commented Oct 2, 2023

Could you add a test case to the it_handles_bitcoin_if_this_predicates function in components/chainhook-cli/src/service/tests/mod.rs, as well as some documentation on this? What you have in the PR description could work great for our docs.

added

The test was designed around the OpReturn matcher only. This change
generalizes it so that we can test other matchers.
This is preparatory work to introduce Wallet descriptor testing.
This introduces support for wallet descriptors.
Descriptors provide a compact and semi-standardized method for
describing how scripts and addresses within a wallet are generated[1].

Chainhooks users that want to track addresses derived from an extended
pubkey or a multisig-wallet for example, can now rely on this feature
instead of defining one predicate per address.

For example if we wanted to track the first 3 addressed generated by
the following descriptor:

```
wpkh(tprv8ZgxMBicQKsPePxn6j3TjvB2MBzQkuhGgc6oRh2WZancZQgxktcnjZJ44XdsRiw3jNkbVTK9JW6KFHvnRKgAMtSyuBevMJprSkZ4PTfmTgV/84'/1'/0'/0/*)
```

which reads: describe a P2WPKH output with the specified extended public
key, and produces these BIP84 addresses:

```
bcrt1qzy2rdyvu8c57qd8exyyp0mw7dk5drsu9ewzdsu
bcrt1qsfsjnagr29m8h3a3vdand2s85cg4cefkcwk2fy
bcrt1qauewfytqe5mtr0xwp786r6fl39kmum2lr65kmj
```

we could use the following predicate:

```json
...
  "networks": {
    "regtest": {
      "if_this": {
        "scope": "outputs",
        "descriptor": {
          "expression": "wpkh(tprv8ZgxMBicQKsPePxn6j3TjvB2MBzQkuhGgc6oRh2WZancZQgxktcnjZJ44XdsRiw3jNkbVTK9JW6KFHvnRKgAMtSyuBevMJprSkZ4PTfmTgV/84'/1'/0'/0/*)",
          "range": [0,3]
        }
      },
      "then_that": {
        "file_append": {
          "path": "txns.txt"
        }
      }
    }
  }
...

```

1: https://bitcoindevkit.org/descriptors/
@qustavo qustavo force-pushed the feat/wallet-descriptors branch from bdb7914 to 5616a6a Compare October 5, 2023 08:25
@hirosystems hirosystems deleted a comment from knowledgebreak Oct 8, 2023
Copy link
Contributor

@lgalabru lgalabru left a comment

Choose a reason for hiding this comment

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

Thanks @qustavo!

@lgalabru lgalabru merged commit 8ab5df4 into hirosystems:develop Oct 23, 2023
1 check failed
Copy link

🎉 This PR is included in version 1.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants