forked from axiom-team/jaklis
Add command currentUd
This commit is contained in:
parent
4e6c100ef7
commit
6cb7e36bd6
|
@ -6,7 +6,7 @@ from shutil import copyfile
|
|||
from dotenv import load_dotenv
|
||||
from duniterpy.key import SigningKey
|
||||
|
||||
__version__ = "0.0.3"
|
||||
__version__ = "0.0.4"
|
||||
|
||||
MY_PATH = os.path.realpath(os.path.dirname(sys.argv[0])) + '/'
|
||||
|
||||
|
@ -39,6 +39,7 @@ history_cmd = subparsers.add_parser('history', help="Voir l'historique des trans
|
|||
balance_cmd = subparsers.add_parser('balance', help="Voir le solde d'un compte Ḡ1")
|
||||
id_cmd = subparsers.add_parser('id', help="Voir l'identité d'une clé publique/username")
|
||||
id_balance_cmd = subparsers.add_parser('idBalance', help="Voir l'identité d'une clé publique/username et son solde")
|
||||
currentUd = subparsers.add_parser('currentUd', help="Affiche la montant actuel du dividende Universel")
|
||||
|
||||
# Messages management
|
||||
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
|
||||
|
@ -99,6 +100,7 @@ balance_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise l
|
|||
id_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
||||
id_cmd.add_argument('-u', '--username', help="Username du compte visé")
|
||||
id_balance_cmd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
|
||||
currentUd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
|
||||
|
||||
|
||||
args = parser.parse_args()
|
||||
|
@ -225,7 +227,7 @@ if cmd in ("read","send","delete","set","get","erase","stars","unstars","getoffe
|
|||
cesium.deleteOffer(args.id)
|
||||
|
||||
# Construct GVA object
|
||||
elif cmd in ("pay","history","balance","id","idBalance"):
|
||||
elif cmd in ("pay","history","balance","id","idBalance","currentUd"):
|
||||
from lib.gva import GvaApi
|
||||
|
||||
if args.node:
|
||||
|
@ -252,6 +254,8 @@ elif cmd in ("pay","history","balance","id","idBalance"):
|
|||
gva.id(args.pubkey, args.username)
|
||||
elif cmd == "idBalance":
|
||||
gva.idBalance(args.pubkey)
|
||||
elif cmd == "currentUd":
|
||||
gva.currentUd()
|
||||
|
||||
|
||||
if keyPath:
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys, re, os.path, json, ast
|
||||
from termcolor import colored
|
||||
from lib.natools import fmt, sign, get_privkey
|
||||
from gql import gql, Client
|
||||
from gql.transport.aiohttp import AIOHTTPTransport
|
||||
|
||||
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||
|
||||
class currentUd:
|
||||
|
||||
def __init__(self, node):
|
||||
# Define Duniter GVA node
|
||||
transport = AIOHTTPTransport(url=node)
|
||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||
|
||||
def sendDoc(self):
|
||||
# Build balance generation document
|
||||
queryBuild = gql(
|
||||
"""
|
||||
query {
|
||||
currentUd {
|
||||
amount
|
||||
}
|
||||
}
|
||||
"""
|
||||
)
|
||||
paramsBuild = {
|
||||
}
|
||||
|
||||
# Send balance document
|
||||
try:
|
||||
udValue = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||
except Exception as e:
|
||||
message = ast.literal_eval(str(e))["message"]
|
||||
sys.stderr.write("Echec de récupération du DU:\n" + message + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
udValueFinal = udValue['currentUd']['amount']
|
||||
|
||||
# print(balanceValue)
|
||||
return udValueFinal
|
12
lib/gva.py
12
lib/gva.py
|
@ -1,3 +1,4 @@
|
|||
from lib.currentUd import currentUd
|
||||
import sys, re
|
||||
from lib.natools import get_privkey
|
||||
from lib.gvaPay import Transaction, PUBKEY_REGEX
|
||||
|
@ -65,6 +66,11 @@ class GvaApi():
|
|||
print(result)
|
||||
|
||||
def idBalance(self, pubkey):
|
||||
gva = Id(self.dunikey, self.node, pubkey)
|
||||
result = gva.sendDoc(True)
|
||||
print(result)
|
||||
gva = Id(self.dunikey, self.node, pubkey)
|
||||
result = gva.sendDoc(True)
|
||||
print(result)
|
||||
|
||||
def currentUd(self):
|
||||
gva = currentUd(self.node)
|
||||
result = gva.sendDoc()
|
||||
print(result)
|
Loading…
Reference in New Issue