bitcoin core – What’s the python equal of this php code $values = unpack(“C*”, pack(“H*”, $scriptpubkey));

on

|

views

and

comments


These pack/unpack php capabilities appear to be precisely because the identically named perl capabilities.

So pack("H*", ...) converts an ascii string to an byte-string.

And unpack("C*", ...) converts a byte-string to an array of byte values.

In python, pack("H*", $scriptpubkey) can be: binascii.a2b_hex(scriptpubkey)

The second step just isn’t wanted in python, since byte-arrays are already lists of byte values in python. Should you entry a single aspect: a[0] you’ll get the integer worth 0x41 on this case. Whereas accessing a subrange: a[1:] would get you a byte-array containing the pubkey.

Then one other comment, in case your variable accommodates a hexadecimal illustration of your script, it may be clearer to point that within the variablename, as an illustration by naming it hex_scriptpubkey.

Share this
Tags

Must-read

Waymo raises $16bn to gas international robotaxi enlargement | Know-how

Self-driving automobile firm Waymo on Monday stated it raised $16bn in a funding spherical that valued the Alphabet subsidiary at $126bn.Waymo co-chief executives...

Self-driving taxis are coming to London – ought to we be anxious? | Jack Stilgoe

At the top of the nineteenth century, the world’s main cities had an issue. The streets had been flooded with manure, the unintended...

US regulators open inquiry into Waymo self-driving automobile that struck youngster in California | Expertise

The US’s federal transportation regulator stated Thursday it had opened an investigation after a Waymo self-driving car struck a toddler close to an...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here