Skip to content

Implement version specific types #116

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GideonBature
Copy link
Contributor

@GideonBature GideonBature commented Apr 5, 2025

Implement Version-Specific Types for Status omitted

This PR addresses issue #115 by implementing the methods with status of 'omitted' in methods with version-specific types. Previously, 'omitted' was used in cases where return types were standard or seemingly inconsequential (e.g., null, standard library types). However, this approach introduced a risk: if the return type of such methods changes in future Bitcoin Core versions, we would not catch it.

To fix this, this PR:

  • Defines version-specific types for affected methods.
  • Updates method definitions to use Method::new_no_model in corresponding methods.
  • Adds integration tests for each updated method to verify correctness and catch future regressions.

This improves type safety, clarity, and future-proofing of the client interface.


Summary of Work Done

🚀 Blockchain Methods

Tested with:

cargo test --features=28_0 --test blockchain
S/N Method Name Implemented Test Written
1 pruneblockchain
2 savemempool
3 scantxoutset
4 verifychain

🌐 Network Methods

Tested with:

cargo test --features=28_0 --test network
S/N Method Name Implemented Test Written
5 addnode
6 clearbanned
7 disconnectnode
8 getconnectioncount
9 listbanned
10 ping
11 setban
12 setnetworkactive

💰 Wallet Methods

Tested with:

cargo test --features=28_0 --test wallet
S/N Method Name Implemented Test Written
13 abandontransaction
14 abortrescan
15 backupwallet
16 encryptwallet
17 importaddress
18 importmulti
19 importprivkey
20 importprunedfunds
21 importpubkey
22 importwallet
23 keypoolrefill
24 lockunspent
25 removeprunedfunds
26 sethdseed
27 settxfee
28 walletlock
29 walletpassphrase
30 walletpassphrasechange

✅ Ready for review

Closes #115

@GideonBature GideonBature changed the title WIP: feat(rpc/v17 - v28): Add initial implementation for pruneblockchain (#115) WIP: feat(rpc/v17 & v28): Add initial implementation for pruneblockchain (#115) Apr 5, 2025
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Looking good mate. I wouldn't personally bother pruning at the moment. At this stage just checking that the returned data is the correct shape is enough.

@GideonBature
Copy link
Contributor Author

I have effected the changes reviewed, please do have a check when you are chanced.

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Getting there man, keep at it.

@GideonBature
Copy link
Contributor Author

Changes effected... Thank you so much for all the reviews, I am really learning and understanding the codebase more.

@tcharding
Copy link
Member

I just introduced a new style of writing test code in #125. Please follow the same style when you write your new tests. Thanks man!

@GideonBature
Copy link
Contributor Author

Alright, I will check it out... Thank you :).

@GideonBature GideonBature changed the title WIP: feat(rpc/v17 & v28): Add initial implementation for pruneblockchain (#115) Implement version specific types Apr 13, 2025
@GideonBature GideonBature marked this pull request as ready for review April 21, 2025 19:48
@tcharding
Copy link
Member

tcharding commented Apr 22, 2025

You got a rebase mistake in there mate. In verify/src/method/

@tcharding
Copy link
Member

In case its useful to you I have this alias

which mc
mc: aliased to git grep -l '<<<<'

Then I use mc to check for merge conflicts after rebasing.

@tcharding
Copy link
Member

This is going to be hard for me to review because its so big but also I appreciate that it is hard to work on this crate without doing big changesets so I'm happy to review this but there may be a few iterations.

@tcharding
Copy link
Member

Some things I found:

  • Need to set the status to done e.g. types/src/v17/mod.rs when each method is added and tested
  • If you could use the new test format I'd appreciate it, otherwise I have to go over all the tests and add it
    let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof)?;
    let model: Result<mtype::VerifyTxOutProof, _> = json.into_model();
    let txids = model.unwrap();

The point to this is to check that all the re-exports were done correctly.

Or using PruneBlockchain

    let _: PruneBlockchain = node.client.prune_blockchain(target_height);

It would probably be best to push up an initial patch that does just one method completely so I can review that and then you could do all the others as a second patch. Sorry I should have said that weeks ago, my bad. There is a way to stage code chunks so you can pull the changes out - let me know if you want more tips on that.

@tcharding
Copy link
Member

Appreciate your efforts man, this is not the easiest crate to work on. Holla at me if you have any other questions.

@GideonBature GideonBature force-pushed the omitted-types-impl branch 6 times, most recently from adeb378 to 6ac7abc Compare April 22, 2025 09:20
@GideonBature
Copy link
Contributor Author

You got a rebase mistake in there mate. In verify/src/method/

Noted, thank you for spotting it out.

@GideonBature
Copy link
Contributor Author

