Fix bug for swap contract dynamic price calculation caused by change to blockbook API
The recent update to the external API introduced a change in the response format, resulting in a bug in our code. This commit adjusts the handling of API responses to accommodate the new format, resolving the issue and ensuring proper functionality.
This commit is contained in:
parent
0eb93ad916
commit
49a3295225
@ -278,17 +278,16 @@ def fetch_dynamic_swap_price(contractStructure, blockinfo):
|
|||||||
# find the first contract transaction which adheres to price change format
|
# find the first contract transaction which adheres to price change format
|
||||||
# {"price-update":{"contract-name": "", "contract-address": "", "price": 3}}
|
# {"price-update":{"contract-name": "", "contract-address": "", "price": 3}}
|
||||||
print(f'oracle address is : {oracle_address}')
|
print(f'oracle address is : {oracle_address}')
|
||||||
response = requests.get(f'{apiUrl}api/v1/addr/{oracle_address}')
|
response = requests.get(f'{apiUrl}api/v1/address/{oracle_address}?details=txs')
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
response = response.json()
|
response = response.json()
|
||||||
if 'transactions' not in response.keys(): # API doesn't return 'transactions' key, if 0 txs present on address
|
if 'txs' not in response.keys(): # API doesn't return 'transactions' key, if 0 txs present on address
|
||||||
return float(contractStructure['price'])
|
return float(contractStructure['price'])
|
||||||
else:
|
else:
|
||||||
transactions = response['transactions']
|
transactions = response['txs']
|
||||||
for transaction_hash in transactions:
|
for transaction in transactions:
|
||||||
transaction_response = requests.get(f'{apiUrl}api/v1/tx/{transaction_hash}')
|
#transaction_response = requests.get(f'{apiUrl}api/v1/tx/{transaction_hash}')
|
||||||
if transaction_response.status_code == 200:
|
# if transaction_response.status_code == 200:
|
||||||
transaction = transaction_response.json()
|
|
||||||
floData = transaction['floData']
|
floData = transaction['floData']
|
||||||
# If the blocktime of the transaction is < than the current block time
|
# If the blocktime of the transaction is < than the current block time
|
||||||
if transaction['time'] < blockinfo['time']:
|
if transaction['time'] < blockinfo['time']:
|
||||||
@ -308,9 +307,9 @@ def fetch_dynamic_swap_price(contractStructure, blockinfo):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
else:
|
# else:
|
||||||
print('API error while fetch_dynamic_swap_price')
|
# print('API error while fetch_dynamic_swap_price')
|
||||||
return None
|
# return None
|
||||||
return float(contractStructure['price'])
|
return float(contractStructure['price'])
|
||||||
else:
|
else:
|
||||||
print('API error while fetch_dynamic_swap_price')
|
print('API error while fetch_dynamic_swap_price')
|
||||||
@ -326,7 +325,7 @@ def find_sender_receiver(transaction_data):
|
|||||||
|
|
||||||
# todo Rule 40 - For each vin, find the feeding address and the fed value. Make an inputlist containing [inputaddress, n value]
|
# todo Rule 40 - For each vin, find the feeding address and the fed value. Make an inputlist containing [inputaddress, n value]
|
||||||
for vin in transaction_data["vin"]:
|
for vin in transaction_data["vin"]:
|
||||||
vinlist.append([vin["addr"], float(vin["value"])])
|
vinlist.append([vin["addresses"][0], float(vin["value"])])
|
||||||
|
|
||||||
totalinputval = float(transaction_data["valueIn"])
|
totalinputval = float(transaction_data["valueIn"])
|
||||||
|
|
||||||
@ -355,7 +354,7 @@ def find_sender_receiver(transaction_data):
|
|||||||
addresscounter = 0
|
addresscounter = 0
|
||||||
inputcounter = 0
|
inputcounter = 0
|
||||||
for obj in transaction_data["vout"]:
|
for obj in transaction_data["vout"]:
|
||||||
if obj["scriptPubKey"]["type"] == "pubkeyhash":
|
if obj["scriptPubKey"]["isAddress"] == True:
|
||||||
addresscounter = addresscounter + 1
|
addresscounter = addresscounter + 1
|
||||||
if inputlist[0] == obj["scriptPubKey"]["addresses"][0]:
|
if inputlist[0] == obj["scriptPubKey"]["addresses"][0]:
|
||||||
inputcounter = inputcounter + 1
|
inputcounter = inputcounter + 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user