Added multiple appstore address, added feature to show description

This commit is contained in:
sairajzero 2019-02-23 00:48:09 +05:30
parent 2fa6999ecc
commit 105c1a8dd3
5 changed files with 138 additions and 18 deletions

View File

@ -12,7 +12,7 @@
"name": "AlternateLove",
"icon": "Icon/AternaLove.png",
"type": "Cmdline",
"location": "apps/aternalove",
"location": "apps/aternalove/",
"exec": "./auto-aterna-love.sh",
"github": "https://github.com/metacoin/aternalove.git"
},

Binary file not shown.

View File

@ -4,11 +4,13 @@ The details are as follows
id - App id
name - Name of the app
icon - Icon img location
description - App Description
type - App type (webapp, cmdline or gui)
exec - Execution Command
github - github link
Note:-Inorder to remove a dapp from the flostore permanently,the authoritative user has to make a transaction of that app,with 'remove' paramater/key(in json format) added in the detail of that dapp.
**Use generateAppData.py for generating the data required to send for the respective app**
Webapps are available as website n should be opened in browser
Gui apps are open by running their binary files

83
generateAppData.py Normal file
View File

@ -0,0 +1,83 @@
import subprocess
import json
import requests
import hashlib
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(JsonAddress):
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)
try:
if 'Dapp' in app.keys():
Dapps = Dappend(Dapps,app['Dapp'])
except:
continue
#print(Dapps)
return Dapps
def findHash(data):
result = hashlib.sha1(data.encode())
return str(result.hexdigest())
JsonAddress=input('Enter Admin address :')
apps = getJsonData(JsonAddress)
#print(apps)
print("Enter app Details :")
appData = {}
appData['id'] = input('Enter App ID \t: ')
if input('Remove app ? (Y/N)') == 'Y':
appData['remove'] = True
else:
appData['name'] = input('Enter App Name \t: ')
appData['description'] = input('Enter Description \t: ')
appData['icon'] = input('Enter Icon location \t: ')
appData['type'] = input('Enter App Type (Webapp|Cmdline|Gui): ')
if appData['type'] == 'Webapp':
appData['url'] = input('Enter App url \t: ')
elif appData['type'] == 'Cmdline' or appData['type'] == 'Gui':
appData['github'] = input('Enter Github link (.git) \t: ')
appData['location'] = 'apps/'+input('Enter Repository name \t: ') +'/'
appData['exec'] = input('Enter execution cmd (eg. ./binary) \t: ')
print(appData)
apps = Dappend(apps ,appData)
#print(apps)
apphash = findHash(str(apps))
floData = json.dumps({'Dapp':appData ,'hash':apphash})
print('\nfloData = '+floData)

67
main.py
View File

@ -11,7 +11,7 @@ import socket
import requests
import hashlib
JsonAddress = "oXa7t72t3CgnR11ycxVfdupz55eucHufHj"
JsonAddresses = ["oXa7t72t3CgnR11ycxVfdupz55eucHufHj","oYcLBQZkgj9taQ5Zj6ziu8eqMREhyAPCcT","oYtGSrrfLvurYLKouZw3E7AyNuM8ZushbC"]
def searchDict(dicArr,key,val):
for i in range(len(dicArr)):
@ -62,7 +62,7 @@ def verifyHash(localHash,txid):
return False
def getJsonData(Dapps, lastTx):
def getJsonData(Dapps, lastTx,JsonAddress):
try:
r = requests.get("https://testnet.florincoin.info/ext/getaddress/"+JsonAddress)
data = json.loads(r.content)
@ -90,10 +90,17 @@ def getJsonData(Dapps, lastTx):
#print(e)
continue
#print(app)
if 'Dapp' in app.keys():
Dapps = Dappend(Dapps,app['Dapp'])
try:
if 'Dapp' in app.keys():
Dapps = Dappend(Dapps,app['Dapp'])
except:
continue
#print(Dapps)
return (Dapps,len(data['last_txs'])-1)
{'Dapps':apps ,'lastTx':lastTx}
returndata = {}
returndata['Dapps'] = Dapps
returndata['lastTx'] = len(data['last_txs'])-1
return (returndata)
class FLOappStore:
def __init__(self, root):
@ -184,8 +191,27 @@ class FLOappStore:
isConnected()
self.appWin = Toplevel()
self.appWin.title(app["name"])
#self.appWin.geometry("500x100")
#self.appWin.resizable(0,0)
self.appWin.geometry("500x400")
self.appWin.resizable(0,0)
try:
description = app["description"]
except:
description = '*NIL*'
Label1 = Label(self.appWin, text="Description")
Label1.pack()
GTextFrame = Frame(self.appWin)
GScroll = Scrollbar(GTextFrame)
GScroll.pack(side=RIGHT, fill=Y)
self.GLMsg = Text(GTextFrame,height=10,width=50,yscrollcommand=GScroll.set)
self.GLMsg.insert(END, description)
self.GLMsg.config(state='disabled')
self.GLMsg.pack(side = LEFT)
GTextFrame.pack()
GScroll.config(command=self.GLMsg.yview)
if(app["type"] == "Gui" or app["type"] == "Cmdline"):
if(os.path.isdir(app["location"]) and subprocess.Popen("git config --get remote.origin.url",cwd=app["location"],stdout=subprocess.PIPE,shell=True).communicate()[0].decode("utf-8").strip()==app["github"]):
openButton = Button(self.appWin,text="Open App",command=lambda :self.openApp(app))
@ -238,22 +264,31 @@ class FLOappStore:
def refreshAppData():
global apps
apps = []
print("Refreshing App Details")
try:
with open('Apps.json','r') as F:
data=json.loads(F.read())
apps = data['Dapps']
lastTx = data['lastTx']
flag = True
except:
apps = []
lastTx = -1
flag = False
data = {}
try:
(apps,lastTx) = getJsonData(apps,lastTx)
except:
sys.exit(1)
for addr in JsonAddresses:
try:
appdata = data[addr]['Dapps']
#print(appdata)
lastTx = data[addr]['lastTx']
except:
appdata = []
lastTx = -1
data[addr] = getJsonData(appdata,lastTx,addr)
#print(data[addr])
apps = apps + data[addr]['Dapps']
with open('Apps.json','w+') as F:
data = json.dumps({'Dapps':apps ,'lastTx':lastTx})
#print(data)
data = json.dumps(data)
F.write(data)
print("Loaded App Details")