比特币交易总是第二次失败,签署问题(blockcypher)

时间:2018-08-01 08:20:18

标签: python blockchain bitcoin blockcypher

我是比特币开发人员的初学者。我正在尝试使用blockcypher api进行交易。 我的问题是我可以用一个新地址进行一次交易,但是第二次我总是得到:

  File "server.py", line 28, in <module>
    signed=make_tx_signatures(txs_to_sign=tx['tosign'], privkey_list=[pk], pubkey_list=[pubk])
  File "/usr/lib/python3.6/site-packages/blockcypher/api.py", line 1843, in make_tx_signatures
    assert len(privkey_list) == len(pubkey_list) == len(txs_to_sign)
AssertionError

我认为该错误出现是因为第二次出现  “签名”哈希。但这应该可以吗?

代码如下:

import requests
import json
from blockcypher import make_tx_signatures

pk="a43c546170ac1f83e539d4ce47d9069b13acacd0d3d0d0b0cb66afc87ee99863"
pubk="035fb26c232bd6ff42df82db2163affcd9ff75fb94fcb794d1928fd3315a3ddca5"
blockcypher_new_tx="http://api.blockcypher.com/v1/btc/test3/txs/new"
blockcypher_send_tx="https://api.blockcypher.com/v1/btc/test3/txs/send?token=MYTOJEN"
server_address="mxHLujwYZdDPe8Dx33suWWom55A4NmV8Mk"


myCommand = {"inputs":[{"addresses": ["mxHLujwYZdDPe8Dx33suWWom55A4NmV8Mk"]}],
            "outputs":[

                        {"addresses": ["mxHLujwYZdDPe8Dx33suWWom55A4NmV8Mk"], "value": 10300}]
            }
r = requests.post(blockcypher_new_tx,json=myCommand)
#print(r.content)
tx=json.loads(r.content)
print(tx)
signed=make_tx_signatures(txs_to_sign=tx['tosign'], privkey_list=[pk], pubkey_list=[pubk])
print(signed)
tx['signatures']=signed
tx['pubkeys']=[pubk]
print(tx)
rsend=requests.post(blockcypher_send_tx,json=tx)
print(json.loads(rsend.content))

edit:出于绝望,我再次运行了脚本,这次又有效了……从那以后我再也没有碰过代码。谁能解释一下?

https://live.blockcypher.com/btc-testnet/address/mxHLujwYZdDPe8Dx33suWWom55A4NmV8Mk/

ps:不在乎给我的pk,是testnet

0 个答案:

没有答案