private static TransactionData ConstructTransactionData(RpcObject @object)
 {
     return(new TransactionData
     {
         Data = @object.GetItem("data"),
         DataType = @object.GetItem("dataType")?.ToString(),
         From = new Address(@object.GetItem("from").ToString()),
         To = new Address(@object.GetItem("to").ToString()),
         Nid = @object.GetItem("nid")?.ToInteger(),
         Nonce = @object.GetItem("nonce")?.ToInteger(),
         StepLimit = @object.GetItem("stepLimit")?.ToInteger(),
         Timestamp = @object.GetItem("timestamp")?.ToInteger(),
         Value = @object.GetItem("value")?.ToInteger(),
         Version = @object.GetItem("version").ToInteger()
     });
 }
        private static void CompareTransactionsDataRpcObjects(RpcObject expectedRpcObject, RpcObject actualRpcObject)
        {
            var expectedKeys = expectedRpcObject.GetKeys().OrderBy(x => x).ToList();
            var actualKeys   = actualRpcObject.GetKeys().OrderBy(x => x);

            Assert.True(expectedKeys.SequenceEqual(actualKeys));

            foreach (var key in expectedKeys)
            {
                var expected = expectedRpcObject.GetItem(key);
                var actual   = actualRpcObject.GetItem(key);

                if (expected is RpcValue expectedRpcValue &&
                    actual is RpcValue actualRpcValue)
                {
                    Assert.Equal(expectedRpcValue.ToString(), actualRpcValue.ToString());
                    continue;
                }

                if (expected is RpcObject expectedObj &&
                    actual is RpcObject actualObj)
                {
                    CompareTransactionsDataRpcObjects(expectedObj, actualObj);
                    continue;
                }

                throw new ArgumentException("Can't compare key values");
            }
        }
        private static void SerializeObjectItems(StringBuilder builder, RpcObject @object)
        {
            var firstItem = true;

            foreach (var key in @object.GetKeys().OrderBy(x => x))
            {
                if (firstItem)
                {
                    firstItem = false;
                }
                else
                {
                    builder.Append(".");
                }

                Serialize(builder.Append(key).Append("."), @object.GetItem(key));
            }
        }
Пример #4
0
        private static object FromRpcObject <T>(RpcObject @object)
        {
            var type = typeof(T);

            if (type.IsAssignableFrom(typeof(RpcObject)))
            {
                return(@object);
            }

            var result = new Dictionary <string, object>();
            var keys   = @object.GetKeys();

            foreach (var key in keys)
            {
                var v = FromRpcItem(@object.GetItem(key));
                if (v != null)
                {
                    result[key] = v;
                }
            }

            return(result);
        }
Пример #5
0
            public BigInteger GetParamIndexed()
            {
                var item = _properties.GetItem("indexed");

                return(item?.ToInteger() ?? 0);
            }
Пример #6
0
        public Bytes GetPrevBlockHash()
        {
            var item = _properties.GetItem("prev_block_hash");

            return(item?.ToBytes());
        }
Пример #7
0
        public BigInteger GetVersion()
        {
            var item = _properties.GetItem("version");

            return(item?.ToInteger() ?? BigInteger.Parse("2"));
        }
Пример #8
0
            public BigInteger GetCode()
            {
                var item = _properties.GetItem("code");

                return(item?.ToInteger() ?? 0);
            }
Пример #9
0
            public List <RpcItem> GetData()
            {
                var field = _properties.GetItem("data");

                return(field?.ToArray().ToList());
            }