internal static void Init(Action <BitcoinServiceOptions> setupAction)
        {
            var options = new BitcoinServiceOptions();

            setupAction.Invoke(options);

            tryCount = options.TryCount;
            delayMs  = options.DelayMs;
            db       = options.DbContext;
            bitcoinExtPubKeyString = options.BitcoinExtPubKeyString;
            isTestNetwork          = options.IsTestNetwork;

            logger = options.LoggerFactory?.CreateLogger(nameof(BitcoinService));

            int lastExchangeIndex = 0;

            if (db.Exchange.Any())
            {
                lastExchangeIndex = db.Exchange
                                    .Where(t => t.SellCurrency == "BTC")
                                    .Max(t => t.PayAddressIndex);
            }

            index = lastExchangeIndex + 1;

            bitcoinWallet = new BitcoinWallet(bitcoinExtPubKeyString, isTestNetwork);
            checker       = new CheckTransactionService(isTestNetwork);

            logger.LogInformation("Init: index - {index}, isTestNetwork - {isTestNetwork}, tryCount - {tryCount}, delayMs - {delayMs}",
                                  index, isTestNetwork, tryCount, delayMs);
        }
        public string GetAddress(WalletKind kind)
        {
            if (_wallets.ContainsKey(kind))
            {
                return(_wallets[kind].Address);
            }

            CryptoWallet wallet;

            switch (kind)
            {
            case WalletKind.Phantasma: wallet = new PhantasmaWallet(keys); break;

            case WalletKind.Neo: wallet = new NeoWallet(keys); break;

            case WalletKind.Bitcoin: wallet = new BitcoinWallet(keys); break;

            case WalletKind.Ethereum: wallet = new EthereumWallet(keys); break;

            case WalletKind.EOS: wallet = new EOSWallet(keys); break;

            default: throw new Exception("Unsupported wallet kind: " + kind);
            }

            _wallets[kind] = wallet;
            return(wallet.Address);
        }
Exemple #3
0
        public void TestBitcoinWallet()
        {
            var keys    = new PhantasmaKeys(Base16.Decode("60cf347dbc59d31c1358c8e5cf5e45b822ab85b79cb32a9f3d98184779a9efc2"));
            var wallet  = new BitcoinWallet(keys);
            var address = wallet.Address;

            Assert.IsTrue(address.Equals("17JsmEygbbEUEpvt4PFtYaTeSqfb9ki1F1", StringComparison.OrdinalIgnoreCase));
        }
Exemple #4
0
        public MarketBase(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin, string bitsharesAccount)
        {
            m_daemon = daemon;
            m_market = market;

            m_bitshares        = bitshares;
            m_bitcoin          = bitcoin;
            m_bitsharesAccount = bitsharesAccount;
        }
Exemple #5
0
        static void Main(string[] args)
        {
            BitcoinWallet wallet = new BitcoinWallet(
                ConfigurationManager.AppSettings["rpc_host"],
                ConfigurationManager.AppSettings["rpc_user"],
                ConfigurationManager.AppSettings["rpc_pw"],
                true);

            ShowCommands(wallet);
        }
Exemple #6
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		    The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		    The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		    The bitshares account. </param>
        /// <param name="bitsharesAsset">		    The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(RpcConfig bitsharesConfig, RpcConfig bitcoinConfig,
                          string bitsharesAccount, string adminUsernames)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin   = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount = bitsharesAccount;
            m_adminUsernames   = adminUsernames.Split(',');

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
Exemple #7
0
        public static void Main(string[] args)
        {
            IWriter writer         = new Writer();
            IReader reader         = new Reader();
            Network currentNetwork = Network.TestNet;

            ICommandFactory cmdFactory = new CommandFactory(writer, reader, currentNetwork);

            IWallet wallet = new BitcoinWallet(cmdFactory);

            wallet.Start();
        }
Exemple #8
0
        public void TestVerifyStringLengthLonger()
        {
            // Arrange
            string        btcAddressLonger = "1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN237";
            BitcoinWallet tWallet          = new BitcoinWallet();

            // Act
            tWallet.VerifyString(btcAddressLonger);

            // Assert
            Assert.IsFalse(tWallet.VerifyString(btcAddressLonger));
        }
Exemple #9
0
        public void TestVerifyStringLengthShorter()
        {
            // Arrange
            string        btcAddressShorter = "3TRY7DEQ5";
            BitcoinWallet tWallet           = new BitcoinWallet();

            // Act
            tWallet.VerifyString(btcAddressShorter);

            // Assert
            Assert.IsFalse(tWallet.VerifyString(btcAddressShorter));
        }
Exemple #10
0
        public void TestVerifyStringEmpty()
        {
            // Arrange
            string        btcAddress = " ";
            BitcoinWallet tWallet    = new BitcoinWallet();

            // Act
            tWallet.VerifyString(btcAddress);

            // Assert
            Assert.IsFalse(tWallet.VerifyString(btcAddress));
        }
Exemple #11
0
        public void TestVerifyValuePositive()
        {
            // Arrange
            string        nbrBitcoin = "10";
            BitcoinWallet tWallet    = new BitcoinWallet();

            // Act
            tWallet.VerifyValue(nbrBitcoin);

            // Assert
            Assert.IsTrue(tWallet.VerifyValue(nbrBitcoin));
        }
Exemple #12
0
        public void TestVerifyValueNegative()
        {
            // Arrange
            string        nbrBitcoin = "-10";
            BitcoinWallet tWallet    = new BitcoinWallet();

            // Act
            tWallet.VerifyValue(nbrBitcoin);

            // Assert
            Assert.IsFalse(tWallet.VerifyValue(nbrBitcoin));
        }
Exemple #13
0
        public void TestVerifyStringStartsWith()
        {
            // Arrange
            string        btcAddress = "bc18t1WpEZ73CNmQviecrnyiWrnqRhWNLy";
            BitcoinWallet tWallet    = new BitcoinWallet();

            // Act
            tWallet.VerifyString(btcAddress);

            // Assert
            Assert.IsFalse(tWallet.VerifyValue(btcAddress));
        }
Exemple #14
0
        public void TestGetCurrentValueInDollarsWithMockObject()
        {
            //set up
            BitcoinWallet tWallet    = new BitcoinWallet();
            double        bitcoinQty = 8;
            Mock <BitcoinPriceService> bitcoinPriceServiceMock = new Mock <BitcoinPriceService>();

            bitcoinPriceServiceMock.Setup(x => x.GetCurrentBitcoinPriceInDollars()).Returns(5000);

            //excercise
            Assert.AreEqual(40000, tWallet.GetCurrentValueInDollars(bitcoinQty, bitcoinPriceServiceMock.Object));
        }
Exemple #15
0
        public void TestVerifyStringLengthValid()
        {
            // Arrange
            string        btcAddressValid = "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy";
            BitcoinWallet tWallet         = new BitcoinWallet();

            // Act
            tWallet.VerifyString(btcAddressValid);

            // Assert
            Assert.IsTrue(tWallet.VerifyString(btcAddressValid));
        }
Exemple #16
0
        public void ShouldGenerateWalletFromPrivateKey()
        {
            IHDWallet <BitcoinWallet> tronHDWallet = new BitcoinHDWallet("conduct stadium ask orange vast impose depend assume income sail chunk tomorrow life grape dutch", "");
            var           account0 = tronHDWallet.GetAccount(0);
            BitcoinWallet wallet0  = account0.GetExternalWallet(0);

            Assert.AreEqual("cdce32b32436ff20c2c32ee55cd245a82fff4c2dc944da855a9e0f00c5d889e4", wallet0.PrivateKey.ToHex());

            var tronWallet = new BitcoinWallet("cdce32b32436ff20c2c32ee55cd245a82fff4c2dc944da855a9e0f00c5d889e4");

            Assert.AreEqual(wallet0.PrivateKey.ToHex(), tronWallet.PrivateKey.ToHex());
            Assert.AreEqual(wallet0.PublicKey, tronWallet.PublicKey);
        }
        public void ShouldGenerateFromPrivateKey()
        {
            var privateKey    = "cdcbe9ad36e694b5686ec4ad937a4fdf7eba7ced829e2452f66aeff0363e5114";
            var bitcoinWallet = new BitcoinWallet(privateKey);

            var pubKey = bitcoinWallet.PublicKey;

            Assert.AreEqual(expected: "0354b36b66431bbcf41607901d1a55e083cedbc3446b9849e06bcff81d0a3b517d", actual: pubKey.ToString());

            var walletAddress = bitcoinWallet.Address;

            Assert.AreEqual(expected: "bc1qpznrn52ajq3uqf3ckmfsqdp2wspaggpl47ul3d", actual: walletAddress);
        }
