Comparing version 0.1.0 to 0.1.1
@@ -7,3 +7,2 @@ "use strict"; | ||
var del = require("del"); | ||
var keythereum = require("./"); | ||
@@ -10,0 +9,0 @@ gulp.task("clean", function (callback) { |
27
index.js
@@ -120,2 +120,29 @@ /** | ||
is_hex: function (str) { | ||
if (str && str.constructor === String) { | ||
if (str.slice(0, 1) === '-' && str.length > 1) { | ||
return /^[0-9A-F]+$/i.test(str.slice(1)); | ||
} | ||
return /^[0-9A-F]+$/i.test(str); | ||
} | ||
return false; | ||
}, | ||
strip_0x: function (str) { | ||
var h = str; | ||
if (h === "-0x0" || h === "0x0") { | ||
return "0"; | ||
} | ||
if (h.slice(0, 2) === "0x" && h.length > 2) { | ||
h = h.slice(2); | ||
} else if (h.slice(0, 3) === "-0x" && h.length > 3) { | ||
h = '-' + h.slice(3); | ||
} | ||
if (this.is_hex(h)) { | ||
return h; | ||
} else { | ||
return str; | ||
} | ||
}, | ||
prefix_hex: function (n) { | ||
@@ -122,0 +149,0 @@ if (n !== undefined && n !== null) { |
{ | ||
"name": "augur-abi", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Contract ABI serialization", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha test/*", | ||
"test": "mocha test/abi.js", | ||
"lint": "jshint index.js && jshint test", | ||
@@ -38,2 +38,3 @@ "coverage": "istanbul cover -x **/lib/** ./node_modules/mocha/bin/_mocha test/abi.js" | ||
"it-each": "^0.3.1", | ||
"jshint": "^2.8.0", | ||
"mocha": "^2.2.5", | ||
@@ -40,0 +41,0 @@ "uglify-js": "^2.4.24" |
augur-abi | ||
========= | ||
Standalone module for Ethereum contract ABI data serialization. | ||
[](https://travis-ci.org/AugurProject/augur-abi) | ||
[](https://coveralls.io/github/AugurProject/augur-abi?branch=master) | ||
[](https://nodei.co/npm/augur-abi/) | ||
augur-abi is a standalone JavaScript module that provides Ethereum contract ABI data serialization methods. [ABI encoding](https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI) is needed to invoke functions on Ethereum smart contracts. | ||
This module presently supports only Serpent contracts; it's my intention to add Solidity data type support when I have time! | ||
Installation | ||
------------ | ||
$ npm install augur-abi | ||
Usage | ||
----- | ||
To use augur-abi in Node.js, just `require` it: | ||
```javascript | ||
var augur_abi = require("augur-abi"); | ||
``` | ||
A minified, browserified file `dist/augur-abi.min.js` is included for use in the browser. Including this file simply attaches the `augur_abi` object to `window`: | ||
```html | ||
<script src="dist/augur-abi.min.js" type="text/javascript"></script> | ||
``` | ||
The `encode` method encodes the full ABI data (prefix + parameters) needed for a contract function call. For example, to encode a method named `double` that takes a single integer parameter with a value of 3: | ||
```javascript | ||
var encoded = augur_abi.encode({ | ||
method: "double", | ||
signature: "i", | ||
params: [3] | ||
}); | ||
// encoded: | ||
'0x6ffa1caa0000000000000000000000000000000000000000000000000000000000000003' | ||
``` | ||
`encoded` is the concatenation of the method's prefix `0x6ffa1caa`, which is derived from the name of the method `"double"` and its signature `"i"`, and the encoded parameter value, `[3]`. | ||
"Signature" refers to the short-form Serpent parameter signature, which allows `i` (int256), `a` (variable-sized int256 array) and `s` (variable-length string/bytes). For example, a method which takes parameter types int256, string, int256, int256, int256, array would have signature `isiiia`. | ||
Tests | ||
----- | ||
Unit tests are in the `test` directory, and can be run with mocha: | ||
$ npm test |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1015106
20477
49
10