为什么BLOCKCHAIN.COM API仅返回收件人BASE58地址,而忽略了BECH32? [英] Why does BLOCKCHAIN.COM API only return recipient BASE58 addresses and omits BECH32s?

查看:91
本文介绍了为什么BLOCKCHAIN.COM API仅返回收件人BASE58地址,而忽略了BECH32?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章之后,我正在尝试访问比特币区块链中#630873区块内的所有交易.

Following this post, I am trying to access all transactions within the #630873 block in the bitcoin blockchain.

import requests

r = requests.get('https://blockchain.info/block-height/630873?format=json')
data = r.json()

在检查此块中的(索引为0的)第四笔交易时(通过data['blocks'][0]['tx'][4]['out']),我得到了:

When inspecting the (0-indexed) 4th transaction within this block (via data['blocks'][0]['tx'][4]['out']), I get this:

[{'n': 0,
  'script': '0014d0aba2c93bac0fcafafe43f2ad39d664ba51910d',
  'spent': False,
  'tx_index': 0,
  'type': 0,
  'value': 19571491},
 {'addr': '1A7tWftaGHohhGcJMVkkm4zAYnF53KjRnU',
  'n': 1,
  'script': '76a9146406a0a47d4ed716f6ddf2eeca20c725932763f188ac',
  'spending_outpoints': [{'n': 0, 'tx_index': 0}],
  'spent': True,
  'tx_index': 0,
  'type': 0,
  'value': 3928145371}]

仅包括该交易的第二个接收者的addr.在blockchain.com网站上,此交易如下:

Only the addr of the second recipient of this transaction is included. On the blockchain.com website this transaction looks like:

bc1q6z469jfm4s8u47h7g0e26wwkvja9rygdqpeykd地址在此处可见.如何通过API访问它?

The bc1q6z469jfm4s8u47h7g0e26wwkvja9rygdqpeykd address is visible there. How to access it through the API?

无法访问的地址具有BECH32格式,而可访问的地址具有BASE58(我通过单击网站上的地址获得的信息).我能够检索收件人地址的那些交易具有BASE58格式.

The unaccessible address has BECH32 format, while the accessible one has BASE58 (which information I get by clicking on the address on the website). Those transactions which I was able to retrieve the reciepient address, had BASE58 format.

链接到我正在谈论的块..

推荐答案

Blochchain.com API尚不完全支持bech32地址.

The Blochchain.com API does not fully support bech32 addresses yet.

因此,您可以使用其他提供程序,例如Blockstream或Blockchair.

So you could use another provider such as Blockstream or Blockchair.

或者您也可以从P2WPKH脚本派生地址.例如,使用BitcoinLib(免责声明:我的图书馆):

Or you can also derive the addresses from the P2WPKH script. For example using BitcoinLib (Disclaimer: my library):

from bitcoinlib.transactions import script_deserialize
from bitcoinlib.keys import Address

locking_script = '0014d0aba2c93bac0fcafafe43f2ad39d664ba51910d'
scr = script_deserialize(locking_script)
a = Address(hashed_data=scr['hashes'][0], script_type=scr['script_type'])
print(a.address)

这篇关于为什么BLOCKCHAIN.COM API仅返回收件人BASE58地址,而忽略了BECH32?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