bosnet / sebak

SEBAK, the next BOScoin Blockchain
https://devteam.blockchainos.org
GNU General Public License v3.0
44 stars 15 forks source link

Operation: Use slightly more clever code to deserialize body #899

Closed Geod24 closed 5 years ago

Geod24 commented 5 years ago
Instead of copy-pasting blocks of code inside a `switch`,
we can just have a function instantiating the type and
greatly reduce duplication.

As `Body` is defined to be an interface to value instead
of an interface to pointer, a bit of magic is needed
with the `reflect` module to make it work.
codecov-io commented 5 years ago

Codecov Report

Merging #899 into master will increase coverage by 0.06%. The diff coverage is 47.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #899      +/-   ##
==========================================
+ Coverage   60.28%   60.34%   +0.06%     
==========================================
  Files         153      153              
  Lines       10768    10749      -19     
==========================================
- Hits         6491     6486       -5     
+ Misses       3532     3518      -14     
  Partials      745      745
Flag Coverage Δ
#integration_tests_long_term 44.44% <47.36%> (+0.05%) :arrow_up:
#integration_tests_node 40.41% <47.36%> (-0.02%) :arrow_down:
#unittests 48.7% <31.57%> (+0.09%) :arrow_up:
Impacted Files Coverage Δ
lib/transaction/operation/operation.go 43.33% <47.36%> (+4.8%) :arrow_up:
lib/network/validator_connection_manager.go 84.18% <0%> (-0.8%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 098de47...1fc7310. Read the comment docs.

Geod24 commented 5 years ago

@spikeekips : For this usage there will really have no impact, because we're essentially dereferencing a pointer. We are already depending on reflect very heavily through json and rlp encoding, to name a few things, who are doing real work with reflect (like looking up struct's fields). Also, as obvious in #836, it allows to reuse the same code for JSON and RLP decoding instead of copy/pasting this function.