public BitcoinDWaiter(
     RPCClient rpc,
     ExplorerConfiguration configuration,
     NBXplorerNetwork network,
     SlimChain chain,
     Repository repository,
     AddressPoolService addressPoolService,
     EventAggregator eventAggregator)
 {
     if (addressPoolService == null)
     {
         throw new ArgumentNullException(nameof(addressPoolService));
     }
     _RPC                = rpc;
     _Configuration      = configuration;
     _AddressPoolService = addressPoolService;
     _Network            = network;
     _Chain              = chain;
     _Repository         = repository;
     State               = BitcoinDWaiterState.NotStarted;
     _EventAggregator    = eventAggregator;
     _ChainConfiguration = _Configuration.ChainConfigurations.First(c => c.CryptoCode == _Network.CryptoCode);
     RPCReadyFile        = Path.Combine(configuration.DataDir, $"{network.CryptoCode.ToLowerInvariant()}_fully_synched");
 }
Exemple #2
0
 public ExplorerClient(NBXplorerNetwork network, Uri serverAddress = null) : this(network, serverAddress, null)
 {
 }
Exemple #3
0
 internal LiquidRepository(DBTrie.DBTrieEngine engine, NBXplorerNetwork network, KeyPathTemplates keyPathTemplates,
                           RPCClient rpcClient) : base(engine, network, keyPathTemplates, rpcClient)
 {
     _rpcClient = rpcClient;
 }
Exemple #4
0
 public Serializer(NBXplorerNetwork network)
 {
     _Network = network?.NBitcoinNetwork;
     ConfigureSerializer(Settings);
 }
Exemple #5
0
 public Repository GetRepository(NBXplorerNetwork network)
 {
     _Repositories.TryGetValue(network.CryptoCode, out Repository repository);
     return(repository);
 }
Exemple #6
0
 private ChainConfiguration GetChainSetting(NBXplorerNetwork net)
 {
     return(_Configuration.ChainConfigurations.FirstOrDefault(c => c.CryptoCode == net.CryptoCode));
 }
 public ExplorerClient(NBXplorerNetwork network, Uri serverAddress = null, IWebProxy proxy = null) : this(network, serverAddress, null, proxy)
 {
 }
Exemple #8
0
 public RPCClient GetRPCClient(NBXplorerNetwork network)
 {
     return(GetRPCClient(network.CryptoCode));
 }
Exemple #9
0
        private async Task <RebroadcastResult> Rebroadcast(NBXplorerNetwork network, TrackedSource trackedSource, IEnumerable <TrackedTransactionKey> txIds)
        {
            var result     = new RebroadcastResult();
            var repository = _Repositories.GetRepository(network);
            var waiter     = _Waiters.GetWaiter(repository.Network);

            if (!waiter.RPCAvailable)
            {
                return(result);
            }
            List <TrackedTransaction>       cleaned = new List <TrackedTransaction>();
            HashSet <TrackedTransactionKey> processedTrackedTransactionKeys = new HashSet <TrackedTransactionKey>();
            HashSet <uint256> processedTransactionId = new HashSet <uint256>();

            foreach (var trackedTxId in txIds)
            {
                if (!processedTransactionId.Add(trackedTxId.TxId))
                {
                    continue;
                }
                var tx = (await repository.GetSavedTransactions(trackedTxId.TxId))?.Select(t => t.Transaction).FirstOrDefault();
                if (tx == null)
                {
                    continue;
                }
                try
                {
                    await waiter.RPC.SendRawTransactionAsync(tx);

                    result.Rebroadcasted.Add(tx);
                    Logs.Explorer.LogInformation($"{repository.Network.CryptoCode}: Rebroadcasted {trackedTxId.TxId}");
                }
                catch (RPCException ex) when(
                    ex.RPCCode == RPCErrorCode.RPC_TRANSACTION_ALREADY_IN_CHAIN ||
                    ex.Message.EndsWith("Missing inputs", StringComparison.OrdinalIgnoreCase) ||
                    ex.Message.EndsWith("bad-txns-inputs-spent", StringComparison.OrdinalIgnoreCase) ||
                    ex.Message.EndsWith("txn-mempool-conflict", StringComparison.OrdinalIgnoreCase))
                {
                    result.MissingInputs.Add(tx);
                    var txs = await repository.GetTransactions(trackedSource, trackedTxId.TxId);

                    foreach (var savedTx in txs)
                    {
                        if (!processedTrackedTransactionKeys.Add(savedTx.Key))
                        {
                            continue;
                        }
                        if (savedTx.BlockHash == null)
                        {
                            cleaned.Add(savedTx);
                            result.Cleaned.Add(savedTx);
                        }
                        else
                        {
                            var resultRPC = await waiter.RPC.SendCommandAsync(new RPCRequest("getblockheader", new[] { savedTx.BlockHash }), throwIfRPCError : false);

                            if (resultRPC.Error?.Code is RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY)
                            {
                                cleaned.Add(savedTx);
                                result.Cleaned.Add(savedTx);
                            }
                            else if (resultRPC.Result.Value <int>("confirmations") == -1)
                            {
                                cleaned.Add(savedTx);
                                result.Cleaned.Add(savedTx);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    result.UnknownFailure.Add(tx);
                    Logs.Explorer.LogInformation($"{repository.Network.CryptoCode}: Unknown exception when broadcasting {tx.GetHash()} ({ex.Message})");
                }
            }

            if (cleaned.Count != 0)
            {
                foreach (var tx in cleaned)
                {
                    EventAggregator.Publish(new EvictedTransactionEvent(tx.TransactionHash));
                }
                await repository.CleanTransactions(trackedSource, cleaned.ToList());
            }
            return(result);
        }
Exemple #10
0
 public RawBlockEvent(Block block, NBXplorerNetwork network)
 {
     Block   = block;
     Network = network;
 }
Exemple #11
0
        private ScannedItems GetScannedItems(ScanUTXOWorkItem workItem, ScanUTXOProgress progress, NBXplorerNetwork network)
        {
            var items = new ScannedItems();
            var derivationStrategy = workItem.DerivationStrategy;

            foreach (var feature in keyPathTemplates.GetSupportedDerivationFeatures())
            {
                var keyPathTemplate = keyPathTemplates.GetKeyPathTemplate(feature);
                var lineDerivation  = workItem.DerivationStrategy.DerivationStrategy.GetLineFor(keyPathTemplate);
                Enumerable.Range(progress.From, progress.Count)
                .Select(index =>
                {
                    var derivation = lineDerivation.Derive((uint)index);
                    var info       = new KeyPathInformation(derivation, derivationStrategy, feature,
                                                            keyPathTemplate.GetKeyPath(index, false), network);
                    items.Descriptors.Add(new ScanTxoutSetObject(ScanTxoutDescriptor.Raw(info.ScriptPubKey)));
                    items.KeyPathInformations.TryAdd(info.ScriptPubKey, info);
                    return(info);
                }).All(_ => true);
            }
            Logs.Explorer.LogInformation($"{workItem.Network.CryptoCode}: Start scanning batch {progress.BatchNumber} of {workItem.DerivationStrategy.ToPrettyString()} from index {progress.From}");
            return(items);
        }
 public FullySynchedEvent(NBXplorerNetwork network)
 {
     Network = network;
 }
Exemple #13
0
 public SlimChain GetChain(NBXplorerNetwork network)
 {
     return(GetChain(network.CryptoCode));
 }
Exemple #14
0
 public BitcoinDWaiter GetWaiter(NBXplorerNetwork network)
 {
     return(GetWaiter(network.CryptoCode));
 }
Exemple #15
0
 public ScanUTXOInformation GetInformation(NBXplorerNetwork network, DerivationStrategyBase derivationScheme)
 {
     _Progress.TryGetValue(new ScanUTXOWorkItem(network, derivationScheme).Id, out var workItem);
     return(workItem?.State);
 }
 private void Add(NBXplorerNetwork network)
 {
     _Networks.Add(network.CryptoCode, network);
 }
Exemple #17
0
 public ConcurrentChain GetChain(NBXplorerNetwork network)
 {
     return(GetChain(network.CryptoCode));
 }