Esempio n. 1
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);

            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);
        }
Esempio n. 2
0
        public ServerCommitmentsProof CheckRevelation(
            [ModelBinder(BinderType = typeof(TumblerParametersModelBinder))]
            ClassicTumblerParameters tumblerId,
            int cycleId,
            [ModelBinder(BinderType = typeof(UInt160ModelBinder))]  uint160 channelId,
            [FromBody] PuzzlePromise.ClientRevelation revelation)
        {
            if (tumblerId == null)
            {
                throw new ArgumentNullException(nameof(tumblerId));
            }
            var session = GetPromiseServerSession(cycleId, channelId, CyclePhase.TumblerChannelEstablishment);

            AssertNotDuplicateQuery(cycleId, channelId);

            // TODO: Need to figure out how to get Bob's key from here
            var feeRate = new NBitcoin.FeeRate(Money.Satoshis(1));
            var proof   = session.CheckRevelation(revelation, new PubKey("0xFIX_ME").Hash, feeRate);

            Repository.Save(cycleId, session);
            return(proof);
        }
Esempio n. 3
0
 public bool IsDust(FeeRate minRelayTxFee)
 {
     return(Value < GetDustThreshold(minRelayTxFee));
 }
Esempio n. 4
0
		/// <summary>
		/// Estimate the fee needed for the transaction, and split among groups according to their fee weight
		/// </summary>
		/// <param name="feeRate"></param>
		/// <returns></returns>
		public TransactionBuilder SendEstimatedFeesSplit(FeeRate feeRate)
		{
			Money feeSent = Money.Zero;
			while(true)
			{
				var tx = BuildTransaction(false);
				var shouldSend = EstimateFees(tx, feeRate);
				var delta = shouldSend - feeSent;
				if(delta <= Money.Zero)
					break;
				SendFeesSplit(delta);
				feeSent += delta;
			}
			return this;
		}
Esempio n. 5
0
		/// <summary>
		/// Estimate fees of an unsigned transaction
		/// </summary>
		/// <param name="tx"></param>
		/// <param name="feeRate">Fee rate</param>
		/// <returns></returns>
		public Money EstimateFees(Transaction tx, FeeRate feeRate)
		{
			if(tx == null)
				throw new ArgumentNullException("tx");
			if(feeRate == null)
				throw new ArgumentNullException("feeRate");

			var estimation = EstimateSize(tx);
			return feeRate.GetFee(estimation);
		}
Esempio n. 6
0
		/// <summary>
		/// Verify that a transaction is fully signed and have enough fees
		/// </summary>
		/// <param name="tx">he transaction to check</param>
		/// <param name="expectedFeeRate">The expected fee rate</param>
		/// <returns>Detected errors</returns>
		public TransactionPolicyError[] Check(Transaction tx, FeeRate expectedFeeRate)
		{
			return Check(tx, expectedFeeRate == null ? null : expectedFeeRate.GetFee(tx));
		}
Esempio n. 7
0
		/// <summary>
		/// Verify that a transaction is fully signed and have enough fees
		/// </summary>
		/// <param name="tx">The transaction to check</param>
		/// <param name="expectedFeeRate">The expected fee rate</param>
		/// <param name="errors">Detected errors</param>
		/// <returns>True if no error</returns>
		public bool Verify(Transaction tx, FeeRate expectedFeeRate, out TransactionPolicyError[] errors)
		{
			if(tx == null)
				throw new ArgumentNullException("tx");
			return Verify(tx, expectedFeeRate == null ? null : expectedFeeRate.GetFee(tx), out errors);
		}
Esempio n. 8
0
		/// <summary>
		/// Verify that a transaction is fully signed and have enough fees
		/// </summary>
		/// <param name="tx">The transaction to check</param>
		/// <param name="expectedFeeRate">The expected fee rate</param>
		/// <returns>True if no error</returns>
		public bool Verify(Transaction tx, FeeRate expectedFeeRate)
		{
			TransactionPolicyError[] errors;
			return Verify(tx, expectedFeeRate, out errors);
		}