diff options
author | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-14 21:19:54 +0800 |
---|---|---|
committer | Marek Kotewicz <marek.kotewicz@gmail.com> | 2015-01-14 21:19:54 +0800 |
commit | b0a9bbf33a022a5763e62a78dbd7f32af250726c (patch) | |
tree | 74257a4b5aee9911131e553ac6b8a87a5d93994f /dist/ethereum.js | |
parent | 6b2ec231323b62f5dc81c7702940d784fac98966 (diff) | |
download | dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar.gz dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar.bz2 dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar.lz dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar.xz dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.tar.zst dexon-b0a9bbf33a022a5763e62a78dbd7f32af250726c.zip |
next part of abi.js docs
Diffstat (limited to 'dist/ethereum.js')
-rw-r--r-- | dist/ethereum.js | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/dist/ethereum.js b/dist/ethereum.js index 88b132005..9dbb8c818 100644 --- a/dist/ethereum.js +++ b/dist/ethereum.js @@ -36,6 +36,10 @@ var decToHex = function (dec) { return parseInt(dec).toString(16); }; +/// Finds first index of array element matching pattern +/// @param array +/// @param callback pattern +/// @returns index of element var findIndex = function (array, callback) { var end = false; var i = 0; @@ -45,31 +49,39 @@ var findIndex = function (array, callback) { return end ? i - 1 : -1; }; +/// @returns a function that is used as a pattern for 'findIndex' var findMethodIndex = function (json, methodName) { return findIndex(json, function (method) { return method.name === methodName; }); }; +/// @param string string to be padded +/// @param number of characters that result string should have +/// @returns right aligned string var padLeft = function (string, chars) { return new Array(chars - string.length + 1).join("0") + string; }; -/// Setups input formatters for solidity types -/// @returns an array of input formatters -var setupInputTypes = function () { - - var prefixedType = function (prefix) { - return function (type, value) { - return type.indexOf(prefix) === 0; - }; +/// @param expected type prefix (string) +/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false +var prefixedType = function (prefix) { + return function (type) { + return type.indexOf(prefix) === 0; }; +}; - var namedType = function (name, formatter) { - return function (type, value) { - return type === name; - }; +/// @param expected type name (string) +/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false +var namedType = function (name) { + return function (type) { + return name === type; }; +}; + +/// Setups input formatters for solidity types +/// @returns an array of input formatters +var setupInputTypes = function () { var formatInt = function (value) { var padding = 32 * 2; @@ -106,6 +118,11 @@ var setupInputTypes = function () { var inputTypes = setupInputTypes(); +/// Formats input params to bytes +/// @param contract json abi +/// @param name of the method that we want to use +/// @param array of params that will be formatted to bytes +/// @returns bytes representation of input params var toAbiInput = function (json, methodName, params) { var bytes = ""; var index = findMethodIndex(json, methodName); @@ -136,23 +153,6 @@ var toAbiInput = function (json, methodName, params) { /// @returns an array of output formatters var setupOutputTypes = function () { - /// @param expected type prefix (string) - /// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false - var prefixedType = function (prefix) { - return function (type) { - var expected = prefix; - return type.indexOf(expected) === 0; - }; - }; - - /// @param expected type name (string) - /// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false - var namedType = function (name) { - return function (type) { - return name === type; - }; - }; - /// @returns input bytes formatted to int var formatInt = function (value) { return value.length <= 8 ? +parseInt(value, 16) : hexToDec(value); @@ -187,6 +187,11 @@ var setupOutputTypes = function () { var outputTypes = setupOutputTypes(); +/// Formats output bytes back to param list +/// @param contract json abi +/// @param name of the method that we want to use +/// @param bytes representtion of output +/// @returns array of output params var fromAbiOutput = function (json, methodName, output) { var index = findMethodIndex(json, methodName); |