web3.js/lib/solidity/real.js
2015-07-28 15:56:18 +02:00

58 lines
1.5 KiB
JavaScript

var f = require('./formatters');
var SolidityType = require('./type');
/**
* SolidityTypeReal is a prootype that represents real type
* It matches:
* real
* real[]
* real[4]
* real[][]
* real[3][]
* real[][6][], ...
* real32
* real64[]
* real8[4]
* real256[][]
* real[3][]
* real64[][6][], ...
*/
var SolidityTypeReal = function () {
this._inputFormatter = f.formatInputReal;
this._outputFormatter = f.formatOutputReal;
};
SolidityTypeReal.prototype = new SolidityType({});
SolidityTypeReal.prototype.constructor = SolidityTypeReal;
SolidityTypeReal.prototype.isType = function (name) {
return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
};
SolidityTypeReal.prototype.staticPartLength = function (name) {
return 32 * this.staticArrayLength(name);
};
SolidityTypeReal.prototype.isDynamicArray = function (name) {
var matches = name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
// is array && doesn't have length specified
return !!matches[2] && !matches[3];
};
SolidityTypeReal.prototype.isStaticArray = function (name) {
var matches = name.match(/real([0-9]*)?(\[([0-9]*)\])?/);
// is array && have length specified
return !!matches[2] && !!matches[3];
};
SolidityTypeReal.prototype.staticArrayLength = function (name) {
return name.match(/real([0-9]*)?(\[([0-9]*)\])?/)[3] || 1;
};
SolidityTypeReal.prototype.nestedName = function (name) {
// removes first [] in name
return name.replace(/\[([0-9])*\]/, '');
};
module.exports = SolidityTypeReal;