MCPcopy Create free account
hub / github.com/ElementsProject/elements / bn2vch

Function bn2vch

test/functional/test_framework/script.py:43–52  ·  view source on GitHub ↗

Convert number to bitcoin-specific little endian format.

(v)

Source from the content-addressed store, hash-verified

41 return ripemd160(sha256(s))
42
43def bn2vch(v):
44 """Convert number to bitcoin-specific little endian format."""
45 # We need v.bit_length() bits, plus a sign bit for every nonzero number.
46 n_bits = v.bit_length() + (v != 0)
47 # The number of bytes for that is:
48 n_bytes = (n_bits + 7) // 8
49 # Convert number to absolute value + sign in top bit.
50 encoded_v = 0 if v == 0 else abs(v) | ((v < 0) << (n_bytes * 8 - 1))
51 # Serialize to bytes
52 return encoded_v.to_bytes(n_bytes, 'little')
53
54class CScriptOp(int):
55 """A single script opcode"""

Callers 2

__coerce_instanceMethod · 0.70
test_bn2vchMethod · 0.70

Calls

no outgoing calls

Tested by 1

test_bn2vchMethod · 0.56