Ejemplo n.º 1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public TxFlood() : base()
        {
            _rand = new Random();

            // This is used for relay directly without enter in our mempool

            _sendDirectlyType = typeof(LocalNode).GetMembers(BindingFlags.NonPublic)
                                .Where(u => u.Name == "SendDirectly")
                                .Cast <Type>()
                                .FirstOrDefault();

            _sendDirectlyField = _sendDirectlyType.GetFields(BindingFlags.Public | BindingFlags.Instance)
                                 .Where(u => u.Name == "Inventory")
                                 .FirstOrDefault();

            // Open wallet

            Wallet = WalletHelper.OpenWallet(WALLET_FILE, WALLET_PASS);

            _sources      = Wallet.GetAccounts().Skip(1).ToArray();
            _destinations = _sources.Skip(1).Concat(_sources.Take(1)).ToArray();

            // Warm up

            Parallel.ForEach(_sources, (a) => a.GetKey());
        }
Ejemplo n.º 2
0
        public ActionResult GetTTLBalance(string privateKeyHex)
        {
            var      wallet   = WalletHelper.GetWallet(privateKeyHex);
            Contract contract = new Contract(CurrentNetwork, privateKeyHex);

            return(Json(contract.GetTokenBalance()));
        }
Ejemplo n.º 3
0
        public void TestGetPrivateKeyFromWIFInvalidPrivateKey()
        {
            var invalidWif = Crypto.Default.Base58CheckEncode(new byte[] { 127, 33, 68, 4, 111, 111, 43, 161, 201, 123, 240, 182, 240, 48, 97, 165, 233, 223, 133, 20, 106, 12, 245, 240, 46, 69, 25, 1, 34, 115, 30, 37, 224, 1 });
            var testee     = new WalletHelper();

            testee.GetPrivateKeyFromWIF(invalidWif);
        }
Ejemplo n.º 4
0
        public void TestGetPrivateKeyFromWIF()
        {
            var wif      = "KxLNhtdXXqaYUW1DKBc1XYQLxhouxXPLgQhR8kk7SYG3ajjR8M8a";
            var testee   = new WalletHelper();
            var result   = testee.GetPrivateKeyFromWIF(wif);
            var expected = new byte[] { 33, 68, 4, 111, 111, 43, 161, 201, 123, 240, 182, 240, 48, 97, 165, 233, 223, 133, 20, 106, 12, 245, 240, 46, 69, 25, 1, 34, 115, 30, 37, 224 };

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Facilitates the invoking of the Treatail Smart Contract
 /// </summary>
 /// <param name="networkType">Network to use</param>
 /// <param name="contextWallet">Wallet to use for signing context</param>
 public Contract(NetworkType networkType, string privateKeyHex)
 {
     _api   = NetworkHelper.GetNeoRPCForType(networkType);
     _token = new NEP5(_api, _contractScriptHash);
     if (privateKeyHex != null)
     {
         _contextWallet = WalletHelper.GetWallet(privateKeyHex);
     }
 }
Ejemplo n.º 6
0
        public bool Create()
        {
            var wallet = WalletHelper.CreateWallet();

            if (wallet == null || String.IsNullOrEmpty(wallet.Address) || String.IsNullOrEmpty(wallet.PrivateKey))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
 public async void ArchiveAddress_NullAddress_ArgumentNullException()
 {
     await Assert.ThrowsAsync <ArgumentNullException>(async() =>
     {
         using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
         {
             WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
             await walletHelper.ArchiveAddress(null);
         }
     });
 }
Ejemplo n.º 8
0
 public async void ListAddresses_NegativeConfirmations_ArgumentOutOfRangeException()
 {
     await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() =>
     {
         using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
         {
             WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
             await walletHelper.ListAddressesAsync(-1);
         }
     });
 }
Ejemplo n.º 9
0
        public async void SendPayment_SendBtc_NoFreeOutputs()
        {
            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() => {
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
                {
                    WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                    await walletHelper.SendAsync(WalletTests.FIRST_ADDRESS, BitcoinValue.FromBtc(1));
                }
            });

            Assert.Contains("No free", apiException.Message);
        }
Ejemplo n.º 10
0
        public async void GetAddresses_Valid()
        {
            using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
            {
                WalletHelper   walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                List <Address> addresses    = await walletHelper.ListAddressesAsync();

                Assert.NotNull(addresses);
                Assert.NotEmpty(addresses);
                Assert.True(addresses.Any(a => string.Equals(a.AddressStr, WalletTests.FIRST_ADDRESS)));
            }
        }
Ejemplo n.º 11
0
        public async void Unarchive_BadAddress_ServerApiException()
        {
            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() => {
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
                {
                    WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                    await walletHelper.UnarchiveAddress("BadAddress");
                }
            });

            Assert.Contains("Checksum", apiException.Message);
        }
