public static async Task <Record> GetRecordVersion(this ILedgerQueries queries, ByteString key, ByteString version) { if (version.Value.Count == 0) { return(new Record(key, ByteString.Empty, ByteString.Empty)); } else { ByteString rawTransaction = await queries.GetTransaction(version); if (rawTransaction == null) { return(null); } else { Transaction transaction = MessageSerializer.DeserializeTransaction(rawTransaction); Mutation mutation = MessageSerializer.DeserializeMutation(transaction.Mutation); Record result = mutation.Records.FirstOrDefault(record => record.Key.Equals(key) && record.Value != null); if (result == null) { return(null); } else { return(result); } } } }
public async Task GetRecordVersion_NonExistingMutation() { this.store = new GetTransactionLedgerQueries(CreateTransaction("a", "b")); Record record = await this.store.GetRecordVersion(new ByteString(Encoding.UTF8.GetBytes("c")), ByteString.Parse("1234")); Assert.Null(record); }
public async Task GetRecordVersion_InitialVersion() { this.store = new GetTransactionLedgerQueries(CreateTransaction("a", "b")); Record record = await this.store.GetRecordVersion(new ByteString(Encoding.UTF8.GetBytes("b")), ByteString.Empty); Assert.Equal(new ByteString(Encoding.UTF8.GetBytes("b")), record.Key); Assert.Equal(ByteString.Empty, record.Value); Assert.Equal(ByteString.Empty, record.Version); }
public async Task GetRecordVersion_Success() { this.store = new GetTransactionLedgerQueries(CreateTransaction("a", "b")); Record record = await this.store.GetRecordVersion(new ByteString(Encoding.UTF8.GetBytes("b")), ByteString.Parse("1234")); Assert.Equal(new ByteString(Encoding.UTF8.GetBytes("b")), record.Key); Assert.Equal(ByteString.Parse("ab"), record.Value); Assert.Equal(ByteString.Parse("cd"), record.Version); }
public static async Task <IReadOnlyList <AccountStatus> > GetAccount(this ILedgerQueries queries, string account) { ByteString prefix = new ByteString(Encoding.UTF8.GetBytes(account + ":ACC:")); IReadOnlyList <Record> records = await queries.GetKeyStartingFrom(prefix); return(records .Select(record => AccountStatus.FromRecord(RecordKey.Parse(record.Key), record)) .ToList() .AsReadOnly()); }
public static async Task <IReadOnlyList <Record> > GetSubaccounts(this ILedgerQueries queries, string rootAccount) { ByteString prefix = new ByteString(Encoding.UTF8.GetBytes(rootAccount)); IReadOnlyList <Record> records = await queries.GetKeyStartingFrom(prefix); return(records .Where(record => !record.Value.Equals(ByteString.Empty)) .ToList() .AsReadOnly()); }
public async Task GetAccount_Success() { this.store = new GetKeyStartingFromLedgerQueries( CreateRecord("/path/to/account/:ACC:/asset/", 1), CreateRecord("/path/to/account/sub/:ACC:/asset/", 2), CreateRecord("/path/to/:ACC:/asset/", 3), CreateRecord("/path/to/account/:DATA:/asset/", 4), CreateRecord("/path/to/accounting/:ACC:/asset/", 5)); IReadOnlyList<AccountStatus> result = await this.store.GetAccount("/path/to/account/"); Assert.Equal(1, result.Count); Assert.Equal("/path/to/account/:ACC:/asset/", result[0].AccountKey.Key.ToString()); Assert.Equal(1, result[0].Balance); Assert.Equal(ByteString.Parse("1234"), result[0].Version); }
public async Task GetAccount_Success() { this.store = new GetKeyStartingFromLedgerQueries( CreateRecord("/path/to/account/:ACC:/asset/", 1), CreateRecord("/path/to/account/sub/:ACC:/asset/", 2), CreateRecord("/path/to/:ACC:/asset/", 3), new Record(new ByteString(Encoding.UTF8.GetBytes("/path/to/account/:ACC:/empty/")), ByteString.Empty, ByteString.Parse("1234")), CreateRecord("/path/to/account/:DATA:/asset/", 4), CreateRecord("/path/to/accounting/:ACC:/asset/", 5)); IReadOnlyList <AccountStatus> result = await this.store.GetAccount("/path/to/account/"); Assert.Equal(1, result.Count); Assert.Equal("/path/to/account/:ACC:/asset/", result[0].AccountKey.Key.ToString()); Assert.Equal(1, result[0].Balance); Assert.Equal(ByteString.Parse("1234"), result[0].Version); }
public async Task GetSubaccounts_Success() { this.store = new GetKeyStartingFromLedgerQueries( CreateRecord("/path/to/account/:ACC:/asset/", 1), CreateRecord("/path/to/account/sub/:ACC:/asset/", 2), CreateRecord("/path/to/:ACC:/asset/", 3), CreateRecord("/path/to/account/:DATA:/asset/", 4), CreateRecord("/path/to/accounting/:ACC:/asset/", 5)); IReadOnlyList<Record> result = await this.store.GetSubaccounts("/path/to/account/"); Assert.Equal(3, result.Count); Assert.Equal("/path/to/account/:ACC:/asset/", Encoding.UTF8.GetString(result[0].Key.Value.ToArray())); Assert.Equal(1, BitConverter.ToInt64(result[0].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[0].Version); Assert.Equal("/path/to/account/sub/:ACC:/asset/", Encoding.UTF8.GetString(result[1].Key.Value.ToArray())); Assert.Equal(2, BitConverter.ToInt64(result[1].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[1].Version); Assert.Equal("/path/to/account/:DATA:/asset/", Encoding.UTF8.GetString(result[2].Key.Value.ToArray())); Assert.Equal(4, BitConverter.ToInt64(result[2].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[2].Version); }
public async Task GetSubaccounts_Success() { this.store = new GetKeyStartingFromLedgerQueries( CreateRecord("/path/to/account/:ACC:/asset/", 1), CreateRecord("/path/to/account/sub/:ACC:/asset/", 2), CreateRecord("/path/to/:ACC:/asset/", 3), new Record(new ByteString(Encoding.UTF8.GetBytes("/path/to/account/:ACC:/empty/")), ByteString.Empty, ByteString.Parse("1234")), CreateRecord("/path/to/account/:DATA:/asset/", 4), CreateRecord("/path/to/accounting/:ACC:/asset/", 5)); IReadOnlyList <Record> result = await this.store.GetSubaccounts("/path/to/account/"); Assert.Equal(3, result.Count); Assert.Equal("/path/to/account/:ACC:/asset/", Encoding.UTF8.GetString(result[0].Key.Value.ToArray())); Assert.Equal(1, BitConverter.ToInt64(result[0].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[0].Version); Assert.Equal("/path/to/account/sub/:ACC:/asset/", Encoding.UTF8.GetString(result[1].Key.Value.ToArray())); Assert.Equal(2, BitConverter.ToInt64(result[1].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[1].Version); Assert.Equal("/path/to/account/:DATA:/asset/", Encoding.UTF8.GetString(result[2].Key.Value.ToArray())); Assert.Equal(4, BitConverter.ToInt64(result[2].Value.Value.Reverse().ToArray(), 0)); Assert.Equal(ByteString.Parse("1234"), result[2].Version); }
public static async Task <IReadOnlyList <Record> > GetSubaccounts(this ILedgerQueries queries, string rootAccount) { ByteString prefix = new ByteString(Encoding.UTF8.GetBytes(rootAccount)); return(await queries.GetKeyStartingFrom(prefix)); }
public QueryController(ILedgerQueries store) { this.store = store; }
public QueryController(IStorageEngine storageEngine, ILedgerQueries store, ILedgerIndexes indexes) { this.storageEngine = storageEngine; this.store = store; this.indexes = indexes; }
public async Task GetRecordVersion_NonExistingTransaction() { this.store = new GetTransactionLedgerQueries(null); Record record = await this.store.GetRecordVersion(new ByteString(Encoding.UTF8.GetBytes("b")), ByteString.Parse("1234")); Assert.Null(record); }