Skip to content

Instantly share code, notes, and snippets.

@NoamDev
Last active September 9, 2021 16:44
Show Gist options
  • Save NoamDev/5ee761d8a41b43e86f0cc84cfeadc7f5 to your computer and use it in GitHub Desktop.
Save NoamDev/5ee761d8a41b43e86f0cc84cfeadc7f5 to your computer and use it in GitHub Desktop.
Rust Net TPS
import requests
def get_last_tx_now():
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Connection': 'keep-alive',
'DNT': '1',
'Origin': 'https://rustnet1.ton.dev',
}
data = '{"query":"{ transactions(orderBy: {path: \\"now\\", direction: DESC}, limit: 1) { now }}"}'
response = requests.post('https://rustnet1.ton.dev/graphql', headers=headers, data=data)
json = response.json()
last_tx = json['data']['transactions'][0]['now']
return last_tx
def get_num_tx_between(start, end):
headers = {
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Connection': 'keep-alive',
'DNT': '1',
'Origin': 'https://rustnet1.ton.dev',
}
data = '{"query":"query {aggregateTransactions(filter: {now: {le: ' + str(end) +', ge: ' + str(start) +'}})}"}'
response = requests.post('https://rustnet1.ton.dev/graphql', headers=headers, data=data)
json = response.json()
return int(json['data']['aggregateTransactions'][0])
sample_size = 3
end = get_last_tx_now()
start = end - sample_size
tps = get_num_tx_between(start,end) / sample_size
print(f'last tx: {end}')
print(f'tps: {tps}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment