public void TryParse_Success() { // Normal case LedgerPath path; bool result = LedgerPath.TryParse("/abc/def/", out path); Assert.Equal(true, result); Assert.Equal("/abc/def/", path.FullPath); Assert.Equal <string>(new[] { "abc", "def" }, path.Segments); // All characters result = LedgerPath.TryParse("/azAZ0189$-_.+!*'(),/", out path); Assert.Equal(true, result); Assert.Equal("/azAZ0189$-_.+!*'(),/", path.FullPath); Assert.Equal <string>(new[] { "azAZ0189$-_.+!*'()," }, path.Segments); // Directory result = LedgerPath.TryParse("/abc/def/", out path); Assert.Equal(true, result); Assert.Equal("/abc/def/", path.FullPath); Assert.Equal <string>(new[] { "abc", "def" }, path.Segments); // Root result = LedgerPath.TryParse("/", out path); Assert.Equal(true, result); Assert.Equal("/", path.FullPath); Assert.Equal <string>(new string[] { }, path.Segments); }
public Task <PermissionSet> GetPermissions(IReadOnlyList <SignatureEvidence> authentication, LedgerPath path, bool recursiveOnly, string recordName) { HashSet <string> identities = new HashSet <string>(authentication.Select(evidence => keyEncoder.GetPubKeyHash(evidence.PublicKey)), StringComparer.Ordinal); LedgerPath pathRecordName; // If the path is root and the record name is a tird-party asset owned by the current identity, // arbitrary modification of the balance is allowed if (LedgerPath.TryParse(recordName, out pathRecordName) && thirdPartyAssetPath.IsStrictParentOf(pathRecordName) && path.Segments.Count == 0 && identities.Contains(pathRecordName.Segments[thirdPartyAssetPath.Segments.Count])) { return(Task.FromResult(new PermissionSet(accountNegative: Access.Permit))); } // Account /asset/p2pkh/[addr]/ if (thirdPartyAssetPath.IsStrictParentOf(path) && path.Segments.Count == thirdPartyAssetPath.Segments.Count + 1 && keyEncoder.IsP2pkh(path.Segments[path.Segments.Count - 1])) { Access ownAccount = identities.Contains(path.Segments[path.Segments.Count - 1]) && recordName != DynamicPermissionLayout.AclResourceName ? Access.Permit : Access.Unset; return(Task.FromResult(new PermissionSet( accountModify: Access.Permit, accountCreate: Access.Permit, accountSpend: ownAccount, dataModify: ownAccount))); } else { return(Task.FromResult(new PermissionSet())); } }
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)); }
public void TryParse_Invalid(string value) { LedgerPath path; bool result = LedgerPath.TryParse(value, out path); Assert.Equal(false, result); Assert.Equal(null, path); }
public void TryParse_InvalidCharacter() { const string invalidCharacters = " \"#%&/:;<=>?@[\\]^`{|}~\t\r\n\0é"; foreach (char c in invalidCharacters) { LedgerPath path; bool result = LedgerPath.TryParse("/" + c + "/", out path); Assert.Equal(null, path); Assert.Equal(false, result); Assert.Equal(false, LedgerPath.IsValidPathSegment(c.ToString())); } }
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())); }
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())); }
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)); }