Exemple #18
0
        /// <summary>
        /// Invoke the chosen method with the entered parameters. Try to convert the parameters
        /// to the appropriate type before invoking the method.
        /// </summary>
        /// <param name="wallet">The wallet to invoke the method on.</param>
        /// <param name="method">The method to invoke.</param>
        /// <param name="inputParts">Parameters to pass to the method.</param>
        private static void InvokeMethode(BitcoinWallet wallet, MethodInfo method, string[] inputParts)
        {
            var parameterInfos = method.GetParameters();

            if (parameterInfos.Count() != inputParts.Length - 1)
            {
                Console.WriteLine("The number of given parameters does not match the number of method parameters.");
                Console.WriteLine("Note: Default parameters have to be entered as well!");
                return;
            }

            object[] parameters = new object[inputParts.Length - 1];
            for (int i = 1; i < inputParts.Length; i++)
            {
                if (parameterInfos[i - 1].ParameterType == typeof(string))
                {
                    parameters[i - 1] = Convert.ToString(inputParts[i]);
                }
                else if (parameterInfos[i - 1].ParameterType == typeof(decimal))
                {
                    parameters[i - 1] = Convert.ToDecimal(inputParts[i]);
                }
                else if (parameterInfos[i - 1].ParameterType == typeof(int))
                {
                    parameters[i - 1] = Convert.ToInt32(inputParts[i]);
                }
                else if (parameterInfos[i - 1].ParameterType == typeof(long))
                {
                    parameters[i - 1] = Convert.ToInt64(inputParts[i]);
                }
                else if (parameterInfos[i - 1].ParameterType == typeof(bool))
                {
                    parameters[i - 1] = Convert.ToBoolean(inputParts[i]);
                }
                else
                {
                    parameters[i - 1] = inputParts[i];
                }
            }

            try
            {
                method.Invoke(wallet, parameters);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong while invoking the method on the wallet: " + ex.Message);
                Console.WriteLine();
                Console.WriteLine("Remember that invoking methods from this console application with complex input parameters (lists, object, etc.) is not supported).");
            }
        }
Exemple #19
0
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 17/01/2015. </remarks>
        ///
        /// <param name="bitsharesConfig">		    The bitshares configuration. </param>
        /// <param name="bitcoinConfig">		    The bitcoin configuration. </param>
        /// <param name="bitsharesAccount">		    The bitshares account. </param>
        /// <param name="bitsharesAsset">		    The bitshares asset. </param>
        /// <param name="bitcoinDespositAddress">	The bitcoin desposit address. </param>
        public DaemonBase(RpcConfig bitsharesConfig, RpcConfig bitcoinConfig,
                          string bitsharesAccount, string bitsharesAsset,
                          string bitcoinDespositAddress)
        {
            m_bitshares = new BitsharesWallet(bitsharesConfig.m_url, bitsharesConfig.m_rpcUser, bitsharesConfig.m_rpcPassword);
            m_bitcoin   = new BitcoinWallet(bitcoinConfig.m_url, bitcoinConfig.m_rpcUser, bitcoinConfig.m_rpcPassword, false);

            m_bitsharesAccount      = bitsharesAccount;
            m_bitsharesAsset        = bitsharesAsset;
            m_bitcoinDespoitAddress = bitcoinDespositAddress;

            m_asset = m_bitshares.BlockchainGetAsset(bitsharesAsset);

            m_addressByteType = (byte)(bitcoinConfig.m_useTestnet ? AltCoinAddressTypeBytes.BitcoinTestnet : AltCoinAddressTypeBytes.Bitcoin);
        }
