Fix scalar types for balance and idty and history GVA
This commit is contained in:
parent
fb4bed8dc2
commit
30f4585223
|
@ -2,3 +2,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
|
|
||||||
*.dunikey
|
*.dunikey
|
||||||
|
not4U
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "/usr/bin/python3.9"
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
pub: HTkEecgbtBd3aZiJJYuUjGwLB7r3Ud232TG4BwLDdB3J
|
||||||
|
sec: 36fT3if1YGLwmhSS89F8vQ6QpmhWmhcLdQyHHmSgxJpbYSxq7C37sDmPKZykmGrE8zmeUxdyAiY256H852p3Lfor
|
Binary file not shown.
|
@ -27,9 +27,9 @@ class History:
|
||||||
# Build history generation document
|
# Build history generation document
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($pubkey: String!, $number: Int!){
|
query ($pubkey: PubKeyGva!, $script: PkOrScriptGva!, $number: Int!){
|
||||||
txsHistoryBc(
|
txsHistoryBc(
|
||||||
pubkeyOrScript: $pubkey
|
script: $script
|
||||||
pagination: { pageSize: $number, ord: DESC }
|
pagination: { pageSize: $number, ord: DESC }
|
||||||
) {
|
) {
|
||||||
both {
|
both {
|
||||||
|
@ -65,7 +65,7 @@ class History:
|
||||||
writtenTime
|
writtenTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balance(script: $pubkey) {
|
balance(script: $script) {
|
||||||
amount
|
amount
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,8 @@ class History:
|
||||||
)
|
)
|
||||||
paramsBuild = {
|
paramsBuild = {
|
||||||
"pubkey": self.pubkey,
|
"pubkey": self.pubkey,
|
||||||
"number": number
|
"number": number,
|
||||||
|
"script": f"SIG({self.pubkey})",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send history document
|
# Send history document
|
||||||
|
|
41
lib/gvaID.py
41
lib/gvaID.py
|
@ -11,13 +11,13 @@ PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||||
class Id:
|
class Id:
|
||||||
|
|
||||||
def __init__(self, dunikey, node, pubkey='', username=''):
|
def __init__(self, dunikey, node, pubkey='', username=''):
|
||||||
|
|
||||||
self.dunikey = dunikey
|
self.dunikey = dunikey
|
||||||
self.pubkey = pubkey if pubkey else get_privkey(dunikey, "pubsec").pubkey
|
self.pubkey = pubkey if pubkey else get_privkey(dunikey, "pubsec").pubkey
|
||||||
self.pubkey = pubkey
|
|
||||||
self.username = username
|
self.username = username
|
||||||
if not re.match(PUBKEY_REGEX, self.pubkey) or len(self.pubkey) > 45:
|
# if not re.match(PUBKEY_REGEX, self.pubkey) or len(self.pubkey) > 45:
|
||||||
sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
# sys.stderr.write("La clé publique n'est pas au bon format.\n")
|
||||||
sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
# Define Duniter GVA node
|
# Define Duniter GVA node
|
||||||
transport = AIOHTTPTransport(url=node)
|
transport = AIOHTTPTransport(url=node)
|
||||||
|
@ -28,14 +28,14 @@ class Id:
|
||||||
if (getBalance):
|
if (getBalance):
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($pubkey: String!){
|
query ($pubkey: PubKeyGva!, $script: PkOrScriptGva!){
|
||||||
idty (pubkey: $pubkey) {
|
idty (pubkey: $pubkey) {
|
||||||
isMember
|
isMember
|
||||||
username
|
username
|
||||||
}
|
}
|
||||||
balance(script: $pubkey) {
|
balance(script: $script) {
|
||||||
amount
|
amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
@ -52,21 +52,30 @@ class Id:
|
||||||
)
|
)
|
||||||
|
|
||||||
paramsBuild = {
|
paramsBuild = {
|
||||||
"pubkey": self.pubkey
|
"pubkey": self.pubkey,
|
||||||
|
"script": f"SIG({self.pubkey})"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send balance document
|
# Send balance document
|
||||||
try:
|
try:
|
||||||
IDResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
queryResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
message = ast.literal_eval(str(e))["message"]
|
sys.stderr.write("Echec de récupération du solde:\n" + str(e) + "\n")
|
||||||
sys.stderr.write("Echec de récupération du solde:\n" + message + "\n")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
jsonBrut = IDResult['idty']
|
jsonBrut = queryResult
|
||||||
if (getBalance):
|
|
||||||
jsonBrut['balance'] = IDResult['balance']['amount']/100
|
if (getBalance):
|
||||||
username = IDResult['idty']['username']
|
if (queryResult['balance'] == None):
|
||||||
isMember = IDResult['idty']['isMember']
|
jsonBrut['balance'] = {"amount": 0.0}
|
||||||
|
else:
|
||||||
|
jsonBrut['balance'] = queryResult['balance']['amount']/100
|
||||||
|
|
||||||
|
if (queryResult['idty'] == None):
|
||||||
|
username = 'Matiou'
|
||||||
|
isMember = False
|
||||||
|
else:
|
||||||
|
username = queryResult['idty']['username']
|
||||||
|
isMember = queryResult['idty']['isMember']
|
||||||
|
|
||||||
return json.dumps(jsonBrut, indent=2)
|
return json.dumps(jsonBrut, indent=2)
|
||||||
|
|
|
@ -4,5 +4,5 @@ pybase64
|
||||||
duniterpy==0.58.1
|
duniterpy==0.58.1
|
||||||
termcolor
|
termcolor
|
||||||
python-dotenv
|
python-dotenv
|
||||||
gql==3.0.0a1
|
gql==3.0.0a5
|
||||||
requests
|
requests
|
||||||
|
|
Loading…
Reference in New Issue