Refactor TxToJSON() and ScriptPubKeyToJSON() #8824

pull jnewbery wants to merge 1 commits into bitcoin:master from jnewbery:JSON_refactor changing 27 files +62 −78
  1. jnewbery commented at 2:20 pm on September 27, 2016: member

    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()

  2. MarcoFalke added the label Refactoring on Sep 27, 2016
  3. MarcoFalke added the label RPC/REST/ZMQ on Sep 27, 2016
  4. jnewbery renamed this:
    refactor TxToJSON() and ScriptPubKeyToJSON()
    [WIP - requires pull/8817] refactor TxToJSON() and ScriptPubKeyToJSON()
    on Sep 27, 2016
  5. jnewbery force-pushed on Oct 14, 2016
  6. jnewbery commented at 9:31 am on October 14, 2016: member
    #8817 has now been merged into master. I’ve rebased this PR.
  7. jnewbery renamed this:
    [WIP - requires pull/8817] refactor TxToJSON() and ScriptPubKeyToJSON()
    Refactor TxToJSON() and ScriptPubKeyToJSON()
    on Oct 14, 2016
  8. jnewbery commented at 10:50 am on October 14, 2016: member
    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.
  9. in src/core_write.cpp: in c3bf285bfa outdated
    151@@ -152,6 +152,8 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
    152 {
    153     entry.pushKV("txid", tx.GetHash().GetHex());
    154     entry.pushKV("version", tx.nVersion);
    155+    entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION));
    156+    entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
    


    jonasschnelli commented at 6:31 am on October 17, 2016:
    Maybe ::GetVirtualTransactionSize(tx)?

    jnewbery commented at 4:40 pm on October 17, 2016:

    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.

  10. jonasschnelli commented at 6:33 am on October 17, 2016: contributor
    Concept ACK. We should make sure, there is no API changes (= maybe ~100% test coverage?) because of the refactoring.
  11. jonasschnelli changes_requested
  12. jnewbery commented at 9:46 am on October 24, 2016: member
    @jonasschnelli - are you happy with my response above? Any further questions?
  13. jnewbery force-pushed on Nov 4, 2016
  14. jnewbery force-pushed on Nov 4, 2016
  15. jnewbery commented at 9:35 am on November 4, 2016: member
    rebased. Is anyone happy to ACK this? @jonasschnelli - did you have time to review my response above?
  16. in src/core_write.cpp: in 22c34e7e4c outdated
    152@@ -153,6 +153,8 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry)
    153     entry.pushKV("txid", tx.GetHash().GetHex());
    154     entry.pushKV("hash", tx.GetWitnessHash().GetHex());
    155     entry.pushKV("version", tx.nVersion);
    156+    entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION));
    157+    entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
    


    jonasschnelli commented at 2:15 pm on November 4, 2016:
    Doesn’t this require std::max(GetTransactionWeight(tx), nSigOpCost * nBytesPerSigOp)? Nm: it’s not required here.
  17. jonasschnelli approved
  18. jonasschnelli commented at 2:21 pm on November 4, 2016: contributor
    Tested ACK 22c34e7e4c74d2c7d1cc64a75c6654f3ae82377b
  19. jnewbery force-pushed on Jan 9, 2017
  20. jnewbery force-pushed on Jan 10, 2017
  21. jnewbery commented at 3:47 pm on January 10, 2017: member
    Rebased
  22. jnewbery force-pushed on Feb 15, 2017
  23. jnewbery commented at 9:55 pm on February 15, 2017: member
    Rebased
  24. in src/rpc/server.h: in 44e66289c9 outdated
    198@@ -198,6 +199,8 @@ extern std::string HelpRequiringPassphrase();
    199 extern std::string HelpExampleCli(const std::string& methodname, const std::string& args);
    200 extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args);
    201 
    202+extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
    


    laanwj commented at 9:06 am on February 16, 2017:
    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.

    laanwj commented at 9:10 am on February 16, 2017:
    Hm, I think you can simply remove the changes to this file as the function is in core_write now?
  25. jnewbery force-pushed on Mar 7, 2017
  26. jnewbery commented at 11:07 pm on March 7, 2017: member
    Addressed @laanwj ’s review comment and rebased.
  27. fanquake commented at 11:45 pm on March 22, 2017: member
    Needs a rebase.
  28. jnewbery force-pushed on Mar 24, 2017
  29. jnewbery commented at 9:01 pm on March 24, 2017: member
    Rebased
  30. laanwj commented at 10:09 am on April 26, 2017: member

    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.

  31. jnewbery commented at 1:39 pm on April 28, 2017: member

    “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.

  32. refactor TxToJSON() and ScriptPubKeyToJSON() 0ff9320bf5
  33. jnewbery force-pushed on Apr 28, 2017
  34. jnewbery commented at 2:02 pm on April 28, 2017: member
    rebased. Last time please :)
  35. laanwj merged this on May 1, 2017
  36. laanwj closed this on May 1, 2017

  37. laanwj referenced this in commit 9c33ffd387 on May 1, 2017
  38. deadalnix referenced this in commit 76c64df039 on Feb 12, 2019
  39. PastaPastaPasta referenced this in commit 4dd841c841 on Jun 6, 2019
  40. PastaPastaPasta referenced this in commit 38c4a24ff8 on Jun 6, 2019
  41. PastaPastaPasta referenced this in commit ffd94367b0 on Jun 9, 2019
  42. PastaPastaPasta referenced this in commit 29299bf498 on Jun 10, 2019
  43. PastaPastaPasta referenced this in commit 47e6b7218a on Jun 10, 2019
  44. UdjinM6 referenced this in commit 56d1d13c43 on Jun 11, 2019
  45. jnewbery deleted the branch on Dec 20, 2019
  46. barrystyle referenced this in commit b0b501320e on Jan 22, 2020
  47. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-19 06:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me