Ejemplo n.º 1
0
        public static void Decode <TItem>(AbiTypeInfo solidityType, ref AbiDecodeBuffer buff, out IEnumerable <TItem> val, IAbiTypeEncoder <TItem> itemEncoder)
        {
            AbiTypeEncoder <IEnumerable <TItem> > encoder;

            switch (solidityType.Category)
            {
            case SolidityTypeCategory.DynamicArray:
                encoder = new DynamicArrayEncoder <TItem>(itemEncoder);
                break;

            case SolidityTypeCategory.FixedArray:
                encoder = new FixedArrayEncoder <TItem>(itemEncoder);
                break;

            default:
                throw new ArgumentException($"Encoder factory for array types was called with a type '{solidityType.Category}'");
            }

            encoder.SetTypeInfo(solidityType);
            encoder.Decode(ref buff, out val);
        }
Ejemplo n.º 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}'");
            }
        }