Skip to content

Commit 48ef2d7

Browse files
authored
Merge pull request #208 from theQRL/testnet
1.0.3 Release
2 parents ffd14d6 + 857dc25 commit 48ef2d7

File tree

15 files changed

+819
-1024
lines changed

15 files changed

+819
-1024
lines changed

imports/startup/both/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
export const SHOR_PER_QUANTA = 1000000000
55

66
// Explorer Version
7-
export const EXPLORER_VERSION = '1.0.2'
7+
export const EXPLORER_VERSION = '1.0.3'
88

99
// Function to cleanly represent large decimal numbers without exponential formatting.
1010
export function numberToString(num) {

imports/startup/client/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Import client startup through a single index entry point
22
import './routes.js'
3+
import { rawAddressToB32Address, rawAddressToHexAddress, b32AddressToRawAddress } from '@theqrl/explorer-helpers'
34
import { EXPLORER_VERSION } from '../both/index.js'
45

56
// Developer note console messages
@@ -38,6 +39,23 @@ export function formatBytes(bytes, decimals) {
3839
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
3940
}
4041

42+
// wrapper to decide which format should addresses be converted to
43+
export function hexOrB32(rawAddress) {
44+
if (Session.get('addressFormat') === 'bech32') {
45+
return rawAddressToB32Address(rawAddress)
46+
}
47+
return rawAddressToHexAddress(rawAddress)
48+
}
49+
50+
export function anyAddressToRaw(address) {
51+
if (address[0] === 'q') {
52+
const answer = b32AddressToRawAddress(address)
53+
return answer
54+
}
55+
return addressForAPI(address)
56+
}
57+
58+
4159
let disconnectTimer = null
4260

4361
// disconnect after 5 mins in background

imports/startup/server/cron.js

+7-136
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint max-len: 0 */
22
import { HTTP } from 'meteor/http'
33
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'
55
import { Blocks, lasttx, homechart, quantausd, status, peerstats } from '/imports/api/index.js'
66
import { SHOR_PER_QUANTA, numberToString } from '../both/index.js'
77
import helpers from '@theqrl/explorer-helpers'
@@ -20,7 +20,7 @@ const refreshBlocks = () => {
2020
const res = Meteor.wrapAsync(getObject)(req)
2121
res.block_extended.extended_transactions.forEach((val) => {
2222
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
2424
}
2525
})
2626
})
@@ -84,147 +84,18 @@ const refreshBlocks = () => {
8484
}
8585

8686
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
15588
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]
16089

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 })
22092

22193
// 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)
22496
const merged = {}
22597
merged.transactions = unconfirmedTxns.concat(confirmedTxns)
22698

227-
22899
// Fetch current data
229100
const current = lasttx.findOne()
230101

0 commit comments

Comments
 (0)