Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Transactions 是否可以从';scriptSig';在原始事务中找到?_Transactions_Decode_Bitcoin - Fatal编程技术网

Transactions 是否可以从';scriptSig';在原始事务中找到?

Transactions 是否可以从';scriptSig';在原始事务中找到?,transactions,decode,bitcoin,Transactions,Decode,Bitcoin,第11行包含汇款人的签名 304502 后跟一个空格,然后是相应的公钥 04b2d。。。。同样,它们都是十六进制的 我可以将十六进制公钥解码为原始比特币地址吗?还是不可能? 谢谢:)是的,这是可能的,下面是实现此功能的函数: 7. "in":[ 8. {"prev_out": 9. {"hash":"2007ae...", 10. "n":0}, 11. "scriptSig":"304502... 042b2d..."}], 在上面的表单中,它是为testn

第11行包含汇款人的签名

304502

后跟一个空格,然后是相应的公钥

04b2d。。。。同样,它们都是十六进制的

我可以将十六进制公钥解码为原始比特币地址吗?还是不可能?
谢谢:)

是的,这是可能的,下面是实现此功能的函数:

7.  "in":[
8.    {"prev_out":
9.      {"hash":"2007ae...",
10.      "n":0},
11.    "scriptSig":"304502... 042b2d..."}],
在上面的表单中,它是为testnet配置的,在mainnet上使用时,只需将
testnet=
更改为
False
或将其从functions arguments元组中删除即可

享受:)

*从存储库中修改

import hashlib
from base58 import b58encode
from binascii import unhexlify

pub = 'public key string you wish to decode'


def addr_decode(pub, testnet=True):
    h3 = hashlib.sha256(unhexlify(pub))
    h4 = hashlib.new('ripemd160', h3.digest())

    result =(b'\x00' if not testnet else b'\x6f') + h4.digest()

    h5 = hashlib.sha256(result)
    h6 = hashlib.sha256(h5.digest())

    result += h6.digest()[:4]

    return b58encode(result)