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
Implement @radspec helper #55
Conversation
src/evaluator/index.js
Outdated
this.ast = ast | ||
this.bindings = bindings | ||
this.eth = new Eth(ethNode || 'https://mainnet.infura.io') | ||
this.eth = eth || new Eth(ethNode || 'https://mainnet.infura.io') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, are we ever passing eth
around? It should just be ethNode
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helpers have the eth
object so they can do network requests, but they don't have the ethNode
. I guess there is a method to get it, but this seemed cleaner to me.
src/helpers/radspec.js
Outdated
if (!fn) { | ||
return { | ||
type: 'string', | ||
value: `Unknown (${methodId})` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could also add the address here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense for errors, although radspec strings don't print anything about the target contract.
How I see this being used in the Actor's execute for example is: Execute '@radspec(target, data)' on 'target'
const functions = processFunctions(require('../data/knownFunctions')) | ||
|
||
// Get method ID | ||
const methodId = data.substr(0, 10) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do some error checking that the data is formatted correctly
src/helpers/radspec.js
Outdated
*/ | ||
async (addr, data) => { | ||
// lazily import radspec to avoid a dependency cycle | ||
const { evaluateRaw } = require('../index') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.__. not sure how well this is going to fly with builders like parcel. Will need to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷♀️ cleaner way I could think of that didn't require a major re-architecture
src/data/knownFunctions.json
Outdated
{ | ||
"setOwner(address)": "Set `$1` as the new owner", | ||
"setOwner(bytes32,address)": "Set `$2` as the new owner of the `$1` node", | ||
"transfer(address,address,uint256)": "Transfer `@tokenAmount($1, $3)` to `$2`" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not generally against this idea, but find it a bit unnecessary.
Instead of re-evaluating radspec, we could just run a javascript function here with the arguments to build the string. We could inject the web3 instance as well, if we really wanted to allow web3 calls.
* @radspec: add fallback to Parity on-chain signature registry * Style comments * Update methodRegistry.js
All good from my side. @sohkai PTAL! |
@izqui Will test locally to see if the recursive require becomes a problem for frontends. Otherwise, I think we should still fix #55 (comment); the relative brittleness of how we handle radspec errors means the more error checking we do, the better. |
The
@radspec
helper allows to recursively execute radspec as part of a radspec string. These strings should be either included in the radspec package or loaded from a trusted registry, as the recursive nature of this feature could be used to crash radspec with an infinite loop.