-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
ABI: enums, structs and timestamps #50
Comments
About |
As per my comment on #47 I still think enum's should be represented as
|
|
Note that recursive data structures are supported by the encoding, but not by the signature and are thus not allowed for now. |
@VoR0220 suggested that the types of json fields should be fixed, i.e.
|
@axic
In the above example, |
I would very much prefer it if It is unclear to me why |
@Souptacular What, if anything, can be done to get this EIP moved forward? It doesn't seem to have much/any active discussion going on, but has been sitting for months. The lack of structs as part of the ABI combined with 16 variable stack limit is really hurting Augur's port to Solidity from Serpent. |
+1 on this. The contract ABI for 0x's |
@MicahZoltu The struct part is being implemented, no need to push this EIP. timestamps and enums or on hold because of the problem mentioned above and the fact that adding support for enums is a breaking change in the ABI for Solidity. |
@MicahZoltu it maps to the YP:
|
So this is an issue with the EVM considering a timetstamp to be unsigned? Unix time is pretty universally considered to be signed since it centers on a point in time in the relatively near past. |
@chriseth Would it make sense to create an EIP PR for the struct part of this so that it can be tracked and eventually merged without having to wait on the other aspects of this EIP? In general I'm a fan of small targeted EIPs over monolithic bucket EIPs like this. |
@MicahZoltu yeah, we should probably write that up. Here is the complete specification that is currently being implemented by Solidity: https://solidity.readthedocs.io/en/develop/abi-spec.html |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
Migration from ethereum#7873 Co-authored-by: Sam Wilson <[email protected]>
This is a combination of several already existing issues about extensions to the ABI. It subsumes #21, #46 and #47.
Time Units
Add the following new elementary types to the ABI:
timestamp
,timespan
Encoding: identical to
int256
for bothSemantics:
timestamp
: point in time as seconds since the unix epoch (Discussion: As we have int256 we could also make it milli or microseconds)timespan
: a span of time in seconds (or smaller unit as above)Enums
At any point in an interface definition where an elementary type is allowed, the following is also allowed:
(A|)
,(A|B)
,(A|B|C)
, ... forA
,B
,C
being from[_$a-zA-Z][_$a-zA-Z0-9]*
Such a type is called an "enum" and the identifiers
A
,B
,C
, ... are encoded as 0, 1, 3, ..., respectively. This means that languages and user interfaces should prefer names over numeric values, but the names are not visible in the binary encoding and the type is treated identical touint256
.Structs
Structs allow several values to be grouped together. This is especially useful if arrays of structs are created. If you look closely, you notice that the set of return values or arguments is already a struct now and the notation will be consistent with this proposal.
Change to function signatures as needed for function identifiers
As function signatures omit parameter names and only specify their types, and struct types should be a generalisation of a list of parameters / return parameters, the following change is proposed:
At any point where a type is allowed, a list of types in the from
(type1,type2,..)
is permitted, to the extent where there may be only one type. Examples:function f((uint256[],uint8,(string,bytes20),(string))[20])
The function takes an array of 20 objects, each of which is of the following type:
uint256
s,uint8
,string
and abytes20
string
Note that this notation is (hopefully) bijective.
Encoding
Structs are actually already part of the encoding specification, hidden in this comment. The gist is that the way arrays are encoded does not rely on the fact that the encoding of every element of the array is the same, so we can encode structs in just the same way as we encode arrays. This means that the encoding of a struct with only fixed-size types is the concatenation of the encodings of its elements. If there are dynamic types, their dynamic part is added at the end and the offset to the dynamic part is calculated from the start of the struct. This means that the offset to the string data is computed in a different way for
(uint256,string)
and(uint256,(string))
.JSON-formatted abi:
inputs
andoutputs
is an array of objects with propertiesname
(optional),type
,subtype
(optional, new) andindexed
(for events).type
can be any of the already supported types ("uint256"
,"uint256[10][]"
, ...), but additional values are permitted:"[]"
or"[k]"
for some integerk
(or a sequence of those, i.e.[][10][]
): If this is used, the object is of array type and the type of the elements of the arrays is specified under the propertysubtype
.If the
subtype
property is used, its value cannot be"[]"
or"[k]"
, but it can be an array of length 1 whose element models the type one deeper in the array hierarchy.Example:
The signature
function f(abc: uint, def: (a: uint, b: (c: string, d: uint16)[10])))
is translated into json-abi as follows:The text was updated successfully, but these errors were encountered: