How to use the ripple-lib.utils function in ripple-lib

To help you get started, we’ve selected a few ripple-lib 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 ripple / rippled / test / nodeutils.js View on Github external
var async = require("async");
var fs	  = require("fs");
var path  = require("path");

var utils  = require("ripple-lib").utils;

// Empty a directory.
// done(err) : err = true if an error occured.
var emptyPath = function(dirPath, done) {
  fs.readdir(dirPath, function(err, files) {
    if (err) {
      done(err);
    }
    else {
      async.some(files.map(function(f) { return path.join(dirPath, f); }), rmPath, done);
    }
  });
};

// Make a directory and sub-directories.
var mkPath = function(dirPath, mode, done) {
github ripple / ripple-data-api / db / ledgerImporter.js View on Github external
function formatRemoteLedger(ledger) {

  ledger.close_time_rpepoch = ledger.close_time;
  ledger.close_time_timestamp = ripple.utils.toTimestamp(ledger.close_time);
  ledger.close_time_human = moment(ripple.utils.toTimestamp(ledger.close_time))
    .utc().format("YYYY-MM-DD HH:mm:ss Z");
  ledger.from_rippled_api = true;

  delete ledger.close_time;
  delete ledger.hash;
  delete ledger.accepted;
  delete ledger.totalCoins;
  delete ledger.closed;
  delete ledger.seqNum;

  // parse ints from strings
  ledger.ledger_index = parseInt(ledger.ledger_index, 10);
  ledger.total_coins = parseInt(ledger.total_coins, 10);

  // add exchange rate field to metadata entries
  ledger.transactions.forEach(function(transaction) {
github ripple / ripple-data-api / app.js View on Github external
var express = require('express'),
    extend = require('extend'),
    fs = require('fs'),
    winston = require('winston'),
    config = require('./config'),
    routes = require('./routes'),
    api = require('./routes/api'),
    model = require('./model'),
    apidata = require('./internal_api_data');

var _ = require('lodash');

var Engine = require('./engine').Engine,
    Range = require('./range').Range;

var utils = require('ripple-lib').utils;
var Amount = require('ripple-lib').Amount;

var app = module.exports = express();

if (process.env.DEBUG) winston.level = 'debug';

var engine = new Engine();

// News data
var News = require('./news').News;
var news = new News(engine.db, engine.remote);

// Configuration
var http_config = {}, pusher;
app.configure(function(){
  extend(http_config, {
github ripple / ripple-data-api / s3upload-chunk.js View on Github external
var _ = require('lodash');
var express = require('express'),
    extend = require('extend'),
    fs = require('fs'),
    winston = require('winston'),
    config = require('./config'),
    model = require('./model');

var app = module.exports = express();

// Ripple client
var ripple = require('ripple-lib');
var utils = require('ripple-lib').utils;
var remote = ripple.Remote.from_config(config.remote);

//Amazon S3
var knox = require('knox');
var client = knox.createClient({
  key: config.s3.key,
  secret: config.s3.secret,
  bucket: config.s3.bucket
});

remote.on('error', function (err) {
  winston.error(err);
});

remote.on('connected', function(connection) {
  winston.info('WebSocket client connected');
github ripple / ripple-rest / lib / formatters / payment-formatter.js View on Github external
no_direct_ripple: (tx.Flags & 0x00010000 ? true : false),
    partial_payment: (tx.Flags & 0x00020000 ? true : false),

    // Generated after validation
    direction: (opts.account ?
      (opts.account === tx.Account ?
        'outgoing' :
        (opts.account === tx.Destination ?
          'incoming' :
          'passthrough')) :
      ''),
    state: tx.state || (tx.meta.TransactionResult === 'tesSUCCESS' ? 'validated' : 'failed'),
    result: tx.meta.TransactionResult || '',
    ledger: '' + (tx.inLedger || tx.ledger_index),
    hash: tx.hash || '',
    timestamp: (tx.date ? new Date(ripple.utils.toTimestamp(tx.date)).toISOString() : ''),
    fee: utils.dropsToXrp(tx.Fee) || '',
    source_balance_changes: [],
    destination_balance_changes: []

  };

  // Add source_balance_changes
  utils.parseBalanceChanges(tx, tx.Account).forEach(function(amount){
    if (amount.value < 0) {
      payment.source_balance_changes.push(amount);
    }
  });

  // Add destination_balance_changes
  utils.parseBalanceChanges(tx, tx.Destination).forEach(function(amount){
    if (amount.value > 0) {
github ripple / ripple-data-api / db / import.js View on Github external
function formatRemoteLedger(ledger) {

  ledger.close_time_rpepoch   = ledger.close_time;
  ledger.close_time_timestamp = ripple.utils.toTimestamp(ledger.close_time);
  ledger.close_time_human     = moment(ripple.utils.toTimestamp(ledger.close_time))
    .utc().format("YYYY-MM-DD HH:mm:ss Z");
  ledger.from_rippled_api = true;

  delete ledger.close_time;
  delete ledger.hash;
  delete ledger.accepted;
  delete ledger.totalCoins;
  delete ledger.closed;
  delete ledger.seqNum;

  // parse ints from strings
  ledger.ledger_index = parseInt(ledger.ledger_index, 10);
  ledger.total_coins = parseInt(ledger.total_coins, 10);

  // add exchange rate field to metadata entries
  ledger.transactions.forEach(function(transaction) {
github ripple / ripple-rest / lib / payment.js View on Github external
paths: JSON.stringify(tx.Paths || []),
    no_direct_ripple: (tx.Flags & 0x00010000 ? true : false),
    partial_payment: (tx.Flags & 0x00020000 ? true : false),

    // Generated after validation
    direction: (opts.address === tx.Account ? 
      'outgoing' : 
      (opts.address === tx.Destination ? 
        'incoming' : 
        'passthrough')),
    state: (tx.meta.TransactionResult === 'tesSUCCESS' ? 'confirmed' : 'failed'),
    result: tx.meta.TransactionResult || '',
    ledger: '' + (tx.inLedger || tx.ledger_index),
    hash: tx.hash || '',
    timestamp: '' + ripple.utils.toTimestamp(tx.date),
    timestamp_human: new Date(ripple.utils.toTimestamp(tx.date)).toUTCString() || '',
    fee: rpparser.dropsToXrp(tx.Fee) || '',
    source_balance_changes: [],
    destination_balance_changes: []

  };

  // Add source_balance_changes
  rpparser.parseBalanceChanges(tx, tx.Account).forEach(function(amount){
    if (amount.value < 0) {
      payment.source_balance_changes.push(amount);
    }
  });

  // Add destination_balance_changes
  rpparser.parseBalanceChanges(tx, tx.Destination).forEach(function(amount){
    if (amount.value > 0) {
github ripple / ripple-data-api / s3upload.js View on Github external
var express = require('express'),
    extend = require('extend'),
    fs = require('fs'),
    winston = require('winston'),
    config = require('./config'),
    model = require('./model');

var app = module.exports = express();

// Ripple client
var ripple = require('ripple-lib');
var utils = require('ripple-lib').utils;
var remote = ripple.Remote.from_config(config.remote);

// MySQL
var mysql = require('mysql');
var db = mysql.createConnection({
  host: config.db.mysql_ip,
  user: config.db.mysql_user,
  password: config.db.mysql_pass,
  database: config.db.mysql_db,
  multipleStatements: true
});

//Amazon S3
var knox = require('knox');
var client = knox.createClient({
  key: config.s3.key,
github ripple / ripple-rest / api / lib / tx-to-rest-converter.js View on Github external
}
    if (tx.meta !== undefined && tx.meta.TransactionResult !== undefined) {
      if (tx.meta.TransactionResult === 'tejSecretInvalid') {
        reject(new Error('Invalid secret provided.'));
      }
    }

    var order;
    var flags = TxToRestConverter.prototype.parseFlagsFromResponse(tx.flags,
      OfferCreateFlags);
    var action = tx.TransactionType === 'OfferCreate'
      ? 'order_create' : 'order_cancel';
    var balance_changes = tx.meta
      ? parseBalanceChanges(tx.meta)[options.account] || [] : [];
    var timestamp = tx.date
      ? new Date(ripple.utils.toTimestamp(tx.date)).toISOString() : '';
    var order_changes = tx.meta ?
      parseOrderBookChanges(tx.meta)[options.account] : [];

    var direction;
    if (options.account === tx.Account) {
      direction = 'outgoing';
    } else if (balance_changes.length && order_changes.length) {
      direction = 'incoming';
    } else {
      direction = 'passthrough';
    }

    if (action === 'order_create') {
      order = {
        account: tx.Account,
        taker_pays: utils.parseCurrencyAmount(tx.TakerPays),
github ripple / ripple-rest / lib / formatters / notification-formatter.js View on Github external
}

  if (previous_transaction_identifier) {
    notification.previous_notification_url = '/v1/accounts/' + notification.account + '/notifications/' + previous_transaction_identifier + (types ? '?types=' + types.join(',') : '');
  }

  if (notification_details.previous_hash) {
    notification.previous_hash = notification_details.previous_hash;
  }

  if (notification_details.next_hash) {
    notification.next_hash = notification_details.next_hash;
  }

  if (transaction.date) {
    notification.timestamp = '' + new Date(ripple.utils.toTimestamp(transaction.date)).toISOString();
  }

  if (transaction.meta) {
    notification.result = transaction.meta.TransactionResult;
  }

  if (transaction.state) {
    notification.state = transaction.state;
  } else {
    if (notification.result === 'tesSUCCESS') {
      notification.state = 'validated';
    } else if (notification.result) {
      notification.state = 'failed';
    }
  }