This is going to be hard for me to review because its so big but also I appreciate that it is hard to work on this crate without doing big changesets so I'm happy to review this but there may be a few iterations.

No Problem, I will make all changes necessary as you review! :).

@GideonBature
Copy link
Contributor Author

Some things I found:

  • Need to set the status to done e.g. types/src/v17/mod.rs when each method is added and tested
  • If you could use the new test format I'd appreciate it, otherwise I have to go over all the tests and add it
    let json: VerifyTxOutProof = node.client.verify_tx_out_proof(&proof)?;
    let model: Result<mtype::VerifyTxOutProof, _> = json.into_model();
    let txids = model.unwrap();

The point to this is to check that all the re-exports were done correctly.

Or using PruneBlockchain

    let _: PruneBlockchain = node.client.prune_blockchain(target_height);

It would probably be best to push up an initial patch that does just one method completely so I can review that and then you could do all the others as a second patch. Sorry I should have said that weeks ago, my bad. There is a way to stage code chunks so you can pull the changes out - let me know if you want more tips on that.

True, almost forgot changing their status to done.

Okayyy, now I see the reason why, for this particular methods, most of them returns null or just a standard type so I will implement for the others just like the example you provided. Thank you so much for the reviews.

I will also push up an initial patch with single method so you can review, before doing the others. I will look it up i.e. stage code chucks, and if there is anything I don't understand, I will definitely ask for clarity.

Once again thank you always :).

@GideonBature GideonBature marked this pull request as draft April 30, 2025 16:55
tcharding added a commit that referenced this pull request May 29, 2025
359ac38 Implement disconnectnode method and test (GideonBature)

