Conversation
| public static UInt160 HexStringToUInt160(this string value) | ||
| { | ||
| var hexString = value; | ||
| if (value.Length == 42 && value.Substring(0, 2) == "0x") | ||
| hexString = value.Substring(2, 40); | ||
| if (hexString.Length != 40) | ||
| throw new Exception(); | ||
| byte[] result = new byte[20]; | ||
| for (int i = 0; i < 20; i++) | ||
| { | ||
| var str = hexString.Substring(i * 2, 2); | ||
| var byte1 = str.Substring(0, 1).StringToByte(); | ||
| var byte2 = str.Substring(1, 1).StringToByte(); | ||
| var byte3 = byte1 << 4; | ||
| var res = (byte)(byte3 + byte2); | ||
| result[i] = res; | ||
| } | ||
| return new UInt160(result.Reverse()); | ||
| } |
There was a problem hiding this comment.
I think this is too complicated for a contract and may cost a huge amount of GAS.
There was a problem hiding this comment.
Or we can add a InteropService?
There was a problem hiding this comment.
For static variables, we can do the conversion in the compiler.
But for function parameters, we can't get the parameter values at compile time.
There was a problem hiding this comment.
On the other hand, the conversion is not used too often, so the GAS consumption is acceptable.
There was a problem hiding this comment.
We can't use a UInt256 as a contract parameter.
There was a problem hiding this comment.
We can't use a UInt256 as a contract parameter.
Why?
There was a problem hiding this comment.
You mean use public static UInt256 TestUInt256(UInt256 str)
and we transfer a String as a parameter?
There was a problem hiding this comment.
We can't use a
UInt256as a contract parameter.
Doesn't Neo already support using UInt160/256 as a contract parameter type? https://github.com/neo-project/neo/blob/master/src/neo/SmartContract/ContractParameterType.cs#L12
|
What's the progress on this? Can we get this in for Preview 4 neo-project/neo#1936? |
| { | ||
| public class Contract_UInt : SmartContract.Framework.SmartContract | ||
| { | ||
| public static UInt160 TestUInt160(String str) |
There was a problem hiding this comment.
We should have tests that take a UInt160/256 as an input parameter too
|
We should also add ECPoint support to smart contract framework. It behaves similarly to UInt160/256. However, we might want to do this as a separate PR |
| case "System.Numerics.BigInteger": return "Integer"; | ||
| case "System.Byte[]": return "ByteArray"; | ||
| case "System.Byte[]": | ||
| case "Neo.SmartContract.Framework.UInt160": |
There was a problem hiding this comment.
Why are we returning UInt160/256 as a byte array?
| HexToBytes, | ||
| ToScriptHash, | ||
| ToBigInteger, | ||
| ToUInt160, |
|
As #362, Performing conversion through VM is expensive, so we can close it. |
Close #208