Changeset View
Changeset View
Standalone View
Standalone View
contrib/linearize/linearize-hashes.py
Show All 26 Lines | |||||
def hex_switchEndian(s): | def hex_switchEndian(s): | ||||
""" Switches the endianness of a hex string (in pairs of hex chars) """ | """ Switches the endianness of a hex string (in pairs of hex chars) """ | ||||
pairList = [s[i:i + 2].encode() for i in range(0, len(s), 2)] | pairList = [s[i:i + 2].encode() for i in range(0, len(s), 2)] | ||||
return b''.join(pairList[::-1]).decode() | return b''.join(pairList[::-1]).decode() | ||||
class BitcoinRPC: | class BitcoinRPC: | ||||
def __init__(self, host, port, username, password): | def __init__(self, host, port, username, password): | ||||
authpair = "%s:%s" % (username, password) | authpair = "{}:{}".format(username, password) | ||||
authpair = authpair.encode('utf-8') | authpair = authpair.encode('utf-8') | ||||
self.authhdr = b"Basic " + base64.b64encode(authpair) | self.authhdr = b"Basic " + base64.b64encode(authpair) | ||||
self.conn = httplib.HTTPConnection(host, port=port, timeout=30) | self.conn = httplib.HTTPConnection(host, port=port, timeout=30) | ||||
def execute(self, obj): | def execute(self, obj): | ||||
try: | try: | ||||
self.conn.request('POST', '/', json.dumps(obj), | self.conn.request('POST', '/', json.dumps(obj), | ||||
{'Authorization': self.authhdr, | {'Authorization': self.authhdr, | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |