Exemplo n.º 1
0
        public IActionResult GetInfo()
        {
            try
            {
                bool isMainchain = this.federationGatewaySettings.IsMainChain;

                var model = new FederationGatewayInfoModel
                {
                    IsActive    = this.federationWalletManager.IsFederationActive(),
                    IsMainChain = isMainchain,
                    FederationNodeIpEndPoints   = this.federationGatewaySettings.FederationNodeIpEndPoints.Select(i => $"{i.Address}:{i.Port}"),
                    MultisigPublicKey           = this.federationGatewaySettings.PublicKey,
                    FederationMultisigPubKeys   = this.federationGatewaySettings.FederationPublicKeys.Select(k => k.ToString()),
                    MiningPublicKey             = isMainchain ? null : this.federationManager.FederationMemberKey?.PubKey.ToString(),
                    FederationMiningPubKeys     = isMainchain ? null : this.federationManager.GetFederationMembers().Select(k => k.ToString()),
                    MultiSigAddress             = this.federationGatewaySettings.MultiSigAddress,
                    MultiSigRedeemScript        = this.federationGatewaySettings.MultiSigRedeemScript.ToString(),
                    MinimumDepositConfirmations = this.federationGatewaySettings.MinimumDepositConfirmations
                };

                return(this.Json(model));
            }
            catch (Exception e)
            {
                this.logger.LogTrace("Exception thrown calling /api/FederationGateway/{0}: {1}.", FederationGatewayRouteEndPoint.GetInfo, e.Message);
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString()));
            }
        }
        public void Call_Sidechain_Gateway_Get_Info()
        {
            string redeemScript   = "2 02fad5f3c4fdf4c22e8be4cfda47882fff89aaa0a48c1ccad7fa80dc5fee9ccec3 02503f03243d41c141172465caca2f5cef7524f149e965483be7ce4e44107d7d35 03be943c3a31359cd8e67bedb7122a0898d2c204cf2d0119e923ded58c429ef97c 3 OP_CHECKMULTISIG";
            string federationIps  = "127.0.0.1:36201,127.0.0.1:36202,127.0.0.1:36203";
            string multisigPubKey = "03be943c3a31359cd8e67bedb7122a0898d2c204cf2d0119e923ded58c429ef97c";

            string[]     args         = new[] { "-sidechain", "-regtest", $"-federationips={federationIps}", $"-redeemscript={redeemScript}", $"-publickey={multisigPubKey}", "-mincoinmaturity=1", "-mindepositconfirmations=1" };
            NodeSettings nodeSettings = new NodeSettings(FederatedPegNetwork.NetworksSelector.Regtest(), ProtocolVersion.ALT_PROTOCOL_VERSION, args: args);

            this.federationWalletManager.IsFederationActive().Returns(true);

            this.federationManager.Initialize();

            FederationGatewaySettings settings = new FederationGatewaySettings(nodeSettings);

            var controller = new FederationGatewayController(
                this.loggerFactory,
                this.network,
                this.leaderProvider,
                this.GetMaturedBlocksProvider(),
                this.leaderReceiver,
                settings,
                this.federationWalletManager,
                this.federationManager);

            IActionResult result = controller.GetInfo();

            result.Should().BeOfType <JsonResult>();
            ((JsonResult)result).Value.Should().BeOfType <FederationGatewayInfoModel>();

            FederationGatewayInfoModel model = ((JsonResult)result).Value as FederationGatewayInfoModel;

            model.IsMainChain.Should().BeFalse();
            model.FederationMiningPubKeys.Should().Equal(((PoAConsensusOptions)FederatedPegNetwork.NetworksSelector.Regtest().Consensus.Options).GenesisFederationPublicKeys.Select(keys => keys.ToString()));
            model.MultiSigRedeemScript.Should().Be(redeemScript);
            string.Join(",", model.FederationNodeIpEndPoints).Should().Be(federationIps);
            model.IsActive.Should().BeTrue();
            model.MinCoinMaturity.Should().Be(1);
            model.MinimumDepositConfirmations.Should().Be(1);
            model.MultisigPublicKey.Should().Be(multisigPubKey);
        }