Closed codingupastorm closed 6 years ago
Update on this:
int, uint, long, and ulong can all be converted to bytes and back in contract code. See https://github.com/stratisproject/StratisBitcoinFullNode/pull/1945
For strings, we can't do to UTF8 and back without Encoding.UTF8 without losing data - see https://gist.github.com/codingupastorm/84ce4e4e17de08898e3ced10d5496e01. Solution at this stage looks like to whitelist Encoding.UTF8.GetBytes()
and GetString()
. We should be able to do hex inline.
Address is part of a more complicated discussion. The 20-byte format is dependent on the Network object. To be able to convert an address to its 20-byte format therefore requires more than we can currently provide in a new static assembly, and would otherwise require (we think) another property on SmartContract. We may come up with a better solution here. Options so far include: new property for serialization methods on SmartContract, a static field, or looping through all known networks and trying to convert to each one.
We ultimately decided to implement a Converter that will be injected into the SmartContract.
Acceptance Criteria:
Converter
, that exposes the serialization methods.Converter
will be added to Stratis.SmartContracts
. It should expose public static methods that perform the serializations described above.
We don't want to open direct access to System.Text or BitConverter, however we still need to convert between bytes and the below types. Useful for hashing etc.
Bool should go back and forwards with byte.
The others should be translatable to bytes:
We should have a NuGet package purely for this implementation, likely something like Stratis.SmartContracts.ByteHelper.