How to use the @arkecosystem/crypto.models 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-blockchain / lib / blockchain.js View on Github external
/* eslint max-len: "off" */
/* eslint no-await-in-loop: "off" */

const { slots } = require('@arkecosystem/crypto')
const { Block } = require('@arkecosystem/crypto').models
const app = require('@arkecosystem/core-container')

const logger = app.resolvePlugin('logger')
const config = app.resolvePlugin('config')
const emitter = app.resolvePlugin('event-emitter')
const delay = require('delay')
const pluralize = require('pluralize')
const stateMachine = require('./state-machine')
const Queue = require('./queue')

module.exports = class Blockchain {
  /**
   * Create a new blockchain manager instance.
   * @param  {Boolean} networkStart
   * @return {void}
   */
github ArkEcosystem / core / packages / core-forger / lib / manager.js View on Github external
/* eslint no-await-in-loop: "off" */

const delay = require('delay')

const container = require('@arkecosystem/core-container')

const logger = container.resolvePlugin('logger')
const config = container.resolvePlugin('config')

const { slots } = require('@arkecosystem/crypto')
const { Delegate, Transaction } = require('@arkecosystem/crypto').models

const isEmpty = require('lodash/isEmpty')
const uniq = require('lodash/uniq')
const pluralize = require('pluralize')

const Client = require('./client')

module.exports = class ForgerManager {
  /**
   * Create a new forger manager instance.
   * @param  {Object} options
   */
  constructor(options) {
    this.secrets = config.delegates ? config.delegates.secrets : null
    this.network = config.network
    this.client = new Client(options.hosts)
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',
github ArkEcosystem / core / packages / core-forger / __tests__ / __fixtures__ / transaction.js View on Github external
const { Transaction } = require('@arkecosystem/crypto').models

module.exports = new Transaction({
  type: 0,
  amount: 245098000000000,
  fee: 0,
  recipientId: 'AHXtmB84sTZ9Zd35h9Y1vfFvPE2Xzqj8ri',
  timestamp: 0,
  asset: {},
  senderPublicKey:
    '035b63b4668ee261c16ca91443f3371e2fe349e131cb7bf5f8a3e93a3ddfdfc788',
  signature:
    '304402205fcb0677e06bde7aac3dc776665615f4b93ef8c3ed0fddecef9900e74fcb00f302206958a0c9868ea1b1f3d151bdfa92da1ce24de0b1fcd91933e64fb7971e92f48d',
  id: 'db1aa687737858cc9199bfa336f9b1c035915c30aaee60b1e0f8afadfdb946bd',
  senderId: 'APnhwwyTbMiykJwYbGhYjNgtHiVJDSEhSn',
})
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-p2p / lib / server / versions / internal / handlers / transactions.js View on Github external
const app = require('@arkecosystem/core-container')

const config = app.resolvePlugin('config')

const { Transaction } = require('@arkecosystem/crypto').models

const schema = require('../schemas/transactions')

/**
 * @type {Object}
 */
exports.verify = {
  /**
   * @param  {Hapi.Request} request
   * @param  {Hapi.Toolkit} h
   * @return {Hapi.Response}
   */
  async handler(request, h) {
    const transaction = new Transaction(
      Transaction.deserialize(request.payload.transaction),
    )
github ArkEcosystem / core / packages / core-p2p / lib / server / versions / internal / handlers.js View on Github external
'use strict'

const container = require('@arkecosystem/core-container')
const config = container.resolvePlugin('config')
const requestIp = require('request-ip')
const logger = container.resolvePlugin('logger')
const emitter = container.resolvePlugin('event-emitter')

const { slots } = require('@arkecosystem/crypto')
const { Transaction } = require('@arkecosystem/crypto').models

const schema = require('./schema')

/**
 * @type {Object}
 */
exports.postVerifyTransaction = {
  /**
   * @param  {Hapi.Request} request
   * @param  {Hapi.Toolkit} h
   * @return {Hapi.Response}
   */
  async handler (request, h) {
    const transaction = new Transaction(Transaction.deserialize(request.payload.transaction))
    const result = await container.resolvePlugin('database').verifyTransaction(transaction)
github ArkEcosystem / core / packages / core-transaction-pool-redis / lib / connection.js View on Github external
'use strict'

const { TransactionPoolInterface } = require('@arkecosystem/core-transaction-pool')
const Redis = require('ioredis')
const container = require('@arkecosystem/core-container')
const logger = container.resolvePlugin('logger')
const emitter = container.resolvePlugin('event-emitter')
const uniq = require('lodash/uniq')

const ark = require('@arkecosystem/crypto')
const { Transaction } = ark.models
const { TRANSACTION_TYPES } = ark.constants
const database = container.resolvePlugin('database')

module.exports = class TransactionPool extends TransactionPoolInterface {
  /**
   * Make the transaction pool instance.
   * @return {TransactionPool}
   */
  make () {
    if (!this.options.enabled) {
      logger.warn('Redis transaction pool disabled - please enable if run in production')

      return this
    }

    this.keyPrefix = this.options.key
github ArkEcosystem / core / packages / core-graphql / lib / helpers / unserialize-transactions.js View on Github external
'use strict';

const { Transaction } = require('@arkecosystem/crypto').models

/**
 * Deserialize multiple transactions
 */
module.exports = async (data) => {
  const deserialize = (buffer) => {
    const serialized = Buffer.from(buffer).toString('hex')
    return Transaction.deserialize(serialized)
  }

  if (Array.isArray(data)) {
    return data.reduce((total, value, key) => {
      total.push(deserialize(value.serialized))

      return total
    }, [])
github ArkEcosystem / core / packages / core-transaction-pool-mem / lib / mem-pool-transaction.js View on Github external
const assert = require('assert')
const crypto = require('@arkecosystem/crypto')

const TRANSACTION_TYPES = crypto.constants.TRANSACTION_TYPES
const Transaction = crypto.models.Transaction

/**
 * A mem pool transaction.
 * A normal transaction
 * + a sequence number used to order by insertion time
 * + a get-expiration-time method used to remove old transactions from the pool
 */
module.exports = class MemPoolTransaction {
  /**
   * Construct a MemPoolTransaction object.
   * @param {Transaction} transaction base transaction object
   * @param {Number}      sequence    insertion order sequence or undefined;
   *                                  if this is undefined at creation time,
   *                                  then it is assigned later using the
   *                                  setter method below
   */