Skip to content

Commit

Permalink
Merge pull request #208 from theQRL/testnet
Browse files Browse the repository at this point in the history
1.0.3 Release
  • Loading branch information
jplomas authored Oct 5, 2018
2 parents ffd14d6 + 857dc25 commit 48ef2d7
Show file tree
Hide file tree
Showing 15 changed files with 819 additions and 1,024 deletions.
2 changes: 1 addition & 1 deletion imports/startup/both/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export const SHOR_PER_QUANTA = 1000000000

// Explorer Version
export const EXPLORER_VERSION = '1.0.2'
export const EXPLORER_VERSION = '1.0.3'

// Function to cleanly represent large decimal numbers without exponential formatting.
export function numberToString(num) {
Expand Down
18 changes: 18 additions & 0 deletions imports/startup/client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Import client startup through a single index entry point
import './routes.js'
import { rawAddressToB32Address, rawAddressToHexAddress, b32AddressToRawAddress } from '@theqrl/explorer-helpers'
import { EXPLORER_VERSION } from '../both/index.js'

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

// wrapper to decide which format should addresses be converted to
export function hexOrB32(rawAddress) {
if (Session.get('addressFormat') === 'bech32') {
return rawAddressToB32Address(rawAddress)
}
return rawAddressToHexAddress(rawAddress)
}

export function anyAddressToRaw(address) {
if (address[0] === 'q') {
const answer = b32AddressToRawAddress(address)
return answer
}
return addressForAPI(address)
}


let disconnectTimer = null

// disconnect after 5 mins in background
Expand Down
143 changes: 7 additions & 136 deletions imports/startup/server/cron.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint max-len: 0 */
import { HTTP } from 'meteor/http'
import sha512 from 'sha512'
import { getLatestData, getObject, getStats, getPeersStat, apiCall } from '/imports/startup/server/index.js'
import { getLatestData, getObject, getStats, getPeersStat, apiCall, makeTxHumanReadable, makeTxListHumanReadable } from '/imports/startup/server/index.js'
import { Blocks, lasttx, homechart, quantausd, status, peerstats } from '/imports/api/index.js'
import { SHOR_PER_QUANTA, numberToString } from '../both/index.js'
import helpers from '@theqrl/explorer-helpers'
Expand All @@ -20,7 +20,7 @@ const refreshBlocks = () => {
const res = Meteor.wrapAsync(getObject)(req)
res.block_extended.extended_transactions.forEach((val) => {
if (val.tx.transactionType === 'coinbase') {
response.blockheaders[key].minedBy = `Q${Buffer.from(val.tx.coinbase.addr_to).toString('hex')}`
response.blockheaders[key].minedBy = val.tx.coinbase.addr_to
}
})
})
Expand Down Expand Up @@ -84,147 +84,18 @@ const refreshBlocks = () => {
}

function refreshLasttx() {
// First get unconfirmed transactions
const unconfirmed = Meteor.wrapAsync(getLatestData)({ filter: 'TRANSACTIONS_UNCONFIRMED', offset: 0, quantity: 10 })
unconfirmed.transactions_unconfirmed.forEach((item, index) => {
// Add a transaction object to the returned transaction so we can use txhash helper
const temp = []
temp.transaction = unconfirmed.transactions_unconfirmed[index]

// Parse the transaction
const output = helpers.txhash(temp)

// we need another Grpc call for transfer token so this stays here for now
try {
if (output.transaction.tx.transactionType === 'transfer_token') {
// Request Token Decimals / Symbol
const symbolRequest = {
query: Buffer.from(output.transaction.tx.transfer_token.token_txhash, 'hex'),
}
const thisSymbolResponse = Meteor.wrapAsync(getObject)(symbolRequest)
const thisSymbol = Buffer.from(thisSymbolResponse.transaction.tx.token.symbol).toString()
const thisName = Buffer.from(thisSymbolResponse.transaction.tx.token.name).toString()
const thisDecimals = thisSymbolResponse.transaction.tx.token.decimals

// Calculate total transferred, and generate a clean structure to display outputs from
let thisTotalTransferred = 0
const thisOutputs = []
_.each(output.transaction.tx.transfer_token.addrs_to, (thisAddress, indexB) => {
const thisOutput = {
address: `Q${Buffer.from(thisAddress).toString('hex')}`,
// eslint-disable-next-line
amount: numberToString(output.transaction.tx.transfer_token.amounts[indexB] / Math.pow(10, thisDecimals)),
}
thisOutputs.push(thisOutput)
// Now update total transferred with the corresponding amount from this output
// eslint-disable-next-line
thisTotalTransferred += parseInt(output.transaction.tx.transfer_token.amounts[indexB], 10)
})
output.transaction.tx.fee = numberToString(output.transaction.tx.fee / SHOR_PER_QUANTA)
output.transaction.tx.addr_from = `Q${Buffer.from(output.transaction.addr_from).toString('hex')}`
output.transaction.tx.public_key = Buffer.from(output.transaction.tx.public_key).toString('hex')
output.transaction.tx.signature = Buffer.from(output.transaction.tx.signature).toString('hex')
output.transaction.tx.transfer_token.token_txhash = Buffer.from(output.transaction.tx.transfer_token.token_txhash).toString('hex')
output.transaction.tx.transfer_token.outputs = thisOutputs
// eslint-disable-next-line
output.transaction.tx.totalTransferred = numberToString(thisTotalTransferred / Math.pow(10, thisDecimals))

output.transaction.explorer = {
from: output.transaction.tx.addr_from,
outputs: thisOutputs,
signature: output.transaction.tx.signature,
publicKey: output.transaction.tx.public_key,
token_txhash: output.transaction.tx.transfer_token.token_txhash,
// eslint-disable-next-line
totalTransferred: numberToString(thisTotalTransferred / Math.pow(10, thisDecimals)),
symbol: thisSymbol,
name: thisName,
type: 'TRANSFER TOKEN',
}
}
} catch (e) {
//
}

// Now put it back
unconfirmed.transactions_unconfirmed[index] = output.transaction
unconfirmed.transactions_unconfirmed[index].tx.confirmed = 'false'
})

// Now get confirmed transactions
// First get confirmed transactions
const confirmed = Meteor.wrapAsync(getLatestData)({ filter: 'TRANSACTIONS', offset: 0, quantity: 10 })
confirmed.transactions.forEach((item, index) => {
// Add a transaction object to the returned transaction so we can use txhash helper
const temp = []
temp.transaction = confirmed.transactions[index]

// Parse the transaction
const output = helpers.txhash(temp)

// we need another Grpc call for transfer token so this stays here for now
try {
if (output.transaction.tx.transactionType === 'transfer_token') {
// Request Token Decimals / Symbol
const symbolRequest = {
query: Buffer.from(output.transaction.tx.transfer_token.token_txhash, 'hex'),
}
const thisSymbolResponse = Meteor.wrapAsync(getObject)(symbolRequest)
const thisSymbol = Buffer.from(thisSymbolResponse.transaction.tx.token.symbol).toString()
const thisName = Buffer.from(thisSymbolResponse.transaction.tx.token.name).toString()
const thisDecimals = thisSymbolResponse.transaction.tx.token.decimals

// Calculate total transferred, and generate a clean structure to display outputs from
let thisTotalTransferred = 0
const thisOutputs = []
_.each(output.transaction.tx.transfer_token.addrs_to, (thisAddress, indexB) => {
const thisOutput = {
address: `Q${Buffer.from(thisAddress).toString('hex')}`,
// eslint-disable-next-line
amount: numberToString(output.transaction.tx.transfer_token.amounts[indexB] / Math.pow(10, thisDecimals)),
}
thisOutputs.push(thisOutput)
// Now update total transferred with the corresponding amount from this output
// eslint-disable-next-line
thisTotalTransferred += parseInt(output.transaction.tx.transfer_token.amounts[indexB], 10)
})
output.transaction.tx.fee = numberToString(output.transaction.tx.fee / SHOR_PER_QUANTA)
output.transaction.tx.addr_from = `Q${Buffer.from(output.transaction.addr_from).toString('hex')}`
output.transaction.tx.public_key = Buffer.from(output.transaction.tx.public_key).toString('hex')
output.transaction.tx.signature = Buffer.from(output.transaction.tx.signature).toString('hex')
output.transaction.tx.transfer_token.token_txhash = Buffer.from(output.transaction.tx.transfer_token.token_txhash).toString('hex')
output.transaction.tx.transfer_token.outputs = thisOutputs
// eslint-disable-next-line
output.transaction.tx.totalTransferred = numberToString(thisTotalTransferred / Math.pow(10, thisDecimals))

output.transaction.explorer = {
from: output.transaction.tx.addr_from,
outputs: thisOutputs,
signature: output.transaction.tx.signature,
publicKey: output.transaction.tx.public_key,
token_txhash: output.transaction.tx.transfer_token.token_txhash,
// eslint-disable-next-line
totalTransferred: numberToString(thisTotalTransferred / Math.pow(10, thisDecimals)),
symbol: thisSymbol,
name: thisName,
type: 'TRANSFER TOKEN',
}
}
} catch (e) {
//
}

// Now put it back
confirmed.transactions[index] = output.transaction
confirmed.transactions[index].tx.confirmed = 'true'
})
// Now get unconfirmed transactions
const unconfirmed = Meteor.wrapAsync(getLatestData)({ filter: 'TRANSACTIONS_UNCONFIRMED', offset: 0, quantity: 10 })

// Merge the two together
const confirmedTxns = confirmed.transactions
const unconfirmedTxns = unconfirmed.transactions_unconfirmed
const confirmedTxns = makeTxListHumanReadable(confirmed.transactions, true)
const unconfirmedTxns = makeTxListHumanReadable(unconfirmed.transactions_unconfirmed, false)
const merged = {}
merged.transactions = unconfirmedTxns.concat(confirmedTxns)


// Fetch current data
const current = lasttx.findOne()

Expand Down
Loading

0 comments on commit 48ef2d7

Please sign in to comment.