Beispiel #1
0
        public async Task <IReadOnlyList <ByteString> > GetTransactions(ByteString from)
        {
            // find last transaction to return
            var resl = await GetLastTransactionInternal();

            if (resl == null)
            {
                return(new List <ByteString>().AsReadOnly());
            }

            // find first transaction to return
            MongoDbTransaction resf = null;

            if (from != null)
            {
                var cmpkey = from.ToByteArray();
                resf = await TransactionCollection.Find(x => x.TransactionHash == cmpkey).FirstOrDefaultAsync();
            }

            List <MongoDbTransaction> l;

            if (resf == null)
            {
                l = await TransactionCollection.Find(x => x.Timestamp <= resl.Timestamp).SortBy(x => x.Timestamp).ToListAsync();
            }
            else
            {
                l = await TransactionCollection.Find(x => x.Timestamp > resf.Timestamp && x.Timestamp <= resl.Timestamp)
                    .SortBy(x => x.Timestamp).ToListAsync();
            }

            return(l.Select(x => new ByteString(x.RawData)).ToList().AsReadOnly());
        }
        public async Task <ByteString> GetTransaction(ByteString mutationHash)
        {
            var key = mutationHash.ToByteArray();
            var res = await TransactionCollection.Find(x => x.MutationHash == key).SingleOrDefaultAsync();

            return(res == null ? null : new ByteString(res.RawData));
        }
Beispiel #3
0
        private async Task <MongoDbTransaction> GetLastTransactionInternal()
        {
            // look for potential last transaction
            var res = await TransactionCollection.Find(x => true)
                      .SortByDescending(x => x.Timestamp)
                      .FirstOrDefaultAsync();

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

            // look if a pending transaction
            var resp = await PendingTransactionCollection.Find(x => true).SortByDescending(x => x.Timestamp).FirstOrDefaultAsync();

            if (resp == null) // no pending transaction
            {
                // return last transaction
                return(res);
            }
            else
            {
                // else return last transaction no younger than pending transaction
                res = await TransactionCollection.Find(x => x.Timestamp < resp.Timestamp)
                      .SortByDescending(x => x.Timestamp)
                      .FirstOrDefaultAsync();

                return(res);
            }
        }
        public async Task <IReadOnlyList <ByteString> > GetRecordMutations(ByteString recordKey)
        {
            var key = recordKey.ToByteArray();
            var res = await TransactionCollection.Find(Builders <MongoDbTransaction> .Filter.AnyEq(x => x.Records, key))
                      .Project(x => x.MutationHash)
                      .SortBy(x => x.Timestamp)
                      .ToListAsync();

            return(res.Select(x => new ByteString(x)).ToList().AsReadOnly());
        }
Beispiel #5
0
        private void deleteTransactionButton_Click(object sender, EventArgs e)
        {
            var data = transactionsListView.SelectedItems[0].SubItems;

            string[] args = new string[data.Count];

            int i = 0;

            foreach (ListViewItem.ListViewSubItem arg in data)
            {
                //Console.WriteLine(arg.Text);
                args[i] = arg.Text;
                i++;
            }

            Transaction newTransaction = new Transaction(args);

            //Console.WriteLine(newTransaction);
            _collection.Remove(_collection.Find(newTransaction));
            UpdateData(_collection);
        }
        public async Task <IReadOnlyList <ByteString> > GetTransactions(ByteString from)
        {
            MongoDbTransaction res = null;

            if (from != null)
            {
                var cmpkey = from.ToByteArray();
                res = await TransactionCollection.Find(x => x.TransactionHash == cmpkey).FirstOrDefaultAsync();
            }
            List <MongoDbTransaction> l;

            if (res == null)
            {
                l = await TransactionCollection.Find(x => true).SortBy(x => x.Timestamp).ToListAsync();
            }
            else
            {
                BsonTimestamp ts = res.Timestamp;
                l = await TransactionCollection.Find(x => x.Timestamp > ts).SortBy(x => x.Timestamp).ToListAsync();
            }

            return(l.Select(x => new ByteString(x.RawData)).ToList().AsReadOnly());
        }
        public async Task <ByteString> GetLastTransaction()
        {
            var res = await TransactionCollection.Find(x => true).SortByDescending(x => x.Timestamp).FirstOrDefaultAsync();

            return(res == null ? ByteString.Empty : new ByteString(res.TransactionHash));
        }