Esempio n. 1
0
 public AbiInputParameter(IAbiParameterDefinition definition, dynamic value, string name = "")
 {
     _nethAbiType = ABIType.CreateABIType(definition.AbiType);
     Definition   = definition;
     Value        = value;
     Name         = name;
 }
Esempio n. 2
0
 public Parameter(string type, string name = null, int order = 1)
 {
     this.Name    = name;
     this.Type    = type;
     this.Order   = order;
     this.ABIType = ABIType.CreateABIType(type);
 }
Esempio n. 3
0
 public AbiInputParameter(string abiType, dynamic value, string name = "")
 {
     _nethAbiType = ABIType.CreateABIType(abiType);
     Definition   = new AbiParameterDefinition(_nethAbiType.Name, name);
     Value        = value;
     Name         = name;
 }
        public virtual void ShouldDecode(string typeName, string expected, string hex)
        {
            var bytesType = ABIType.CreateABIType(typeName);
            var result    = bytesType.Decode <byte[]>(hex);

            Assert.Equal(expected, result.ToHex(true));
        }
        public virtual void ShouldEncode(string typeName, string hex, string expected)
        {
            var bytesType = ABIType.CreateABIType(typeName);
            var result    = bytesType.Encode(hex.HexToByteArray());

            Assert.Equal(expected, result.ToHex(true));
        }
        public virtual void ShouldEncodeGuid()
        {
            var bytesType = ABIType.CreateABIType("bytes16");
            var guid      = Guid.NewGuid();
            var result    = bytesType.Encode(guid);

            Assert.Equal("0x" + guid.ToByteArray().ToHex() + "00000000000000000000000000000000", result.ToHex(true));
        }
Esempio n. 7
0
 public Parameter(string type, string name = null, int order = 1, string serpentSignature = null)
 {
     Name             = name;
     Type             = type;
     Order            = order;
     SerpentSignature = serpentSignature;
     ABIType          = ABIType.CreateABIType(type);
 }
Esempio n. 8
0
 private void InitialiseElementType(string name)
 {
     int indexFirstBracket = name.IndexOf("[", StringComparison.Ordinal);
     string elementTypeName = name.Substring(0, indexFirstBracket);
     int indexSecondBracket = name.IndexOf("]", indexFirstBracket, StringComparison.Ordinal);
     string subDim = indexSecondBracket + 1 == name.Length ? "" : name.Substring(indexSecondBracket + 1);
     ElementType = ABIType.CreateABIType(elementTypeName + subDim);
 }
Esempio n. 9
0
 public Parameter(string type, string name = null, int order = 1, string serpentSignature = null)
 {
     this.Name             = name;
     this.Type             = type;
     this.Order            = order;
     this.SerpentSignature = serpentSignature;
     this.ABIType          = ABIType.CreateABIType(type);
 }
        public virtual void ShouldDecodeGuid()
        {
            var bytesType = ABIType.CreateABIType("bytes16");
            var guid      = Guid.NewGuid();
            var encoded   = bytesType.Encode(guid);

            var result = bytesType.Decode <Guid>(encoded);

            Assert.Equal(guid, result);
        }
        public void InitTupleComponentsFromTypeAttributes(Type type, ABIType abiType)
        {
            if (abiType is TupleType abiTupleType)
            {
                var properties       = PropertiesExtractor.GetPropertiesWithParameterAttribute(type);
                var parameters       = new List <Parameter>();
                var parameterObjects = new List <Parameter>();

                foreach (var property in properties)
                {
                    var parameterAttribute = property.GetCustomAttribute <ParameterAttribute>(true);
                    parameterAttribute.Parameter.DecodedType = property.PropertyType;
                    InitTupleComponentsFromTypeAttributes(property.PropertyType, parameterAttribute.Parameter.ABIType);

                    parameterObjects.Add(parameterAttribute.Parameter);
                }
                abiTupleType.SetComponents(parameterObjects.ToArray());
            }

            var abiArrayType = abiType as ArrayType;

            while (abiArrayType != null)
            {
                var arrayListType = ArrayTypeDecoder.GetIListElementType(type);
                if (arrayListType == null)
                {
                    throw new Exception("Only types that implement IList<T> are supported for encoding");
                }

                if (abiArrayType.ElementType is TupleType arrayTupleType)
                {
                    InitTupleComponentsFromTypeAttributes(arrayListType, arrayTupleType);
                    abiArrayType = null;
                }
                else
                {
                    abiArrayType = abiArrayType.ElementType as ArrayType;
                }
            }
        }
 public StaticArrayTypeEncoder(ABIType elementType, int arraySize)
 {
     this.elementType = elementType;
     this.arraySize = arraySize;
 }
