Update for hashing
This commit is contained in:
parent
31b45cad15
commit
ce6b08d569
BIN
FLO_appStore
BIN
FLO_appStore
Binary file not shown.
79
getJson.py
79
getJson.py
@ -1,8 +1,9 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import hashlib
|
||||||
|
|
||||||
JsonAddress = "ocZXNtzpiUqBvzQorjAKmZ5MhXxGTLKeSH"
|
JsonAddress = 'oXa7t72t3CgnR11ycxVfdupz55eucHufHj'
|
||||||
|
|
||||||
def searchDict(dicArr,key,val):
|
def searchDict(dicArr,key,val):
|
||||||
for i in range(len(dicArr)):
|
for i in range(len(dicArr)):
|
||||||
@ -10,6 +11,10 @@ def searchDict(dicArr,key,val):
|
|||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
def findHash(data):
|
||||||
|
result = hashlib.sha1(data.encode())
|
||||||
|
return str(result.hexdigest())
|
||||||
|
|
||||||
def readUnitFromBlockchain(txid):
|
def readUnitFromBlockchain(txid):
|
||||||
rawtx = subprocess.check_output(["flo-cli","--testnet", "getrawtransaction", str(txid)])
|
rawtx = subprocess.check_output(["flo-cli","--testnet", "getrawtransaction", str(txid)])
|
||||||
rawtx = str(rawtx)
|
rawtx = str(rawtx)
|
||||||
@ -17,28 +22,68 @@ def readUnitFromBlockchain(txid):
|
|||||||
tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)])
|
tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)])
|
||||||
content = json.loads(tx)
|
content = json.loads(tx)
|
||||||
text = content['floData']
|
text = content['floData']
|
||||||
return text
|
return str(text)
|
||||||
|
|
||||||
def getJsonData():
|
def Dappend(Dapps,app):
|
||||||
|
i = searchDict(Dapps,'id',app['id'])
|
||||||
|
if (i!=-1):
|
||||||
|
del(Dapps[i])
|
||||||
|
if ('remove' not in app.keys()):
|
||||||
|
Dapps = Dapps + [app]
|
||||||
|
return Dapps
|
||||||
|
|
||||||
|
def verifyHash(localHash,txid):
|
||||||
|
content = readUnitFromBlockchain(txid)
|
||||||
|
try:
|
||||||
|
if(json.loads(content)['hash'] == localHash):
|
||||||
|
print("true")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def getJsonData(Dapps, lastTx):
|
||||||
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
|
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
|
||||||
data = json.loads(r.content)
|
data = json.loads(r.content)
|
||||||
#print(data)
|
#print(data)
|
||||||
Dapps = []
|
localHash = findHash(str(Dapps))
|
||||||
for i in range(len(data['last_txs'])):
|
if(lastTx == -1 or not verifyHash(localHash,data['last_txs'][lastTx]['addresses'])):
|
||||||
|
lastTx = 0
|
||||||
|
print(lastTx)
|
||||||
|
for i in range(lastTx,len(data['last_txs'])):
|
||||||
|
print(i)
|
||||||
if(data['last_txs'][i]['type']=='vin'):
|
if(data['last_txs'][i]['type']=='vin'):
|
||||||
content = readUnitFromBlockchain(data['last_txs'][i]['addresses'])
|
content = readUnitFromBlockchain(data['last_txs'][i]['addresses'])
|
||||||
#print(content)
|
#print(content)
|
||||||
if content.startswith("text:Dapps"):
|
try:
|
||||||
#print(data['last_txs'][i]['addresses'])
|
app = json.loads(content)
|
||||||
pos = content.find('{')
|
except Exception as e:
|
||||||
app = json.loads(content[pos:])
|
#print(e)
|
||||||
i = searchDict(Dapps,'id',app['id'])
|
continue
|
||||||
if (i!=-1):
|
#print(app)
|
||||||
del(Dapps[i])
|
if 'Dapp' in app.keys():
|
||||||
if ('remove' not in app.keys()):
|
Dapps = Dappend(Dapps,app['Dapp'])
|
||||||
Dapps = Dapps + [app]
|
|
||||||
#print(Dapps)
|
#print(Dapps)
|
||||||
return Dapps
|
return (Dapps,len(data['last_txs'])-1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open('Apps.json','r') as F:
|
||||||
|
data=json.loads(F.read())
|
||||||
|
apps = data['Dapps']
|
||||||
|
lastTx = data['lastTx']
|
||||||
|
except:
|
||||||
|
apps = []
|
||||||
|
lastTx = -1
|
||||||
|
|
||||||
|
print(apps)
|
||||||
|
print(lastTx)
|
||||||
|
(apps,lastTx) = getJsonData(apps,lastTx)
|
||||||
|
|
||||||
|
with open('Apps.json','w+') as F:
|
||||||
|
data = json.dumps({'Dapps':apps ,'lastTx':lastTx})
|
||||||
|
print(data)
|
||||||
|
F.write(data)
|
||||||
|
|
||||||
|
|
||||||
apps = getJsonData()
|
|
||||||
print(apps)
|
|
||||||
78
main.py
78
main.py
@ -8,8 +8,9 @@ import json
|
|||||||
import math
|
import math
|
||||||
import socket
|
import socket
|
||||||
import requests
|
import requests
|
||||||
|
import hashlib
|
||||||
|
|
||||||
JsonAddress = "ocZXNtzpiUqBvzQorjAKmZ5MhXxGTLKeSH"
|
JsonAddress = "oXa7t72t3CgnR11ycxVfdupz55eucHufHj"
|
||||||
|
|
||||||
def searchDict(dicArr,key,val):
|
def searchDict(dicArr,key,val):
|
||||||
for i in range(len(dicArr)):
|
for i in range(len(dicArr)):
|
||||||
@ -17,6 +18,10 @@ def searchDict(dicArr,key,val):
|
|||||||
return i
|
return i
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
def findHash(data):
|
||||||
|
result = hashlib.sha1(data.encode())
|
||||||
|
return str(result.hexdigest())
|
||||||
|
|
||||||
def isConnected():
|
def isConnected():
|
||||||
try:
|
try:
|
||||||
socket.create_connection(("www.github.com", 80))
|
socket.create_connection(("www.github.com", 80))
|
||||||
@ -32,28 +37,53 @@ def readUnitFromBlockchain(txid):
|
|||||||
tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)])
|
tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)])
|
||||||
content = json.loads(tx)
|
content = json.loads(tx)
|
||||||
text = content['floData']
|
text = content['floData']
|
||||||
return text
|
return str(text)
|
||||||
|
|
||||||
def getJsonData():
|
def Dappend(Dapps,app):
|
||||||
|
i = searchDict(Dapps,'id',app['id'])
|
||||||
|
if (i!=-1):
|
||||||
|
del(Dapps[i])
|
||||||
|
if ('remove' not in app.keys()):
|
||||||
|
Dapps = Dapps + [app]
|
||||||
|
return Dapps
|
||||||
|
|
||||||
|
def verifyHash(localHash,txid):
|
||||||
|
content = readUnitFromBlockchain(txid)
|
||||||
|
try:
|
||||||
|
if(json.loads(content)['hash'] == localHash):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def getJsonData(Dapps, lastTx):
|
||||||
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
|
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
|
||||||
data = json.loads(r.content)
|
data = json.loads(r.content)
|
||||||
#print(data)
|
#print(data)
|
||||||
Dapps = []
|
localHash = findHash(str(Dapps))
|
||||||
for i in range(len(data['last_txs'])):
|
try:
|
||||||
|
if(lastTx == -1 or not verifyHash(localHash,data['last_txs'][lastTx]['addresses'])):
|
||||||
|
lastTx = 0
|
||||||
|
except:
|
||||||
|
lastTx = 0
|
||||||
|
#print(lastTx)
|
||||||
|
for i in range(lastTx,len(data['last_txs'])):
|
||||||
|
print(i)
|
||||||
if(data['last_txs'][i]['type']=='vin'):
|
if(data['last_txs'][i]['type']=='vin'):
|
||||||
content = readUnitFromBlockchain(data['last_txs'][i]['addresses'])
|
content = readUnitFromBlockchain(data['last_txs'][i]['addresses'])
|
||||||
#print(content)
|
#print(content)
|
||||||
if content.startswith("text:Dapps"):
|
try:
|
||||||
#print(data['last_txs'][i]['addresses'])
|
app = json.loads(content)
|
||||||
pos = content.find('{')
|
except Exception as e:
|
||||||
app = json.loads(content[pos:])
|
#print(e)
|
||||||
i = searchDict(Dapps,'id',app['id'])
|
continue
|
||||||
if (i!=-1):
|
#print(app)
|
||||||
del(Dapps[i])
|
if 'Dapp' in app.keys():
|
||||||
if ('remove' not in app.keys()):
|
Dapps = Dappend(Dapps,app['Dapp'])
|
||||||
Dapps = Dapps + [app]
|
|
||||||
#print(Dapps)
|
#print(Dapps)
|
||||||
return Dapps
|
return (Dapps,len(data['last_txs'])-1)
|
||||||
|
|
||||||
class FLOappStore:
|
class FLOappStore:
|
||||||
def __init__(self, root):
|
def __init__(self, root):
|
||||||
@ -202,7 +232,23 @@ else:
|
|||||||
with open('AppData.json',encoding='utf-8') as F:
|
with open('AppData.json',encoding='utf-8') as F:
|
||||||
apps=json.loads(F.read())["Dapps"]
|
apps=json.loads(F.read())["Dapps"]
|
||||||
'''
|
'''
|
||||||
apps = getJsonData()
|
|
||||||
|
try:
|
||||||
|
with open('Apps.json','r') as F:
|
||||||
|
data=json.loads(F.read())
|
||||||
|
apps = data['Dapps']
|
||||||
|
lastTx = data['lastTx']
|
||||||
|
except:
|
||||||
|
apps = []
|
||||||
|
lastTx = -1
|
||||||
|
|
||||||
|
(apps,lastTx) = getJsonData(apps,lastTx)
|
||||||
|
|
||||||
|
with open('Apps.json','w+') as F:
|
||||||
|
data = json.dumps({'Dapps':apps ,'lastTx':lastTx})
|
||||||
|
print(data)
|
||||||
|
F.write(data)
|
||||||
|
|
||||||
root = Tk()
|
root = Tk()
|
||||||
root.title("FLOappStore")
|
root.title("FLOappStore")
|
||||||
root.geometry("1100x500")
|
root.geometry("1100x500")
|
||||||
|
|||||||
89
send_floData.py
Normal file
89
send_floData.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
import random
|
||||||
|
import requests
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
JsonAddress = 'oXa7t72t3CgnR11ycxVfdupz55eucHufHj'
|
||||||
|
toAddress = 'oXa7t72t3CgnR11ycxVfdupz55eucHufHj'
|
||||||
|
tempAcc = str(random.randint(100000,999999))
|
||||||
|
amt = '0.01'
|
||||||
|
|
||||||
|
def searchDict(dicArr,key,val):
|
||||||
|
for i in range(len(dicArr)):
|
||||||
|
if(dicArr[i][key]==val):
|
||||||
|
return i
|
||||||
|
return -1
|
||||||
|
|
||||||
|
def readUnitFromBlockchain(txid):
|
||||||
|
rawtx = subprocess.check_output(["flo-cli","--testnet", "getrawtransaction", str(txid)])
|
||||||
|
rawtx = str(rawtx)
|
||||||
|
rawtx = rawtx[2:-3]
|
||||||
|
tx = subprocess.check_output(["flo-cli","--testnet", "decoderawtransaction", str(rawtx)])
|
||||||
|
content = json.loads(tx)
|
||||||
|
text = content['floData']
|
||||||
|
return str(text)
|
||||||
|
|
||||||
|
def Dappend(Dapps,app):
|
||||||
|
i = searchDict(Dapps,'id',app['id'])
|
||||||
|
if (i!=-1):
|
||||||
|
del(Dapps[i])
|
||||||
|
if ('remove' not in app.keys()):
|
||||||
|
Dapps = Dapps + [app]
|
||||||
|
return Dapps
|
||||||
|
|
||||||
|
def getJsonData():
|
||||||
|
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
|
||||||
|
data = json.loads(r.content)
|
||||||
|
#print(data)
|
||||||
|
Dapps = []
|
||||||
|
for i in range(len(data['last_txs'])):
|
||||||
|
if(data['last_txs'][i]['type']=='vin'):
|
||||||
|
content = readUnitFromBlockchain(data['last_txs'][i]['addresses'])
|
||||||
|
try:
|
||||||
|
app = json.loads(content)
|
||||||
|
except :
|
||||||
|
continue
|
||||||
|
print(app)
|
||||||
|
if 'Dapp' in app.keys():
|
||||||
|
Dapps = Dappend(Dapps,app['Dapp'])
|
||||||
|
#print(Dapps)
|
||||||
|
return Dapps
|
||||||
|
|
||||||
|
def findHash(data):
|
||||||
|
result = hashlib.sha1(data.encode())
|
||||||
|
return str(result.hexdigest())
|
||||||
|
|
||||||
|
apps = getJsonData()
|
||||||
|
print(apps)
|
||||||
|
|
||||||
|
print("Enter floData :")
|
||||||
|
lines = []
|
||||||
|
while True:
|
||||||
|
line = input()
|
||||||
|
if line:
|
||||||
|
lines.append(line)
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
appData = ' '.join(lines)
|
||||||
|
try:
|
||||||
|
appData=json.loads(appData)
|
||||||
|
except:
|
||||||
|
print('Unable to parse JSON : '+appData)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
print(appData)
|
||||||
|
apps = Dappend(apps , appData)
|
||||||
|
print(apps)
|
||||||
|
apphash = findHash(str(apps))
|
||||||
|
|
||||||
|
floData = json.dumps({'Dapp':appData ,'hash':apphash})
|
||||||
|
print('floData = '+floData)
|
||||||
|
|
||||||
|
process = subprocess.Popen(['flo-cli','-testnet','getaccount',JsonAddress], stdout=subprocess.PIPE)
|
||||||
|
account = process.communicate()[0].decode().strip()
|
||||||
|
process = subprocess.Popen(['flo-cli','-testnet','setaccount',JsonAddress,tempAcc], stdout=subprocess.PIPE)
|
||||||
|
process = subprocess.Popen(['flo-cli','-testnet','sendfrom',tempAcc,toAddress,amt,'6','','',floData], stdout=subprocess.PIPE)
|
||||||
|
txid = process.communicate()[0].decode()
|
||||||
|
print('txid : '+txid)
|
||||||
|
process = subprocess.Popen(['flo-cli','-testnet','setaccount',JsonAddress,account], stdout=subprocess.PIPE)
|
||||||
Loading…
Reference in New Issue
Block a user