from pprint import pprint
from copy import deepcopy
tx1 = {"_id":"a82bcbade7f2ab98a0b9208dae2e5fa6b44f5e37f8403ec8f74ca63c4d6189d2",
"blocknumber":80002,
"blocktime":1284615935,
"vin":[{"id":"11","value":50.0,"address":["1LgsbKRKTcw7gYohUwntSUh6rtEWShxSH8"]},
{"id":"232","value":530.0,"address":["qwe234"]},
{"id":"22","value":50.0,"address":["qwerty123"]},
{"id":"22","value":50.0,"address":["qwerty12323455"]},
],
"vout":[{"id":"0","value":50.0,"address":["1LgsbKRKTcw7gYohUwntSUh6rtEWShxSH8"]},
{"id":"22","value":50.0,"address":["qwe123"]},
{"id":"232","value":530.0,"address":["zuuEcUSsBjL7s"]},
{"id":"232","value":530.0,"address":["eeeeeeee"]},
{"id":"232","value":530.0,"address":["qwerty12323455"]}
]}
# pprint(tx)
def get_outputList(tx):
vout=tx["vout"] # list
vin=tx["vin"] # list
for vi in vin:
if vi['id'] == 'coinbase':
for vout_data in vout:
if vout_data["address"] != "":
dic={
"address": vout_data["address"][0],
"value": vout_data["value"]
}
# outputList.append(dic)
pprint(dic)
return dic
else:
# 判断vin中的地址是否在vout中出现,若出现在vout中,则删除掉vout中的这笔交易
vout1 =deepcopy(vout)
for vi in vin:
for vo in vout1:
if vi["address"] == vo["address"]:
vout1.remove(vo)
outputList=[]
for vo1 in vout1:
output = {
"address":vo1["address"][0],
"value":vo1["value"]
}
outputList.append(output)
pprint(outputList)
return outputList
# outputList.append(vout)
# pprint(outputList)
if __name__ == '__main__':
tx = {'_id': '0ca067b886f20efcf9c4cdaa4317f68bb39e0d3adf04eba5ddc025a8ef35119d',
'blocknumber': 77913,
'blocktime': 1283548095,
'vin': [{'address': [''], 'id': 'coinbase', 'value': 0.0}],
'vout': [{'address': ['1BwaFhJVVAwzv7zWyfyxfW9QKBdmruYUB4'],
'id': '0',
'value': 50.0}]}
get_outputList(tx1)