From fb4bed8dc224618763b40f504c2114b50cee221f Mon Sep 17 00:00:00 2001 From: poka Date: Fri, 26 Feb 2021 04:11:02 +0100 Subject: [PATCH] Add idBalance command --- jaklis.py | 8 ++++++-- lib/gva.py | 5 +++++ lib/gvaID.py | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/jaklis.py b/jaklis.py index ad91964..29314b1 100755 --- a/jaklis.py +++ b/jaklis.py @@ -38,6 +38,7 @@ pay_cmd = subparsers.add_parser('pay', help="Payer en Ḡ1") history_cmd = subparsers.add_parser('history', help="Voir l'historique des transactions d'un compte Ḡ1") 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") # Messages management read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages") @@ -97,6 +98,7 @@ balance_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé") balance_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise les sources en Mempool") 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é") args = parser.parse_args() @@ -133,7 +135,7 @@ try: except: profile = False -if cmd in ('history','balance','get','id') and (pubkey or profile): +if cmd in ('history','balance','get','id','idBalance') and (pubkey or profile): noNeedDunikey = True keyPath = False try: @@ -223,7 +225,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"): +elif cmd in ("pay","history","balance","id","idBalance"): from lib.gva import GvaApi if args.node: @@ -248,6 +250,8 @@ elif cmd in ("pay","history","balance","id"): gva.balance(args.mempool) elif cmd == "id": gva.id(args.pubkey, args.username) + elif cmd == "idBalance": + gva.idBalance(args.pubkey) if keyPath: diff --git a/lib/gva.py b/lib/gva.py index 3e08609..efb57f0 100755 --- a/lib/gva.py +++ b/lib/gva.py @@ -63,3 +63,8 @@ class GvaApi(): gva = Id(self.dunikey, self.node, pubkey, username) result = gva.sendDoc() print(result) + + def idBalance(self, pubkey): + gva = Id(self.dunikey, self.node, pubkey) + result = gva.sendDoc(True) + print(result) \ No newline at end of file diff --git a/lib/gvaID.py b/lib/gvaID.py index 4e6626b..176c8c2 100644 --- a/lib/gvaID.py +++ b/lib/gvaID.py @@ -23,18 +23,34 @@ class Id: transport = AIOHTTPTransport(url=node) self.client = Client(transport=transport, fetch_schema_from_transport=True) - def sendDoc(self): + def sendDoc(self, getBalance=False): # Build balance generation document - queryBuild = gql( - """ - query ($pubkey: String!){ - idty (pubkey: $pubkey) { - isMember - username + if (getBalance): + queryBuild = gql( + """ + query ($pubkey: String!){ + idty (pubkey: $pubkey) { + isMember + username + } + balance(script: $pubkey) { + amount } - } - """ - ) + } + """ + ) + else: + queryBuild = gql( + """ + query ($pubkey: String!){ + idty (pubkey: $pubkey) { + isMember + username + } + } + """ + ) + paramsBuild = { "pubkey": self.pubkey } @@ -48,6 +64,8 @@ class Id: sys.exit(1) jsonBrut = IDResult['idty'] + if (getBalance): + jsonBrut['balance'] = IDResult['balance']['amount']/100 username = IDResult['idty']['username'] isMember = IDResult['idty']['isMember']