forked from cerc-io/plugeth
real, ureal paddings and implicit paddings for uint, int and hash
This commit is contained in:
parent
1d139f7a0b
commit
210682b734
2
dist/ethereum.js
vendored
2
dist/ethereum.js
vendored
@ -1,5 +1,5 @@
|
||||
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
||||
var hexToDec,decToHex,findIndex,findMethodIndex,padLeft,setupInputTypes,inputTypes,toAbiInput,setupOutputTypes,outputTypes,fromAbiOutput,inputParser,outputParser;hexToDec=function(hex){return parseInt(hex,16).toString()},decToHex=function(dec){return parseInt(dec).toString(16)},findIndex=function(array,callback){for(var end=!1,i=0;i<array.length&&!end;i++)end=callback(array[i]);return end?i-1:-1},findMethodIndex=function(json,methodName){return findIndex(json,function(method){return method.name===methodName})},padLeft=function(string,chars){return new Array(chars-string.length+1).join("0")+string},setupInputTypes=function(){var prefixedType=function(prefix,bitsInNumber){return function(type,value){var padding,expected=prefix;return 0!==type.indexOf(expected)?!1:(padding=parseInt(type.slice(expected.length))/8*bitsInNumber,value="number"==typeof value?value.toString(16):"string"==typeof value?web3.toHex(value):0===value.indexOf("0x")?value.substr(2):(+value).toString(16),padLeft(value,2*padding))}},namedType=function(name,padding,formatter){return function(type,value){return type!==name?!1:padLeft(formatter?formatter(value):value,2*padding)}},formatBool=function(value){return value?"0x1":"0x0"};return[prefixedType("uint",1),prefixedType("int",1),prefixedType("hash",1),prefixedType("string",8),namedType("address",20),namedType("bool",1,formatBool)]},inputTypes=setupInputTypes(),toAbiInput=function(json,methodName,params){var method,i,found,j,bytes="",index=findMethodIndex(json,methodName);if(-1!==index){for(bytes="0x"+padLeft(index.toString(16),2),method=json[index],i=0;i<method.inputs.length;i++){for(found=!1,j=0;j<inputTypes.length&&!found;j++)found=inputTypes[j](method.inputs[i].type,params[i]);found||console.error("unsupported json type: "+method.inputs[i].type),bytes+=found}return bytes}},setupOutputTypes=function(){var prefixedType=function(prefix,bitsInNumber){return function(type){var padding,expected=prefix;return 0!==type.indexOf(expected)?-1:(padding=parseInt(type.slice(expected.length))/8*bitsInNumber,2*padding)}},namedType=function(name,padding){return function(type){return name===type?2*padding:-1}},formatInt=function(value){return value.length<=8?+parseInt(value,16):hexToDec(value)},formatHash=function(value){return"0x"+value},formatBool=function(value){return"1"===value?!0:!1},formatString=function(value){return web3.toAscii(value)};return[{padding:prefixedType("uint",1),format:formatInt},{padding:prefixedType("int",1),format:formatInt},{padding:prefixedType("hash",1),format:formatHash},{padding:prefixedType("string",8),format:formatString},{padding:namedType("address",20)},{padding:namedType("bool",1),format:formatBool}]},outputTypes=setupOutputTypes(),fromAbiOutput=function(json,methodName,output){var result,method,i,padding,j,res,formatter,index=findMethodIndex(json,methodName);if(-1!==index){for(output=output.slice(2),result=[],method=json[index],i=0;i<method.outputs.length;i++){for(padding=-1,j=0;j<outputTypes.length&&-1===padding;j++)padding=outputTypes[j].padding(method.outputs[i].type);-1!==padding&&(res=output.slice(0,padding),formatter=outputTypes[j-1].format,result.push(formatter?formatter(res):"0x"+res),output=output.slice(padding))}return result}},inputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(){var params=Array.prototype.slice.call(arguments);return toAbiInput(json,method.name,params)}}),parser},outputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(output){return fromAbiOutput(json,method.name,output)}}),parser},module.exports={inputParser:inputParser,outputParser:outputParser};
|
||||
var hexToDec,decToHex,findIndex,findMethodIndex,padLeft,calcBitPadding,calcBytePadding,calcRealPadding,setupInputTypes,inputTypes,toAbiInput,setupOutputTypes,outputTypes,fromAbiOutput,inputParser,outputParser;hexToDec=function(hex){return parseInt(hex,16).toString()},decToHex=function(dec){return parseInt(dec).toString(16)},findIndex=function(array,callback){for(var end=!1,i=0;i<array.length&&!end;i++)end=callback(array[i]);return end?i-1:-1},findMethodIndex=function(json,methodName){return findIndex(json,function(method){return method.name===methodName})},padLeft=function(string,chars){return new Array(chars-string.length+1).join("0")+string},calcBitPadding=function(type,expected){var value=type.slice(expected.length);return""===value?32:parseInt(value)/8},calcBytePadding=function(type,expected){var value=type.slice(expected.length);return""===value?32:parseInt(value)},calcRealPadding=function(type,expected){var sizes,padding,i,value=type.slice(expected.length);if(""===value)return 32;for(sizes=value.split("x"),padding=0,i=0;sizes>i;i++)padding+=sizes[i]/8;return padding},setupInputTypes=function(){var prefixedType=function(prefix,calcPadding){return function(type,value){var padding,expected=prefix;return 0!==type.indexOf(expected)?!1:(padding=calcPadding(type,expected),value="number"==typeof value?value.toString(16):"string"==typeof value?web3.toHex(value):0===value.indexOf("0x")?value.substr(2):(+value).toString(16),padLeft(value,2*padding))}},namedType=function(name,padding,formatter){return function(type,value){return type!==name?!1:padLeft(formatter?formatter(value):value,2*padding)}},formatBool=function(value){return value?"0x1":"0x0"};return[prefixedType("uint",calcBitPadding),prefixedType("int",calcBitPadding),prefixedType("hash",calcBitPadding),prefixedType("string",calcBytePadding),prefixedType("real",calcRealPadding),prefixedType("ureal",calcRealPadding),namedType("address",20),namedType("bool",1,formatBool)]},inputTypes=setupInputTypes(),toAbiInput=function(json,methodName,params){var method,i,found,j,bytes="",index=findMethodIndex(json,methodName);if(-1!==index){for(bytes="0x"+padLeft(index.toString(16),2),method=json[index],i=0;i<method.inputs.length;i++){for(found=!1,j=0;j<inputTypes.length&&!found;j++)found=inputTypes[j](method.inputs[i].type,params[i]);found||console.error("unsupported json type: "+method.inputs[i].type),bytes+=found}return bytes}},setupOutputTypes=function(){var prefixedType=function(prefix,calcPadding){return function(type){var padding,expected=prefix;return 0!==type.indexOf(expected)?-1:(padding=calcPadding(type,expected),2*padding)}},namedType=function(name,padding){return function(type){return name===type?2*padding:-1}},formatInt=function(value){return value.length<=8?+parseInt(value,16):hexToDec(value)},formatHash=function(value){return"0x"+value},formatBool=function(value){return"1"===value?!0:!1},formatString=function(value){return web3.toAscii(value)};return[{padding:prefixedType("uint",calcBitPadding),format:formatInt},{padding:prefixedType("int",calcBitPadding),format:formatInt},{padding:prefixedType("hash",calcBitPadding),format:formatHash},{padding:prefixedType("string",calcBytePadding),format:formatString},{padding:prefixedType("real",calcRealPadding),format:formatInt},{padding:prefixedType("ureal",calcRealPadding),format:formatInt},{padding:namedType("address",20)},{padding:namedType("bool",1),format:formatBool}]},outputTypes=setupOutputTypes(),fromAbiOutput=function(json,methodName,output){var result,method,i,padding,j,res,formatter,index=findMethodIndex(json,methodName);if(-1!==index){for(output=output.slice(2),result=[],method=json[index],i=0;i<method.outputs.length;i++){for(padding=-1,j=0;j<outputTypes.length&&-1===padding;j++)padding=outputTypes[j].padding(method.outputs[i].type);-1!==padding&&(res=output.slice(0,padding),formatter=outputTypes[j-1].format,result.push(formatter?formatter(res):"0x"+res),output=output.slice(padding))}return result}},inputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(){var params=Array.prototype.slice.call(arguments);return toAbiInput(json,method.name,params)}}),parser},outputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(output){return fromAbiOutput(json,method.name,output)}}),parser},module.exports={inputParser:inputParser,outputParser:outputParser};
|
||||
},{}],2:[function(require,module,exports){
|
||||
var AutoProvider=function(userOptions){var options,self,closeWithSuccess,ws;if(!web3.haveProvider()){if(this.sendQueue=[],this.onmessageQueue=[],navigator.qt)return void(this.provider=new web3.providers.QtProvider);userOptions=userOptions||{},options={httprpc:userOptions.httprpc||"http://localhost:8080",websockets:userOptions.websockets||"ws://localhost:40404/eth"},self=this,closeWithSuccess=function(success){ws.close(),success?self.provider=new web3.providers.WebSocketProvider(options.websockets):(self.provider=new web3.providers.HttpRpcProvider(options.httprpc),self.poll=self.provider.poll.bind(self.provider)),self.sendQueue.forEach(function(payload){self.provider(payload)}),self.onmessageQueue.forEach(function(handler){self.provider.onmessage=handler})},ws=new WebSocket(options.websockets),ws.onopen=function(){closeWithSuccess(!0)},ws.onerror=function(){closeWithSuccess(!1)}}};AutoProvider.prototype.send=function(payload){return this.provider?void this.provider.send(payload):void this.sendQueue.push(payload)},Object.defineProperty(AutoProvider.prototype,"onmessage",{set:function(handler){return this.provider?void(this.provider.onmessage=handler):void this.onmessageQueue.push(handler)}}),module.exports=AutoProvider;
|
||||
},{}],3:[function(require,module,exports){
|
||||
|
2
dist/ethereum.js.map
vendored
2
dist/ethereum.js.map
vendored
@ -17,7 +17,7 @@
|
||||
"sourceRoot": "",
|
||||
"sourcesContent": [
|
||||
"(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})",
|
||||
"var hexToDec,decToHex,findIndex,findMethodIndex,padLeft,setupInputTypes,inputTypes,toAbiInput,setupOutputTypes,outputTypes,fromAbiOutput,inputParser,outputParser;hexToDec=function(hex){return parseInt(hex,16).toString()},decToHex=function(dec){return parseInt(dec).toString(16)},findIndex=function(array,callback){for(var end=!1,i=0;i<array.length&&!end;i++)end=callback(array[i]);return end?i-1:-1},findMethodIndex=function(json,methodName){return findIndex(json,function(method){return method.name===methodName})},padLeft=function(string,chars){return new Array(chars-string.length+1).join(\"0\")+string},setupInputTypes=function(){var prefixedType=function(prefix,bitsInNumber){return function(type,value){var padding,expected=prefix;return 0!==type.indexOf(expected)?!1:(padding=parseInt(type.slice(expected.length))/8*bitsInNumber,value=\"number\"==typeof value?value.toString(16):\"string\"==typeof value?web3.toHex(value):0===value.indexOf(\"0x\")?value.substr(2):(+value).toString(16),padLeft(value,2*padding))}},namedType=function(name,padding,formatter){return function(type,value){return type!==name?!1:padLeft(formatter?formatter(value):value,2*padding)}},formatBool=function(value){return value?\"0x1\":\"0x0\"};return[prefixedType(\"uint\",1),prefixedType(\"int\",1),prefixedType(\"hash\",1),prefixedType(\"string\",8),namedType(\"address\",20),namedType(\"bool\",1,formatBool)]},inputTypes=setupInputTypes(),toAbiInput=function(json,methodName,params){var method,i,found,j,bytes=\"\",index=findMethodIndex(json,methodName);if(-1!==index){for(bytes=\"0x\"+padLeft(index.toString(16),2),method=json[index],i=0;i<method.inputs.length;i++){for(found=!1,j=0;j<inputTypes.length&&!found;j++)found=inputTypes[j](method.inputs[i].type,params[i]);found||console.error(\"unsupported json type: \"+method.inputs[i].type),bytes+=found}return bytes}},setupOutputTypes=function(){var prefixedType=function(prefix,bitsInNumber){return function(type){var padding,expected=prefix;return 0!==type.indexOf(expected)?-1:(padding=parseInt(type.slice(expected.length))/8*bitsInNumber,2*padding)}},namedType=function(name,padding){return function(type){return name===type?2*padding:-1}},formatInt=function(value){return value.length<=8?+parseInt(value,16):hexToDec(value)},formatHash=function(value){return\"0x\"+value},formatBool=function(value){return\"1\"===value?!0:!1},formatString=function(value){return web3.toAscii(value)};return[{padding:prefixedType(\"uint\",1),format:formatInt},{padding:prefixedType(\"int\",1),format:formatInt},{padding:prefixedType(\"hash\",1),format:formatHash},{padding:prefixedType(\"string\",8),format:formatString},{padding:namedType(\"address\",20)},{padding:namedType(\"bool\",1),format:formatBool}]},outputTypes=setupOutputTypes(),fromAbiOutput=function(json,methodName,output){var result,method,i,padding,j,res,formatter,index=findMethodIndex(json,methodName);if(-1!==index){for(output=output.slice(2),result=[],method=json[index],i=0;i<method.outputs.length;i++){for(padding=-1,j=0;j<outputTypes.length&&-1===padding;j++)padding=outputTypes[j].padding(method.outputs[i].type);-1!==padding&&(res=output.slice(0,padding),formatter=outputTypes[j-1].format,result.push(formatter?formatter(res):\"0x\"+res),output=output.slice(padding))}return result}},inputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(){var params=Array.prototype.slice.call(arguments);return toAbiInput(json,method.name,params)}}),parser},outputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(output){return fromAbiOutput(json,method.name,output)}}),parser},module.exports={inputParser:inputParser,outputParser:outputParser};",
|
||||
"var hexToDec,decToHex,findIndex,findMethodIndex,padLeft,calcBitPadding,calcBytePadding,calcRealPadding,setupInputTypes,inputTypes,toAbiInput,setupOutputTypes,outputTypes,fromAbiOutput,inputParser,outputParser;hexToDec=function(hex){return parseInt(hex,16).toString()},decToHex=function(dec){return parseInt(dec).toString(16)},findIndex=function(array,callback){for(var end=!1,i=0;i<array.length&&!end;i++)end=callback(array[i]);return end?i-1:-1},findMethodIndex=function(json,methodName){return findIndex(json,function(method){return method.name===methodName})},padLeft=function(string,chars){return new Array(chars-string.length+1).join(\"0\")+string},calcBitPadding=function(type,expected){var value=type.slice(expected.length);return\"\"===value?32:parseInt(value)/8},calcBytePadding=function(type,expected){var value=type.slice(expected.length);return\"\"===value?32:parseInt(value)},calcRealPadding=function(type,expected){var sizes,padding,i,value=type.slice(expected.length);if(\"\"===value)return 32;for(sizes=value.split(\"x\"),padding=0,i=0;sizes>i;i++)padding+=sizes[i]/8;return padding},setupInputTypes=function(){var prefixedType=function(prefix,calcPadding){return function(type,value){var padding,expected=prefix;return 0!==type.indexOf(expected)?!1:(padding=calcPadding(type,expected),value=\"number\"==typeof value?value.toString(16):\"string\"==typeof value?web3.toHex(value):0===value.indexOf(\"0x\")?value.substr(2):(+value).toString(16),padLeft(value,2*padding))}},namedType=function(name,padding,formatter){return function(type,value){return type!==name?!1:padLeft(formatter?formatter(value):value,2*padding)}},formatBool=function(value){return value?\"0x1\":\"0x0\"};return[prefixedType(\"uint\",calcBitPadding),prefixedType(\"int\",calcBitPadding),prefixedType(\"hash\",calcBitPadding),prefixedType(\"string\",calcBytePadding),prefixedType(\"real\",calcRealPadding),prefixedType(\"ureal\",calcRealPadding),namedType(\"address\",20),namedType(\"bool\",1,formatBool)]},inputTypes=setupInputTypes(),toAbiInput=function(json,methodName,params){var method,i,found,j,bytes=\"\",index=findMethodIndex(json,methodName);if(-1!==index){for(bytes=\"0x\"+padLeft(index.toString(16),2),method=json[index],i=0;i<method.inputs.length;i++){for(found=!1,j=0;j<inputTypes.length&&!found;j++)found=inputTypes[j](method.inputs[i].type,params[i]);found||console.error(\"unsupported json type: \"+method.inputs[i].type),bytes+=found}return bytes}},setupOutputTypes=function(){var prefixedType=function(prefix,calcPadding){return function(type){var padding,expected=prefix;return 0!==type.indexOf(expected)?-1:(padding=calcPadding(type,expected),2*padding)}},namedType=function(name,padding){return function(type){return name===type?2*padding:-1}},formatInt=function(value){return value.length<=8?+parseInt(value,16):hexToDec(value)},formatHash=function(value){return\"0x\"+value},formatBool=function(value){return\"1\"===value?!0:!1},formatString=function(value){return web3.toAscii(value)};return[{padding:prefixedType(\"uint\",calcBitPadding),format:formatInt},{padding:prefixedType(\"int\",calcBitPadding),format:formatInt},{padding:prefixedType(\"hash\",calcBitPadding),format:formatHash},{padding:prefixedType(\"string\",calcBytePadding),format:formatString},{padding:prefixedType(\"real\",calcRealPadding),format:formatInt},{padding:prefixedType(\"ureal\",calcRealPadding),format:formatInt},{padding:namedType(\"address\",20)},{padding:namedType(\"bool\",1),format:formatBool}]},outputTypes=setupOutputTypes(),fromAbiOutput=function(json,methodName,output){var result,method,i,padding,j,res,formatter,index=findMethodIndex(json,methodName);if(-1!==index){for(output=output.slice(2),result=[],method=json[index],i=0;i<method.outputs.length;i++){for(padding=-1,j=0;j<outputTypes.length&&-1===padding;j++)padding=outputTypes[j].padding(method.outputs[i].type);-1!==padding&&(res=output.slice(0,padding),formatter=outputTypes[j-1].format,result.push(formatter?formatter(res):\"0x\"+res),output=output.slice(padding))}return result}},inputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(){var params=Array.prototype.slice.call(arguments);return toAbiInput(json,method.name,params)}}),parser},outputParser=function(json){var parser={};return json.forEach(function(method){parser[method.name]=function(output){return fromAbiOutput(json,method.name,output)}}),parser},module.exports={inputParser:inputParser,outputParser:outputParser};",
|
||||
"var AutoProvider=function(userOptions){var options,self,closeWithSuccess,ws;if(!web3.haveProvider()){if(this.sendQueue=[],this.onmessageQueue=[],navigator.qt)return void(this.provider=new web3.providers.QtProvider);userOptions=userOptions||{},options={httprpc:userOptions.httprpc||\"http://localhost:8080\",websockets:userOptions.websockets||\"ws://localhost:40404/eth\"},self=this,closeWithSuccess=function(success){ws.close(),success?self.provider=new web3.providers.WebSocketProvider(options.websockets):(self.provider=new web3.providers.HttpRpcProvider(options.httprpc),self.poll=self.provider.poll.bind(self.provider)),self.sendQueue.forEach(function(payload){self.provider(payload)}),self.onmessageQueue.forEach(function(handler){self.provider.onmessage=handler})},ws=new WebSocket(options.websockets),ws.onopen=function(){closeWithSuccess(!0)},ws.onerror=function(){closeWithSuccess(!1)}}};AutoProvider.prototype.send=function(payload){return this.provider?void this.provider.send(payload):void this.sendQueue.push(payload)},Object.defineProperty(AutoProvider.prototype,\"onmessage\",{set:function(handler){return this.provider?void(this.provider.onmessage=handler):void this.onmessageQueue.push(handler)}}),module.exports=AutoProvider;",
|
||||
"var abi,contract;abi=require(\"./abi\"),contract=function(address,desc){var inputParser=abi.inputParser(desc),outputParser=abi.outputParser(desc),contract={};return desc.forEach(function(method){contract[method.name]=function(){var params=Array.prototype.slice.call(arguments),parsed=inputParser[method.name].apply(null,params),onSuccess=function(result){return outputParser[method.name](result)};return{call:function(extra){return extra=extra||{},extra.to=address,extra.data=parsed,web3.eth.call(extra).then(onSuccess)},transact:function(extra){return extra=extra||{},extra.to=address,extra.data=parsed,web3.eth.transact(extra).then(onSuccess)}}}}),contract},module.exports=contract;",
|
||||
"function formatJsonRpcObject(object){return{jsonrpc:\"2.0\",method:object.call,params:object.args,id:object._id}}function formatJsonRpcMessage(message){var object=JSON.parse(message);return{_id:object.id,data:object.result,error:object.error}}var HttpRpcProvider=function(host){this.handlers=[],this.host=host};HttpRpcProvider.prototype.sendRequest=function(payload,cb){var data=formatJsonRpcObject(payload),request=new XMLHttpRequest;request.open(\"POST\",this.host,!0),request.send(JSON.stringify(data)),request.onreadystatechange=function(){4===request.readyState&&cb&&cb(request)}},HttpRpcProvider.prototype.send=function(payload){var self=this;this.sendRequest(payload,function(request){self.handlers.forEach(function(handler){handler.call(self,formatJsonRpcMessage(request.responseText))})})},HttpRpcProvider.prototype.poll=function(payload,id){var self=this;this.sendRequest(payload,function(request){var parsed=JSON.parse(request.responseText);!parsed.error&&(parsed.result instanceof Array?0!==parsed.result.length:parsed.result)&&self.handlers.forEach(function(handler){handler.call(self,{_event:payload.call,_id:id,data:parsed.result})})})},Object.defineProperty(HttpRpcProvider.prototype,\"onmessage\",{set:function(handler){this.handlers.push(handler)}}),module.exports=HttpRpcProvider;",
|
||||
|
2
dist/ethereum.min.js
vendored
2
dist/ethereum.min.js
vendored
File diff suppressed because one or more lines are too long
61
lib/abi.js
61
lib/abi.js
@ -54,17 +54,44 @@ var padLeft = function (string, chars) {
|
||||
return new Array(chars - string.length + 1).join("0") + string;
|
||||
};
|
||||
|
||||
var calcBitPadding = function (type, expected) {
|
||||
var value = type.slice(expected.length);
|
||||
if (value === "") {
|
||||
return 32;
|
||||
}
|
||||
return parseInt(value) / 8;
|
||||
};
|
||||
|
||||
var calcBytePadding = function (type, expected) {
|
||||
var value = type.slice(expected.length);
|
||||
if (value === "") {
|
||||
return 32;
|
||||
}
|
||||
return parseInt(value);
|
||||
};
|
||||
|
||||
var calcRealPadding = function (type, expected) {
|
||||
var value = type.slice(expected.length);
|
||||
if (value === "") {
|
||||
return 32;
|
||||
}
|
||||
var sizes = value.split('x');
|
||||
for (var padding = 0, i = 0; i < sizes; i++) {
|
||||
padding += (sizes[i] / 8);
|
||||
}
|
||||
return padding;
|
||||
};
|
||||
|
||||
var setupInputTypes = function () {
|
||||
// @param prefix is the string prefix of the type
|
||||
// @param bitsInNumber is number of bits per number in type
|
||||
var prefixedType = function (prefix, bitsInNumber) {
|
||||
|
||||
var prefixedType = function (prefix, calcPadding) {
|
||||
return function (type, value) {
|
||||
var expected = prefix;
|
||||
if (type.indexOf(expected) !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var padding = parseInt(type.slice(expected.length)) / 8 * bitsInNumber;
|
||||
var padding = calcPadding(type, expected);
|
||||
if (typeof value === "number")
|
||||
value = value.toString(16);
|
||||
else if (typeof value === "string")
|
||||
@ -92,10 +119,12 @@ var setupInputTypes = function () {
|
||||
};
|
||||
|
||||
return [
|
||||
prefixedType('uint', 1),
|
||||
prefixedType('int', 1),
|
||||
prefixedType('hash', 1),
|
||||
prefixedType('string', 8),
|
||||
prefixedType('uint', calcBitPadding),
|
||||
prefixedType('int', calcBitPadding),
|
||||
prefixedType('hash', calcBitPadding),
|
||||
prefixedType('string', calcBytePadding),
|
||||
prefixedType('real', calcRealPadding),
|
||||
prefixedType('ureal', calcRealPadding),
|
||||
namedType('address', 20),
|
||||
namedType('bool', 1, formatBool),
|
||||
];
|
||||
@ -129,16 +158,14 @@ var toAbiInput = function (json, methodName, params) {
|
||||
|
||||
var setupOutputTypes = function () {
|
||||
|
||||
// @param prefix is the string prefix of the type
|
||||
// @param bitsInNumber is number of bits per number in type
|
||||
var prefixedType = function (prefix, bitsInNumber) {
|
||||
var prefixedType = function (prefix, calcPadding) {
|
||||
return function (type) {
|
||||
var expected = prefix;
|
||||
if (type.indexOf(expected) !== 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var padding = parseInt(type.slice(expected.length)) / 8 * bitsInNumber;
|
||||
var padding = calcPadding(type, expected);
|
||||
return padding * 2;
|
||||
};
|
||||
};
|
||||
@ -166,10 +193,12 @@ var setupOutputTypes = function () {
|
||||
};
|
||||
|
||||
return [
|
||||
{ padding: prefixedType('uint', 1), format: formatInt },
|
||||
{ padding: prefixedType('int', 1), format: formatInt },
|
||||
{ padding: prefixedType('hash', 1), format: formatHash },
|
||||
{ padding: prefixedType('string', 8), format: formatString },
|
||||
{ padding: prefixedType('uint', calcBitPadding), format: formatInt },
|
||||
{ padding: prefixedType('int', calcBitPadding), format: formatInt },
|
||||
{ padding: prefixedType('hash', calcBitPadding), format: formatHash },
|
||||
{ padding: prefixedType('string', calcBytePadding), format: formatString },
|
||||
{ padding: prefixedType('real', calcRealPadding), format: formatInt },
|
||||
{ padding: prefixedType('ureal', calcRealPadding), format: formatInt },
|
||||
{ padding: namedType('address', 20) },
|
||||
{ padding: namedType('bool', 1), format: formatBool }
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user