mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
removed _mode field
This commit is contained in:
parent
bdd68cde1a
commit
b815c5561a
@ -25,22 +25,10 @@ var utils = require('../utils/utils');
|
|||||||
var f = require('./formatters');
|
var f = require('./formatters');
|
||||||
var SolidityParam = require('./param');
|
var SolidityParam = require('./param');
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to check if a type is an array type
|
|
||||||
*
|
|
||||||
* @method isArrayType
|
|
||||||
* @param {String} type
|
|
||||||
* @return {Bool} true is the type is an array, otherwise false
|
|
||||||
*/
|
|
||||||
var isArrayType = function (type) {
|
|
||||||
return type.slice(-2) === '[]';
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SolidityType prototype is used to encode/decode solidity params of certain type
|
* SolidityType prototype is used to encode/decode solidity params of certain type
|
||||||
*/
|
*/
|
||||||
var SolidityType = function (config) {
|
var SolidityType = function (config) {
|
||||||
this._mode = config.mode;
|
|
||||||
this._inputFormatter = config.inputFormatter;
|
this._inputFormatter = config.inputFormatter;
|
||||||
this._outputFormatter = config.outputFormatter;
|
this._outputFormatter = config.outputFormatter;
|
||||||
};
|
};
|
||||||
@ -56,44 +44,6 @@ SolidityType.prototype.isType = function (name) {
|
|||||||
throw "this method should be overrwritten!";
|
throw "this method should be overrwritten!";
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to transform plain param to SolidityParam object
|
|
||||||
*
|
|
||||||
* @method formatInput
|
|
||||||
* @param {Object} param - plain object, or an array of objects
|
|
||||||
* @param {Bool} arrayType - true if a param should be encoded as an array
|
|
||||||
* @return {SolidityParam} encoded param wrapped in SolidityParam object
|
|
||||||
*/
|
|
||||||
SolidityType.prototype.formatInput = function (param, arrayType) {
|
|
||||||
if (utils.isArray(param) && arrayType) { // TODO: should fail if this two are not the same
|
|
||||||
var self = this;
|
|
||||||
return param.map(function (p) {
|
|
||||||
return self._inputFormatter(p);
|
|
||||||
}).reduce(function (acc, current) {
|
|
||||||
return acc.combine(current);
|
|
||||||
}, f.formatInputInt(param.length)).withOffset(32);
|
|
||||||
}
|
|
||||||
return this._inputFormatter(param);
|
|
||||||
};
|
|
||||||
|
|
||||||
//SolidityType.prototype.totalOffset = function (value, name) {
|
|
||||||
//if (this.isDynamicArray(name)) {
|
|
||||||
//var nestedName = this.nestedName(name);
|
|
||||||
//var self = this;
|
|
||||||
//return value.reduce(function (acc, current) {
|
|
||||||
//return acc + self.totalOffset(current, nestedName);
|
|
||||||
//}, 64); // add pointer to data && length of data
|
|
||||||
//} else if (this.isStaticArray(name)) {
|
|
||||||
//var nestedName = this.nestedName(name);
|
|
||||||
//var self = this;
|
|
||||||
//return value.reduce(function (acc, current) {
|
|
||||||
//return acc + self.totalOffset(current, nestedName);
|
|
||||||
//}, 0);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//return this.staticPartLength(name);
|
|
||||||
//};
|
|
||||||
|
|
||||||
SolidityType.prototype.encode = function (value, name) {
|
SolidityType.prototype.encode = function (value, name) {
|
||||||
if (this.isDynamicArray(name)) {
|
if (this.isDynamicArray(name)) {
|
||||||
var length = value.length; // in int
|
var length = value.length; // in int
|
||||||
@ -193,18 +143,6 @@ SolidityCoder.prototype._requireType = function (type) {
|
|||||||
return solidityType;
|
return solidityType;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Should be used to transform plain param of given type to SolidityParam
|
|
||||||
*
|
|
||||||
* @method _formatInput
|
|
||||||
* @param {String} type of param
|
|
||||||
* @param {Object} plain param
|
|
||||||
* @return {SolidityParam}
|
|
||||||
*/
|
|
||||||
SolidityCoder.prototype._formatInput = function (type, param) {
|
|
||||||
return this._requireType(type).formatInput(param, isArrayType(type));
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should be used to encode plain param
|
* Should be used to encode plain param
|
||||||
*
|
*
|
||||||
@ -370,7 +308,6 @@ SolidityCoder.prototype.getSolidityTypes = function (types) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeAddress = function () {
|
var SolidityTypeAddress = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputInt;
|
this._inputFormatter = f.formatInputInt;
|
||||||
this._outputFormatter = f.formatOutputAddress;
|
this._outputFormatter = f.formatOutputAddress;
|
||||||
};
|
};
|
||||||
@ -430,7 +367,6 @@ SolidityTypeAddress.prototype.formatOutput = function (param, unused, name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeBool = function () {
|
var SolidityTypeBool = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputBool;
|
this._inputFormatter = f.formatInputBool;
|
||||||
this._outputFormatter = f.formatOutputBool;
|
this._outputFormatter = f.formatOutputBool;
|
||||||
};
|
};
|
||||||
@ -451,7 +387,6 @@ SolidityTypeBool.prototype.decode = function (bytes, offset, type) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeInt = function () {
|
var SolidityTypeInt = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputInt;
|
this._inputFormatter = f.formatInputInt;
|
||||||
this._outputFormatter = f.formatOutputInt;
|
this._outputFormatter = f.formatOutputInt;
|
||||||
};
|
};
|
||||||
@ -468,7 +403,6 @@ SolidityTypeInt.prototype.staticPartLength = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeUInt = function () {
|
var SolidityTypeUInt = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputInt;
|
this._inputFormatter = f.formatInputInt;
|
||||||
this._outputFormatter = f.formatOutputUInt;
|
this._outputFormatter = f.formatOutputUInt;
|
||||||
};
|
};
|
||||||
@ -485,7 +419,6 @@ SolidityTypeUInt.prototype.staticPartLength = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeDynamicBytes = function () {
|
var SolidityTypeDynamicBytes = function () {
|
||||||
this._mode = 'bytes';
|
|
||||||
this._inputFormatter = f.formatInputDynamicBytes;
|
this._inputFormatter = f.formatInputDynamicBytes;
|
||||||
this._outputFormatter = f.formatOutputDynamicBytes;
|
this._outputFormatter = f.formatOutputDynamicBytes;
|
||||||
};
|
};
|
||||||
@ -502,7 +435,6 @@ SolidityTypeDynamicBytes.prototype.isType = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeBytes = function () {
|
var SolidityTypeBytes = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputBytes;
|
this._inputFormatter = f.formatInputBytes;
|
||||||
this._outputFormatter = f.formatOutputBytes;
|
this._outputFormatter = f.formatOutputBytes;
|
||||||
};
|
};
|
||||||
@ -519,7 +451,6 @@ SolidityTypeBytes.prototype.staticPartLength = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeString = function () {
|
var SolidityTypeString = function () {
|
||||||
this._mode = 'bytes';
|
|
||||||
this._inputFormatter = f.formatInputString;
|
this._inputFormatter = f.formatInputString;
|
||||||
this._outputFormatter = f.formatOutputString;
|
this._outputFormatter = f.formatOutputString;
|
||||||
};
|
};
|
||||||
@ -536,7 +467,6 @@ SolidityTypeString.prototype.staticPartLength = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeReal = function () {
|
var SolidityTypeReal = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputReal;
|
this._inputFormatter = f.formatInputReal;
|
||||||
this._outputFormatter = f.formatOutputReal;
|
this._outputFormatter = f.formatOutputReal;
|
||||||
};
|
};
|
||||||
@ -553,7 +483,6 @@ SolidityTypeReal.prototype.staticPartLength = function (name) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var SolidityTypeUReal = function () {
|
var SolidityTypeUReal = function () {
|
||||||
this._mode = 'value';
|
|
||||||
this._inputFormatter = f.formatInputReal;
|
this._inputFormatter = f.formatInputReal;
|
||||||
this._outputFormatter = f.formatOutputUReal;
|
this._outputFormatter = f.formatOutputUReal;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user