RPCClientFactory.cs 1.26 KB
Newer Older
Maxim Bogdanov's avatar
Maxim Bogdanov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
using System;
using NBitcoin;
using Stratis.Bitcoin.Utilities;

namespace Stratis.Bitcoin.Features.RPC
{
    /// <summary>
    /// An interface for a factory that can create <see cref="IRPCClient"/> instances.
    /// </summary>
    public interface IRPCClientFactory
    {
        /// <summary>
        /// Create a new RPCClient instance.
        /// </summary>
        /// <param name="authenticationString">username:password or the content of the .cookie file or null to auto configure.</param>
        /// <param name="address">The binding address.</param>
        /// <param name="network">The network.</param>
        IRPCClient Create(string authenticationString, Uri address, Network network);
    }

    /// <summary>
    /// A factory for creating new instances of an <see cref="RPCClient"/>.
    /// </summary>
    public class RPCClientFactory : IRPCClientFactory
    {
        /// <inheritdoc/>
        public IRPCClient Create(string authenticationString, Uri address, Network network)
        {
            Guard.NotNull(authenticationString, nameof(authenticationString));
            Guard.NotNull(address, nameof(address));
            Guard.NotNull(network, nameof(network));

            return new RPCClient(authenticationString, address, network);
        }
    }
}