Ejemplo n.º 12
0
        protected WalletCore(NodeServices nodeServices, string walletPath)
        {
            this.nodeServices = nodeServices;

            this.WalletPath               = walletPath;
            this.x1WalletFile             = WalletHelper.LoadX1WalletFile(walletPath);
            this.x1WalletFile.CurrentPath = walletPath;
            this.WalletName               = this.x1WalletFile.WalletName;
            this.metadataPath             = this.x1WalletFile.WalletName.GetX1WalletMetaDataFilepath(C.Network, nodeServices.DataFolder);
            this.metadata = WalletHelper.LoadOrCreateX1WalletMetadataFile(this.metadataPath, this.x1WalletFile, C.Network.GenesisHash);

            ScheduleSyncing();
        }
Ejemplo n.º 13
0
        public async void SendPayment_SendMultiBtc_NoFreeOutputs()
        {
            ServerApiException apiException = await Assert.ThrowsAsync <ServerApiException>(async() => {
                using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
                {
                    WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                    Dictionary <string, BitcoinValue> recipients = new Dictionary <string, BitcoinValue>()
                    {
                        { "17VYDFsDxBMovM1cKGEytgeqdijNcr4L5", BitcoinValue.FromBtc(1) }
                    };
                    await walletHelper.SendManyAsync(recipients);
                }
            });

            Assert.Contains("No free", apiException.Message);
        }
Ejemplo n.º 14
0
        public async void NewAddress_ArchiveThenConsolidate_Valid()
        {
            using (BlockchainApiHelper apiHelper = new BlockchainApiHelper())
            {
                WalletHelper walletHelper = apiHelper.CreateWalletHelper(WalletTests.WALLET_ID, WalletTests.WALLET_PASSWORD, WalletTests.WALLET_PASSWORD2);
                Address      address      = await walletHelper.NewAddress("Test");

                Assert.NotNull(address);

                string archivedAddress = await walletHelper.ArchiveAddress(address.AddressStr);

                Assert.NotNull(archivedAddress);


                string unarchivedAddress = await walletHelper.UnarchiveAddress(archivedAddress);

                Assert.NotNull(unarchivedAddress);
            }
        }
Ejemplo n.º 15
0
        public async void SendMany_NullReeipients_ArgumentNUllException()
        {
            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendManyAsync(null);
                }
            });

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendManyAsync(new Dictionary <string, BitcoinValue>());
                }
            });
        }
Ejemplo n.º 16
0
        public async void Send_BadParameters_ArgumentExceptions()
        {
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendAsync(null, BitcoinValue.Zero);
                }
            });

            await Assert.ThrowsAsync <ArgumentException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.SendAsync("Test", BitcoinValue.FromBtc(-1));
                }
            });
        }
Ejemplo n.º 17
0
        public async void GetAddress_BadParameters_ArgumentExceptions()
        {
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.GetAddressAsync(null);
                }
            });

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() =>
            {
                using (BlockchainApiHelper apiHelper = UnitTestUtil.GetFakeHelper())
                {
                    WalletHelper walletHelper = this.GetWalletHelper(apiHelper);
                    await walletHelper.GetAddressAsync("Test", -1);
                }
            });
        }
        private bool TryUnlockWalletForStakingOnly(out string errorMessage)
        {
            WalletHelper helper = new WalletHelper(m_dataConnector);

            // Attempt 2 unlocks to work around a wallet bug where the first unlock for staking only seems to unlock the whole wallet.
            if (!helper.TryUnlockWallet(
                    m_walletPassphrase,
                    m_config.RunFrequencyInMilliSeconds * 3,
                    true,
                    out errorMessage))
            {
                return(false);
            }

            return(helper.TryUnlockWallet(
                       m_walletPassphrase,
                       m_config.RunFrequencyInMilliSeconds * 3,
                       true,
                       out errorMessage));
        }
Ejemplo n.º 19
0
 public Nep6WalletManager(IFileWrapper fileWrapper, IJsonConverter jsonConverter)
 {
     _walletHelper  = new WalletHelper();
     _fileWrapper   = fileWrapper;
     _jsonConverter = jsonConverter;
 }
        private bool TryCheckWalletCompaitibility(out string errorMessage)
        {
            WalletHelper helper = new WalletHelper(m_dataConnector);

            return(helper.TryCheckWalletCompaitibility(MessageService, out errorMessage));
        }
        private bool TryUnlockWallet(out string errorMessage)
        {
            WalletHelper helper = new WalletHelper(m_dataConnector);

            return(helper.TryUnlockWallet(m_walletPassphrase, 5, false, out errorMessage));
        }
Ejemplo n.º 22
0
        public decimal GetGASBalance(NetworkType network, string privateKeyHex)
        {
            var wallet = WalletHelper.GetWallet(privateKeyHex);

            return(wallet.GetBalance(network, WalletBalanceType.GAS));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates the wallet and user account for the hosted user wallet
 /// </summary>
 /// <returns>The created wallet info</returns>
 public ActionResult Create()
 {
     return(Json(WalletHelper.CreateWallet(), JsonRequestBehavior.AllowGet));
 }
Ejemplo n.º 24
0
 public ActionResult GetGASBalance(string privateKeyHex)
 {
     return(Json(WalletHelper.GetWallet(privateKeyHex).GetBalance(CurrentNetwork, WalletBalanceType.GAS)));
 }
Ejemplo n.º 25
0
        public void TestGetPrivateKeyFromWIFNull()
        {
            var testee = new WalletHelper();

            testee.GetPrivateKeyFromWIF(null);
        }