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

Implement @radspec helper #55

Merged
merged 10 commits into from Feb 22, 2019
Merged

Implement @radspec helper #55

merged 10 commits into from Feb 22, 2019

Conversation

izqui
Copy link
Contributor

@izqui izqui commented Feb 4, 2019

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.

@izqui izqui requested a review from sohkai February 4, 2019 14:57
@sohkai sohkai added this to the A1 Sprint: 4.1 milestone Feb 4, 2019
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')
Copy link
Contributor

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.

Copy link
Contributor Author

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.

if (!fn) {
return {
type: 'string',
value: `Unknown (${methodId})`
Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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

*/
async (addr, data) => {
// lazily import radspec to avoid a dependency cycle
const { evaluateRaw } = require('../index')
Copy link
Contributor

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.

Copy link
Contributor Author

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

{
"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`"
Copy link
Contributor

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
@izqui izqui changed the title [WIP] Implement @radspec helper Implement @radspec helper Feb 12, 2019
@izqui
Copy link
Contributor Author

izqui commented Feb 12, 2019

All good from my side. @sohkai PTAL!

@izqui izqui mentioned this pull request Feb 12, 2019
5 tasks
@sohkai
Copy link
Contributor

sohkai commented Feb 12, 2019

@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.

@sohkai sohkai merged commit f020a29 into master Feb 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants