public async Task <ActionResult> GetRecordsByName(
            [FromQuery(Name = "name")]
            string recordName,
            [FromQuery(Name = "type")]
            string recordType)
        {
            if (recordName == null)
            {
                return(BadRequest());
            }

            RecordKey record;

            try
            {
                record = RecordKey.ParseRecord(recordType, LedgerPath.FromSegments(), recordName);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(BadRequest());
            }

            IReadOnlyList <Record> records = await this.indexes.GetAllRecords(record.RecordType, record.Name);

            return(Json(records.Select(GetRecordJson).ToArray()));
        }
Esempio n. 2
0
        public async Task <ActionResult> GetTransactionsByPath(
            [FromQuery(Name = "path")]
            string path)
        {
            if (!LedgerPath.TryParse(path, out LedgerPath ledgerPath))
            {
                return(BadRequest());
            }

            var directory = LedgerPath.FromSegments(ledgerPath.Segments.ToArray());
            var accounts  = await this.store.GetSubaccounts(directory.FullPath);

            var keys             = accounts.Where(x => RecordKey.Parse(x.Key).RecordType == RecordType.Account).Select(x => x.Key);
            var transactionsData = await this.storageEngine.GetTransactionByRecordKeys(keys, new TransactionFilter());

            var transactions = transactionsData.Select(x => new ExtTransaction(x)).ToList();

            var hashtable = new Hashtable();

            foreach (var transaction in transactions)
            {
                foreach (var record in transaction.Mutation.Records)
                {
                    var val = BitConverter.ToInt64(record.Value.Value.Reverse().ToArray(), 0);
                    hashtable.Add(transaction.MutationHash + record.Key.ToString(), val);
                }
            }

            var res = transactions.Select(x => TransactionToJsonExt(x, hashtable).Value).ToArray();

            return(Json(res));
        }
Esempio n. 3
0
        public void FromSegments_ArgumentOutOfRangeException()
        {
            ArgumentOutOfRangeException exception;

            exception = Assert.Throws <ArgumentOutOfRangeException>(() => LedgerPath.FromSegments("@"));
            Assert.Equal("segments", exception.ParamName);

            exception = Assert.Throws <ArgumentOutOfRangeException>(() => LedgerPath.FromSegments(null));
            Assert.Equal("segments", exception.ParamName);

            exception = Assert.Throws <ArgumentOutOfRangeException>(() => LedgerPath.FromSegments(""));
            Assert.Equal("segments", exception.ParamName);
        }
Esempio n. 4
0
        public void FromSegments_Success()
        {
            LedgerPath path = LedgerPath.FromSegments();

            Assert.Equal("/", path.FullPath);
            Assert.Equal <string>(new string[0], path.Segments);

            path = LedgerPath.FromSegments("a");
            Assert.Equal("/a/", path.FullPath);
            Assert.Equal <string>(new[] { "a" }, path.Segments);

            path = LedgerPath.FromSegments("a", "b");
            Assert.Equal("/a/b/", path.FullPath);
            Assert.Equal <string>(new[] { "a", "b" }, path.Segments);
        }
        public async Task <ActionResult> GetSubaccounts(
            [FromQuery(Name = "account")]
            string account)
        {
            LedgerPath path;

            if (!LedgerPath.TryParse(account, out path))
            {
                return(BadRequest());
            }

            LedgerPath directory = LedgerPath.FromSegments(path.Segments.ToArray());

            IReadOnlyList <Record> accounts = await this.store.GetSubaccounts(directory.FullPath);

            return(Json(accounts.Select(GetRecordJson).ToArray()));
        }
Esempio n. 6
0
        private async Task <PermissionSet> GetPermissions(IReadOnlyList <SignatureEvidence> signedAddresses, LedgerPath path, string recordName)
        {
            PermissionSet accumulativePermissions = PermissionSet.DenyAll;

            for (int i = 0; i <= path.Segments.Count; i++)
            {
                bool            recursiveOnly = i != path.Segments.Count;
                LedgerPath      currentPath   = LedgerPath.FromSegments(path.Segments.Take(i).ToArray());
                PermissionSet[] permissions   = await Task.WhenAll(this.permissions.Select(item => item.GetPermissions(signedAddresses, currentPath, recursiveOnly, recordName)));

                PermissionSet currentLevelPermissions = permissions
                                                        .Aggregate(PermissionSet.Unset, (previous, current) => previous.Add(current));

                accumulativePermissions = accumulativePermissions.AddLevel(currentLevelPermissions);
            }

            return(accumulativePermissions);
        }
Esempio n. 7
0
        public async Task <ActionResult> GetSubaccounts(string account)
        {
            LedgerPath path;

            if (!LedgerPath.TryParse(account, out path))
            {
                return(HttpBadRequest());
            }

            LedgerPath directory = LedgerPath.FromSegments(path.Segments.ToArray());

            IReadOnlyList <Record> accounts = await this.store.GetSubaccounts(directory.FullPath);

            return(Json(accounts.Select(result => new
            {
                key = result.Key.ToString(),
                value = result.Value.ToString(),
                version = result.Version.ToString()
            }).ToArray()));
        }
Esempio n. 8
0
        public async Task <ActionResult> GetFilteredTransactions()
        {
            string            path;
            TransactionFilter filter;
            JObject           body;

            try
            {
                string bodyContent;
                using (StreamReader streamReader = new StreamReader(Request.Body))
                    bodyContent = await streamReader.ReadToEndAsync();

                body = JObject.Parse(bodyContent);
                path = body["path"].ToString();
                var jFilter = (JObject)body["filter"];
                filter = new TransactionFilter()
                {
                    StartDate = (DateTime)jFilter["start"],
                    EndDate   = (DateTime)jFilter["end"]
                };
            }
            catch (JsonReaderException)
            {
                return(BadRequest());
            }


            if (!LedgerPath.TryParse(path, out LedgerPath ledgerPath))
            {
                return(BadRequest());
            }

            var directory = LedgerPath.FromSegments(ledgerPath.Segments.ToArray());
            var accounts  = await this.store.GetSubaccounts(directory.FullPath);

            var keys = accounts.Where(x => RecordKey.Parse(x.Key).RecordType == RecordType.Account).Select(x => x.Key);

            var transactionsData = await this.storageEngine.GetTransactionByRecordKeys(keys, filter);

            var transactions = transactionsData.Select(x => new ExtTransaction(x)).ToList();

            var hash = new List <ByteString>();

            foreach (var transaction in transactions)
            {
                hash.AddRange(transaction.Mutation.Records.Select(x => x.Version));
            }

            var prevTransactionsData = await this.storageEngine.GetTransactionsByMutationHash(hash.Distinct());

            var prevTransactions = prevTransactionsData.Select(x => new ExtTransaction(x)).ToList();

            var hashtable = new Hashtable();

            foreach (var transaction in prevTransactions)
            {
                foreach (var record in transaction.Mutation.Records)
                {
                    var val = BitConverter.ToInt64(record.Value.Value.Reverse().ToArray(), 0);
                    hashtable.Add(transaction.MutationHash + record.Key.ToString(), val);
                }
            }

            var res = transactions.Select(x => TransactionToJsonExt(x, hashtable).Value).ToArray();

            return(Json(res));
        }