How to use ripple-lib - 10 common examples

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 / testutils.js View on Github external
function verify_limit(remote, src, amount, callback) {
  assert.strictEqual(arguments.length, 4);

  var _m = amount.match(/^(\d+\/...\/[^\:]+)(?::(\d+)(?:,(\d+))?)?$/);

  if (!_m) {
    // console.log('credit_limit: parse error: %s', amount);
    return callback(new Error('parse_error'));
  }

  // console.log('_m', _m.length, _m);
  // console.log('verify_limit: parsed: %s', JSON.stringify(_m, undefined, 2));
  var account_limit = _m[1];
  var quality_in    = Number(_m[2]);
  var quality_out   = Number(_m[3]);
  var limit         = Amount.from_json(account_limit);

  var options = {
    account:   src,
    issuer:    limit.issuer().to_json(),
    currency:  limit.currency().to_json(),
    ledger:    'current'
  };

  remote.request_ripple_balance(options, function(err, m) {
    if (err) {
      callback(err);
    } else {
      assert(m.account_limit.equals(limit));
      assert(isNaN(quality_in) || m.account_quality_in === quality_in);
      assert(isNaN(quality_out) || m.account_quality_out === quality_out);
      callback(null);
github ripple / rippled / test / mocha-loader-patch.js View on Github external
require('babel/register');

var extend = require('extend');
var mocha = require('mocha');
var ripplelib = require('ripple-lib');

// Optionally use a more useful (but noisy) logger
if (process.env.USE_RCONSOLE) {
  require('rconsole');
};

// Stash a reference away to this
extend(ripplelib, ripplelib._DEPRECATED);

var config = ripplelib.config = {
  load: function (newOpts) {
    extend(ripplelib.config, newOpts);
    return config;
  }
}

// camelCase to under_scored API conversion
function attachUnderscored(c) {
  var o = ripplelib[c];

  Object.keys(o.prototype).forEach(function(key) {
    var UPPERCASE = /([A-Z]{1})[a-z]+/g;

    if (!UPPERCASE.test(key)) {
      return;
    }
github ripple / rippled / test / mocha-loader-patch.js View on Github external
require('babel/register');

var extend = require('extend');
var mocha = require('mocha');
var ripplelib = require('ripple-lib');

// Optionally use a more useful (but noisy) logger
if (process.env.USE_RCONSOLE) {
  require('rconsole');
};

// Stash a reference away to this
extend(ripplelib, ripplelib._DEPRECATED);

var config = ripplelib.config = {
  load: function (newOpts) {
    extend(ripplelib.config, newOpts);
    return config;
  }
}

// camelCase to under_scored API conversion
function attachUnderscored(c) {
  var o = ripplelib[c];

  Object.keys(o.prototype).forEach(function(key) {
    var UPPERCASE = /([A-Z]{1})[a-z]+/g;

    if (!UPPERCASE.test(key)) {
github radrbiz / radard / test / testutils.js View on Github external
var async       = require('async');
var assert      = require('assert');
var extend      = require('extend');
var Amount      = require('ripple-lib').Amount;
var Remote      = require('ripple-lib').Remote;
var Transaction = require('ripple-lib').Transaction;
var UInt160     = require('ripple-lib').UInt160;

var Server      = require('./server').Server;
var path        = require("path");
var server      = { };

function get_config() {
  var cfg = require(__dirname + '/config-example');

  // See if the person testing wants to override the configuration by creating a
  // file called test/config.js.
  try {
    cfg = extend({}, cfg, require(__dirname + '/config'));
  } catch (e) { }

  return cfg;
};
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-lib / test / sjcl-montgomery.js View on Github external
/* eslint-disable max-len */
/* eslint new-cap: [2, {newIsCapExceptions: ["bn"]}] */
'use strict';
const assert = require('assert');
const sjcl = require('ripple-lib').sjcl;

// fix normalize bug in scjl:
// https://github.com/bitwiseshiftleft/sjcl/pull/221
function normalizeFix(bn) {
  while (bn.limbs.length > 0 && bn.limbs[bn.limbs.length - 1] === 0) {
    bn.limbs.pop();
  }
  return bn;
}

function testExp(vec) {
  const actual = normalizeFix(new sjcl.bn(vec.g).powermod(
    new sjcl.bn(vec.e), new sjcl.bn(vec.m)));
  const expected = new sjcl.bn(vec.r);
  assert.strictEqual(actual.toString(), expected.toString());
}
github ripple / rippled / test / testutils.js View on Github external
function connect_websocket(callback) {
        self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
        self.remote.once('connected', function() {
        // self.remote.once('ledger_closed', function() {
          callback();
        });
        self.remote.connect();
      }
    ];
github radrbiz / radard / test / testutils.js View on Github external
function connect_websocket(callback) {
        self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws);
        self.remote.once('connected', function() {
        // self.remote.once('ledger_closed', function() {
          callback();
        });
        self.remote.connect();
      }
    ];
github ripple / rippled / bin / rlint.js View on Github external
var finish = function (remote) {
  remote.disconnect();

  // XXX Because remote.disconnect() doesn't work:
  process.exit();
};

console.log("args: ", process.argv.length);
console.log("args: ", process.argv);

if (process.argv.length < 4) {
  usage();
}
else {
  var remote  = Remote.from_config({
        websocket_ip:   process.argv[2],
        websocket_port: process.argv[3],
      })
    .once('ledger_closed', function (m) {
        console.log("ledger_closed: ", JSON.stringify(m, undefined, 2));

        if (process.argv.length === 5) {
          var ledger_index  = process.argv[4];

          ledger_request(remote, ledger_index, function (l) {
              if (l) {
                ledger_verify(l);
              }

              finish(remote);
            });
github ripple-unmaintained / ripple-watch / bot.js View on Github external
+ say_type + " "
        + (say_watch_irc || say_watch);

    var output_irc  =
        m.engine_result === 'tesSUCCESS'
          ? output_irc_base
          : m.engine_result.match('tecPATH_DRY|tecPATH_PARTIAL') === null
            ? irc.colors.wrap('light_red', m.engine_result)
            : undefined;

    writeWatch(output_irc, output_console);
  }
};
 
remote  =
  Remote
    .from_config(remote_config)
    .once('ledger_closed', function (m) {
        self.rippled  = true;

        console.log("*** Connected to rippled");

        if (process.argv.length > 2)
        {
          remote
            .request_tx(process.argv[2])
            .on('success', function (m) {
                // Send transaction as per normal.
                console.log("REPLAY %s", JSON.stringify(m, undefined, 2));

                remote.emit('transaction_all', {
                  transaction: m,