public void Given_AWalletIsPresent_When_GetWatchOnlyWalletIsCalled_ThenthewalletIsreturned()
        {
            DataFolder      dataFolder = CreateDataFolder(this);
            WatchOnlyWallet wallet     = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, this.networkTestNet, dataFolder, this.signals);

            walletManager.Initialize();

            // Retrieve the wallet.
            WatchOnlyWallet returnedWallet = walletManager.GetWatchOnlyWallet();

            Assert.NotNull(returnedWallet);
            Assert.Equal(wallet.CreationTime.ToString("u"), returnedWallet.CreationTime.ToString("u"));
        }
        public void Given_AWatchedAddress_And_A_WatchedTransaction_CanPopulateLookup()
        {
            DataFolder      dataFolder      = CreateDataFolder(this);
            WatchOnlyWallet watchOnlyWallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            // Only need to watch a single address/transaction
            Script newScript      = BitcoinAddress.Create("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE", this.networkTestNet).ScriptPubKey;
            string transactionHex = "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff230384041200fe0eb3a959fe1af507000963676d696e6572343208000000000000000000ffffffff02155e8b09000000001976a9144bfe90c8e6c6352c034b3f57d50a9a6e77a62a0788ac0000000000000000266a24aa21a9ed0bc6e4bfe82e04a1c52e66b72b199c5124794dd8c3c368f6ab95a0ba6cde277d0120000000000000000000000000000000000000000000000000000000000000000000000000";

            // Ensure transaction appears in block
            Transaction transaction = this.networkTestNet.CreateTransaction(transactionHex);
            Block       block       = this.networkTestNet.Consensus.ConsensusFactory.CreateBlock();

            block.AddTransaction(transaction);
            block.UpdateMerkleRoot();

            var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, this.networkTestNet, dataFolder, this.signals);

            walletManager.Initialize();
            walletManager.WatchAddress("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE");
            walletManager.StoreTransaction(new WatchTransactionData()
            {
                Id  = transaction.GetHash(),
                Hex = transactionHex
            });
            walletManager.ProcessBlock(block);

            WatchOnlyWallet wallet = walletManager.GetWatchOnlyWallet();

            // Artificially remove info from the watched address version of the transaction
            WatchedAddress       addressInWallet    = wallet.WatchedAddresses[newScript.ToString()];
            WatchTransactionData watchedTransaction = addressInWallet.Transactions.Values.First();

            watchedTransaction.MerkleProof = null;
            watchedTransaction.BlockHash   = null;

            // Now populate lookup
            ConcurrentDictionary <uint256, WatchTransactionData> lookup = wallet.GetWatchedTransactions();

            // Expect that the cached version of the transaction has a
            // Merkle proof and block hash

            WatchTransactionData lookupTransaction = lookup[transaction.GetHash()];

            Assert.NotNull(lookupTransaction.MerkleProof);
            Assert.NotNull(lookupTransaction.BlockHash);
        }
        public void Given_AWatchedAddress_When_ATransactionIsReceivedInABlock_ThenTransactionDataIsAddedToTheAddress()
        {
            // Arrange.
            string dir        = AssureEmptyDir("TestData/WatchOnlyWalletManagerTest/Given_AWatchedAddress_When_ATransactionIsReceivedInABlock_ThenTransactionDataIsAddedToTheAddress");
            var    dataFolder = new DataFolder(new NodeSettings {
                DataDir = dir
            });

            // Create the wallet to watch.
            var wallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            // Create the address to watch.
            Script newScript  = BitcoinAddress.Create("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE", Network.TestNet).ScriptPubKey;
            string newAddress = newScript.GetDestinationAddress(Network.TestNet).ToString();

            // Create a transaction to be received.
            string      transactionHex = "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff230384041200fe0eb3a959fe1af507000963676d696e6572343208000000000000000000ffffffff02155e8b09000000001976a9144bfe90c8e6c6352c034b3f57d50a9a6e77a62a0788ac0000000000000000266a24aa21a9ed0bc6e4bfe82e04a1c52e66b72b199c5124794dd8c3c368f6ab95a0ba6cde277d0120000000000000000000000000000000000000000000000000000000000000000000000000";
            Transaction transaction    = new Transaction(transactionHex);
            var         block          = new Block();

            block.AddTransaction(transaction);
            block.UpdateMerkleRoot();

            // Act.
            var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, Network.TestNet, dataFolder);

            walletManager.Initialize();
            walletManager.WatchAddress("mnSmvy2q4dFNKQF18EBsrZrS7WEy6CieEE");
            walletManager.ProcessBlock(block);

            // Assert.
            var returnedWallet = walletManager.GetWatchOnlyWallet();

            Assert.NotNull(returnedWallet);

            var addressInWallet = returnedWallet.WatchedAddresses[newScript.ToString()];

            Assert.NotNull(addressInWallet);
            Assert.False(addressInWallet.Transactions.IsEmpty);
            Assert.Single(addressInWallet.Transactions);

            var transactionExpected = addressInWallet.Transactions.Single().Value;

            Assert.Equal(transactionHex, transactionExpected.Hex);
            Assert.NotNull(transactionExpected.BlockHash);
            Assert.NotNull(transactionExpected.MerkleProof);
        }
