Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async __buildDelegates () {
// Register...
const transactions = await this.query
.select('sender_public_key', 'serialized')
.from('transactions')
.where('type', TRANSACTION_TYPES.DELEGATE_REGISTRATION)
.all()
for (let i = 0; i < transactions.length; i++) {
const wallet = this.walletManager.findByPublicKey(transactions[i].senderPublicKey)
wallet.username = Transaction.deserialize(transactions[i].serialized.toString('hex')).asset.delegate.username
this.walletManager.reindex(wallet)
}
// Rate...
const delegates = await this.query
.select('public_key', 'vote_balance', 'missed_blocks')
.from('wallets')
.whereIn('public_key', transactions.map(transaction => transaction.senderPublicKey))
.orderBy({
'vote_balance': 'DESC',
'public_key': 'ASC'
})
.all()
// Forged Blocks...
async handler (request, h) {
const transaction = new Transaction(Transaction.deserialize(request.payload.transaction))
const result = await container.resolvePlugin('database').verifyTransaction(transaction)
return { success: result }
}
}
block.transactions = transactions.map(({ serialized }) => Transaction.deserialize(serialized.toString('hex')))
const transactions = rows.map(row => {
const transaction = Transaction.deserialize(
row.serialized.toString('hex'),
)
transaction.blockId = row.block_id
transaction.senderId = crypto.getAddress(transaction.senderPublicKey)
return transaction
})
async handler(request, h) {
const transaction = new Transaction(
Transaction.deserialize(request.payload.transaction),
)
return {
data: {
valid: await app
.resolvePlugin('database')
.verifyTransaction(transaction),
},
}
},
options: {
__deserializeTransaction (transaction) {
try {
const buffer = Buffer.from(transaction, 'hex')
const serialized = Buffer.from(buffer).toString('hex')
const data = Transaction.deserialize(serialized)
return data
} catch (error) {
logger.error(`Deserializing transaction: ${error.message}`)
return null
}
}
transactions = transactions.map(tx => {
const data = Transaction.deserialize(tx.serialized.toString('hex'))
data.blockId = tx.blockId
return data
})
}
const deserialize = (buffer) => {
const serialized = Buffer.from(buffer).toString('hex')
return Transaction.deserialize(serialized)
}
data.forEach(row => {
const wallet = this.walletManager.findByPublicKey(row.senderPublicKey)
if (!wallet.multisignature) {
wallet.multisignature = Transaction.deserialize(row.serialized.toString('hex')).asset.multisignature
}
})
}