Esempio n. 13
0
 public ArrayTypeDecoder(ABIType elementType)
 {
     this.ElementType = elementType;
 }
Esempio n. 14
0
 public ArrayTypeDecoder(ABIType elementType, int size)
 {
     Size        = size;
     ElementType = elementType;
     _attributesToABIExtractor = new AttributesToABIExtractor();
 }
Esempio n. 15
0
 public AbiOutputParameter(string abiType, string name = "")
 {
     _nethAbiType = ABIType.CreateABIType(abiType);
     Definition   = new AbiParameterDefinition(name, abiType);
     Name         = name;
 }
Esempio n. 16
0
 public AbiOutputParameter(IAbiParameterDefinition definition, string name = "")
 {
     _nethAbiType = ABIType.CreateABIType(definition.AbiType);
     Definition   = definition;
     Name         = name;
 }
 public AbiOutputParameter(string abitype, string name = "")
 {
     this._nethABIType = ABIType.CreateABIType(abitype);
     this.Definition   = new AbiOutputParameterDefinition(name, abitype);
 }
Esempio n. 18
0
 public ABIValue(string abiType, object value)
 {
     ABIType = ABIType.CreateABIType(abiType);
     Value   = value;
 }
Esempio n. 19
0
 public ArrayTypeDecoder(ABIType elementType, int size)
 {
     Size        = size;
     ElementType = elementType;
 }
Esempio n. 20
0
 public ArrayTypeDecoder(ABIType elementType)
 {
     this.ElementType = elementType;
 }
 public DynamicArrayTypeDecoder(ABIType elementType) : base(elementType)
 {
 }
Esempio n. 22
0
 public AbiInputParameter(IAbiParameterDefinition definition, dynamic value)
 {
     this._nethABIType = ABIType.CreateABIType(definition.ABIType);
     this.Definition   = definition;
     this.Value        = value;
 }
Esempio n. 23
0
 public ABIValue(ABIType abiType, object value)
 {
     ABIType = abiType;
     Value   = value;
 }
 public DynamicArrayTypeEncoder(ABIType elementType)
 {
     this._elementType = elementType;
     _intTypeEncoder   = new IntTypeEncoder();
 }
 public AbiOutputParameter(IAbiParameterDefinition definition)
 {
     this._nethABIType = ABIType.CreateABIType(definition.ABIType);
     this.Definition   = definition;
 }
 public DynamicArrayTypeEncoder(ABIType elementType)
 {
     this.elementType = elementType;
     this.intTypeEncoder = new IntTypeEncoder();
 }
 public StaticArrayTypeEncoder(ABIType elementType, int arraySize)
 {
     this.elementType = elementType;
     this.arraySize   = arraySize;
     intTypeEncoder   = new IntTypeEncoder();
 }
 public AbiEncodingException(int order, ABIType abiType, object value, string message, Exception innerException) : base(message, innerException)
 {
     Order   = order;
     ABIType = abiType;
     Value   = value;
 }
 public DynamicArrayTypeDecoder(ABIType elementType) : base(elementType)
 {
 }
Esempio n. 30
0
 public AbiInputParameter(string abitype, dynamic value, string name = "")
 {
     this._nethABIType = ABIType.CreateABIType(abitype);
     this.Definition   = new AbiInputParameterDefinition(this._nethABIType.Name, name);
     this.Value        = value;
 }
Esempio n. 31
0
        private static void AddJTokenValueInputParameters(List <object> inputParameters, ABIType abiType, JToken jToken)
        {
            var tupleAbi = abiType as TupleType;

            if (tupleAbi != null)
            {
                var tupleValue = jToken;
                inputParameters.Add(ConvertToFunctionInputParameterValues(tupleValue, tupleAbi.Components));
            }

            var arrayAbi = abiType as ArrayType;

            if (arrayAbi != null)
            {
                var array       = (JArray)jToken;
                var elementType = arrayAbi.ElementType;
                var arrayOutput = new List <object>();
                foreach (var element in array)
                {
                    AddJTokenValueInputParameters(arrayOutput, elementType, element);
                }
                inputParameters.Add(arrayOutput);
            }

            if (abiType is Bytes32Type || abiType is BytesType)
            {
                var bytes = jToken.ToObject <string>().HexToByteArray();
                inputParameters.Add(bytes);
            }

            if (abiType is StringType || abiType is AddressType)
            {
                inputParameters.Add(jToken.ToObject <string>());
            }

            if (abiType is IntType)
            {
                inputParameters.Add(BigInteger.Parse(jToken.ToObject <string>()));
            }

            if (abiType is BoolType)
            {
                inputParameters.Add(jToken.ToObject <bool>());
            }
        }