Ejemplo n.º 1
0
        public void RepositorySerializerTest(string cryptoCode)
        {
            var networkProvider = new NRustLightningNetworkProvider(NetworkType.Regtest);
            var ser             = new RepositorySerializer(networkProvider.GetByCryptoCode(cryptoCode));
            // utxo response
            var resp        = new UTXOChangesWithMetadata();
            var confirmed   = new UTXOChangeWithSpentOutput();
            var unconfirmed = new UTXOChangeWithSpentOutput();

            confirmed.SpentOutPoint = new List <OutPoint>()
            {
                OutPoint.Zero
            };
            var coinBaseTx =
                Transaction.Parse(
                    "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0401750101ffffffff0200f2052a0100000017a914d4bb8bf5f987cd463a2f5e6e4f04618c7aaed1b5870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000", Network.RegTest);
            var utxo = new UTXO(new NBXplorer.Models.UTXO(coinBaseTx.Outputs.AsCoins().First()));

            Assert.NotNull(JsonSerializer.Serialize(utxo, ser.Options));
            confirmed.UTXO = new List <UTXOChangeWithMetadata>()
            {
                new UTXOChangeWithMetadata(utxo, UTXOKind.UserDeposit, new AddressTrackedSource(coinBaseTx.Outputs[0].ScriptPubKey.GetDestinationAddress(Network.RegTest)))
            };
            resp.Confirmed   = confirmed;
            resp.UnConfirmed = unconfirmed;
            var res = JsonSerializer.Serialize(resp, ser.Options);

            Assert.NotNull(res);
        }
        public Task <UTXOChangesWithMetadata> ListUnspent(NRustLightningNetwork network)
        {
            var res         = new UTXOChangesWithMetadata();
            var confirmed   = new UTXOChangeWithSpentOutput();
            var unconfirmed = new UTXOChangeWithSpentOutput();

            confirmed.SpentOutPoint = new List <OutPoint>()
            {
                OutPoint.Zero
            };
            var coinBaseTx =
                Transaction.Parse(
                    "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff0401750101ffffffff0200f2052a0100000017a914d4bb8bf5f987cd463a2f5e6e4f04618c7aaed1b5870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000", network.NBitcoinNetwork);

            confirmed.UTXO = new List <UTXOChangeWithMetadata>()
            {
                new UTXOChangeWithMetadata(new UTXO(new NBXplorer.Models.UTXO(coinBaseTx.Outputs.AsCoins().First())), UTXOKind.UserDeposit, new AddressTrackedSource(coinBaseTx.Outputs[0].ScriptPubKey.GetDestinationAddress(network.NBitcoinNetwork)))
            };
            res.Confirmed   = confirmed;
            res.UnConfirmed = unconfirmed;
            return(Task.FromResult(res));
        }
Ejemplo n.º 3
0
        public async Task <UTXOChangesWithMetadata> ListUnspent(NRustLightningNetwork n)
        {
            var _cli  = _nbXplorerClientProvider.GetClient(n);
            var deriv = await GetOurDerivationStrategyAsync(n);

            var confirmedUtxo             = new List <UTXOChangeWithMetadata>();
            var unconfirmedUtxo           = new List <UTXOChangeWithMetadata>();
            var confirmedSpentOutpoints   = new List <OutPoint>();
            var unconfirmedSpentOutpoints = new List <OutPoint>();

            var nativeFundsResponse = await _cli.GetUTXOsAsync(deriv);

            foreach (var utxo in nativeFundsResponse.Confirmed.UTXOs)
            {
                var item = new UTXOChangeWithMetadata(new UTXO(utxo), UTXOKind.UserDeposit, new DerivationSchemeTrackedSource(deriv));
                confirmedUtxo.Add(item);
            }
            foreach (var utxo in nativeFundsResponse.Unconfirmed.UTXOs)
            {
                unconfirmedUtxo.Add(new UTXOChangeWithMetadata(new UTXO(utxo), UTXOKind.UserDeposit, new DerivationSchemeTrackedSource(deriv)));
            }

            confirmedSpentOutpoints.AddRange(nativeFundsResponse.Confirmed.SpentOutpoints);
            unconfirmedSpentOutpoints.AddRange(nativeFundsResponse.Unconfirmed.SpentOutpoints);

            var repo = _repositoryProvider.GetRepository(n);

            // TODO: Refactor when https://github.com/dgarage/NBXplorer/issues/291 is ready
            await foreach (var o in repo.GetAllSpendableOutputDescriptors())
            {
                var addr           = o.Output.ScriptPubKey.GetDestinationAddress(n.NBitcoinNetwork);
                var ts             = new AddressTrackedSource(addr);
                var lnUTXOResposne = await _cli.GetUTXOsAsync(ts);

                foreach (var utxo in lnUTXOResposne.Confirmed.UTXOs)
                {
                    confirmedUtxo.Add(new UTXOChangeWithMetadata(new UTXO(utxo), o.GetKind(), ts));
                }
                foreach (var utxo in lnUTXOResposne.Unconfirmed.UTXOs)
                {
                    unconfirmedUtxo.Add(new UTXOChangeWithMetadata(new UTXO(utxo), o.GetKind(), ts));
                }
                confirmedSpentOutpoints.AddRange(lnUTXOResposne.Confirmed.SpentOutpoints);
                unconfirmedSpentOutpoints.AddRange(lnUTXOResposne.Unconfirmed.SpentOutpoints);
            }
            ;

            var confirmed = new UTXOChangeWithSpentOutput()
            {
                UTXO = confirmedUtxo, SpentOutPoint = confirmedSpentOutpoints
            };
            var unconfirmed = new UTXOChangeWithSpentOutput()
            {
                UTXO = unconfirmedUtxo, SpentOutPoint = unconfirmedSpentOutpoints
            };

            return(new UTXOChangesWithMetadata()
            {
                Confirmed = confirmed, UnConfirmed = unconfirmed, CurrentHeight = nativeFundsResponse.CurrentHeight
            });
        }