Exemple #20
0
        /// <summary>
        /// Print a list of all public methods in the wallet. The methods can be invoked from the command line,
        /// except for the ones with complex types (like lists, classes and dictionaries) as input parameters.
        /// </summary>
        /// <param name="wallet">Wallet to list commands for.</param>
        public static void ShowCommands(BitcoinWallet wallet)
        {
            Type type    = wallet.GetType();
            var  methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
                           .Where(m => m.IsPublic && !m.IsConstructor && !m.IsSpecialName)
                           .OrderBy(m => m.Name)
                           .ToList();

            string input = "h";

            while (input != "q")
            {
                Console.Clear();

                int      index;
                string[] inputParts = input.Split(new[] { "," }, StringSplitOptions.None);
                if (!string.IsNullOrEmpty(input) && int.TryParse(inputParts[0], out index) && methods.Count > index)
                {
                    InvokeMethode(wallet, methods[index], inputParts);
                }
                else
                {
                    Console.WriteLine("[h] Show this menu");
                    Console.WriteLine("===================");

                    for (int methodIndex = 0; methodIndex < methods.Count; methodIndex++)
                    {
                        Console.Write("[{0}] ", methodIndex);
                        PrintMethod(methods[methodIndex]);
                    }

                    Console.WriteLine("===================");
                    Console.WriteLine("[q] Quit");
                }

                input = Console.ReadLine();
            }
        }
Exemple #21
0
        static void Main(string[] args)
        {
            BitcoinWallet _wallet = new BitcoinWallet("http://127.0.0.1:8332", "dcuser_node", "JMzipYlSb4VxSC3N7eguTNkkyThE1Luxb1qdxISj", true);
            Decimal       balance = _wallet.GetBalance("1N5qam5vqiKobt8QFy2bx5d8kLPU51xhht");

            String tx = _wallet.SendRawTransaction("0100000002c4e646db121146bf0e894d3db8c9846717b79cac525df355a2f82ff1d6211da6010000008b48304502200ec3f9d78e8ba71ea6d9b7ff717f1ed27bbb45379d5d31237fe91b11e965a05c022100bd1f447160fc5927ef8aaf053492199fd73cee103ef5d69b49cecf4936c2fcf6014104a8cbfeacff41f6b04eb5c5cda31d1a75d9febbe20e9f750d519842f0a138d70d9d013207f6ed617840ad9f78b667e986c7b90f0708f4f44395aa1f4f69bf631cffffffff1f060effe001471ae8cbcc88f4748e7ae88723f1299ced6c8b31fbaf98ab32c5000000008b483045022064ec164a4f2cea955ea103cafeae056526035ede198e166c5d0c533c80a66bda022100e1c37a3ba64a89cb1c297ccc2dd6547ee3b0874794b1629012d485b9475f0c36014104a8cbfeacff41f6b04eb5c5cda31d1a75d9febbe20e9f750d519842f0a138d70d9d013207f6ed617840ad9f78b667e986c7b90f0708f4f44395aa1f4f69bf631cffffffff02c95bbd00000000001976a914d0acbaa610e441aef23937866345ef8512640c2788ac80969800000000001976a914e20134d6a50e4f4f9519109aa9c4395bee61887088ac00000000");

            //const String PRIVATE_KEY_AS_DEC2 = "56264673822963068407370790525340191907437491654303176136090258467429147271236";
            //srLocal.AtmClient localClient = new srLocal.AtmClient();

            //localClient.SendBitcoins2(PRIVATE_KEY_AS_DEC2, "1DugongACGcyyvvgvcy8skYyezsx5jy3aV", 0.001M);

            localClient.SendBitcoins2(PRIVATE_KEY_AS_DEC2, "1DugongACGcyyvvgvcy8skYyezsx5jy3aV", 0.0001M);

            String gc = "01000000020BA61AB58CF807E091515BDA6CC3B58E47A5702A53AFB90126E2376E1AD4FE9E000000008B4830450221008C8C0A7D0B813992F9E443E12DA2B1C4CCE72604757483B5AC8CF4089CF6365202206F3C67D01EBA34D9E8450E8FAC39D089A119BF8C16D8F02FA02785ED7D829F7E014104A8CBFEACFF41F6B04EB5C5CDA31D1A75D9FEBBE20E9F750D519842F0A138D70D9D013207F6ED617840AD9F78B667E986C7B90F0708F4F44395AA1F4F69BF631CFFFFFFFFDB7C5C3C2011CEE5B4402FEDD03BA0B37566B905CA49857ACF97C10D33438415000000008A47304402201DD98389E5A59E7F2E5AC8F4E2D359472CCD3E25C2256E458A712BB0A734AF9D02204E03FDF5B675DC154E44CD1848B30DC6F273EA8D6C72EB1A7456740520653C17014104A8CBFEACFF41F6B04EB5C5CDA31D1A75D9FEBBE20E9F750D519842F0A138D70D9D013207F6ED617840AD9F78B667E986C7B90F0708F4F44395AA1F4F69BF631CFFFFFFFF01706F9800000000001976A914B769ACCEE57C332F74B18A133CAEE9B283285A4688AC00000000";
            //string sk = "01000000020BA61AB58CF807E091515BDA6CC3B58E47A5702A53AFB90126E2376E1AD4FE9E000000008B48304502206BDD05C4741DC75B7087F0FCD8BC2DFC7A19A0E3A203A60F49D98B601950767D022100AED6E4CF8F4AD4AAC00EB58B7B9D505AA81087A80AF2002CE8C37EA652B71583014104A8CBFEACFF41F6B04EB5C5CDA31D1A75D9FEBBE20E9F750D519842F0A138D70D9D013207F6ED617840AD9F78B667E986C7B90F0708F4F44395AA1F4F69BF631CFFFFFFFFDB7C5C3C2011CEE5B4402FEDD03BA0B37566B905CA49857ACF97C10D33438415000000008B48304502203A8D7173F83EC95DEED64A30926EE9F42F20C1F53FAD3631F8E9841093B17E4F022100C27CE4561872A3735796926C4309CC71D7E772BBB0338140F3F903F238624058014104A8CBFEACFF41F6B04EB5C5CDA31D1A75D9FEBBE20E9F750D519842F0A138D70D9D013207F6ED617840AD9F78B667E986C7B90F0708F4F44395AA1F4F69BF631CFFFFFFFF01706F9800000000001976A91407BDEC596751A706C76C8F110E27E7F6F2AB5ECE88AC00000000";

            //var trans =_wallet.DecodeRawTransaction(gc);

            String txn = _wallet.SendRawTransaction(gc);

            Console.WriteLine(txn);
            Console.ReadKey();
        }
