Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Testnet version #109

Merged
merged 14 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions front/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
STRAPI_URL=http://localhost:1337
GTM_TAG=GTM-W8TFHD8
IS_PROD=false
NFT_DISABLED=true
189 changes: 189 additions & 0 deletions front/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import sqlite3
from flask import Flask, jsonify, request
import json
from flask_cors import CORS

app = Flask(__name__)
CORS(app)

def fetch_data_with_count(query, count_query):
conn = sqlite3.connect('./log/commands.sqlite')
cursor = conn.cursor()

cursor.execute(count_query)
total_records = cursor.fetchone()[0]

cursor.execute(query)
data = [json.loads(row[0]) for row in cursor.fetchall()]

conn.close()
return data, total_records

def get_nullifiers_params(data):
nullifiers = []
for entry in data:
for event in entry.get('events', []):
if event.get('name') == "new-nullifier":
params_list = event.get('params', [])
for inner_list in params_list:
if isinstance(inner_list, list):
for params in inner_list:
if 'int' in params:
nullifiers.append(params['int'])
return nullifiers

@app.route('/getNullifiers')
def get_nullifiers():
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 500))
salt = int(request.args.get('salt', 949))
offset = (page - 1) * per_page

data_query = f"SELECT result FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt} LIMIT {per_page} OFFSET {offset}"
count_query = f"SELECT COUNT(*) FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt}"

data, total_records = fetch_data_with_count(data_query, count_query)

nullifiers_params = get_nullifiers_params(data)

total_pages = -(-total_records // per_page)
is_last_page = page >= total_pages

return jsonify({
"data": nullifiers_params,
"is_last_page": is_last_page
})


def get_commitments_params(data):
commitments = []

for entry in data:
for event in entry.get('events', []):
if event.get('name') == "new-commitment":
params = event.get('params', [])
if len(params) >= 2:
value = params[0].get("int")
order = params[1].get("int")
if value and order:
commitment = {
"value": str(value),
"order": str(order)
}
commitments.append(commitment)

return commitments

@app.route('/getCommitments')
def get_commitments():
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 500))
salt = int(request.args.get('salt', 949))
offset = (page - 1) * per_page

data_query = f"SELECT result FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt} LIMIT {per_page} OFFSET {offset}"
count_query = f"SELECT COUNT(*) FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt}"

data, total_records = fetch_data_with_count(data_query, count_query)

commitments_params = get_commitments_params(data)

total_pages = -(-total_records // per_page)
is_last_page = page >= total_pages

return jsonify({
"data": commitments_params,
"is_last_page": is_last_page
})

def get_encrypted_params(data):
encrypted_values = []
for entry in data:
for event in entry.get('events', []):
if event.get('name') == "new-encrypted-output":
params = event.get('params', [])
if params:
encrypted_values.append(params[0])
return encrypted_values

@app.route('/getEncrypted')
def get_encrypted():
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 500))
salt = int(request.args.get('salt', 949))
offset = (page - 1) * per_page

data_query = f"SELECT result FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt} LIMIT {per_page} OFFSET {offset}"
count_query = f"SELECT COUNT(*) FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt}"

data, total_records = fetch_data_with_count(data_query, count_query)

encrypted_params = get_encrypted_params(data)

last_tx_id = data[-1]["txId"] if data else None

total_pages = -(-total_records // per_page)
is_last_page = page >= total_pages

return jsonify({
"data": encrypted_params,
"is_last_page": is_last_page,
"last_tx_id": last_tx_id
})

def get_receipts_params(data):
receipts = []
for entry in data:
for event in entry.get('events', []):
if event.get('name') == "new-transaction":
params = event.get('params', [])
if params:
receipts.append(params[0])
return receipts

@app.route('/getReceipts')
def get_receipts():
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 500))
salt = int(request.args.get('salt', 949))
offset = (page - 1) * per_page

data_query = f"SELECT result FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt} LIMIT {per_page} OFFSET {offset}"
count_query = f"SELECT COUNT(*) FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt}"

data, total_records = fetch_data_with_count(data_query, count_query)

receipts_params = get_receipts_params(data)

last_tx_id = data[-1]["txId"] if data else None

total_pages = -(-total_records // per_page)
is_last_page = page >= total_pages

return jsonify({
"data": receipts_params,
"is_last_page": is_last_page,
"last_tx_id": last_tx_id
})

@app.route('/getdata')
def get_data():
page = int(request.args.get('page', 1))
per_page = int(request.args.get('per_page', 500))
salt = int(request.args.get('salt', 949))

offset = (page - 1) * per_page

conn = sqlite3.connect('./log/commands.sqlite')
cursor = conn.cursor()

cursor.execute(f"SELECT result FROM pactCommands WHERE result LIKE '%transact%' AND txid >= {salt} LIMIT {per_page} OFFSET {offset}")

data = [json.loads(row[0]) for row in cursor.fetchall()]

conn.close()

return jsonify(data)

if __name__ == '__main__':
app.run(host='0.0.0.0')
6 changes: 6 additions & 0 deletions front/app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { getConfig } from 'opact-sdk'

useHead({
titleTemplate: title => title || 'Home',
meta: [
Expand All @@ -20,6 +22,10 @@ useHead({
}
]
})

const runtimeConfig = useRuntimeConfig()

getConfig(runtimeConfig.public.opactSDKNetwork)
</script>

<template>
Expand Down
9 changes: 0 additions & 9 deletions front/apps/site/.gitignore

This file was deleted.

36 changes: 0 additions & 36 deletions front/apps/site/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions front/apps/site/app.vue

This file was deleted.

10 changes: 0 additions & 10 deletions front/apps/site/index.css

This file was deleted.

2 changes: 0 additions & 2 deletions front/apps/site/nuxt.config.ts

This file was deleted.

24 changes: 0 additions & 24 deletions front/apps/site/package.json

This file was deleted.

21 changes: 0 additions & 21 deletions front/apps/site/pages/index.vue

This file was deleted.

23 changes: 0 additions & 23 deletions front/apps/site/pages/tickets.vue

This file was deleted.

11 changes: 0 additions & 11 deletions front/chains/ethereum/chain.ts

This file was deleted.

Loading
Loading