1
1
/* eslint max-len: 0 */
2
2
import { HTTP } from 'meteor/http'
3
3
import sha512 from 'sha512'
4
- import { getLatestData , getObject , getStats , getPeersStat , apiCall } from '/imports/startup/server/index.js'
4
+ import { getLatestData , getObject , getStats , getPeersStat , apiCall , makeTxHumanReadable , makeTxListHumanReadable } from '/imports/startup/server/index.js'
5
5
import { Blocks , lasttx , homechart , quantausd , status , peerstats } from '/imports/api/index.js'
6
6
import { SHOR_PER_QUANTA , numberToString } from '../both/index.js'
7
7
import helpers from '@theqrl/explorer-helpers'
@@ -20,7 +20,7 @@ const refreshBlocks = () => {
20
20
const res = Meteor . wrapAsync ( getObject ) ( req )
21
21
res . block_extended . extended_transactions . forEach ( ( val ) => {
22
22
if ( val . tx . transactionType === 'coinbase' ) {
23
- response . blockheaders [ key ] . minedBy = `Q ${ Buffer . from ( val . tx . coinbase . addr_to ) . toString ( 'hex' ) } `
23
+ response . blockheaders [ key ] . minedBy = val . tx . coinbase . addr_to
24
24
}
25
25
} )
26
26
} )
@@ -84,147 +84,18 @@ const refreshBlocks = () => {
84
84
}
85
85
86
86
function refreshLasttx ( ) {
87
- // First get unconfirmed transactions
88
- const unconfirmed = Meteor . wrapAsync ( getLatestData ) ( { filter : 'TRANSACTIONS_UNCONFIRMED' , offset : 0 , quantity : 10 } )
89
- unconfirmed . transactions_unconfirmed . forEach ( ( item , index ) => {
90
- // Add a transaction object to the returned transaction so we can use txhash helper
91
- const temp = [ ]
92
- temp . transaction = unconfirmed . transactions_unconfirmed [ index ]
93
-
94
- // Parse the transaction
95
- const output = helpers . txhash ( temp )
96
-
97
- // we need another Grpc call for transfer token so this stays here for now
98
- try {
99
- if ( output . transaction . tx . transactionType === 'transfer_token' ) {
100
- // Request Token Decimals / Symbol
101
- const symbolRequest = {
102
- query : Buffer . from ( output . transaction . tx . transfer_token . token_txhash , 'hex' ) ,
103
- }
104
- const thisSymbolResponse = Meteor . wrapAsync ( getObject ) ( symbolRequest )
105
- const thisSymbol = Buffer . from ( thisSymbolResponse . transaction . tx . token . symbol ) . toString ( )
106
- const thisName = Buffer . from ( thisSymbolResponse . transaction . tx . token . name ) . toString ( )
107
- const thisDecimals = thisSymbolResponse . transaction . tx . token . decimals
108
-
109
- // Calculate total transferred, and generate a clean structure to display outputs from
110
- let thisTotalTransferred = 0
111
- const thisOutputs = [ ]
112
- _ . each ( output . transaction . tx . transfer_token . addrs_to , ( thisAddress , indexB ) => {
113
- const thisOutput = {
114
- address : `Q${ Buffer . from ( thisAddress ) . toString ( 'hex' ) } ` ,
115
- // eslint-disable-next-line
116
- amount : numberToString ( output . transaction . tx . transfer_token . amounts [ indexB ] / Math . pow ( 10 , thisDecimals ) ) ,
117
- }
118
- thisOutputs . push ( thisOutput )
119
- // Now update total transferred with the corresponding amount from this output
120
- // eslint-disable-next-line
121
- thisTotalTransferred += parseInt ( output . transaction . tx . transfer_token . amounts [ indexB ] , 10 )
122
- } )
123
- output . transaction . tx . fee = numberToString ( output . transaction . tx . fee / SHOR_PER_QUANTA )
124
- output . transaction . tx . addr_from = `Q${ Buffer . from ( output . transaction . addr_from ) . toString ( 'hex' ) } `
125
- output . transaction . tx . public_key = Buffer . from ( output . transaction . tx . public_key ) . toString ( 'hex' )
126
- output . transaction . tx . signature = Buffer . from ( output . transaction . tx . signature ) . toString ( 'hex' )
127
- output . transaction . tx . transfer_token . token_txhash = Buffer . from ( output . transaction . tx . transfer_token . token_txhash ) . toString ( 'hex' )
128
- output . transaction . tx . transfer_token . outputs = thisOutputs
129
- // eslint-disable-next-line
130
- output . transaction . tx . totalTransferred = numberToString ( thisTotalTransferred / Math . pow ( 10 , thisDecimals ) )
131
-
132
- output . transaction . explorer = {
133
- from : output . transaction . tx . addr_from ,
134
- outputs : thisOutputs ,
135
- signature : output . transaction . tx . signature ,
136
- publicKey : output . transaction . tx . public_key ,
137
- token_txhash : output . transaction . tx . transfer_token . token_txhash ,
138
- // eslint-disable-next-line
139
- totalTransferred : numberToString ( thisTotalTransferred / Math . pow ( 10 , thisDecimals ) ) ,
140
- symbol : thisSymbol ,
141
- name : thisName ,
142
- type : 'TRANSFER TOKEN' ,
143
- }
144
- }
145
- } catch ( e ) {
146
- //
147
- }
148
-
149
- // Now put it back
150
- unconfirmed . transactions_unconfirmed [ index ] = output . transaction
151
- unconfirmed . transactions_unconfirmed [ index ] . tx . confirmed = 'false'
152
- } )
153
-
154
- // Now get confirmed transactions
87
+ // First get confirmed transactions
155
88
const confirmed = Meteor . wrapAsync ( getLatestData ) ( { filter : 'TRANSACTIONS' , offset : 0 , quantity : 10 } )
156
- confirmed . transactions . forEach ( ( item , index ) => {
157
- // Add a transaction object to the returned transaction so we can use txhash helper
158
- const temp = [ ]
159
- temp . transaction = confirmed . transactions [ index ]
160
89
161
- // Parse the transaction
162
- const output = helpers . txhash ( temp )
163
-
164
- // we need another Grpc call for transfer token so this stays here for now
165
- try {
166
- if ( output . transaction . tx . transactionType === 'transfer_token' ) {
167
- // Request Token Decimals / Symbol
168
- const symbolRequest = {
169
- query : Buffer . from ( output . transaction . tx . transfer_token . token_txhash , 'hex' ) ,
170
- }
171
- const thisSymbolResponse = Meteor . wrapAsync ( getObject ) ( symbolRequest )
172
- const thisSymbol = Buffer . from ( thisSymbolResponse . transaction . tx . token . symbol ) . toString ( )
173
- const thisName = Buffer . from ( thisSymbolResponse . transaction . tx . token . name ) . toString ( )
174
- const thisDecimals = thisSymbolResponse . transaction . tx . token . decimals
175
-
176
- // Calculate total transferred, and generate a clean structure to display outputs from
177
- let thisTotalTransferred = 0
178
- const thisOutputs = [ ]
179
- _ . each ( output . transaction . tx . transfer_token . addrs_to , ( thisAddress , indexB ) => {
180
- const thisOutput = {
181
- address : `Q${ Buffer . from ( thisAddress ) . toString ( 'hex' ) } ` ,
182
- // eslint-disable-next-line
183
- amount : numberToString ( output . transaction . tx . transfer_token . amounts [ indexB ] / Math . pow ( 10 , thisDecimals ) ) ,
184
- }
185
- thisOutputs . push ( thisOutput )
186
- // Now update total transferred with the corresponding amount from this output
187
- // eslint-disable-next-line
188
- thisTotalTransferred += parseInt ( output . transaction . tx . transfer_token . amounts [ indexB ] , 10 )
189
- } )
190
- output . transaction . tx . fee = numberToString ( output . transaction . tx . fee / SHOR_PER_QUANTA )
191
- output . transaction . tx . addr_from = `Q${ Buffer . from ( output . transaction . addr_from ) . toString ( 'hex' ) } `
192
- output . transaction . tx . public_key = Buffer . from ( output . transaction . tx . public_key ) . toString ( 'hex' )
193
- output . transaction . tx . signature = Buffer . from ( output . transaction . tx . signature ) . toString ( 'hex' )
194
- output . transaction . tx . transfer_token . token_txhash = Buffer . from ( output . transaction . tx . transfer_token . token_txhash ) . toString ( 'hex' )
195
- output . transaction . tx . transfer_token . outputs = thisOutputs
196
- // eslint-disable-next-line
197
- output . transaction . tx . totalTransferred = numberToString ( thisTotalTransferred / Math . pow ( 10 , thisDecimals ) )
198
-
199
- output . transaction . explorer = {
200
- from : output . transaction . tx . addr_from ,
201
- outputs : thisOutputs ,
202
- signature : output . transaction . tx . signature ,
203
- publicKey : output . transaction . tx . public_key ,
204
- token_txhash : output . transaction . tx . transfer_token . token_txhash ,
205
- // eslint-disable-next-line
206
- totalTransferred : numberToString ( thisTotalTransferred / Math . pow ( 10 , thisDecimals ) ) ,
207
- symbol : thisSymbol ,
208
- name : thisName ,
209
- type : 'TRANSFER TOKEN' ,
210
- }
211
- }
212
- } catch ( e ) {
213
- //
214
- }
215
-
216
- // Now put it back
217
- confirmed . transactions [ index ] = output . transaction
218
- confirmed . transactions [ index ] . tx . confirmed = 'true'
219
- } )
90
+ // Now get unconfirmed transactions
91
+ const unconfirmed = Meteor . wrapAsync ( getLatestData ) ( { filter : 'TRANSACTIONS_UNCONFIRMED' , offset : 0 , quantity : 10 } )
220
92
221
93
// Merge the two together
222
- const confirmedTxns = confirmed . transactions
223
- const unconfirmedTxns = unconfirmed . transactions_unconfirmed
94
+ const confirmedTxns = makeTxListHumanReadable ( confirmed . transactions , true )
95
+ const unconfirmedTxns = makeTxListHumanReadable ( unconfirmed . transactions_unconfirmed , false )
224
96
const merged = { }
225
97
merged . transactions = unconfirmedTxns . concat ( confirmedTxns )
226
98
227
-
228
99
// Fetch current data
229
100
const current = lasttx . findOne ( )
230
101
0 commit comments