/// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="fullNode">Full Node.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
        /// <param name="walletManager">The wallet manager.</param>
        /// <param name="posMinting">PoS staker or null if PoS staking is not enabled.</param>
        public MinerController(IFullNode fullNode, ILoggerFactory loggerFactory, IWalletManager walletManager, IPosMinting posMinting = null)
        {
            Guard.NotNull(fullNode, nameof(fullNode));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));

            this.fullNode      = fullNode;
            this.logger        = loggerFactory.CreateLogger(this.GetType().FullName);
            this.walletManager = walletManager;
            this.posMinting    = posMinting;
        }
 public StakingBroadcaster(
     ILoggerFactory loggerFactory,
     IPosMinting posMinting,
     INodeLifetime nodeLifetime,
     IAsyncProvider asyncProvider,
     EventsHub eventsHub)
     : base(eventsHub, loggerFactory, nodeLifetime, asyncProvider)
 {
     this.posMinting = posMinting;
 }
 public StakingBroadcaster(
     ILoggerFactory loggerFactory,
     IPosMinting posMinting,
     INodeLifetime nodeLifetime,
     IAsyncProvider asyncProvider,
     IEventsSubscriptionService subscriptionService = null)
     : base(loggerFactory, nodeLifetime, asyncProvider, subscriptionService)
 {
     this.posMinting = posMinting;
 }
示例#4
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="fullNode">Full Node.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
        /// <param name="walletManager">The wallet manager.</param>
        /// <param name="posMinting">PoS staker or null if PoS staking is not enabled.</param>
        public StakingController(IFullNode fullNode, ILoggerFactory loggerFactory, IWalletManager walletManager, IPosMinting posMinting = null)
        {
            Guard.NotNull(fullNode, nameof(fullNode));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));

            this.fullNode      = fullNode;
            this.logger        = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
            this.walletManager = walletManager;
            this.posMinting    = posMinting;
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the object.
        /// </summary>
        /// <param name="powMining">PoW miner.</param>
        /// <param name="fullNode">Full node to offer mining RPC.</param>
        /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
        /// <param name="walletManager">The wallet manager.</param>
        /// <param name="posMinting">PoS staker or null if PoS staking is not enabled.</param>
        public MiningRPCController(IPowMining powMining, IFullNode fullNode, ILoggerFactory loggerFactory, IWalletManager walletManager, IPosMinting posMinting = null) : base(fullNode: fullNode)
        {
            Guard.NotNull(powMining, nameof(powMining));
            Guard.NotNull(fullNode, nameof(fullNode));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));

            this.fullNode      = fullNode;
            this.logger        = loggerFactory.CreateLogger(this.GetType().FullName);
            this.walletManager = walletManager;
            this.powMining     = powMining;
            this.posMinting    = posMinting;
        }
示例#6
0
        /// <summary>
        ///     Initializes a new instance of the object.
        /// </summary>
        public StakingController(IFullNode fullNode, ILoggerFactory loggerFactory, IWalletManager walletManager,
                                 MinerSettings minerSettings, IPosMinting posMinting = null)
        {
            Guard.NotNull(fullNode, nameof(fullNode));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(walletManager, nameof(walletManager));

            this.fullNode      = fullNode;
            this.logger        = loggerFactory.CreateLogger(GetType().FullName);
            this.walletManager = walletManager;
            this.minerSettings = minerSettings;
            this.posMinting    = posMinting;
        }
 /// <summary>
 /// Initializes the instance of the object.
 /// </summary>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="minerSettings">Settings relevant to mining or staking.</param>
 /// <param name="nodeSettings">The node's configuration settings.</param>
 /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
 /// <param name="timeSyncBehaviorState">State of time synchronization feature that stores collected data samples.</param>
 /// <param name="powMining">POW miner.</param>
 /// <param name="posMinting">POS staker.</param>
 public MiningFeature(
     Network network,
     MinerSettings minerSettings,
     NodeSettings nodeSettings,
     ILoggerFactory loggerFactory,
     ITimeSyncBehaviorState timeSyncBehaviorState,
     IPowMining powMining,
     IPosMinting posMinting = null)
 {
     this.network               = network;
     this.minerSettings         = minerSettings;
     this.nodeSettings          = nodeSettings;
     this.powMining             = powMining;
     this.timeSyncBehaviorState = timeSyncBehaviorState;
     this.posMinting            = posMinting;
     this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
 }
示例#8
0
 /// <summary>
 /// Initializes the instance of the object.
 /// </summary>
 /// <param name="network">Specification of the network the node runs on - regtest/testnet/mainnet.</param>
 /// <param name="minerSettings">Settings relevant to mining or staking.</param>
 /// <param name="nodeSettings">The node's configuration settings.</param>
 /// <param name="loggerFactory">Factory to be used to create logger for the node.</param>
 /// <param name="powMining">POW miner.</param>
 /// <param name="posMinting">POS staker.</param>
 /// <param name="walletManager">Manager providing operations on wallets.</param>
 public MiningFeature(
     Network network,
     MinerSettings minerSettings,
     NodeSettings nodeSettings,
     ILoggerFactory loggerFactory,
     IPowMining powMining,
     IPosMinting posMinting       = null,
     IWalletManager walletManager = null)
 {
     this.network       = network;
     this.minerSettings = minerSettings;
     this.minerSettings.Load(nodeSettings);
     this.powMining     = powMining;
     this.posMinting    = posMinting;
     this.walletManager = walletManager;
     this.logger        = loggerFactory.CreateLogger(this.GetType().FullName);
 }
