本文整理汇总了Python中pycoin.serialize.b2h_rev函数的典型用法代码示例。如果您正苦于以下问题:Python b2h_rev函数的具体用法?Python b2h_rev怎么用?Python b2h_rev使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了b2h_rev函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_bip143_tx
def check_bip143_tx(self, tx_u_hex, tx_s_hex, txs_out_value_scripthex_pair, tx_in_count, tx_out_count, version, lock_time):
tx_u = Tx.from_hex(tx_u_hex)
tx_s = Tx.from_hex(tx_s_hex)
txs_out = [
TxOut(int(coin_value * 1e8), h2b(script_hex)) for coin_value, script_hex in txs_out_value_scripthex_pair
]
for tx in (tx_u, tx_s):
self.assertEqual(len(tx.txs_in), tx_in_count)
self.assertEqual(len(tx.txs_out), tx_out_count)
self.assertEqual(tx.version, version)
self.assertEqual(tx.lock_time, lock_time)
tx.set_unspents(txs_out)
self.check_unsigned(tx_u)
self.check_signed(tx_s)
tx_hex = tx_u.as_hex()
self.assertEqual(tx_hex, tx_u_hex)
tx_hex = tx_s.as_hex()
self.assertEqual(tx_hex, tx_s_hex)
tx_u_prime = self.unsigned_copy(tx_s)
tx_hex = tx_u_prime.as_hex()
self.assertEqual(tx_hex, tx_u_hex)
self.assertEqual(b2h_rev(double_sha256(h2b(tx_s_hex))), tx_s.w_id())
self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.w_id())
self.assertEqual(b2h_rev(double_sha256(h2b(tx_u_hex))), tx_u.id())
return tx_u, tx_s
示例2: test_h2b
def test_h2b(self):
h = "000102"
b = b"\x00\x01\x02"
self.assertEqual(h2b(h), b)
self.assertEqual(b2h(b), h)
self.assertEqual(h2b_rev(h), b[::-1])
self.assertEqual(b2h_rev(b), "020100")
示例3: save_spendable
def save_spendable(self, spendable):
tx_hash = b2h_rev(spendable.tx_hash)
script = b2h(spendable.script)
c = self._exec_sql("insert or replace into Spendable values (?, ?, ?, ?, ?, ?, ?)", tx_hash,
spendable.tx_out_index, spendable.coin_value, script,
spendable.block_index_available, spendable.does_seem_spent,
spendable.block_index_spent)
示例4: query_links
def query_links (self, proxy):
if self.previous_hash != 0:
tx = ProxyTx.from_txhash(proxy, b2h_rev(self.previous_hash), do_query_links=False)
txout = tx.txs_out[self.previous_index]
self._address = txout.address(addrversion=proxy.addrversion)
self.coin_value = txout.coin_value
self.is_shallow = False
示例5: tx_for_tx_hash
def tx_for_tx_hash(self, tx_hash):
URL = "%s/api/tx/%s" % (self.base_url, b2h_rev(tx_hash))
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = tx_from_json_dict(r)
if tx.hash() == tx_hash:
return tx
return None
示例6: get_tx
def get_tx(self, tx_hash):
url = "%s/rawtx/%s" % (self.base_url, b2h_rev(tx_hash))
result = json.loads(urlopen(url).read().decode("utf8"))
tx = Tx.from_hex(result["rawtx"])
if tx.hash() == tx_hash:
return tx
return None
示例7: get_tx
def get_tx(self, tx_hash):
URL = "%s/api/rawtx/%s" % (self.base_url, b2h_rev(tx_hash))
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.tx_from_hex(r['rawtx'])
if tx.hash() == tx_hash:
return tx
return None
示例8: reformat
def reformat(spendable):
return {
"txid": b2h_rev(spendable.tx_hash),
"index": spendable.tx_out_index,
"value": spendable.coin_value,
"script": b2h(spendable.script),
}
示例9: dump_inputs
def dump_inputs(tx, netcode, verbose_signature, address_prefix, traceback_f, disassembly_level):
def signature_for_hash_type_f(hash_type, script):
return tx.signature_hash(script, idx, hash_type)
for idx, tx_in in enumerate(tx.txs_in):
if tx.is_coinbase():
print("%4d: COINBASE %12.5f mBTC" % (idx, satoshi_to_mbtc(tx.total_in())))
continue
suffix = ""
if tx.missing_unspent(idx):
tx_out = None
address = tx_in.bitcoin_address(address_prefix=address_prefix)
else:
tx_out = tx.unspents[idx]
sig_result = " sig ok" if tx.is_signature_ok(idx, traceback_f=traceback_f) else " BAD SIG"
suffix = " %12.5f mBTC %s" % (satoshi_to_mbtc(tx_out.coin_value), sig_result)
address = tx_out.bitcoin_address(netcode=netcode)
t = "%4d: %34s from %s:%-4d%s" % (idx, address, b2h_rev(tx_in.previous_hash),
tx_in.previous_index, suffix)
print(t.rstrip())
if disassembly_level > 0:
dump_disassembly(tx_in, tx_out, tx.lock_time, signature_for_hash_type_f)
if verbose_signature:
dump_signatures(tx, tx_in, tx_out, idx, netcode, address_prefix, traceback_f, disassembly_level)
示例10: get_tx
def get_tx(tx_hash):
"""
Get a Tx by its hash.
"""
URL = "%s/tx/raw/%s" % (blockrendpoint.url, b2h_rev(tx_hash))
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx").get("hex"))))
return tx
示例11: get_tx
def get_tx(tx_hash):
"""
Get a Tx by its hash.
"""
URL = "http://btc.blockr.io/api/v1/tx/raw/%s" % b2h_rev(tx_hash)
r = json.loads(urlopen(URL).read().decode("utf8"))
tx = Tx.parse(io.BytesIO(h2b(r.get("data").get("tx").get("hex"))))
return tx
示例12: tx_for_tx_hash
def tx_for_tx_hash(tx_hash):
URL = "https://api.biteasy.com/blockchain/v1/transactions/%s" % b2h_rev(tx_hash)
r = Request(URL,
headers={"content-type": "application/json", "accept": "*/*", "User-Agent": "curl/7.29.0" })
d = urlopen(r).read()
tx = json_to_tx(d.decode("utf8"))
if tx.hash() == tx_hash:
return tx
return None
示例13: put
def put(self, tx):
name = b2h_rev(tx.hash())
if self.writable_cache_path:
try:
path = os.path.join(self.writable_cache_path, "%s_tx.bin" % name)
with open(path, "wb") as f:
tx.stream(f)
except IOError:
pass
示例14: tx_for_tx_hash
def tx_for_tx_hash(self, tx_hash):
"""
Get a Tx by its hash.
"""
url = "%s/rawtx/%s" % (self.url, b2h_rev(tx_hash))
d = urlopen(url).read()
j = json.loads(d.decode("utf8"))
tx = Tx.from_hex(j.get("rawtx", ""))
if tx.hash() == tx_hash:
return tx
示例15: confirms
def confirms(self, txid):
try:
url = "%s/tx/%s" % (self.base_url, b2h_rev(txid))
result = json.loads(urlopen(url).read().decode("utf8"))
return result.get("confirmations", 0)
except HTTPError as ex:
if ex.code == 404: # unpublished tx
return None
else:
raise ex