Json smart contract parser#785
Conversation
Codecov Report
@@ Coverage Diff @@
## master #785 +/- ##
==========================================
+ Coverage 36.82% 37.11% +0.28%
==========================================
Files 174 175 +1
Lines 12262 12296 +34
==========================================
+ Hits 4516 4564 +48
+ Misses 7746 7732 -14
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #785 +/- ##
==========================================
+ Coverage 36.82% 37.75% +0.92%
==========================================
Files 174 176 +2
Lines 12262 12439 +177
==========================================
+ Hits 4516 4696 +180
+ Misses 7746 7743 -3
Continue to review full report at Codecov.
|
erikzhang
left a comment
There was a problem hiding this comment.
Neo.Json.Serialize - serialize a StackItem object to a JSON string.
Neo.Json.Deserialize - deserialize a JSON string to a StackItem object.
{"a": [1, "2"]}It will be converted to a Map, whose key is a ByteArray, and value is an Array with 2 elements. The first element is an Integer, and second element is a ByteArray.
neo.UnitTests/UT_JsonParser.cs
Outdated
| var map = (VM.Types.Map)items; | ||
|
|
||
| Assert.IsTrue(map.TryGetValue(new VM.Types.ByteArray(Encoding.UTF8.GetBytes("test")), out var value)); | ||
| Assert.AreEqual(((VM.Types.Integer)value).GetBigInteger(), 123); |
There was a problem hiding this comment.
parsing int to BigInt may be an issue... let's see.
neo/SmartContract/InteropService.cs
Outdated
| public static readonly uint System_Runtime_GetTime = Register("System.Runtime.GetTime", Runtime_GetTime, 0_00000250); | ||
| public static readonly uint System_Runtime_Serialize = Register("System.Runtime.Serialize", Runtime_Serialize, 0_00100000); | ||
| public static readonly uint System_Runtime_Deserialize = Register("System.Runtime.Deserialize", Runtime_Deserialize, 0_00500000); | ||
| public static readonly uint System_Runtime_ParseJon = Register("System.Runtime.ParseJson", Runtime_ParseJson, 100_00000000/*TODO: Compute gast cost*/); |
There was a problem hiding this comment.
I think we should abolish fixed prices on Neo 3.0. One problem less, and one problem we cannot solve without market and consensus nodes.
|
I approved what is now... but I agree Erik's interface is better: |
|
|
||
| private static bool Json_Deserialize(ApplicationEngine engine) | ||
| { | ||
| var json = Encoding.UTF8.GetString(engine.CurrentContext.EvaluationStack.Pop().GetByteArray()); |
There was a problem hiding this comment.
Maybe we need to handle the illegal characters consistently in smart contracts.
There was a problem hiding this comment.
JObject.Parse should deal with this, what do you propose?
There was a problem hiding this comment.
Yes. We should deal with this in JObject.Parse().
|
I am concerned that different languages handle JSON differently and may lead to inconsistencies in smart contracts. We must impose strict restrictions on |
|
Yes, we should be able to parse |
|
|
|
So, do you think maybe Python will not produce exactly the same output as us? We can solve this in the specification, and unit tests. |
|
Yes, we must ensure that it is handled in strict accordance with the JSON specification. |
|
I will do with our json classes |
|
@neo-project/core do you think that there are any pending unit test? we need to ensure the deterministic behaviour |
|
Yes. See the followings:
For example: Some implementation may return
And these limits must be set. |
|
I think other clients should avoid libraries and do their own implementation, according to this, that we should specify in the specifications. |
|
We must use |
|
This is a non-generic version of |
|
I'm afraid you didn't really use |
|
i forget to commit this file xD |
* release-2.10.0 * Update v2.10.0.md (neo-project#785) * Update v2.10.0.md * Update v2.10.0.md * Update and rename v2.10.0.md to v2.10.0 * Update v2.10.0 * update exchange * Introduction for gas related rpc (neo-project#788) Introduction for gas related rpc * add plugin * Update v2.10.0.md * update English files
* release-2.10.0 * Update v2.10.0.md (neo-project#785) * Update v2.10.0.md * Update v2.10.0.md * Update and rename v2.10.0.md to v2.10.0 * Update v2.10.0 * update exchange * add new api * Add new api/gettransactionheight.md * fix fix * Update claimgas.md * Update importkey.md
@shargon is it me or is there no code for the following restrictions?
|
The vm has this limmit. Outside the VM you can use any length. According to the character content. We force strict utf8 now neo/src/neo/IO/Json/JObject.cs Line 83 in d5b962c |
|
Then I'm good. Thanks! :-) |
Related to #779
TODO: max length for items