Merge #19940: rpc: Return fee and vsize from testmempoolaccept

23c35bf005 [test] add get_vsize util for more programmatic testing (gzhao408)
2233a93a10 [rpc] Return fee and vsize from testmempoolaccept (codeShark149)

Pull request description:

  From #19093 and resolves #19057.

  Difference from #19093: return `vsize` and `fees` object (similar to `getmempoolentry`) when the test accept is successful. Updates release-notes.md.

ACKs for top commit:
  jnewbery:
    utACK 23c35bf005
  fjahr:
    utACK 23c35bf
  instagibbs:
    reACK 23c35bf005

Tree-SHA512: dcb81b7b817a4684e9076bc5d427a6f2d549d2edc66544e718260c4b5f8f1d5ae1d47b754175e9f0c8a3bd8371ce116c2dca0583588d513a7d733d5d614f2b04
This commit is contained in:
fanquake
2020-09-19 14:34:52 +08:00
7 changed files with 53 additions and 15 deletions

View File

@ -22,6 +22,7 @@ from codecs import encode
import copy
import hashlib
from io import BytesIO
import math
import random
import socket
import struct
@ -67,6 +68,8 @@ MSG_WITNESS_TX = MSG_TX | MSG_WITNESS_FLAG
FILTER_TYPE_BASIC = 0
WITNESS_SCALE_FACTOR = 4
# Serialization/deserialization tools
def sha256(s):
return hashlib.new('sha256', s).digest()
@ -537,6 +540,13 @@ class CTransaction:
return False
return True
# Calculate the virtual transaction size using witness and non-witness
# serialization size (does NOT use sigops).
def get_vsize(self):
with_witness_size = len(self.serialize_with_witness())
without_witness_size = len(self.serialize_without_witness())
return math.ceil(((WITNESS_SCALE_FACTOR - 1) * without_witness_size + with_witness_size) / WITNESS_SCALE_FACTOR)
def __repr__(self):
return "CTransaction(nVersion=%i vin=%s vout=%s wit=%s nLockTime=%i)" \
% (self.nVersion, repr(self.vin), repr(self.vout), repr(self.wit), self.nLockTime)