Ejemplo n.º 1
0
        public ActionResult <BlockResponse> Get(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            var data = (id.Length > 30 && id.Substring(0, 2).Equals("0x")) ?
                       _dataAdapter.GetBlockByHash(_metadataSchema.DatabaseSchema.TableList.ToArray(), id, "-1") :
                       _dataAdapter.GetBlockByNumber(_metadataSchema.DatabaseSchema.TableList.ToArray(), id);

            if (data == null)
            {
                return(null);
            }

            var result = BlockResponse.Default();

            result.Data               = ResponseWrapper.BlockData(data);
            result.Data.Id            = id;
            result.Data.Attributes.Id = id;
            result.Includes           = ResponseWrapper.Block(data);

            var inh = new Inherents();
            var lst = new List <InherentsItem>();

            foreach (var item in result.Includes)
            {
                lst.Add(new InherentsItem {
                    Id         = item.Id,
                    Type       = "extrinsic",
                    Attributes = item.Attributes
                });
            }

            inh.Data = lst;

            result.Data.Relationships = new Relationship
            {
                Event        = new string[] { },
                Logs         = new string[] { },
                Inherents    = inh,
                Transactions = new string[] { }
            };

            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult <ExtrinsicBase> Get(string id)
        {
            var targetTables = _metadataSchema.DatabaseSchema.TableList.Where(i => i.Title.Contains("Call")).ToArray();

            if (!string.IsNullOrWhiteSpace(id))
            {
                string addId = "";
                Dictionary <TableSchema, IEnumerable <string> > data2;

                if (id.Length > 30)
                {
                    var ids = id.Split('-');
                    if (ids.Count() > 1)
                    {
                        id    = ids.ElementAt(0);
                        addId = ids.ElementAt(1);
                    }

                    data2 = _dataAdapter.GetBlockByHash(targetTables, id, addId);
                    if (data2.Count == 0)
                    {
                        data2 = _dataAdapter.GetTransactionByHash(targetTables, id, addId);
                    }
                }
                else
                {
                    var ids = id.Split('-');

                    if (ids.Count() > 1)
                    {
                        id    = ids.ElementAt(0);
                        addId = ids.ElementAt(1);
                    }

                    var tables =

                        data2 = _dataAdapter.GetBlockByNumber(targetTables, id);
                }

                var resultData = ResponseWrapper.Transaction(data2, addId);

                if (resultData == null)
                {
                    return(NotFound());
                }

                var result2 = DTO.ExtrinsicResponseSingle.Default();
                result2.Data = resultData;

                return(result2);
            }

            var result    = DTO.ExtrinsicResponse.Default();
            var uriParams = UriParse.PolkadotParseUri(Request.QueryString.Value);

            var tf = new TransactionFilter
            {
                Module      = UriParse.TryGetValue(uriParams, "filter", "module_id"),
                Method      = UriParse.TryGetValue(uriParams, "filter", "call_id"),
                AddressFrom = UriParse.TryGetValue(uriParams, "filter", "address_from"),
                AddressTo   = UriParse.TryGetValue(uriParams, "filter", "address_to")
            };

            var limit = Convert.ToInt32(UriParse.TryGetValue(uriParams, "page", "size"));
            var pnum  = Convert.ToInt32(UriParse.TryGetValue(uriParams, "page", "number"));
            var data  = _dataAdapter.GetFilteredTransactionList(tf, 0, 0);
            var list  = ResponseWrapper.TransactionList(data);

            if (pnum > 1)
            {
                list = list.Skip((pnum - 1) * limit);
            }

            result.Data = list.Take(limit);

            return(result);
        }