Pull request description:

  Going by the conversations with tcharding for PR [#116 ](#116) on implementing one method at a time for easier review: This is the disconnectnode method which is a specific type that returns a (json null). Once this is approved, I’ll proceed with the next one.

ACKs for top commit:
  tcharding:
    ACK 359ac38

Tree-SHA512: 3b16431e732e81edea1f290cf6436ae5ad0e72a591546b09e69eb47092c95ccef5e07be8908f20d32fb87a77cf623caf07eee0e96b96bc2fab7240af23e4286a
tcharding added a commit that referenced this pull request May 31, 2025
2408e45 Implement getconnectioncount method and test (GideonBature)

Pull request description:

  The JSON-RPC method `getconnectioncount` does return a numeric. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `numeric`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 2408e45

Tree-SHA512: 8fadbbe57fe567daebe150cf76cce96d0693ee1763bd8bbfafe4b736751da8dc42b2681aeccf7eb8fbc03083a2ecb131ee59ffc24608ea20ec3693b944477147
tcharding added a commit that referenced this pull request May 31, 2025
e266b9f Update 'returns (std)' to 'version' for version methods (GideonBature)

Pull request description:

  This PR updates `returns (std)` to `version` for all methods that have been implemented to return a type which wraps a standard value.

  Ref: #116

ACKs for top commit:
  tcharding:
    ACK e266b9f

Tree-SHA512: 1162ac34fbffe51070d799cfc70fd9d6442817a8f3f916ea852c33b9eaa760e65422d7886382409ce8e087c88d24637a2fbc603005ac7d70b0954438e33b5bc7
tcharding added a commit that referenced this pull request Jun 1, 2025
8b1f578 Implement ping method and test (GideonBature)

Pull request description:

  The JSON-RPC method `ping` does return null. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 8b1f578

Tree-SHA512: c2626a22f96179e22154a8830a53d6b2568c959515244445dc6481572bde8f45ea9eec16f82bafa19ad8c31814c49d6ccf2e3d0a1d279191548e420d3d15d55d
tcharding added a commit that referenced this pull request Jun 8, 2025
e071183 Format code changes (GideonBature)
9753048 Implement setnetworkactive method and test (GideonBature)

Pull request description:

  The JSON-RPC method `setnetworkactive` does return a boolean. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `boolean`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK e071183

Tree-SHA512: 8a1a4f82da9cceeb2b7cb525893337fbe76595a5377887811831a4ee43962fe47b7c3c58e19ee545ad19a9e39ea08a5a1534fa3f9a61af52bcc695ce4981a388
tcharding added a commit that referenced this pull request Jun 9, 2025
5d6b977 Implement abandontransaction and test (GideonBature)

Pull request description:

  The JSON-RPC method `abandontransaction` does return null. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  jamillambert:
    ACK 5d6b977
  tcharding:
    ACK 5d6b977

Tree-SHA512: 4801603b099f0fd04fd234dced71318e619cb201a22cb801140010cc88ce4ed316e372718c8c475b52e4caed8ce7cf8676b5197838953ee35e6c5482920b49ca
tcharding added a commit that referenced this pull request Jun 12, 2025
4b4e084 Implement importprivkey and test (GideonBature)

Pull request description:

  The JSON-RPC method `importprivkey` does return null. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 4b4e084

Tree-SHA512: 9a506b8b250d55099027241c53b2fa169f73cb988e92667c7dcb10ab30f63c14462b6501db40b595129be39a8f1e9d07581e53dcea02154f2249924c013c981c
tcharding added a commit that referenced this pull request Jun 13, 2025
9a24cfd Format code (GideonBature)
5decd11 Implement abortrescan method and test (GideonBature)

Pull request description:

  The JSON-RPC method `abortrescan` does return a type. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  jamillambert:
    ACK 9a24cfd
  tcharding:
    ACK 9a24cfd

Tree-SHA512: 1c5c58fc482691e7354d5ea61398b7bf37bae3b16578305d70ac8eb57c222c57102d12da7ab340b59faa49f2e1977259cadaa519917137b646bb0a64f03df54c
tcharding added a commit that referenced this pull request Jun 16, 2025
f76918a Format code (GideonBature)
99751f6 Implement listbanned method and test (GideonBature)

Pull request description:

  The JSON-RPC method `listbanned` does return a type. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  jamillambert:
    ACK f76918a
  tcharding:
    ACK f76918a

Tree-SHA512: e7b5ad83a485ed4ea98fdda2d7eaa52ce13af506f0444e0a0b666331b321125c043fe31545745e2c357c625618f0c034cf2191c74cd1a669217c574f6316d17a
tcharding added a commit that referenced this pull request Jun 16, 2025
8c14cd0 Implement backupwallet method and test (GideonBature)

Pull request description:

  The JSON-RPC method `backupwallet` does return null. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 8c14cd0

Tree-SHA512: ee68c57b2e8be5c10408b7e21f05d477429d20bcd6a6e4758a933f6607f277f6d4cca825885cca1780524761ffe89c2ad64866bee76d5b934f27807efc0f2626
tcharding added a commit that referenced this pull request Jun 19, 2025
e513cbe Format code changes (GideonBature)
2d469bf Implement encryptwallet method and test (GideonBature)

Pull request description:

  The JSON-RPC method `encryptwallet` does return a type. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  jamillambert:
    ACK e513cbe
  tcharding:
    ACK e513cbe

Tree-SHA512: 276126a1b80ba96aa5b1c4ef48e47288188a0e2c94e323b190a498feb322e9d6157d86175aa60bb133fa96feeac8e96ba042f7368bd0e63cf73d6dcebc6a0d78
tcharding added a commit that referenced this pull request Jun 19, 2025
859ec74 Implement importaddress method and test (GideonBature)

Pull request description:

  The JSON-RPC method `importaddress` does return null. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  jamillambert:
    ACK 859ec74
  tcharding:
    ACK 859ec74

Tree-SHA512: 1a4c4eceba4f7e7adb2928b50ea7ce42116388522874df2eb4179b7330370376f8f9db0b91b6f71633258a0ea5a95292221a0f2d6e162b2a44dd14fff72b9b10
tcharding added a commit that referenced this pull request Jun 24, 2025
4eef869 Format code (GideonBature)
e6d00b9 Implement importprunedfunds and test (GideonBature)

Pull request description:

  The JSON-RPC method `importprunedfunds` does not return anything. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 4eef869

Tree-SHA512: a589ac5cefd2510546e1621c268d10d223727d76c4dce05689de4f5a894bd653857a8ea537f5b345fdfa990479db05eb400aa2d91c1dc5ec8c37e7b0deddc657
tcharding added a commit that referenced this pull request Jun 25, 2025
1430723 Implement importpubkey method and test (GideonBature)

Pull request description:

  The JSON-RPC method `importpubkey` does not return anything. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than `null`, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK 1430723

Tree-SHA512: 06ed71c3636a386d7b90750fdea74b846a8514b68066bd44d5b71c7300a20e023729ad944871da57d6f3bf33cabb8cdebf7359ac1c1acc9a00a7f938be168b54
tcharding added a commit that referenced this pull request Jun 28, 2025
ec24420 Format code (GideonBature)
4667b26 Implement importmulti method and test (GideonBature)

Pull request description:

  The JSON-RPC method `importmulti` does return a type. We want to test this to catch any changes in behavior in future Core versions.

  This PR adds a client function that errors if the return value is anything other than the type it returns, along with an integration test that calls this function.

  Ref: [#116](#116)

ACKs for top commit:
  tcharding:
    ACK ec24420

Tree-SHA512: 97294e566586bd51e05042be06ca169272689b131510a239682dc6bade95eb87acbf9d86553cba1e06e3554389402b0525bd925eb5ee2c5ceb71d9a6aa4208eb
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.

Implement version specific types for status 'omitted' methods
2 participants