Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ethers refactor #100

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
CI: true
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
0xGabi marked this conversation as resolved.
Show resolved Hide resolved
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ and
}]
```

Note you can also use [Human-Redable abis](https://blog.ricmoo.com/human-readable-contract-abis-in-ethers-js-141902f4d917). For the above example that would be:

```json
["function setAge(uint256 numYears) public view"]
```
---

Write a simple tool using radspec to interpret this:

```js
Expand All @@ -88,7 +95,7 @@ radspec.evaluate(expression, call)
.then(console.log) // => "Set the tree age to 10 years"
```

See more examples [here](examples) and in the [tests](test/examples/examples.js).
Or see more examples [here](examples) and in the [tests](test/examples/examples.js).

Please let us know if there's anything else you'd like Radspec to be able to evaluate by filing an [issue](https://github.com/aragon/radspec/issues/new)!

Expand Down
18 changes: 4 additions & 14 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,11 @@ Evaluate a radspec expression (`source`) for a transaction (`call`)

- `source` **[string][7]** The radspec expression
- `call` **[Object][6]** The call that determines the bindings for this evaluation
- `call.abi` **[Array][11]** The ABI used to decode the transaction data
- `call.abi` **[Array][11]** The ABI used to decode the transaction data. Supports [JSON and Human-Readable formats][12].
- `call.transaction` **[Object][6]** The transaction to decode for this evaluation
- `call.transaction.to` **[string][7]** The destination address for this transaction
- `call.transaction.data` **[string][7]** The transaction data
- `options` **[Object][6]?** An options object (optional, default `{}`)
- `options.ethNode` **[string][7]?** The URL to an Ethereum node

**Examples**

Expand All @@ -67,18 +66,7 @@ import radspec from 'radspec'

const expression = 'Will multiply `a` by 7 and return `a * 7`.'
const call = {
abi: [{
name: 'multiply',
constant: false,
type: 'function',
inputs: [{
name: 'a',
type: 'uint256'
}],
outputs: [{
name: 'd',
type: 'uint256'
}]
abi: ['function multiply(uint256 a) public view returns(uint256)']
}],
transaction: {
to: '0x8521742d3f456bd237e312d6e30724960f72517a',
Expand Down Expand Up @@ -113,3 +101,5 @@ Returns **[Promise][10]<[string][7]>** The result of the evaluation
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise

[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[12]: https://docs-beta.ethers.io/api/utils/abi/interface/#Interface--creating-instances
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This is a list of examples using radspec.

- [Basic](basic): Perform some basic math in a radspec expression and evaluate it with a transaction.
- [User Helpers](user-helpers): Use custom functions in randspec expressions.
- [Web3 Calls](web3-calls): Showcasing radspec's support for calls to external contracts
- [Contract Calls](contract-calls): Showcasing radspec's support for calls to external contracts
14 changes: 1 addition & 13 deletions examples/basic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,7 @@ import * as radspec from '../../src'

const expression = 'Will multiply `a` by 7 and return `a * 7`.'
const call = {
abi: [{
name: 'multiply',
constant: false,
type: 'function',
inputs: [{
name: 'a',
type: 'uint256'
}],
outputs: [{
name: 'd',
type: 'uint256'
}]
}],
abi: ['function multiply(uint256 a) public view returns(uint256)'],
transaction: {
data: '0xc6888fa1000000000000000000000000000000000000000000000000000000000000007a'
}
Expand Down
28 changes: 2 additions & 26 deletions examples/web3-calls/index.js → examples/contract-calls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,7 @@ const expressions = [
{
expression: 'Allocate `_amount _token.symbol(): string`.',
call: {
abi: [{
name: 'allocate',
constant: false,
type: 'function',
inputs: [{
name: '_token',
type: 'address'
}, {
name: '_amount',
type: 'uint256'
}],
outputs: []
}],
abi: ['function allocate(address _token, uint256 _amount) public view'],
transaction: {
data: '0xb78b52df000000000000000000000000960b236a07cf122663c4303350609a66a7b288c00000000000000000000000000000000000000000000000000000000000000064'
}
Expand All @@ -25,19 +13,7 @@ const expressions = [
{
expression: 'Send `_amount` wei to `(_token.controller(): address).sale(): address` to buy `_token.symbol(): string`',
call: {
abi: [{
name: 'allocate',
constant: false,
type: 'function',
inputs: [{
name: '_token',
type: 'address'
}, {
name: '_amount',
type: 'uint256'
}],
outputs: []
}],
abi: ['function allocate(address _token, uint256 _amount) public view'],
transaction: {
data: '0xb78b52df000000000000000000000000960b236a07cf122663c4303350609a66a7b288c00000000000000000000000000000000000000000000000000000000000000064'
}
Expand Down
22 changes: 5 additions & 17 deletions examples/user-helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
import { ethers } from 'ethers'

import * as radspec from '../../src'
import web3Utils from 'web3-utils'

const expression = '`@toUtf8(gretting)` world.'
const expression = '`@toUtf8(greeting)` world.'
const call = {
abi: [
{
name: 'sayHi',
constant: false,
type: 'function',
inputs: [
{
name: 'gretting',
type: 'bytes'
}
],
outputs: []
}
],
abi: ['function sayHi(bytes greeting) public'],
transaction: {
data: '0x2e8dedd00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000548656c6c6f000000000000000000000000000000000000000000000000000000'
}
Expand All @@ -26,7 +14,7 @@ const options = {
toUtf8: () => async (hex) => {
return {
type: 'string',
value: web3Utils.toUtf8(hex)
value: ethers.toUtf8String(hex)
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.0",
"@babel/register": "^7.0.0",
"ava": "^1.0.0-rc.1",
"@babel/register": "^7.10.1",
"ava": "^3.8.2",
"babel-eslint": "^10.0.1",
"babel-preset-minify": "^0.5.0",
"codecov": "^3.6.5",
"documentation": "^9.0.0-alpha.0",
"documentation": "^13.0.1",
"nyc": "^14.1.1",
"standard": "^12.0.1"
},
"dependencies": {
"@babel/runtime": "^7.1.2",
"bn.js": "^4.11.8",
"date-fns": "2.0.0-alpha.22",
"web3-eth": "^1.2.1",
"web3-eth-abi": "^1.2.1",
"web3-utils": "^1.2.1"
"dayjs": "^1.8.28",
"ethers": "^5.0.0-beta.190"
},
"ava": {
"require": [
Expand Down
1 change: 1 addition & 0 deletions src/defaults.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const DEFAULT_ETH_NODE = 'wss://mainnet.eth.aragon.network/ws'
export const DEFAULT_API_4BYTES = 'https://www.4byte.directory/api/v1/signatures/'
Loading