Full history with pagination
This commit is contained in:
parent
66c2070ef8
commit
9a64979aa7
|
@ -74,6 +74,7 @@ pay_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise les s
|
||||||
pay_cmd.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction")
|
pay_cmd.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction")
|
||||||
|
|
||||||
history_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
history_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
||||||
|
history_cmd.add_argument('-n', '--number',type=int, default=10, help="Affiche les NUMBER dernières transactions")
|
||||||
history_cmd.add_argument('-j', '--json', action='store_true', help="Affiche le résultat en format JSON")
|
history_cmd.add_argument('-j', '--json', action='store_true', help="Affiche le résultat en format JSON")
|
||||||
history_cmd.add_argument('--nocolors', action='store_true', help="Affiche le résultat en noir et blanc")
|
history_cmd.add_argument('--nocolors', action='store_true', help="Affiche le résultat en noir et blanc")
|
||||||
|
|
||||||
|
@ -217,7 +218,7 @@ elif cmd in ("pay","history","balance"):
|
||||||
if cmd == "pay":
|
if cmd == "pay":
|
||||||
gva.pay(args.amount, args.comment, args.mempool, args.verbose)
|
gva.pay(args.amount, args.comment, args.mempool, args.verbose)
|
||||||
if cmd == "history":
|
if cmd == "history":
|
||||||
gva.history(args.json, args.nocolors)
|
gva.history(args.json, args.nocolors, args.number)
|
||||||
if cmd == "balance":
|
if cmd == "balance":
|
||||||
gva.balance(args.mempool)
|
gva.balance(args.mempool)
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,9 @@ class GvaApi():
|
||||||
gva.signDoc()
|
gva.signDoc()
|
||||||
return gva.sendTXDoc()
|
return gva.sendTXDoc()
|
||||||
|
|
||||||
def history(self, isJSON=False, noColors=False):
|
def history(self, isJSON=False, noColors=False, number=10):
|
||||||
gva = History(self.dunikey, self.node, self.destPubkey)
|
gva = History(self.dunikey, self.node, self.destPubkey)
|
||||||
gva.sendDoc()
|
gva.sendDoc(number)
|
||||||
transList = gva.parseHistory()
|
transList = gva.parseHistory()
|
||||||
|
|
||||||
if isJSON:
|
if isJSON:
|
||||||
|
|
|
@ -23,14 +23,14 @@ class History:
|
||||||
transport = AIOHTTPTransport(url=node)
|
transport = AIOHTTPTransport(url=node)
|
||||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||||
|
|
||||||
def sendDoc(self):
|
def sendDoc(self, number):
|
||||||
# Build history generation document
|
# Build history generation document
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
query ($pubkey: String!){
|
query ($pubkey: String!, $number: Int!){
|
||||||
txsHistoryBc(
|
txsHistoryBc(
|
||||||
pubkeyOrScript: $pubkey
|
pubkeyOrScript: $pubkey
|
||||||
pagination: { pageSize: 10, ord: DESC }
|
pagination: { pageSize: $number, ord: DESC }
|
||||||
) {
|
) {
|
||||||
both {
|
both {
|
||||||
pageInfo {
|
pageInfo {
|
||||||
|
@ -57,6 +57,13 @@ class History:
|
||||||
outputs
|
outputs
|
||||||
writtenTime
|
writtenTime
|
||||||
}
|
}
|
||||||
|
receiving {
|
||||||
|
currency
|
||||||
|
issuers
|
||||||
|
comment
|
||||||
|
outputs
|
||||||
|
writtenTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
balance(script: $pubkey) {
|
balance(script: $pubkey) {
|
||||||
amount
|
amount
|
||||||
|
@ -75,7 +82,8 @@ class History:
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
paramsBuild = {
|
paramsBuild = {
|
||||||
"pubkey": self.pubkey
|
"pubkey": self.pubkey,
|
||||||
|
"number": number
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send history document
|
# Send history document
|
||||||
|
@ -95,13 +103,16 @@ class History:
|
||||||
self.UD = self.historyDoc['currentUd']['amount']/100
|
self.UD = self.historyDoc['currentUd']['amount']/100
|
||||||
|
|
||||||
|
|
||||||
resBc = self.historyDoc['txsHistoryBc']['both']['edges'][0]
|
# Parse transactions in blockchain
|
||||||
for transaction in resBc:
|
resBc = []
|
||||||
direction = resBc['direction']
|
resBc = self.historyDoc['txsHistoryBc']['both']['edges']
|
||||||
transaction = resBc['node']
|
for j, transaction in enumerate(resBc):
|
||||||
|
# print(transaction)
|
||||||
|
direction = resBc[j]['direction']
|
||||||
|
transaction = resBc[j]['node']
|
||||||
output = transaction['outputs'][0]
|
output = transaction['outputs'][0]
|
||||||
outPubkey = output.split("SIG(")[1].replace(')','')
|
outPubkey = output.split("SIG(")[1].replace(')','')
|
||||||
if direction == 'RECEIVED' or self.pubkey != outPubkey:
|
# if direction == 'RECEIVED' or self.pubkey != outPubkey:
|
||||||
trans.append(i)
|
trans.append(i)
|
||||||
trans[i] = []
|
trans[i] = []
|
||||||
trans[i].append(direction)
|
trans[i].append(direction)
|
||||||
|
@ -122,6 +133,36 @@ class History:
|
||||||
trans[i].append(base)
|
trans[i].append(base)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
# Parse transactions in mempool
|
||||||
|
for direction in self.historyDoc['txsHistoryMp']:
|
||||||
|
resBc = []
|
||||||
|
resBc = self.historyDoc['txsHistoryMp'][direction]
|
||||||
|
for j, transaction in enumerate(resBc):
|
||||||
|
# print(transaction)
|
||||||
|
transaction = resBc[j]
|
||||||
|
output = transaction['outputs'][0]
|
||||||
|
outPubkey = output.split("SIG(")[1].replace(')','')
|
||||||
|
# if direction == 'RECEIVING' or self.pubkey != outPubkey:
|
||||||
|
trans.append(i)
|
||||||
|
trans[i] = []
|
||||||
|
trans[i].append(direction)
|
||||||
|
trans[i].append(int(time.time()))
|
||||||
|
if direction == 'SENDING':
|
||||||
|
trans[i].append(outPubkey)
|
||||||
|
amount = int('-' + output.split(':')[0])
|
||||||
|
else:
|
||||||
|
trans[i].append(transaction['issuers'][0])
|
||||||
|
amount = int(output.split(':')[0])
|
||||||
|
base = int(output.split(':')[1])
|
||||||
|
applyBase = base-currentBase
|
||||||
|
amount = round(amount*pow(10,applyBase)/100, 2)
|
||||||
|
# if referential == 'DU': amount = round(amount/UD, 2)
|
||||||
|
trans[i].append(amount)
|
||||||
|
trans[i].append(round(amount/self.UD, 2))
|
||||||
|
trans[i].append(transaction['comment'])
|
||||||
|
trans[i].append(base)
|
||||||
|
i += 1
|
||||||
|
|
||||||
# Order transactions by date
|
# Order transactions by date
|
||||||
trans.sort(key=lambda x: x[1])
|
trans.sort(key=lambda x: x[1])
|
||||||
|
|
||||||
|
@ -157,13 +198,14 @@ class History:
|
||||||
print(isBold + "|{: <19} | {: <12} | {: <7} | {: <7} | {: <30}".format(" Date"," De / À"," {0}".format(currency)," DU/{0}".format(currency.lower()),"Commentaire") + isBoldEnd)
|
print(isBold + "|{: <19} | {: <12} | {: <7} | {: <7} | {: <30}".format(" Date"," De / À"," {0}".format(currency)," DU/{0}".format(currency.lower()),"Commentaire") + isBoldEnd)
|
||||||
print('|', end='')
|
print('|', end='')
|
||||||
for t in trans:
|
for t in trans:
|
||||||
if t[0] == "received": color = "green"
|
if t[0] == "RECEIVED": color = "green"
|
||||||
|
elif t[0] == "SENT": color = "blue"
|
||||||
elif t[0] == "receiving": color = "yellow"
|
elif t[0] == "receiving": color = "yellow"
|
||||||
elif t[0] == "sending": color = "red"
|
elif t[0] == "sending": color = "red"
|
||||||
else: color = "blue"
|
else: color = None
|
||||||
if noColors:
|
if noColors:
|
||||||
color = None
|
color = None
|
||||||
if t[0] in ('receiving','sending'):
|
if t[0] in ('RECEIVING','SENDING'):
|
||||||
comment = '(EN ATTENTE) ' + t[5]
|
comment = '(EN ATTENTE) ' + t[5]
|
||||||
else:
|
else:
|
||||||
comment = t[5]
|
comment = t[5]
|
||||||
|
|
Loading…
Reference in New Issue