Use new History shema with paginiation

This commit is contained in:
poka 2020-12-15 20:15:18 +01:00
parent 24a58e7e03
commit 66c2070ef8
1 changed files with 54 additions and 49 deletions

View File

@ -28,28 +28,34 @@ class History:
queryBuild = gql( queryBuild = gql(
""" """
query ($pubkey: String!){ query ($pubkey: String!){
transactionsHistory(pubkey: $pubkey) { txsHistoryBc(
received { pubkeyOrScript: $pubkey
writtenTime pagination: { pageSize: 10, ord: DESC }
) {
both {
pageInfo {
hasPreviousPage
hasNextPage
}
edges {
direction
node {
currency
issuers issuers
outputs outputs
comment comment
}
sent {
writtenTime writtenTime
issuers
outputs
comment
} }
}
}
}
txsHistoryMp(pubkey: $pubkey) {
receiving { receiving {
currency
issuers issuers
outputs
comment comment
}
sending {
issuers
outputs outputs
comment writtenTime
} }
} }
balance(script: $pubkey) { balance(script: $pubkey) {
@ -88,24 +94,23 @@ class History:
currentBase = int(self.historyDoc['currentUd']['base']) currentBase = int(self.historyDoc['currentUd']['base'])
self.UD = self.historyDoc['currentUd']['amount']/100 self.UD = self.historyDoc['currentUd']['amount']/100
for sens in 'received','sent','receiving','sending':
res = self.historyDoc['transactionsHistory'][sens] resBc = self.historyDoc['txsHistoryBc']['both']['edges'][0]
for bloc in res: for transaction in resBc:
output = bloc['outputs'][0] direction = resBc['direction']
transaction = resBc['node']
output = transaction['outputs'][0]
outPubkey = output.split("SIG(")[1].replace(')','') outPubkey = output.split("SIG(")[1].replace(')','')
if sens in ('received','receiving') or self.pubkey != outPubkey: if direction == 'RECEIVED' or self.pubkey != outPubkey:
trans.append(i) trans.append(i)
trans[i] = [] trans[i] = []
trans[i].append(sens) trans[i].append(direction)
if sens in ('receiving','sending'): trans[i].append(transaction['writtenTime'])
trans[i].append(int(time.time())) if direction == 'SENT':
else:
trans[i].append(bloc['writtenTime'])
if sens in ('sent','sending'):
trans[i].append(outPubkey) trans[i].append(outPubkey)
amount = int('-' + output.split(':')[0]) amount = int('-' + output.split(':')[0])
else: else:
trans[i].append(bloc['issuers'][0]) trans[i].append(transaction['issuers'][0])
amount = int(output.split(':')[0]) amount = int(output.split(':')[0])
base = int(output.split(':')[1]) base = int(output.split(':')[1])
applyBase = base-currentBase applyBase = base-currentBase
@ -113,7 +118,7 @@ class History:
# if referential == 'DU': amount = round(amount/UD, 2) # if referential == 'DU': amount = round(amount/UD, 2)
trans[i].append(amount) trans[i].append(amount)
trans[i].append(round(amount/self.UD, 2)) trans[i].append(round(amount/self.UD, 2))
trans[i].append(bloc['comment']) trans[i].append(transaction['comment'])
trans[i].append(base) trans[i].append(base)
i += 1 i += 1