70 lines
1.4 KiB
Python
70 lines
1.4 KiB
Python
|
#!/usr/bin/env python3
|
||
|
|
||
|
import sys
|
||
|
from userEnv import issuer, dunikey, node
|
||
|
from natools import fmt, sign, get_privkey
|
||
|
from gql import gql, Client
|
||
|
from gql.transport.aiohttp import AIOHTTPTransport
|
||
|
|
||
|
# Define Duniter GVA node
|
||
|
transport = AIOHTTPTransport(url=node)
|
||
|
client = Client(transport=transport, fetch_schema_from_transport=True)
|
||
|
|
||
|
recipient = sys.argv[1]
|
||
|
amount = int(sys.argv[2])
|
||
|
comment = sys.argv[3]
|
||
|
|
||
|
## GraphQL queries
|
||
|
|
||
|
# Build the TX Document
|
||
|
queryBuild = gql(
|
||
|
"""
|
||
|
query ($recipient: String!, $issuer: String!, $amount: Int!, $comment: String!){ genTxs(
|
||
|
amount: $amount
|
||
|
comment: $comment
|
||
|
issuer: $issuer
|
||
|
recipient: $recipient
|
||
|
)
|
||
|
}
|
||
|
"""
|
||
|
)
|
||
|
paramsBuild = {
|
||
|
"recipient": recipient,
|
||
|
"issuer": issuer,
|
||
|
"amount": amount,
|
||
|
"comment": comment
|
||
|
}
|
||
|
|
||
|
# Send TX document
|
||
|
txDoc = str(client.execute(queryBuild, variable_values=paramsBuild))[13:-3].replace('\\n','\n').encode()
|
||
|
|
||
|
# Sign TX document
|
||
|
|
||
|
signature = fmt["64"](sign(txDoc, get_privkey(dunikey, "pubsec"))[:-len(txDoc)])
|
||
|
signedDoc = txDoc.decode() + signature.decode()
|
||
|
|
||
|
print(signedDoc)
|
||
|
|
||
|
querySign = gql(
|
||
|
"""
|
||
|
mutation ($signedDoc: String!){ tx(
|
||
|
rawTx: $signedDoc
|
||
|
) {
|
||
|
version
|
||
|
issuers
|
||
|
outputs
|
||
|
}
|
||
|
}
|
||
|
"""
|
||
|
)
|
||
|
paramsSign = {
|
||
|
"signedDoc": signedDoc
|
||
|
}
|
||
|
|
||
|
# Send TX Signed document
|
||
|
result = client.execute(querySign, variable_values=paramsSign)
|
||
|
|
||
|
# print the result
|
||
|
print(result)
|
||
|
|