コード例 #1
0
        public void VerifyThatColdStakeTransactionCanBeFiltered()
        {
            this.Initialize();
            this.CreateMempoolManager();

            this.coldStakingManager.CreateWallet(walletPassword, walletName1, walletPassphrase, new Mnemonic(walletMnemonic1));

            Wallet.Wallet wallet1 = this.coldStakingManager.GetWalletByName(walletName1);

            // This will add a normal account to our wallet.
            Transaction trx1 = this.AddSpendableTransactionToWallet(wallet1);

            // This will add a secondary account to our wallet.
            Transaction trx2 = this.AddSpendableColdstakingTransactionToWallet(wallet1);

            // THis will add a cold staking transaction to the secondary normal account address. This simulates activation of cold staking onto any normal address.
            Transaction trx3 = this.AddSpendableColdstakingTransactionToNormalWallet(wallet1);

            var accounts = wallet1.GetAccounts(Wallet.Wallet.AllAccounts).ToArray();

            // We should have 2 accounts in our wallet.
            Assert.Equal(2, accounts.Length);

            // But not if we use default or specify to only return normal accounts.
            Assert.Single(wallet1.GetAccounts().ToArray()); // Defaults to NormalAccounts
            Assert.Single(wallet1.GetAccounts(Wallet.Wallet.NormalAccounts).ToArray());

            // Verify that we actually have an cold staking activation UTXO in the wallet of 202 coins.
            // This should normally not be returned by the GetAllTransactions, and should never be included in balance calculations.
            Assert.True(accounts[0].ExternalAddresses.ToArray()[1].Transactions.ToArray()[0].IsColdCoinStake);
            Assert.Equal(new Money(202, MoneyUnit.BTC), accounts[0].ExternalAddresses.ToArray()[1].Transactions.ToArray()[0].Amount);

            Assert.Single(wallet1.GetAllTransactions().ToArray());                                                  // Default to NormalAccounts, should filter out cold staking (trx3) from normal wallet.
            Assert.Single(wallet1.GetAllTransactions(Wallet.Wallet.NormalAccounts).ToArray());
            Assert.Single(wallet1.GetAllSpendableTransactions(5, 0, Wallet.Wallet.NormalAccounts).ToArray());       // Default to NormalAccounts
            Assert.Equal(2, wallet1.GetAllTransactions(Wallet.Wallet.AllAccounts).ToArray().Length);
            Assert.Equal(2, wallet1.GetAllSpendableTransactions(5, 0, Wallet.Wallet.AllAccounts).ToArray().Length); // Specified AllAccounts, should include cold-staking transaction.

            // Verify balance on normal account
            var balance1 = accounts[0].GetBalances(true);
            var balance2 = accounts[0].GetBalances(false);

            Assert.Equal(new Money(101, MoneyUnit.BTC), balance1.ConfirmedAmount);
            Assert.Equal(new Money(303, MoneyUnit.BTC), balance2.ConfirmedAmount);

            // Verify balance on special account.
            // Verify balance on normal account
            var balance3 = accounts[1].GetBalances(true);
            var balance4 = accounts[1].GetBalances(false);

            // The only transaction that exists in the cold staking wallet, is a normal one, and should be returned for both balance queries.
            Assert.Equal(new Money(101, MoneyUnit.BTC), balance3.ConfirmedAmount);
            Assert.Equal(new Money(101, MoneyUnit.BTC), balance4.ConfirmedAmount);
        }
コード例 #2
0
        public IActionResult StakingExpiry([FromBody] StakingExpiryRequest request)
        {
            try
            {
                if (!this.fullNode.Network.Consensus.IsProofOfStake)
                {
                    return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed", "Method not available for Proof of Stake"));
                }

                if (!this.minerSettings.EnforceStakingFlag)
                {
                    return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Operation not allowed", "This operation is only allowed if EnforceStakingFlag is true"));
                }

                Wallet.Wallet wallet = this.walletManager.GetWallet(request.WalletName);

                foreach (Wallet.HdAccount account in wallet.GetAccounts(account => true))
                {
                    foreach (Wallet.HdAddress address in account.GetCombinedAddresses())
                    {
                        if ((address.Address == request.Address) || address.Bech32Address == request.Address)
                        {
                            address.StakingExpiry = request.StakingExpiry;
                        }
                    }
                }

                return(this.Ok());
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
コード例 #3
0
        public List <Transaction> RetrieveFilteredUtxos(string walletName, string walletPassword, string transactionHex, FeeRate feeRate, string walletAccount = null)
        {
            var retrievalTransactions = new List <Transaction>();

            Transaction transactionToReclaim = this.network.Consensus.ConsensusFactory.CreateTransaction(transactionHex);

            foreach (TxOut output in transactionToReclaim.Outputs)
            {
                Wallet.Wallet wallet = this.GetWallet(walletName);

                HdAddress address = wallet.GetAllAddresses(Wallet.Wallet.AllAccounts).FirstOrDefault(a => a.ScriptPubKey == output.ScriptPubKey);

                // The address is not in the wallet so ignore this output.
                if (address == null)
                {
                    continue;
                }

                HdAccount destinationAccount = wallet.GetAccounts(Wallet.Wallet.NormalAccounts).First();

                // This shouldn't really happen unless the user has no proper accounts in the wallet.
                if (destinationAccount == null)
                {
                    continue;
                }

                Script destination = destinationAccount.GetFirstUnusedReceivingAddress().ScriptPubKey;

                ISecret extendedPrivateKey = wallet.GetExtendedPrivateKeyForAddress(walletPassword, address);

                Key privateKey = extendedPrivateKey.PrivateKey;

                var builder = new TransactionBuilder(this.network);

                var coin = new Coin(transactionToReclaim, output);

                builder.AddCoins(coin);
                builder.AddKeys(privateKey);
                builder.Send(destination, output.Value);
                builder.SubtractFees();
                builder.SendEstimatedFees(feeRate);

                Transaction builtTransaction = builder.BuildTransaction(true);

                retrievalTransactions.Add(builtTransaction);
            }

            return(retrievalTransactions);
        }
コード例 #4
0
        public IActionResult GetStakingNotExpired(StakingNotExpiredRequest request)
        {
            try
            {
                if (!this.fullNode.Network.Consensus.IsProofOfStake)
                {
                    return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.MethodNotAllowed, "Method not allowed", "Method not available for Proof of Stake"));
                }

                if (!this.minerSettings.EnforceStakingFlag)
                {
                    return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.Forbidden, "Operation not allowed", "This operation is only allowed if EnforceStakingFlag is true"));
                }

                Wallet.Wallet wallet = this.walletManager.GetWallet(request.WalletName);

                GetStakingAddressesModel model = new GetStakingAddressesModel {
                    Addresses = new List <GetStakingAddressesModelItem>()
                };

                foreach (Wallet.HdAccount account in wallet.GetAccounts(account => true))
                {
                    foreach (Wallet.HdAddress address in account.GetCombinedAddresses())
                    {
                        if (address.StakingExpiry != null && address.StakingExpiry > DateTime.UtcNow)
                        {
                            model.Addresses.Add(new GetStakingAddressesModelItem
                            {
                                Addresses = request.Segwit ? address.Bech32Address : address.Address,
                                Expiry    = address.StakingExpiry
                            });
                        }
                    }
                }

                return(this.Json(model));
            }
            catch (Exception e)
            {
                this.logger.LogError("Exception occurred: {0}", e.ToString());
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }