How to use the @arkecosystem/crypto.Block function in @arkecosystem/crypto

To help you get started, we’ve selected a few @arkecosystem/crypto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ArkEcosystem / core / packages / core-p2p / lib / server / versions / peer / handlers / blocks.js View on Github external
if (blockchain.pingBlock(request.payload.block)) {
      return h.response(null).code(202)
    }

    // already got it?
    const lastDownloadedBlock = blockchain.getLastDownloadedBlock()

    // Are we ready to get it?
    if (
      lastDownloadedBlock &&
      lastDownloadedBlock.data.height + 1 !== request.payload.block.height
    ) {
      return h.response(null).code(202)
    }

    const block = new Block(request.payload.block)

    if (!block.verification.verified) {
      return Boom.badData()
    }

    blockchain.pushPingBlock(block.data)

    if (block.headerOnly) {
      let transactions = []

      let peer = await monitor.getPeer(requestIp.getClientIp(request))

      // NOTE: only for test because it can be used for DDOS attack
      if (!peer && process.env.NODE_ENV === 'test_p2p') {
        peer = await monitor.getRandomPeer()
      }
github ArkEcosystem / core / packages / core-blockchain / __tests__ / __fixtures__ / genesisBlock.js View on Github external
const { Block } = require('@arkecosystem/crypto').models

module.exports = new Block({
  'version': 0,
  'totalAmount': 12500000000000000,
  'totalFee': 0,
  'reward': 0,
  'payloadHash': 'd9acd04bde4234a81addb8482333b4ac906bed7be5a9970ce8ada428bd083192',
  'timestamp': 0,
  'numberOfTransactions': 153,
  'payloadLength': 35960,
  'previousBlock': null,
  'generatorPublicKey': '03b47f6b6719c76bad46a302d9cff7be9b1c2b2a20602a0d880f139b5b8901f068',
  'transactions': [{
    'type': 0,
    'amount': 245098000000000,
    'fee': 0,
    'recipientId': 'AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri',
    'timestamp': 0,
github ArkEcosystem / core / packages / core-forger / __tests__ / __fixtures__ / block.js View on Github external
const { Block } = require('@arkecosystem/crypto').models

module.exports = new Block({
  id: '4398082439836560423',
  version: 0,
  timestamp: 35751416,
  height: 3342573,
  previousBlock: '14909996519459393858',
  numberOfTransactions: 0,
  totalAmount: 0,
  totalFee: 0,
  reward: 200000000,
  payloadLength: 0,
  payloadHash:
    'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
  generatorPublicKey:
    '03806036bc1bb470144184b10f815431c580ae2b806d5fd0ba2118dca823c5c4a6',
  generatorId: 'DMrWy7PddjmDiJFm4bToMj4MhDBa9Wm9vN',
  blockSignature:
github ArkEcosystem / core / packages / core-api / __tests__ / __fixtures__ / genesisBlock.js View on Github external
const { Block } = require('@arkecosystem/crypto').models

module.exports = new Block(require('../__support__/config/genesisBlock.json'))
github ArkEcosystem / core / packages / core-blockchain / lib / state-machine.js View on Github external
async init() {
    try {
      let block = await blockchain.database.getLastBlock()

      if (!block) {
        logger.warn('No block found in database :hushed:')

        block = new Block(config.genesisBlock)

        if (block.data.payloadHash !== config.network.nethash) {
          logger.error(
            'FATAL: The genesis block payload hash is different from configured the nethash :rotating_light:',
          )

          return blockchain.dispatch('FAILURE')
        }

        await blockchain.database.saveBlock(block)
      }

      if (!blockchain.restoredDatabaseIntegrity) {
        logger.info('Verifying database integrity :hourglass_flowing_sand:')

        const blockchainAudit = await blockchain.database.verifyBlockchain()
github ArkEcosystem / core / packages / core-blockchain / lib / blockchain.js View on Github external
async removeTopBlocks(count) {
    const blocks = await this.database.getTopBlocks(count)

    logger.info(
      `Removing ${pluralize(
        'block',
        blocks.length,
        true,
      )} from height ${blocks[0].height.toLocaleString()}`,
    )

    for (let block of blocks) {
      block = new Block(block)

      this.database.enqueueDeleteRound(block.data.height)
      this.database.enqueueDeleteBlock(block)
    }

    await this.database.commitQueuedQueries()
  }
github ArkEcosystem / core / packages / core-database-sequelize / lib / connection.js View on Github external
.first()

    if (!block) {
      return null
    }

    const transactions = await this.query
      .select('serialized')
      .from('transactions')
      .where('block_id', block.id)
      .orderBy('sequence', 'ASC')
      .all()

    block.transactions = transactions.map(({ serialized }) => Transaction.deserialize(serialized.toString('hex')))

    return new Block(block)
  }
github ArkEcosystem / core / packages / core-blockchain / lib / queue / process.js View on Github external
this.queue = async.queue((block, cb) => {
      try {
        return blockchain.processBlock(new Block(block), cb)
      } catch (error) {
        logger.error(`Failed to process block in ProcessQueue: ${block.height.toLocaleString()}`)
        logger.error(error.stack)
        return cb()
      }
    }, 1)
github ArkEcosystem / core / packages / core-blockchain / lib / blockchain.js View on Github external
const blockSlot = slots.getSlotNumber(block.timestamp);

    if (blockSlot > currentSlot) {
      logger.info(`Block disregarded because the block takes a future slot.`)
      return;
    }

    if (
      this.state.started &&
      this.state.blockchain.value === 'idle' &&
      !this.state.forked
    ) {
      this.dispatch('NEWBLOCK')

      this.processQueue.push(block)
      this.state.lastDownloadedBlock = new Block(block)
    } else {
      logger.info(
        `Block disregarded because blockchain is ${
          this.state.forked ? 'forked' : 'not ready'
        } :exclamation:`,
      )
    }
  }