I have written following script to get Vin address from Vin txids.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests,json
url="http://asd:asdf@localhost:2332"
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
for some txids i get proper o/p for example:
[{u'MKHWXiX9Xm37jdCM8EzWMWNRJPhuwUxWiN': 50.0},{u'MVTpa2h3DGFWxkcmEkYLv4cYGggVprjjDZ': 300.0}]
but for other its says
response= response["result"]["vin"]
TypeError: 'NoneType' object has no attribute '__getitem__'
Why is it behaving like this? Isnt it supposed to have uniform output irrespective of txids? If my approach is wrong then how was i getting correct for some tx ids again?