Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Moved minting to a separate thread
Browse files Browse the repository at this point in the history
  • Loading branch information
rtrevinnoc committed Feb 17, 2021
1 parent eca1ee9 commit 9ea90be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Monad.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ def mintTokens(queryVec: np.array, answerVec: np.array) -> int:
if WEB3API.isConnected():
queryVec = (queryVec * 100).astype(int).tolist()
answerVec = (answerVec * 100).astype(int).tolist()
return contract.functions.mint(queryVec, answerVec).call()
response = contract.functions.mint(queryVec, answerVec).call()
print("Tokens minted:", response)
return response
else:
raise "Cannot connect to Ethereum network."

Expand Down
8 changes: 5 additions & 3 deletions future.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#########################################################################

from Monad import *
import os.path, os, shutil, json, random, sys, socket, re, mimetypes, datetime, lmdb, hnswlib, time, bson, requests, socket, ast, functools, asyncio, concurrent.futures, itertools, mimetypes, io
import os.path, os, shutil, json, random, sys, socket, re, mimetypes, datetime, lmdb, hnswlib, time, bson, requests, socket, ast, functools, asyncio, concurrent.futures, itertools, mimetypes, io, threading
import numpy as np
import numexpr as ne
from flask import (Flask, render_template, request, redirect,
Expand Down Expand Up @@ -319,7 +319,8 @@ def loadMoreUrls(q_vec: np.ndarray, queryLanguage: str, numberOfURLs: int,
} for url in search["results"]]

try:
print("Tokens minted:", mintTokens(q_vec, np.frombuffer(search["results"][0]["vec"], dtype=np.float32)))
minter_thread = threading.Thread(target=mintTokens, args=(q_vec, np.frombuffer(search["results"][0]["vec"], dtype=np.float32)))
minter_thread.start()
except:
print("The contract rejected the answer and did not award tokens.")

Expand Down Expand Up @@ -359,7 +360,8 @@ def loadMoreImages(term: np.ndarray, number, page: int) -> dict:
imageDBTransaction.get(str(image).encode("utf-8")))
if idx == 1:
try:
print("Tokens minted:", mintTokens(term, np.frombuffer(image["vec"], dtype=np.float32)))
minter_thread = threading.Thread(target=mintTokens, args=(term, np.frombuffer(image["vec"], dtype=np.float32)))
minter_thread.start()
except:
print("The contract rejected the answer and did not award tokens.")
resultImages.append({
Expand Down

0 comments on commit 9ea90be

Please sign in to comment.