How to use the web3-core-helpers.formatters function in web3-core-helpers

To help you get started, we’ve selected a few web3-core-helpers 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 ethereum / web3.js / packages / web3-eth-personal / src / index.js View on Github external
along with web3.js.  If not, see .
*/
/**
 * @file index.js
 * @author Fabian Vogelsteller 
 * @date 2017
 */

"use strict";

var core = require('web3-core');
var Method = require('web3-core-method');
var utils = require('web3-utils');
var Net = require('web3-net');

var formatters = require('web3-core-helpers').formatters;


var Personal = function Personal() {
    var _this = this;

    // sets _requestmanager
    core.packageInit(this, arguments);

    this.net = new Net(this.currentProvider);

    var defaultAccount = null;
    var defaultBlock = 'latest';

    Object.defineProperty(this, 'defaultAccount', {
        get: function () {
            return defaultAccount;
github ethereum / web3.js / packages / web3-eth-accounts / src / index.js View on Github external
}

        if (tx.nonce < 0 ||
            tx.gas < 0 ||
            tx.gasPrice < 0 ||
            tx.chainId < 0) {
            error = new Error('Gas, gasPrice, nonce or chainId is lower than 0');
        }

        if (error) {
            callback(error);
            return Promise.reject(error);
        }

        try {
            var transaction = helpers.formatters.inputCallFormatter(_.clone(tx));
            transaction.to = transaction.to || '0x';
            transaction.data = transaction.data || '0x';
            transaction.value = transaction.value || '0x';
            transaction.chainId = utils.numberToHex(transaction.chainId);

            // Because tx has no ethereumjs-tx signing options we use fetched vals.
            if (!hasTxSigningOptions) {
                transactionOptions.common = Common.forCustomChain(
                    'mainnet',
                    {
                        name: 'custom-network',
                        networkId: transaction.networkId,
                        chainId: transaction.chainId
                    },
                    'petersburg'
                );
github OpenST / openst.js / utils / SignEIP1077Extension.js View on Github external
utils.toEIP1077TransactionHash = (transaction, version) => {
  transaction = helpers.formatters.inputCallFormatter(transaction);

  transaction.value = utils.toBN(transaction.value || '0').toString();
  transaction.gasPrice = utils.toBN(transaction.gasPrice || '0').toString();
  transaction.gas = utils.toBN(transaction.gas || '0').toString();
  transaction.gasToken = utils.toBN(transaction.gasToken || '0').toString();
  transaction.operationType = utils.toBN(transaction.operationType || '0').toString();
  transaction.nonce = utils.toBN(transaction.nonce || '0').toString();
  transaction.to = transaction.to || '0x';
  transaction.data = transaction.data || '0x';
  transaction.extraHash = transaction.extraHash || '0x00';

  /** EIP1077
   keccak256(
   byte(0x19), // Will be taken care by hashEIP191Message
   byte(0), // Will be taken care by hashEIP191Message
   from,
github ninabreznik / voting-ethereum-contract / node_modules / web3-core-method / src / index.js View on Github external
You should have received a copy of the GNU Lesser General Public License
    along with web3.js.  If not, see .
*/
/**
 * @file index.js
 * @author Fabian Vogelsteller 
 * @author Marek Kotewicz 
 * @date 2017
 */

"use strict";

var _ = require('underscore');
var errors = require('web3-core-helpers').errors;
var formatters = require('web3-core-helpers').formatters;
var utils = require('web3-utils');
var promiEvent = require('web3-core-promievent');
var Subscriptions = require('web3-core-subscriptions').subscriptions;

var TIMEOUTBLOCK = 50;
var POLLINGTIMEOUT = 15 * TIMEOUTBLOCK; // ~average block time (seconds) * TIMEOUTBLOCK
var CONFIRMATIONBLOCKS = 24;

var Method = function Method(options) {

    if(!options.call || !options.name) {
        throw new Error('When creating a method you need to provide at least the "name" and "call" property.');
    }

    this.name = options.name;
    this.call = options.call;
github ethereum / web3.js / packages / web3-eth / src / accounts.js View on Github external
signTransaction: function sign(tx, privKey, callback) {
        var _this = this;

        if(tx.to) {
            tx.to = helpers.formatters.inputAddressFormatter(tx.to);
        }

        // return synchronous
        if(tx.gas && _.isFinite(tx.gasPrice) && _.isFinite(tx.chainId) && _.isFinite(tx.nonce)) {
            var signature = signer.sign(tx, privKey);

            if (_.isFunction(callback)) {
                callback(null, signature);
            }
            return signature;
        }

        // make it async and retrive missing values
        // probably need to convert gas, chainId, nonce to HEX using utils.numberToHex()

        var account = this.privateToAccount(privKey);
github citahub / cita-sdk-js / packages / cita-sdk / src / base / neuron.ts View on Github external
const formatters = require('web3-core-helpers').formatters
const utils = require('web3-utils')

export const getAccounts = {
  name: 'getAccounts',
  call: 'personal_listAccounts',
  params: 0,
  outputFormatter: utils.toChecksumAddress
}
export const newAccount = {
  name: 'newAccount',
  call: 'personal_newAccount',
  params: 1,
  inputFormatter: [null],
  outputFormatter: utils.toChecksumAddress
}
github poanetwork / bridge-ui / lib / web3-eth / index.js View on Github external
var _ = require('underscore');
var core = require('web3-core');
var helpers = require('web3-core-helpers');
var Subscriptions = require('web3-core-subscriptions').subscriptions;
var Method = require('web3-core-method');
var utils = require('web3-utils');
var Net = require('web3-net');

var Personal = require('web3-eth-personal');
var BaseContract = require('web3-eth-contract');
var Iban = require('web3-eth-iban');
var Accounts = require('web3-eth-accounts');
var abi = require('web3-eth-abi');

var getNetworkType = require('./getNetworkType.js');
var formatter = helpers.formatters;


var blockCall = function (args) {
    return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
};

var transactionFromBlockCall = function (args) {
    return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
};

var uncleCall = function (args) {
    return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
};

var getBlockTransactionCountCall = function (args) {
    return (_.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
github celo-org / celo-monorepo / packages / faucet / src / protocol / signing-utils.ts View on Github external
const signed = (tx: any) => {
    if (!tx.gas && !tx.gasLimit) {
      throw new Error('"gas" is missing')
    }

    if (tx.nonce < 0 || tx.gas < 0 || tx.gasPrice < 0 || tx.chainId < 0) {
      throw new Error('Gas, gasPrice, nonce or chainId is lower than 0')
    }

    try {
      tx = helpers.formatters.inputCallFormatter(tx)

      const transaction = tx
      transaction.to = tx.to || '0x'
      transaction.data = tx.data || '0x'
      transaction.value = tx.value || '0x'
      transaction.chainId = web3.utils.numberToHex(tx.chainId)
      transaction.feeCurrency = tx.feeCurrency || '0x'
      transaction.gatewayFeeRecipient = tx.gatewayFeeRecipient || '0x'
      transaction.gatewayFee = tx.gatewayFee || '0x'

      const rlpEncoded = RLP.encode([
        bytes.fromNat(transaction.nonce),
        bytes.fromNat(transaction.gasPrice),
        bytes.fromNat(transaction.gas),
        transaction.feeCurrency.toLowerCase(),
        transaction.gatewayFeeRecipient.toLowerCase(),
github ethereum / web3.js / packages / web3 / src / factories / CoreFactory.js View on Github external
CoreFactory.prototype.createFormatters = function () {
    return helpers.formatters;
};
github ethereum / web3.js / packages / web3-eth-abi / src / types / address.js View on Github external
var f = require('./formatters');
var formatters = require('web3-core-helpers').formatters;
var SolidityType = require('./type');

/**
 * SolidityTypeAddress is a protoype that represents address type
 * It matches:
 * address
 * address[]
 * address[4]
 * address[][]
 * address[3][]
 * address[][6][], ...
 */
var SolidityTypeAddress = function () {
    this._inputFormatter = function(){
        var args = Array.prototype.slice.call(arguments);
        args[0] = formatters.inputAddressFormatter(args[0]);