Skip to content

Conversation

@jnewbery
Copy link
Contributor

This PR removes almost all of the TxToJSON() and ScriptPubKeyToJSON() code from bitcoin-rpc and places it in bitcoin-common, removing about 80 lines of duplicate code. The only part that can't be moved into bitcoin-common is parsing block contextual information (confirmations and blocktime), which are not available to bitcoin-common code.

This PR should be merged along with #8817 , which ensures that witness data gets returned from calls to TxToUniv()

@jnewbery jnewbery changed the title refactor TxToJSON() and ScriptPubKeyToJSON() [WIP - requires pull/8817] refactor TxToJSON() and ScriptPubKeyToJSON() Sep 27, 2016
@jnewbery
Copy link
Contributor Author

#8817 has now been merged into master. I've rebased this PR.

@jnewbery jnewbery changed the title [WIP - requires pull/8817] refactor TxToJSON() and ScriptPubKeyToJSON() Refactor TxToJSON() and ScriptPubKeyToJSON() Oct 14, 2016
@jnewbery
Copy link
Contributor Author

bitcoin-test-util.py now fails json tests because output includes transaction size and vsize. I'll fix up the tests in a new commit.

@jonasschnelli
Copy link
Contributor

Concept ACK.
We should make sure, there is no API changes (= maybe ~100% test coverage?) because of the refactoring.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe ::GetVirtualTransactionSize(tx)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GetVirtualTransactionSize() is declared in policy.h, which isn't included in core_write.

Why is GetVirtualTransactionSize() in policy? Because transaction virtual size isn't a consensus rule, and is only used for mempool admittance/miner selection. On top of that, after #8365 , virtual size has been overloaded to mean both transaction weight/4 and an adjusted virtual size taking account of sigops cost.

I could update core_write.cpp to include policy, but I don't think it's a good idea to include policy more widely than necessary.

@jnewbery
Copy link
Contributor Author

@jonasschnelli - are you happy with my response above? Any further questions?

@jnewbery jnewbery force-pushed the JSON_refactor branch 2 times, most recently from 3952ae4 to 22c34e7 Compare November 4, 2016 09:35
@jnewbery
Copy link
Contributor Author

jnewbery commented Nov 4, 2016

rebased. Is anyone happy to ACK this?

@jonasschnelli - did you have time to review my response above?

Copy link
Contributor

@jonasschnelli jonasschnelli Nov 4, 2016

Choose a reason for hiding this comment

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

Doesn't this require std::max(GetTransactionWeight(tx), nSigOpCost * nBytesPerSigOp)?
Nm: it's not required here.

@jonasschnelli
Copy link
Contributor

Tested ACK 22c34e7e4c74d2c7d1cc64a75c6654f3ae82377b

@jnewbery jnewbery force-pushed the JSON_refactor branch 2 times, most recently from e9deba0 to bf7b745 Compare January 10, 2017 15:47
@jnewbery
Copy link
Contributor Author

Rebased

@jnewbery
Copy link
Contributor Author

Rebased

src/rpc/server.h Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Server is the wrong place for this - the conceptual idea is that it is a purely a RPC server, and independent of anything bitcoin specific.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, I think you can simply remove the changes to this file as the function is in core_write now?

@jnewbery
Copy link
Contributor Author

jnewbery commented Mar 7, 2017

Addressed @laanwj 's review comment and rebased.

@fanquake
Copy link
Member

Needs a rebase.

@jnewbery
Copy link
Contributor Author

Rebased

@laanwj
Copy link
Member

laanwj commented Apr 26, 2017

It looks like this got entangled with a test change?

here's a rebased version: https://github.com/laanwj/bitcoin/tree/2017_04_jnewbery_JSON_refactor

Was planning to merge it, but the json test changes in a RPC refactoring pull don't look right.

@jnewbery
Copy link
Contributor Author

"size" was added to the getrawtransaction output in #7072. "vsize" was added in #8149. Because bitcoin-tx used TxToUniv() and the rawtransaction RPCs used TxToJSON(), bitcoin-tx functionality fell behind the ratransaction RPC functionality and didn't include these new fields. This PR removes the duplicate code between TxToUniv() and TxToJSON(), and as a result restores parity between bitcoin-tx and the _rawtransaction RPCs.

Sorry that wasn't clear in the OP.

@jnewbery
Copy link
Contributor Author

rebased. Last time please :)

@laanwj laanwj merged commit 0ff9320 into bitcoin:master May 1, 2017
laanwj added a commit that referenced this pull request May 1, 2017
0ff9320 refactor TxToJSON() and ScriptPubKeyToJSON() (jonnynewbs)

Tree-SHA512: caf7d590829e221522edd5b1ab8ce67b53a2c6986d3bbe8477eab420b1007bf60f885ed0a25ba9587e468c00768360ddc31db37847e862858573eaed5ed8b0d6
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 12, 2019
Summary:
This PR removes almost all of the TxToJSON() and ScriptPubKeyToJSON() code from bitcoin-rpc and places it in bitcoin-common, removing about 80 lines of duplicate code. The only part that can't be moved into bitcoin-common is parsing block contextual information (confirmations and blocktime), which are not available to bitcoin-common code.

Backports Core PR8824 bitcoin/bitcoin#8824

Completes T500.

Test Plan: make check

Reviewers: jasonbcox, deadalnix, O1 Bitcoin ABC, #bitcoin_abc, Fabien

Reviewed By: deadalnix, O1 Bitcoin ABC, #bitcoin_abc

Subscribers: teamcity

Differential Revision: https://reviews.bitcoinabc.org/D2499
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jun 9, 2019
0ff9320 refactor TxToJSON() and ScriptPubKeyToJSON() (jonnynewbs)

Tree-SHA512: caf7d590829e221522edd5b1ab8ce67b53a2c6986d3bbe8477eab420b1007bf60f885ed0a25ba9587e468c00768360ddc31db37847e862858573eaed5ed8b0d6
UdjinM6 pushed a commit to dashpay/dash that referenced this pull request Jun 11, 2019
* Merge bitcoin#8824: Refactor TxToJSON() and ScriptPubKeyToJSON()

0ff9320 refactor TxToJSON() and ScriptPubKeyToJSON() (jonnynewbs)

Tree-SHA512: caf7d590829e221522edd5b1ab8ce67b53a2c6986d3bbe8477eab420b1007bf60f885ed0a25ba9587e468c00768360ddc31db37847e862858573eaed5ed8b0d6

* remove witness and vsize

Signed-off-by: Pasta <[email protected]>

* Add valueSat

To preserve rpc output format

* Move extrapayload and special tx json output to `TxToUniv`

* Add spent index info
@jnewbery jnewbery deleted the JSON_refactor branch December 20, 2019 14:31
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants