예제 #1
0
        public static ExternalServices CreateFromRPCClient(RPCClient rpc, IRepository repository, Tracker tracker)
        {
            var info        = rpc.SendCommand(RPCOperations.getinfo);
            var minimumRate = new NBitcoin.FeeRate(NBitcoin.Money.Coins((decimal)(double)((Newtonsoft.Json.Linq.JValue)(info.Result["relayfee"])).Value * 2), 1000);

            ExternalServices service = new ExternalServices();

            service.FeeService = new RPCFeeService(rpc)
            {
                MinimumFeeRate = minimumRate
            };

            // on regtest the estimatefee always fails
            if (rpc.Network == NBitcoin.Network.RegTest)
            {
                service.FeeService = new RPCFeeService(rpc)
                {
                    MinimumFeeRate  = minimumRate,
                    FallBackFeeRate = new NBitcoin.FeeRate(NBitcoin.Money.Satoshis(50), 1)
                };
            }

            var cache = new RPCWalletCache(rpc, repository);

            service.WalletService           = new RPCWalletService(rpc);
            service.BroadcastService        = new RPCBroadcastService(rpc, cache, repository);
            service.BlockExplorerService    = new RPCBlockExplorerService(rpc, cache, repository);
            service.TrustedBroadcastService = new RPCTrustedBroadcastService(rpc, service.BroadcastService, service.BlockExplorerService, repository, cache, tracker)
            {
                //BlockExplorer will already track the addresses, since they used a shared bitcoind, no need of tracking again (this would overwrite labels)
                TrackPreviousScriptPubKey = false
            };
            return(service);
        }
예제 #2
0
        public static ExternalServices CreateFromRPCClient(RPCClient rpc, IRepository repository, Tracker tracker, bool useBatching)
        {
            var network     = rpc.Network;
            var minimumRate = new FeeRate(network.MinRelayTxFee);

            ExternalServices service = new ExternalServices();

            service.FeeService = new RPCFeeService(network)
            {
                MinimumFeeRate = minimumRate
            };

            // on regtest or testnet the estimatefee often fails
            if (rpc.Network.NetworkType == NetworkType.Regtest || rpc.Network.NetworkType == NetworkType.Testnet)
            {
                service.FeeService = new RPCFeeService(network)
                {
                    MinimumFeeRate  = minimumRate,
                    FallBackFeeRate = new NBitcoin.FeeRate(NBitcoin.Money.Satoshis(50), 1)
                };
            }

            var cache = new RPCWalletCache(rpc, repository);

            var clientBatchInterval = TimeSpan.FromMilliseconds(100);

            service.WalletService = new RPCWalletService(rpc)
            {
                BatchInterval = useBatching ? TimeSpan.FromSeconds(160) : clientBatchInterval,
                AddressGenerationBatchInterval = useBatching ? TimeSpan.FromSeconds(1) : TimeSpan.FromMilliseconds(10)
            };
            service.BroadcastService = new RPCBroadcastService(rpc, cache, repository)
            {
                BatchInterval = useBatching ? TimeSpan.FromSeconds(5) : clientBatchInterval
            };
            service.BlockExplorerService = new RPCBlockExplorerService(rpc, cache, repository)
            {
                BatchInterval = useBatching ? TimeSpan.FromSeconds(5) : clientBatchInterval
            };
            service.TrustedBroadcastService = new RPCTrustedBroadcastService(rpc, service.BroadcastService, service.BlockExplorerService, repository, cache, tracker)
            {
                //BlockExplorer will already track the addresses, since they used a shared bitcoind, no need of tracking again (this would overwrite labels)
                TrackPreviousScriptPubKey = false
            };
            return(service);
        }
예제 #3
0
        public static ExternalServices CreateFromRPCClient(RPCClient rpc, IRepository repository, Tracker tracker, bool useBatching)
        {
            var info        = rpc.SendCommand(RPCOperations.getinfo);
            var minimumRate = new NBitcoin.FeeRate(NBitcoin.Money.Coins((decimal)(double)((Newtonsoft.Json.Linq.JValue)(info.Result["relayfee"])).Value * 2), 1000);

            ExternalServices service = new ExternalServices();

            service.FeeService = new RPCFeeService(rpc)
            {
                MinimumFeeRate = minimumRate
            };

            // on regtest or testnet the estimatefee often fails
            if (rpc.Network == NBitcoin.Network.RegTest || rpc.Network == Network.TestNet)
            {
                service.FeeService = new RPCFeeService(rpc)
                {
                    MinimumFeeRate  = minimumRate,
                    FallBackFeeRate = new NBitcoin.FeeRate(NBitcoin.Money.Satoshis(50), 1)
                };
            }

            var cache = new RPCWalletCache(rpc, repository);

            var clientBatchInterval = TimeSpan.FromMilliseconds(100);

            if (rpc.Network != NBitcoin.Network.RegTest)
            {
                service.WalletService = new RPCWalletService(rpc)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(160) : clientBatchInterval,
                    AddressGenerationBatchInterval = useBatching ? TimeSpan.FromSeconds(1) : TimeSpan.FromMilliseconds(10)
                };

                service.BroadcastService = new RPCBroadcastService(rpc, cache, repository)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(5) : clientBatchInterval
                };
                service.BlockExplorerService = new RPCBlockExplorerService(rpc, cache, repository)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(5) : clientBatchInterval
                };
                service.TrustedBroadcastService = new RPCTrustedBroadcastService(rpc, service.BroadcastService, service.BlockExplorerService, repository, cache, tracker)
                {
                    //BlockExplorer will already track the addresses, since they used a shared bitcoind, no need of tracking again (this would overwrite labels)
                    TrackPreviousScriptPubKey = false
                };
            }
            else
            {
                // For integration tests on regtest the batching needs to be almost nonexistent due to the low
                // inter-block delays

                service.WalletService = new RPCWalletService(rpc)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(1) : clientBatchInterval,
                    AddressGenerationBatchInterval = useBatching ? TimeSpan.FromSeconds(1) : TimeSpan.FromMilliseconds(10)
                };

                service.BroadcastService = new RPCBroadcastService(rpc, cache, repository)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(1) : clientBatchInterval
                };
                service.BlockExplorerService = new RPCBlockExplorerService(rpc, cache, repository)
                {
                    BatchInterval = useBatching ? TimeSpan.FromSeconds(1) : clientBatchInterval
                };
                service.TrustedBroadcastService = new RPCTrustedBroadcastService(rpc, service.BroadcastService, service.BlockExplorerService, repository, cache, tracker)
                {
                    //BlockExplorer will already track the addresses, since they used a shared bitcoind, no need of tracking again (this would overwrite labels)
                    TrackPreviousScriptPubKey = false
                };
            }

            return(service);
        }
예제 #4
0
 public BroadcasterJob(ExternalServices services)
 {
     BroadcasterService        = services.BroadcastService;
     TrustedBroadcasterService = services.TrustedBroadcastService;
     BlockExplorerService      = services.BlockExplorerService;
 }