示例#9
0
 public MiningFeature(
     ConnectionManagerSettings connectionManagerSettings,
     Network network,
     MinerSettings minerSettings,
     NodeSettings nodeSettings,
     ILoggerFactory loggerFactory,
     ITimeSyncBehaviorState timeSyncBehaviorState,
     IPowMining powMining,
     IPosMinting posMinting = null)
 {
     this.connectionManagerSettings = connectionManagerSettings;
     this.network               = network;
     this.minerSettings         = minerSettings;
     this.nodeSettings          = nodeSettings;
     this.powMining             = powMining;
     this.timeSyncBehaviorState = timeSyncBehaviorState;
     this.posMinting            = posMinting;
     this.logger = loggerFactory.CreateLogger("Impleum.Bitcoin.Fullnode");
 }
示例#10
0
        public async Task WalletCanReturnStakingHistoryCorrectlyAsync()
        {
            using var builder = NodeBuilder.Create(this);

            var configParameters = new NodeConfigParameters {
                { "txindex", "1" }
            };
            var network = new StraxRegTestAdjusedCoinbaseMaturity();

            // Start 2 nodes
            CoreNode miner  = builder.CreateStratisPosNode(network, "history-1-nodeA", configParameters: configParameters).OverrideDateTimeProvider().WithWallet().Start();
            CoreNode syncer = builder.CreateStratisPosNode(network, "history-1-nodeB", configParameters: configParameters).OverrideDateTimeProvider().WithWallet().Start();

            TestHelper.ConnectAndSync(miner, syncer);

            // Get mining address
            IEnumerable <string> miningAddresses = await $"http://localhost:{miner.ApiPort}/api"
                                                   .AppendPathSegment("wallet/unusedAddresses")
                                                   .SetQueryParams(new { walletName = "mywallet", accountName = "account 0", count = 1 })
                                                   .GetJsonAsync <IEnumerable <string> >();

            // Assert empty history call result.
            var noHistoryCall = $"http://localhost:{miner.ApiPort}/api"
                                .AppendPathSegment("wallet/history")
                                .SetQueryParams(new WalletHistoryRequest {
                WalletName = "mywallet", AccountName = "account 0"
            })
                                .GetAsync()
                                .ReceiveJson <WalletHistoryModel>().GetAwaiter().GetResult();

            Assert.Empty(noHistoryCall.AccountsHistoryModel.First().TransactionsHistory);

            // Mine some blocks to receive the premine and mature the chain.
            TestHelper.MineBlocks(miner, 20, miningAddress: miningAddresses.First());

            // Start staking on the node.
            IPosMinting minter = miner.FullNode.NodeService <IPosMinting>();

            minter.Stake(new List <WalletSecret>()
            {
                new WalletSecret()
                {
                    WalletName = "mywallet", WalletPassword = "******"
                }
            });

            // Stake to block height 30
            TestBase.WaitLoop(() => TestHelper.IsNodeSyncedAtHeight(miner, 30, 120), waitTimeSeconds: 120);

            // Stop staking.
            minter.StopStake();

            // Ensure nodes are synced.
            TestBase.WaitLoop(() => TestHelper.AreNodesSynced(miner, syncer));

            // Assert ordering
            var history = await CallHistoryAsync(miner);

            // Staking items should appear first in the result.
            var stakingTxs = history.Where(t => t.Type == TransactionItemType.Staked);

            Assert.NotEmpty(stakingTxs);
            var index = 0;

            do
            {
                var item = history[index];
                if (item.Type == TransactionItemType.Mined)
                {
                    break;
                }

                Assert.Equal(Money.Coins(9), item.Amount);
                Assert.Equal(TransactionItemType.Staked, item.Type);

                index += 1;
            } while (true);

            // Then the rest are mining txs
            for (int mIndex = index; mIndex < index + 20; mIndex++)
            {
                var item = history[mIndex];
                if ((miner.FullNode.ChainIndexer.Tip.Height - 2) == mIndex)
                {
                    Assert.Equal(Money.Coins(130_000_000), item.Amount); //premine
                }
                else
                {
                    Assert.Equal(Money.Coins(18), item.Amount);
                }

                Assert.Equal(miningAddresses.First(), item.ToAddress);
                Assert.Equal(TransactionItemType.Mined, item.Type);
            }

            // Assert Pagination and ordering
            var paging = $"http://localhost:{miner.ApiPort}/api"
                         .AppendPathSegment("wallet/history")
                         .SetQueryParams(new WalletHistoryRequest {
                WalletName = "mywallet", AccountName = "account 0", Skip = 0, Take = 10
            })
                         .GetAsync()
                         .ReceiveJson <WalletHistoryModel>().GetAwaiter().GetResult();

            Assert.Equal(10, paging.AccountsHistoryModel.First().TransactionsHistory.Count());
        }