do_send
2018-08-03 17:51:30 0 举报
AI智能生成
Qtum在热钱包上签名流程
作者其他创作
大纲/内容
read_send_tab
make_unsigned_transaction
checkoutput,checkinput
add_input_info
change address
fee_estimator
i_max
i_max is None
coinbase:make_tx
self.p = PRNG()
tx = Transaction.from_io
bucketize_coins(coins)
keys = self.keys(coins)
buckets = defaultdict
(list)
(list)
list(map(make_Bucket,buckets.keys(),buckets.values())
choose bucket
old first spent
strip_unneeded
tx.add_input
change_outputs
change_amounts
output_amount
确定找零地址的个数
计算找零,找零大于1时候随机化
change
tx.中添加输入和找零
i_max is not None
直接由make_io获得tx
tx.qtum_sort()
查验输出数量,交易佣金是否
过少,交易是否需要密码
过少,交易是否需要密码
sign_tx_with_password
tx_extend_keypairs
Transaction.sign
get_sorted_pubkeys
从Txin中获取公钥
从公钥获取私钥,以及该私钥是否压缩的信息
sign_txin
prehash = Hash(bfh(self.serialize_preimage(txin_index)))
serialize_preimage
get_preimage_script()
if txin[type] == "p2pkh"
bitcoin.address_to_script(txin['address'])
segwit? yes 另行处理
b58_address_to_hash160(addr)
addrtype:P2PKH?yes/no
script = "76a9"
script = push_script(bh2u(hash_160))
script += "88ac"
addrtype:P2SH?yes/no
script = 'a9'
script += push_script(bh2u(hash_160))
script += '87'
if txin[type] in ["p2sh","p2wsh","p2wsh-p2sh"
multisig_script
op_m = format(opcodes.OP_1 + m - 1, 'x')
op_n = format(opcodes.OP_1 + n - 1, 'x')
keylist = [op_push(len(k)//2) + k for k in public_keys]
return op_m + ''.join(keylist) + op_n + 'ae'
if txin['type'] in ['p2wpkh', 'p2wpkh-p2sh']:
pubkey = pubkeys[0]
pkh = bh2u(bitcoin.hash_160(bfh(pubkey)))
return '76a9' + push_script(pkh) + '88ac'
if txin['type'] in ['p2wpkh', 'p2wpkh-p2sh']
pubkey = pubkeys[0]
return bitcoin.public_key_to_p2pk_script(pubkey)
serialize_input
serialize_outpoint
s: 序列化outpoint+len(script)+script+int_to_hex(txin[sequence])
serialize_output
s = 8字节长的16进制的数量
script=pay_script
if output_type == TYPE_ADDRESS:
return bitcoin.address_to_script(addr)
return bitcoin.address_to_script(addr)
先执行隔离见证,if True,直接返回
b58_address_to_hash160(addr)
addr = to_bytes(addr,"ascii")
_bytes = base_decode(addr,25,base=58)
return _bytes[0],_bytes[1:21]
根据上步操作返回的addrtype为script中首先写入不同的操作码
script+=push_script(bh2u(hash_160))
再次根据不同的addrtype写入不同的操作码
if output_type == TYPE_PUBKEY or output_type == 'coinstake':
return bitcoin.public_key_to_p2pk_script(addr)
return bitcoin.public_key_to_p2pk_script(addr)
script = push_script(pubkey)
op_push(data_len)
script+= "ac"
s+=var_int(len(script)//2)
s += script
privkey.sign_transaction(prehash)
sign(locate:ecc.py)
sig = bh2u(sig)+"01"
wallet.sign_transaction
keystore.can_sign
keystore.get_tx_derivation
parse_xpubkey
keystore.sign_transaction
get_tx_derivation
get_private_key
tx.sign(keypairs)
收藏
收藏
0 条评论
下一页