-
Notifications
You must be signed in to change notification settings - Fork 146
Added extra dictionary mapping from string -> uint #62
Conversation
An extra dictionary from string to uint will help complementing interop function accesses. That will help implementing it on Neo: neo-project/neo#264 This is a small continuation of this PR: neo-project#61
@erikzhang Sorry for not thinking that before.. this PR will help a lot to efficiently implement function recognition on Neo project. |
Calculating prices depending on neo-vm dictionary: neo-project/neo-vm#62
src/neo-vm/InteropService.cs
Outdated
|
||
public uint InteropHash(string method) | ||
{ | ||
return dictionaryStr[method]; |
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.
TryGet or if you pass a wrong value you will get an exception
src/neo-vm/InteropService.cs
Outdated
} | ||
|
||
internal bool Invoke(byte[] method, ExecutionEngine engine) | ||
{ | ||
uint hash = method.Length == 4 | ||
? BitConverter.ToUInt32(method, 0) | ||
: method.ToInteropMethodHash(); | ||
: dictionaryStr[method]; |
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.
Here we should choose in wich dictionary we need to looking for, otherwise we can get exceptions too
src/neo-vm/InteropService.cs
Outdated
@@ -6,6 +6,12 @@ namespace Neo.VM | |||
public class InteropService | |||
{ | |||
private Dictionary<uint, Func<ExecutionEngine, bool>> dictionary = new Dictionary<uint, Func<ExecutionEngine, bool>>(); | |||
private Dictionary<string, uint> dictionaryStr = new Dictionary<string, uint>(); |
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.
Dictionary<string, Func<ExecutionEngine, bool>> dictionaryStr = new Dictionary<string, Func<ExecutionEngine, bool>>();
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.
In this case, I will need string to.m uint, to be able to compare it inside Neo project.... example, if user passes uint 1000 I need to know if its a Storage.Put, to know the price.
Lines 41 to 47 in e074f00
Why not add the dictionary at here? Then we can use |
@erikzhang I think I finally understood what you meant by using this Helper class... I used the dictionary here to act as a caching/memoisation for future accesses, so it will only take time during first access. |
src/neo-vm/Helper.cs
Outdated
return hash; | ||
hash = ToInteropMethodHash(Encoding.ASCII.GetBytes(method)); | ||
method_hashes[method] = hash; | ||
return hash; |
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.
Much more readable.
Now it should work perfectly. |
An extra dictionary from string to uint will help complementing interop function accesses. That will help implementing it on Neo: neo-project/neo#264
This is a small continuation of this PR: #61