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
Compile external code snippets #1272
Comments
Increasing priority as it seems that go-ethereum just implemented the required RPC interface. |
An idea how to make this a more integrated language feature:
A
How this maps into the JSON interface: currently there is an output member |
Sounds good! I would prefer a little less syntax, though - we do not really need two nested elements: The name of the snippet can be the name of the function. Perhaps
although it should perhaps be a bit more obvious that it is a snippet and pulls in the context from Token. |
On one side I agree that it looks overkill, but:
In the above format the snippet could be extended with named functions which can be called from within the entry point (
Although this could easily become complex. |
Note that I really want to get this down to a javascript UI expression that looks something like: var c = ... ; // the compiled contract, only need to compile it once for the full app
var bal = await c.eval("m_balance[0x123]"); // This is compiled on the fly (but cached) So the idea is to get seamless interoperability between Solidity and the frontend code. This means that the name of the snippet does not have to be seen by the programmer and is only relevant to address it in the compiler interface. Oh and I hope that you can soon use inline-defined functions anyway. So I think we can get this down to expressions by also allowing snippet $someassignedname for Token {
m_balance[0x123]
} and then snippet $someassignedname2(uint) returns (uint8) for Token {
return 8 * m_balance[0x123];
} but also snippet $someassignedname2 for Token {
function namedFunction(uint) returns (uint8) {
return 8 * m_balance[0x123];
}
} Perhaps this can be combined with inline functions in general... |
I think that has no relation, because it is up to The single-line query (albeit I'm not sure that single lines will be very useful)
could be translated to
by Although I'm not sure it makes sense for the compiler to figure out the type conversions. |
I don't think solc-js can do it, because it does not know the type of the expression. Because of that I think this has to be a compiler feature. On the other hand, web3.js cannot work with the result because it does not know how to decode it without the type. |
Exactly, that's why I'm not sure it should be a single line as above. Is that too much to write? It is expressive at least.
Also I'm not sure these snippets would be single line in the first case, the above example is kind of broken, because getting the balance is usually available as a getter anyway. |
Removing |
This seems to be revived in light of ethereum/go-ethereum#19836, should we continue the syntax discussion here? We'd basically need some syntax to compile the code supplied for such a new eth_call, right? Then solidity code using this syntax could e.g. be compiled via standardjson and then passed on to the eth_call directly? This all sounds pretty cool :-). Syntax wise I like @axic's proposal - I'd generally think of this as a special kind of "external inheritance". So I'm in favour of
When actually using this for eth_call we could in fact append a function signature and an argument encoding to the produced bytecode similar to constructor arguments for contracts and that way execute some specific function in the snippet code. That way one could compile one snippet containing a lot of functions with arguments, etc. and call any of them. Code size won't really matter, right? |
It would be great if we could also have a short form like |
I'm not so sure anymore we really need the surrounding context to be in text format. I cannot really imagine snippets to be used without a more complex framework that accesses the compiler. Furthermore, if we just use During the discussion in #10825 it came up that it might be useful to parse snippets in the context of functions (without the need for generating code) and output the AST, so it could be useful to open up the context a bit wider. If we have more support from a framework, we could specify this as a feature that assumes it is used via standard-json (or maybe even the LSP). This means snippet compilation requests could be a section in the standard-json (or an equivalent in the commandline) that look like:
|
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
This is the solidity part of EIP 144
This feature will give users the ability to compile code snippet in the context of an existing contract without necessarily having to combine it with the contract itself.
If the compiler is in a state where source code is parsed and type checked, we can call
compileSnippet(code, contract)
, wherecode
is valid solidity code - either an expression or an internal function - in the context ofcontract
. This function returns EVM bytecode that, when executed, behaves like the snippet.This should also be supported in the generic json input #1129 where the target contract key could be used for this.
The text was updated successfully, but these errors were encountered: