Transactions

如何從僅給出 txid 的 vin 獲取輸入地址(Insight-Api)

  • May 4, 2018

我喜歡為這樣的 vin 找到輸入地址和金額:

"vin": [
   {
       "txid": "e3f0e88ce224d342a0189c1b9d2fd488d8bda2f303dbe1e1dbbaa5f51d9f4a53",
       "vout": 1,
       "scriptSig": {
           "asm": "3044022036c454ee41d67ee7c00fade55d57b573794916c1e1d9f301a038547daa5fcc0502202c99917b5590adf2ede1b8e3a6773369690a268c7b445664223ec8f92288e81e010272491cc9c405bfdc35f766bd849ddc58268088c202425cec224aa05cbf8547be"
       },
       "sequence": 4294967295,
       "n": 0,
       "unconfirmedInput": 1
   }
]

這是來自 txid:f4f2ddb44a8d155bc795e3e7497714fd6a1f035a6438b22403a7faa67012b9ec

謝謝

首先,使用 API 獲取txid.

/api/tx/e3f0e88ce224d342a0189c1b9d2fd488d8bda2f303dbe1e1dbbaa5f51d9f4a53

此結果將包括您要查找的所有詳細資訊。這是您要詢問的部分。我相信這裡對應的是上面的數字,和n值是輸入的金額和地址。vout``value``addresses

"value": "2405.38864196",
"n": 1,
"scriptPubKey": {
   ...
   "addresses": [
       "1NG1nT2ZuFw47f41mGjYpPp7J837yTQZhB"
   ]
},
...

您可以對其進行編碼,Python 2.7 的實現同樣是:

#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ ="cryptoKTM"

import requests,json
url="http://username:password@server:PORT"
payload={}
payload = {"jsonrpc":1,"id":"curltext"}
txid= "10ff6ff5bdc73d7bb6d711c6896618a05479d061e67f576a0950328c1389035f"
addresses = []
payload["method"]="getrawtransaction"
payload["params"]=[txid,1]
response = requests.post(url,json.dumps(payload))
response =response.json()
response= response["result"]["vin"]
for data in response:
   raw_tx1=data["txid"]
   vout_int=data["vout"]
   payload["params"]=[raw_tx1,1]
   response_ = requests.post(url,json.dumps(payload))
   response_= response_.json()
   data_ =response_["result"]["vout"]
   for item in data_:
       if item["n"] == vout_int:
           json_data ={}
           json_data[item["scriptPubKey"]["addresses"][0]] = item["value"]
           addresses.append(json_data)

print addresses

引用自:https://bitcoin.stackexchange.com/questions/25540