本文整理汇总了Python中pycoin.serialize.b2h方法的典型用法代码示例。如果您正苦于以下问题:Python serialize.b2h方法的具体用法?Python serialize.b2h怎么用?Python serialize.b2h使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pycoin.serialize
的用法示例。
在下文中一共展示了serialize.b2h方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_const_function
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def call_const_function( priv_key, value, contract_hash, contract_abi, function_name, args ):
src_address = b2h( utils.privtoaddr(priv_key) )
translator = ContractTranslator(contract_abi)
call = translator.encode_function_call(function_name, args)
nonce = get_num_transactions( src_address )
gas_price = get_gas_price_in_wei()
start_gas = eval_startgas( src_address, contract_hash, value, b2h(call), gas_price )
nonce = int( nonce, 16 )
gas_price = int( gas_price, 16 )
start_gas = int( start_gas, 16 ) + 100000
params = { "from" : "0x" + src_address,
"to" : "0x" + contract_hash,
"gas" : "0x" + str(start_gas),
"gasPrice" : "0x" + str(gas_price),
"value" : str(value),
"data" : "0x" + b2h(call) }
return_value = json_call( "eth_call", [params])
return_value = h2b(return_value[2:]) # remove 0x
return translator.decode(function_name, return_value)
示例2: test_bitcoind_connector_spendables
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_bitcoind_connector_spendables(self):
SelectParams('testnet')
bc = BitcoindConnector('testnet')
spendables = bc.spendables_for_address('mz7poFND7hVGRtPWjiZizcCnjf6wEDWjjT')
self.assertEquals(len(spendables), 3)
self.assertEquals(b2h(spendables[0].tx_hash),
'08f6528ac70c828e1633babc8f0d49ecb11649fd7451f76923821a0dbc81eb34')
self.assertEquals(spendables[0].coin_value, 49000000)
self.assertEquals(spendables[1].coin_value, 2750)
self.assertEquals(spendables[2].coin_value, 2750)
# TODO: this test isn't calling the bitcoin RPC proxy because of the changed configuration. This will most likely
# need to be different in the open source. Fix this test and connectors.
# def test_get_balance(self):
# bitcoin.SelectParams('testnet')
# connector = ServiceProviderConnector('XTN', 'na')
# balance = connector.get_balance('mz7poFND7hVGRtPWjiZizcCnjf6wEDWjjT')
# self.assertEquals(balance, 49005500)
示例3: prepare_batch
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def prepare_batch(self):
"""
Propagates exception on failure
:return: byte array to put on the blockchain
"""
# validate batch
for _, metadata in self.certificates_to_issue.items():
self.certificate_handler.validate_certificate(metadata)
# sign batch
with FinalizableSigner(self.secret_manager) as signer:
for _, metadata in self.certificates_to_issue.items():
self.certificate_handler.sign_certificate(signer, metadata)
self.merkle_tree.populate(self.get_certificate_generator())
logging.info('here is the op_return_code data: %s', b2h(self.merkle_tree.get_blockchain_data()))
return self.merkle_tree.get_blockchain_data()
示例4: test_blanked_hash
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_blanked_hash(self):
tx = Tx.from_hex(TX_E1A18B843FC420734DEEB68FF6DF041A2585E1A0D7DBF3B82AAB98291A6D9952_HEX)
self.assertEqual(tx.id(), "e1a18b843fc420734deeb68ff6df041a2585e1a0d7dbf3b82aab98291a6d9952")
self.assertEqual(
b2h(tx.blanked_hash()), "909579526c4c2c441687c7478d3f96249724d2ff071d2272b44500d6cf70d5d6")
tx.txs_in[0].script = b"foo"
self.assertEqual(
b2h(tx.blanked_hash()), "909579526c4c2c441687c7478d3f96249724d2ff071d2272b44500d6cf70d5d6")
tx.txs_out[0].coin_value += 1
self.assertEqual(
b2h(tx.blanked_hash()), "10d4e87f7bf35f2949e7693e7a4a84189aad8631f0b2b0999e88f7261066cbe5")
tx.txs_in[0].script = b"bar"
self.assertEqual(
b2h(tx.blanked_hash()), "10d4e87f7bf35f2949e7693e7a4a84189aad8631f0b2b0999e88f7261066cbe5")
tx.txs_in[0].script = b""
self.assertEqual(b2h(tx.hash()), "10d4e87f7bf35f2949e7693e7a4a84189aad8631f0b2b0999e88f7261066cbe5")
tx.txs_in[0].script = b"foo"
self.assertEqual(b2h(tx.hash()), "c91910058722f1c0f52fc5c734939053c9b87882a9c72b609f21632e0bd13751")
示例5: menu_item_handler
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def menu_item_handler(self, text):
# Main menu items
if "PUB" in text:
self.root.ids.sm.current = "ypub"
elif "PIN" in text:
self.root.ids.sm.current = "pin"
elif "UTXO" in text:
self.root.ids.sm.current = "utxo"
elif "Settings" in text:
self.open_settings()
# UTXO menu items
elif self.root.ids.sm.current == "utxo":
addr = self.utxo.address(self.chain.netcode)
key = self.wallet.search_for_key(addr)
if not key:
key = self.wallet.search_for_key(addr, change=True)
if "Private" in text:
self.show_dialog("Private key", "", qrdata=key.wif())
if "Redeem" in text:
if self.bech32:
return
script = b2h(key.p2wpkh_script())
self.show_dialog("Redeem script", "", qrdata=script)
示例6: test_txout_ordering
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_txout_ordering(txout_small_coin_small_script,
txout_large_coin_small_script,
txout_small_coin_large_script,
txout_large_coin_large_script):
a, b = txout_large_coin_large_script, TxOut(10, b"\xFF")
assert (a.coin_value, b2h(a.script)) == (b.coin_value, b2h(b.script))
txout_list = [txout_small_coin_small_script,
txout_large_coin_small_script,
txout_small_coin_large_script,
txout_large_coin_large_script]
random.shuffle(txout_list)
txout_list.sort(key=lambda txo: (txo.coin_value, b2h(txo.script)))
assert txout_list[0] == txout_small_coin_small_script
assert txout_list[1] == txout_small_coin_large_script
assert txout_list[2] == txout_large_coin_small_script
assert txout_list[3] == txout_large_coin_large_script
示例7: make_transaction
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def make_transaction( src_priv_key, dst_address, value, data ):
src_address = b2h( utils.privtoaddr(src_priv_key) )
nonce = get_num_transactions( src_address )
gas_price = get_gas_price_in_wei()
data_as_string = b2h(data)
start_gas = eval_startgas( src_address, dst_address, value, data_as_string, gas_price )
nonce = int( nonce, 16 )
gas_price = int( gas_price, 16 )
start_gas = int( start_gas, 16 ) + 100000
tx = transactions.Transaction( nonce,
gas_price,
start_gas,
dst_address,
value,
data ).sign(src_priv_key)
tx_hex = b2h(rlp.encode(tx))
tx_hash = b2h( tx.hash )
if use_ether_scan:
params = [{"hex" : "0x" + tx_hex }]
else:
params = ["0x" + tx_hex]
return_value = json_call( "eth_sendRawTransaction", params )
if return_value == "0x0000000000000000000000000000000000000000000000000000000000000000":
print "Transaction failed"
return False
wait_for_confirmation(tx_hash)
return return_value
示例8: get_account_balance
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def get_account_balance( key ):
url = "https://testnet.etherscan.io/api"
payload = {"module" : "account",
"action" : "balance",
"tag" : "latest",
"address" : "0x" + b2h( utils.privtoaddr(key) ),
"apikey" : ether_scan_api_key }
response = requests.post( url, params=payload )
balance = response.json()[ 'result' ]
if balance is None:
return 0
return int(balance)
示例9: suggest_private_keys
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def suggest_private_keys( max_addresses ):
num_found = 0
for key in private_keys:
if get_account_balance(key) > min_balance:
print "0x" + b2h(key)
num_found += 1
if num_found == max_addresses:
break
return num_found
示例10: do_submit
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def do_submit( key, conf_string, date_string, king_name ):
(day,month,year) = date_string.split('/')
if len(day) != 2 or len(month) != 2 or len(year) != 4:
print "invalid date format (should be dd/mm/yyyy)"
return False
day = int(day)
month = int(month)
year = int(year)
if( not call_function( key, tx_cost, contract_hash, abi, "submit", [conf_string,day,month,year,king_name] ) ):
print "tx failed"
return False
#print "submitted with key = 0x" + b2h(key)
return True
示例11: handle_send_raw_tx
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def handle_send_raw_tx(method_name, params, rpc_version, id, current_timestamp):
global pending_txs
raw_tx = params[0]
tx_hash = b2h(utils.sha3(h2b(raw_tx[2:])))
pending_txs.add(PendingTx(raw_tx, tx_hash, current_timestamp))
return {"id": id, "jsonrpc": rpc_version, "result": tx_hash}
示例12: call_const_function
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def call_const_function(priv_key, value, contract_hash, contract_abi, function_name, args):
# src_address = b2h(utils.privtoaddr(priv_key))
translator = ContractTranslator(json.loads(contract_abi))
call = translator.encode_function_call(function_name, args)
# nonce = get_num_transactions(src_address)
# gas_price = get_gas_price_in_wei()
# start_gas = eval_startgas(
# src_address, contract_hash, value, b2h(call), gas_price)
# nonce = int(nonce, 16)
# gas_price = int(gas_price, 16)
# start_gas = int(start_gas, 16) + 100000
# start_gas = 7612288
params = {
# "from": "0x" + src_address,
"to": "0x" + contract_hash,
# "gas": "0x" + "%x" % start_gas,
# "gasPrice": "0x" + "%x" % gas_price,
# "value": "0x" + str(value),
"data": "0x" + b2h(call)
}
return_value = json_call("eth_call", [params, "latest"])
# print return_value
return_value = h2b(return_value[2:]) # remove 0x
return translator.decode_function_result(function_name, return_value)
#
示例13: test_generate
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_generate(self):
merkle_tree_generator = MerkleTreeGenerator()
merkle_tree_generator.populate(get_test_data_generator())
byte_array = merkle_tree_generator.get_blockchain_data()
self.assertEqual(b2h(byte_array), '0932f1d2e98219f7d7452801e2b64ebd9e5c005539db12d9b1ddabe7834d9044')
示例14: test_verify_transaction
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_verify_transaction(self):
SelectParams('testnet')
b = h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154')
tx_input = Spendable(200, b'18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA', b, 0)
tx_outs = [tx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
op_return_val = h2b('e9cee71ab932fde863338d08be4de9dfe39ea049bdafb342ce659ec5450b69ae')
tx = tx_utils.create_trx(op_return_val, 3, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, [tx_input])
hextx = b2h(tx.serialize())
tx_utils.verify_transaction(hextx, b2h(op_return_val))
示例15: test_create_trx
# 需要导入模块: from pycoin import serialize [as 别名]
# 或者: from pycoin.serialize import b2h [as 别名]
def test_create_trx(self):
SelectParams('testnet')
b = h2b('8443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b154')
tx_input = Spendable(200, b'18eKkAWyU9kvRNHPKxnZb6wwtPMrNmRRRA',
b, 0)
tx_outs = [tx_utils.create_transaction_output('mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', 0.0000275)]
tx = tx_utils.create_trx('TEST'.encode('utf-8'), 3, 'mgAqW5ZCnEp7fjvpj8RUL3WxsBy8rcDcCi', tx_outs, [tx_input])
hextx = b2h(tx.serialize())
self.assertEquals(hextx,
'01000000018443b07464c762d7fb404ea918a5ac9b3618d5cd6a0c5ea6e4dd5d7bbe28b1540000000000ffffffff0300000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88acc5000000000000001976a914072a22e5913cd939904c46bbd0bc56755543384b88ac0000000000000000066a045445535400000000')