Skip to content

Implement BIP 370 PSBTv2#21283

Open
achow101 wants to merge 34 commits intobitcoin:masterfrom
achow101:psbt2
Open

Implement BIP 370 PSBTv2#21283
achow101 wants to merge 34 commits intobitcoin:masterfrom
achow101:psbt2

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Feb 23, 2021

BIP 370 PSBTv2 introduces several new fields and different invariants for PSBT. This PR implements those new fields and restructures the PSBT implementation to match PSBTv2 but still remain compatible with PSBTv0.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 24, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/21283.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK rkrux
Stale ACK scgbckbone

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34520 (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko)
  • #34124 (refactor: make CCoinsView a pure virtual interface by l0rinc)
  • #33014 (rpc: Fix internal bug in descriptorprocesspsbt when encountering invalid signatures by b-l-u-e)
  • #32876 (refactor: use options struct for signing and PSBT operations by Sjors)
  • #32857 (wallet: allow skipping script paths by Sjors)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Comment on lines 1192 to 1193
result.pushKV("input_count", psbtx.inputs.size());
result.pushKV("output_count", psbtx.inputs.size());
Copy link
Member

Choose a reason for hiding this comment

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

Getting a compile error consistent with the CI for these two lines:

rpc/rawtransaction.cpp:1192:16: error: call to member function 'pushKV' is ambiguous
        result.pushKV("input_count", psbtx.inputs.size());
        ~~~~~~~^~~~~~
./univalue/include/univalue.h:127:10: note: candidate function
    bool pushKV(const std::string& key, int64_t val_) {
         ^
./univalue/include/univalue.h:131:10: note: candidate function
    bool pushKV(const std::string& key, uint64_t val_) {
         ^
./univalue/include/univalue.h:135:10: note: candidate function
    bool pushKV(const std::string& key, bool val_) {
         ^
./univalue/include/univalue.h:139:10: note: candidate function
    bool pushKV(const std::string& key, int val_) {
         ^
./univalue/include/univalue.h:143:10: note: candidate function
    bool pushKV(const std::string& key, double val_) {
         ^
./univalue/include/univalue.h:118:10: note: candidate function
    bool pushKV(const std::string& key, const UniValue& val);
         ^
./univalue/include/univalue.h:119:10: note: candidate function not viable: no known conversion from 'std::__1::vector<PSBTInput, std::__1::allocator<PSBTInput> >::size_type' (aka 'unsigned long') to 'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') for 2nd argument
    bool pushKV(const std::string& key, const std::string& val_) {
         ^
./univalue/include/univalue.h:123:10: note: candidate function not viable: no known conversion from 'std::__1::vector<PSBTInput, std::__1::allocator<PSBTInput> >::size_type' (aka 'unsigned long') to 'const char *' for 2nd argument
    bool pushKV(const std::string& key, const char *val_) {
         ^
rpc/rawtransaction.cpp:1193:16: error: call to member function 'pushKV' is ambiguous
        result.pushKV("output_count", psbtx.inputs.size());
        ~~~~~~~^~~~~~
./univalue/include/univalue.h:127:10: note: candidate function
    bool pushKV(const std::string& key, int64_t val_) {
         ^
./univalue/include/univalue.h:131:10: note: candidate function
    bool pushKV(const std::string& key, uint64_t val_) {
         ^
./univalue/include/univalue.h:135:10: note: candidate function
    bool pushKV(const std::string& key, bool val_) {
         ^
./univalue/include/univalue.h:139:10: note: candidate function
    bool pushKV(const std::string& key, int val_) {
         ^
./univalue/include/univalue.h:143:10: note: candidate function
    bool pushKV(const std::string& key, double val_) {
         ^
./univalue/include/univalue.h:118:10: note: candidate function
    bool pushKV(const std::string& key, const UniValue& val);
         ^
./univalue/include/univalue.h:119:10: note: candidate function not viable: no known conversion from 'std::__1::vector<PSBTInput, std::__1::allocator<PSBTInput> >::size_type' (aka 'unsigned long') to 'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char> >') for 2nd argument
    bool pushKV(const std::string& key, const std::string& val_) {
         ^
./univalue/include/univalue.h:123:10: note: candidate function not viable: no known conversion from 'std::__1::vector<PSBTInput, std::__1::allocator<PSBTInput> >::size_type' (aka 'unsigned long') to 'const char *' for 2nd argument
    bool pushKV(const std::string& key, const char *val_) {
         ^
2 errors generated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't replicate this error at all, but I think I have fixed it.

@darosior
Copy link
Member

darosior commented Feb 3, 2026

In 20 days it will have been 5 years since this PR was open. Let's try to re-gain some momentum around reviewing this?

If a few other regular contributors volunteer to review this, i will commit to review it too. Some (re?)testing from users and outside contributors could be useful too.

assert len(psbt.tx.vin) == 1
assert len(psbt.tx.vout) == 1
assert len(psbt.i) == 1
assert len(psbt.i) == 1

Choose a reason for hiding this comment

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

Should this be ‎psbt.o instead of ‎psbt.i here?

if (amount == std::nullopt) {
throw std::ios_base::failure("Output amount is required in PSBTv2");
}
if (!script.has_value()) {
Copy link

@kannapoix kannapoix Feb 10, 2026

Choose a reason for hiding this comment

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

PSBT_OUT_SCRIPT is not required in BIP375. Should we address that here, or is it out of scope for this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.