예제 #1
0
        public static Process Start(BlockChainIdentity intendedNetwork)
        {
            if (intendedNetwork == null)
                throw new ArgumentNullException(nameof(intendedNetwork));

            // Note: when mainnet becomes the default this should use "testnet" and
            // not "testnet3" as the flag.
            string networkFlag = "";
            if (intendedNetwork != BlockChainIdentity.TestNet3)
                networkFlag = $"--{intendedNetwork.Name}";

            var processInfo = new ProcessStartInfo();
            processInfo.FileName = "btcwallet";
            processInfo.Arguments = networkFlag + " --noinitialload";
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;
            processInfo.CreateNoWindow = true;

            var process = Process.Start(processInfo);
            process.ErrorDataReceived += (sender, args) => Console.WriteLine("err> {0}", args.Data);
            process.OutputDataReceived += (sender, args) => Console.WriteLine("{0}", args.Data);
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            return process;
        }
예제 #2
0
        public static void ValidPayToScriptHashAddresses(string encodedAddress, BlockChainIdentity intendedBlockChain)
        {
            Address address;
            Assert.True(Address.TryDecode(encodedAddress, out address));
            address = Address.Decode(encodedAddress);

            Assert.IsType<Address.PayToScriptHash>(address);
            var p2shAddress = (Address.PayToScriptHash)address;

            Assert.Same(address.IntendedBlockChain, intendedBlockChain);

            var newAddress = new Address.PayToPubKeyHash(intendedBlockChain, p2shAddress.ScriptHash);
            var reencodedAddress = address.Encode();
            Assert.Equal(encodedAddress, reencodedAddress);
        }
예제 #3
0
        public static string RpcListenAddress(string hostnameOrIp, BlockChainIdentity intendedNetwork)
        {
            if (intendedNetwork == null)
                throw new ArgumentNullException(nameof(intendedNetwork));

            string port;
            if (intendedNetwork == BlockChainIdentity.MainNet)
                port = "8332";
            else if (intendedNetwork == BlockChainIdentity.TestNet3)
                port = "18332";
            else if (intendedNetwork == BlockChainIdentity.SimNet)
                port = "18554";
            else
                throw new UnknownBlockChainException(intendedNetwork);

            return $"{hostnameOrIp}:{port}";
        }
예제 #4
0
        public static void ValidPayToPubKeyHashAddresses(string encodedAddress, BlockChainIdentity intendedBlockChain)
        {
            // Assert TryDecode and Decode succeed on valid address.
            Address address;
            Assert.True(Address.TryDecode(encodedAddress, out address));
            address = Address.Decode(encodedAddress);

            // Assert actual instance type is PayToPubKeyHash
            Assert.IsType<Address.PayToPubKeyHash>(address);
            var p2pkhAddress = (Address.PayToPubKeyHash)address;

            // Assert address is for the correct intended network.
            Assert.Same(address.IntendedBlockChain, intendedBlockChain);

            // Assert reencoded address string is equal to the test input.
            var newAddress = new Address.PayToPubKeyHash(intendedBlockChain, p2pkhAddress.PubKeyHash);
            var reencodedAddress = newAddress.Encode();
            Assert.Equal(encodedAddress, reencodedAddress);
        }
예제 #5
0
 public static bool IdentityForPubKeyHashID(byte pubKeyHashID, out BlockChainIdentity identity)
 {
     if (pubKeyHashID == MainNet.AddressPubKeyHashID)
     {
         identity = MainNet;
         return true;
     }
     else if (pubKeyHashID == TestNet3.AddressPubKeyHashID)
     {
         identity = TestNet3;
         return true;
     }
     else if (pubKeyHashID == SimNet.AddressPubKeyHashID)
     {
         identity = SimNet;
         return true;
     }
     else
     {
         identity = null;
         return false;
     }
 }
예제 #6
0
        public static Process Start(BlockChainIdentity intendedNetwork, string appDataDirectory)
        {
            if (intendedNetwork == null)
                throw new ArgumentNullException(nameof(intendedNetwork));
            if (appDataDirectory == null)
                throw new ArgumentNullException(nameof(appDataDirectory));

            var networkFlag = "";
            if (intendedNetwork == BlockChainIdentity.TestNet3)
            {
                // While the actual name of the network is "testnet3", the wallet uses
                // the --testnet flag for this network.
                networkFlag = "--testnet";
            }
            else if (intendedNetwork != BlockChainIdentity.MainNet)
            {
                networkFlag = $"--{intendedNetwork.Name}";
            }

            var v4ListenAddress = RpcListenAddress("127.0.0.1", intendedNetwork);

            var processInfo = new ProcessStartInfo();
            processInfo.FileName = "btcwallet";
            processInfo.Arguments = $"{networkFlag} --noinitialload --experimentalrpclisten={v4ListenAddress} --onetimetlskey --datadir=\"{appDataDirectory}\"";
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardError = true;
            processInfo.RedirectStandardOutput = true;
            processInfo.CreateNoWindow = true;

            var process = Process.Start(processInfo);
            process.ErrorDataReceived += (sender, args) => Console.WriteLine("err> {0}", args.Data);
            process.OutputDataReceived += (sender, args) => Console.WriteLine("{0}", args.Data);
            process.BeginErrorReadLine();
            process.BeginOutputReadLine();
            return process;
        }
예제 #7
0
 private ProcessArguments(BlockChainIdentity intendedNetwork)
 {
     IntendedNetwork = intendedNetwork;
 }
예제 #8
0
 public UnknownBlockChainException(BlockChainIdentity identity)
     : base($"Unknown blockchain `{identity.Name}`")
 { }
예제 #9
0
 public UnknownBlockChainException(BlockChainIdentity identity)
     : base($"Unknown blockchain `{identity.Name}`")
 {
 }