public FetchCoinsResponse FetchCoins(OutPoint[] utxos)
        {
            FetchCoinsResponse res = new FetchCoinsResponse();

            using (DBreeze.Transactions.Transaction transaction = this.CreateTransaction())
            {
                transaction.SynchronizeTables("BlockHash", "Coins");
                transaction.ValuesLazyLoadingIsOn = false;

                using (new StopwatchDisposable(o => this.performanceCounter.AddQueryTime(o)))
                {
                    this.performanceCounter.AddQueriedEntities(utxos.Length);

                    foreach (OutPoint outPoint in utxos)
                    {
                        Row <byte[], byte[]> row     = transaction.Select <byte[], byte[]>("Coins", outPoint.ToBytes());
                        Utilities.Coins      outputs = row.Exists ? this.dBreezeSerializer.Deserialize <Utilities.Coins>(row.Value) : null;

                        this.logger.LogDebug("Outputs for '{0}' were {1}.", outPoint, outputs == null ? "NOT loaded" : "loaded");

                        res.UnspentOutputs.Add(outPoint, new UnspentOutput(outPoint, outputs));
                    }
                }
            }

            return(res);
        }
Exemplo n.º 2
0
        public FetchCoinsResponse FetchCoins(OutPoint[] utxos)
        {
            FetchCoinsResponse res = new FetchCoinsResponse();

            using (new StopwatchDisposable(o => this.performanceCounter.AddQueryTime(o)))
            {
                this.performanceCounter.AddQueriedEntities(utxos.Length);

                foreach (OutPoint outPoint in utxos)
                {
                    byte[]          row     = this.leveldb.Get(new byte[] { coinsTable }.Concat(outPoint.ToBytes()).ToArray());
                    Utilities.Coins outputs = row != null?this.dBreezeSerializer.Deserialize <Utilities.Coins>(row) : null;

                    this.logger.LogTrace("Outputs for '{0}' were {1}.", outPoint, outputs == null ? "NOT loaded" : "loaded");

                    res.UnspentOutputs.Add(outPoint, new UnspentOutput(outPoint, outputs));
                }
            }

            return(res);
        }
Exemplo n.º 3
0
        public FetchCoinsResponse FetchCoins(OutPoint[] utxos)
        {
            FetchCoinsResponse res = new FetchCoinsResponse();

            using (var session = this.db.NewSession())
            {
                using (new StopwatchDisposable(o => this.performanceCounter.AddQueryTime(o)))
                {
                    this.performanceCounter.AddQueriedEntities(utxos.Length);

                    Types.StoreInput   input   = new Types.StoreInput();
                    Types.StoreOutput  output  = new Types.StoreOutput();
                    Types.StoreContext context = new Types.StoreContext();
                    var readKey = new Types.StoreKey {
                        tableType = "Coins"
                    };

                    foreach (OutPoint outPoint in utxos)
                    {
                        output.value = null;
                        readKey.key  = outPoint.ToBytes();
                        var addStatus = session.Read(ref readKey, ref input, ref output, context, 1);

                        if (addStatus == Status.PENDING)
                        {
                            session.CompletePending(true);
                            context.FinalizeRead(ref addStatus, ref output);
                        }

                        Utilities.Coins outputs = addStatus == Status.OK ? this.dBreezeSerializer.Deserialize <Utilities.Coins>(output.value.value) : null;

                        this.logger.LogDebug("Outputs for '{0}' were {1}.", outPoint, outputs == null ? "NOT loaded" : "loaded");

                        res.UnspentOutputs.Add(outPoint, new UnspentOutput(outPoint, outputs));
                    }
                }
            }

            return(res);
        }