Beispiel #4
0
        public void Given_AWalletIsPresent_When_GetWatchOnlyWalletIsCalled_ThenthewalletIsreturned()
        {
            string dir        = AssureEmptyDir("TestData/WatchOnlyWalletManagerTest/Given_AWalletIsPresent_When_GetWatchOnlyWalletIsCalled_ThenthewalletIsreturned");
            var    dataFolder = new DataFolder(new NodeSettings {
                DataDir = dir
            });
            var wallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            var walletManager = new WatchOnlyWalletManager(this.LoggerFactory.Object, Network.Main, dataFolder);

            walletManager.Initialize();

            // Retrieve the wallet.
            var returnedWallet = walletManager.GetWatchOnlyWallet();

            Assert.NotNull(returnedWallet);
            Assert.Equal(wallet.CreationTime.ToString("u"), returnedWallet.CreationTime.ToString("u"));
        }
        public void Given_AnAddressIsPassed_When_WatchAddressIsCalled_ThenAnAddressIsAddedToTheWatchList()
        {
            DataFolder      dataFolder = CreateDataFolder(this);
            WatchOnlyWallet wallet     = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            var walletManager = new WatchOnlyWalletManager(DateTimeProvider.Default, this.LoggerFactory.Object, this.networkTestNet, dataFolder, this.signals);

            walletManager.Initialize();

            // create the wallet
            Script newScript  = new Key().ScriptPubKey;
            string newAddress = newScript.GetDestinationAddress(this.networkTestNet).ToString();

            walletManager.WatchAddress(newAddress);

            WatchOnlyWallet returnedWallet = walletManager.GetWatchOnlyWallet();

            Assert.NotNull(returnedWallet);
            Assert.True(returnedWallet.WatchedAddresses.ContainsKey(newScript.ToString()));
        }
Beispiel #6
0
        public void Given_AnAddressIsPassed_When_WatchAddressIsCalled_ThenAnAddressIsAddedToTheWatchList()
        {
            string dir        = AssureEmptyDir("TestData/WatchOnlyWalletManagerTest/Given_AnAddressIsPassed_When_WatchAddressIsCalled_ThenAnAddressIsAddedToTheWatchList");
            var    dataFolder = new DataFolder(new NodeSettings {
                DataDir = dir
            });
            var wallet = this.CreateAndPersistAWatchOnlyWallet(dataFolder);

            var walletManager = new WatchOnlyWalletManager(this.LoggerFactory.Object, Network.Main, dataFolder);

            walletManager.Initialize();

            // create the wallet
            Script newScript  = new Key().ScriptPubKey;
            string newAddress = newScript.GetDestinationAddress(Network.Main).ToString();

            walletManager.WatchAddress(newAddress);

            var returnedWallet = walletManager.GetWatchOnlyWallet();

            Assert.NotNull(returnedWallet);
            Assert.True(returnedWallet.WatchedAddresses.ContainsKey(newScript.ToString()));
        }