Exemple #22
0
 public Bitcoind(String host, String user, String password)
 {
     _wallet = new BitcoinWallet(host, user, password, true);
 }
        /// <summary>	Constructor. </summary>
        ///
        /// <remarks>	Paul, 05/02/2015. </remarks>
        ///
        /// <param name="uid">			    The UID. </param>
        /// <param name="base">			    The base. </param>
        /// <param name="quote">		    The quote. </param>
        /// <param name="bitshares">	    The bitshares. </param>
        /// <param name="bitcoin">		    The bitcoin. </param>
        /// <param name="bitsharesAccount">	The bitshares account. </param>
        public InternalMarket(MetaDaemonApi daemon, MarketRow market, BitsharesWallet bitshares, BitcoinWallet bitcoin,
                              string bitsharesAccount, CurrenciesRow bitsharesAsset) :
            base(daemon, market, bitshares, bitcoin, bitsharesAccount)
        {
            m_currency = bitsharesAsset;
            m_flipped  = m_market.GetBase(daemon.m_AllCurrencies) != bitsharesAsset;
            m_asset    = m_bitshares.BlockchainGetAsset(CurrencyHelpers.ToBitsharesSymbol(bitsharesAsset));

            Dictionary <int, ulong> allBitsharesBalances = m_bitshares.WalletAccountBalance(bitsharesAccount)[bitsharesAccount];
            decimal bitcoinBalance = bitcoin.GetBalance();

            ComputeMarketPricesAndLimits(ref m_market, allBitsharesBalances, bitcoinBalance);
        }