solidity-to-abi
Advanced tools
Comparing version 1.0.2 to 1.0.4
@@ -17,1 +17,8 @@ # 1.0.0 -- Unit testing, Module Complete, Published | ||
14. Publish to npm | ||
# 1.0.4 -- Support for Constant / Event Type and Indexed Events | ||
1. Event supported | ||
2. Constant | ||
3. Payable support | ||
4. Indexed Types |
@@ -19,10 +19,11 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.solidityToABI = f()}})(function(){var define,module,exports;return (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 type = inputData[0]; | ||
var name = inputData[1] || ''; | ||
var indexed = inputData.length === 3 && inputData.indexOf('indexed') !== -1; | ||
var name = indexed ? inputData[2] || '' : inputData[1] || ''; | ||
// if type exists | ||
if (type !== '' && typeof type !== 'undefined') { | ||
returnArray.push({ | ||
returnArray.push(Object.assign(indexed ? { indexed: indexed } : {}, { | ||
type: type, | ||
name: name | ||
}); | ||
})); | ||
} | ||
@@ -36,2 +37,4 @@ }); | ||
function solidityToABI(methodInterface) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
// count open and clsoed | ||
@@ -64,4 +67,11 @@ var methodABIObject = {}; | ||
methodABIObject.name = methodInterface.slice(0, methodInterface.indexOf('(')); | ||
methodABIObject.type = 'function'; | ||
methodABIObject.constant = false; | ||
methodABIObject.type = options.type || 'function'; | ||
// add payable | ||
if (methodABIObject.type === 'function') { | ||
methodABIObject.payable = options.payable || false; | ||
} | ||
// constant | ||
methodABIObject.constant = options.constant || true; | ||
var methodInputsString = methodInterface.slice(methodInterface.indexOf('(') + 1, methodInterface.indexOf(')')).trim(); | ||
@@ -68,0 +78,0 @@ var methodOutputString = (hasOutputs && methodInterface.slice(methodInterface.lastIndexOf('(') + 1, methodInterface.lastIndexOf(')')) || '').trim(); |
@@ -76,1 +76,5 @@ # User Guide | ||
``` | ||
## Gotchas | ||
- No type checking for solidity input and output types |
{ | ||
"name": "solidity-to-abi", | ||
"version": "1.0.2", | ||
"version": "1.0.4", | ||
"description": "Converts Solidity method interface string to a web3 ABI interface object.", | ||
@@ -57,2 +57,3 @@ "scripts": { | ||
"chai": "^3.5.0", | ||
"child_process": "^1.0.2", | ||
"coveralls": "^2.11.9", | ||
@@ -59,0 +60,0 @@ "cross-env": "^1.0.7", |
@@ -19,10 +19,12 @@ # solidity-to-abi | ||
<!-- Test Coverage --> | ||
<!-- Test Coverage | ||
<a href="https://coveralls.io/r/SilentCicero/solidity-to-abi"> | ||
<img src="https://coveralls.io/repos/github/SilentCicero/solidity-to-abi/badge.svg" alt="Test Coverage" /> | ||
</a> | ||
--> | ||
<!-- NPM Version --> | ||
<a href="https://www.npmjs.org/package/solidity-to-abi"> | ||
<img src="http://img.shields.io/npm/v/solidity-to-abi.svg" alt="NPM version" /> | ||
<img src="http://img.shields.io/npm/v/solidity-to-abi.svg" | ||
alt="NPM version" /> | ||
</a> | ||
@@ -86,3 +88,3 @@ | ||
- [User guide](docs/user-guide.md) - Usage, configuration, FAQ and complementary tools. | ||
- [Developer guide](docs/developer-guide.md) - Contributing to default and writing your own plugins & formatters. | ||
- [Developer guide](docs/developer-guide.md) - Contributing to solidity-to-abi and writing your own plugins & formatters. | ||
@@ -89,0 +91,0 @@ ## Help out |
@@ -14,10 +14,11 @@ // build inputs or outputs array from raw inputs string | ||
const type = inputData[0]; | ||
const name = inputData[1] || ''; | ||
const indexed = inputData.length === 3 && inputData.indexOf('indexed') !== -1; | ||
const name = indexed ? (inputData[2] || '') : inputData[1] || ''; | ||
// if type exists | ||
if (type !== '' && typeof type !== 'undefined') { | ||
returnArray.push({ | ||
returnArray.push(Object.assign(indexed ? { indexed } : {}, { | ||
type, | ||
name, | ||
}); | ||
})); | ||
} | ||
@@ -30,3 +31,3 @@ }); | ||
// parse a solidity method interface | ||
function solidityToABI(methodInterface) { | ||
function solidityToABI(methodInterface, options = {}) { | ||
// count open and clsoed | ||
@@ -59,4 +60,11 @@ const methodABIObject = {}; | ||
methodABIObject.name = methodInterface.slice(0, methodInterface.indexOf('(')); | ||
methodABIObject.type = 'function'; | ||
methodABIObject.constant = false; | ||
methodABIObject.type = options.type || 'function'; | ||
// add payable | ||
if (methodABIObject.type === 'function') { | ||
methodABIObject.payable = options.payable || false; | ||
} | ||
// constant | ||
methodABIObject.constant = options.constant || true; | ||
const methodInputsString = methodInterface.slice(methodInterface.indexOf('(') + 1, methodInterface.indexOf(')')).trim(); | ||
@@ -63,0 +71,0 @@ const methodOutputString = (hasOutputs && methodInterface.slice(methodInterface.lastIndexOf('(') + 1, methodInterface.lastIndexOf(')')) || '').trim(); |
@@ -20,2 +20,18 @@ import { assert } from 'chai'; | ||
it('should convert event with indexed inputs', () => { | ||
const methodABI = solidityToABI('_Application(bytes32 indexed listingHash, uint256 indexed deposit, string data)', { type: 'event' }); | ||
assert.equal(typeof methodABI, 'object'); | ||
assert.equal(methodABI.type, 'event'); | ||
assert.equal(methodABI.outputs.length, 0); | ||
assert.equal(methodABI.inputs.length, 3); | ||
assert.equal(methodABI.name, '_Application'); | ||
assert.equal(methodABI.inputs[0].name, 'listingHash'); | ||
assert.equal(methodABI.inputs[0].type, 'bytes32'); | ||
assert.equal(methodABI.inputs[1].name, 'deposit'); | ||
assert.equal(methodABI.inputs[1].type, 'uint256'); | ||
assert.equal(methodABI.inputs[2].name, 'data'); | ||
assert.equal(methodABI.inputs[2].type, 'string'); | ||
}); | ||
it('should convert double input/output Solidity method to ABI', () => { | ||
@@ -22,0 +38,0 @@ const doubleMethodABI = solidityToABI('anotherMethod(bool _yes, address _addr):(uint256 balance, uint8 num)'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26976
264
137
27