예제 #1
0
        public static void Decode(AbiTypeInfo solidityType, ref AbiDecodeBuffer buff, out Hash val)
        {
            var encoder = new BytesMEncoder();

            encoder.SetTypeInfo(solidityType);
            encoder.Decode(ref buff, out var bytes);
            val = new Hash(bytes is byte[] b ? b : bytes.ToArray());
        }
예제 #2
0
        public static void Decode(AbiTypeInfo solidityType, ref AbiDecodeBuffer buff, out IEnumerable <byte> val)
        {
            switch (solidityType.Category)
            {
            case SolidityTypeCategory.Bytes:
            {
                var encoder = new BytesEncoder();
                encoder.SetTypeInfo(solidityType);
                encoder.Decode(ref buff, out val);
                break;
            }

            case SolidityTypeCategory.DynamicArray:
            {
                var encoder = new DynamicArrayEncoder <byte>(new UInt8Encoder());
                encoder.SetTypeInfo(solidityType);
                encoder.Decode(ref buff, out val);
                break;
            }

            case SolidityTypeCategory.FixedArray:
            {
                var encoder = new FixedArrayEncoder <byte>(new UInt8Encoder());
                encoder.SetTypeInfo(solidityType);
                encoder.Decode(ref buff, out val);
                break;
            }

            case SolidityTypeCategory.Elementary when solidityType.ElementaryBaseType == SolidityTypeElementaryBase.Bytes:
            {
                var encoder = new BytesMEncoder();
                encoder.SetTypeInfo(solidityType);
                encoder.Decode(ref buff, out val);
                break;
            }

            default:
                throw new ArgumentException($"Encoder factor method for byte arrays called with type '{solidityType.Category}'");
            }
        }