예제 #1
0
        public void CheckRPCFailures()
        {
            using (NodeBuilder builder = NodeBuilder.Create())
            {
                var node = builder.CreateStratisPowNode();
                builder.StartAll();
                var client = node.CreateRPCClient();
                var hash   = client.GetBestBlockHash();
                try
                {
                    client.SendCommand("lol");
                    Assert.True(false, "should throw");
                }
                catch (RPCException ex)
                {
                    Assert.Equal(RPCErrorCode.RPC_METHOD_NOT_FOUND, ex.RPCCode);
                }
                Assert.Equal(hash, Network.RegTest.GetGenesis().GetHash());
                var oldClient = client;
                client = new NBitcoin.RPC.RPCClient("abc:def", client.Address, client.Network);
                try
                {
                    client.GetBestBlockHash();
                    Assert.True(false, "should throw");
                }
                catch (Exception ex)
                {
                    Assert.Contains("401", ex.Message);
                }
                client = oldClient;

                try
                {
                    client.SendCommand("addnode", "regreg", "addr");
                    Assert.True(false, "should throw");
                }
                catch (RPCException ex)
                {
                    Assert.Equal(RPCErrorCode.RPC_MISC_ERROR, ex.RPCCode);
                }
            }
        }
예제 #2
0
		public RPCClient CreateClient()
		{
			if(!Server)
				throw new InvalidOperationException("This BitcoinQ process is not a server (-server parameter)");
			RPCClient client = new RPCClient(new System.Net.NetworkCredential(RPCUser, RPCPassword), new Uri(RPCService, UriKind.Absolute), Network);

			return client;
		}
예제 #3
0
        /// <returns>(allowed, reject-reason)</returns>
        public static async Task <(bool accept, string rejectReason)> TestMempoolAcceptAsync(this RPCClient rpc, IEnumerable <Coin> coins)
        {
            // Check if mempool would accept a fake transaction created with the registered inputs.
            // This will catch ascendant/descendant count and size limits for example.
            var fakeTransaction = rpc.Network.CreateTransaction();

            fakeTransaction.Inputs.AddRange(coins.Select(coin => new TxIn(coin.Outpoint)));
            Money fakeOutputValue = NBitcoinHelpers.TakeAReasonableFee(coins.Sum(coin => coin.TxOut.Value));

            fakeTransaction.Outputs.Add(fakeOutputValue, new Key());
            MempoolAcceptResult testMempoolAcceptResult = await rpc.TestMempoolAcceptAsync(fakeTransaction, allowHighFees : true);

            if (!testMempoolAcceptResult.IsAllowed)
            {
                string rejected = testMempoolAcceptResult.RejectReason;

                if (!(rejected.Contains("mandatory-script-verify-flag-failed", StringComparison.OrdinalIgnoreCase) ||
                      rejected.Contains("non-mandatory-script-verify-flag", StringComparison.OrdinalIgnoreCase)))
                {
                    return(false, rejected);
                }
            }
            return(true, "");
        }
예제 #4
0
        /// <summary>
        /// Waits for a specific new block and returns useful info about it.
        /// </summary>
        /// <param name="blockHash">Block hash to wait for</param>
        /// <param name="timeout">Time in milliseconds to wait for a response. 0 indicates no timeout.</param>
        /// <returns>Returns the current block on timeout or exit</returns>
        public static async Task <(Height height, uint256 hash)> WaitForBlockAsync(this RPCClient rpc, uint256 blockHash, long timeout = 0)
        {
            var resp = await rpc.SendCommandAsync("waitforblock", blockHash, timeout);

            return(int.Parse(resp.Result["height"].ToString()), uint256.Parse(resp.Result["hash"].ToString()));
        }
		public RPCTransactionRepository(RPCClient client)
		{
			if(client == null)
				throw new ArgumentNullException("client");
			_Client = client;
		}