private Transaction CreateRegistrationTransaction() { var config = new ServiceNodeRegistrationConfig { ProtocolVersion = (int)ServiceNodeProtocolVersion.INITIAL, Ipv4Address = IPAddress.Parse("127.0.0.1"), Port = 37123, CollateralPubKeyHash = this.walletSecret.PubKeyHash, RewardPubKeyHash = this.walletSecret.PubKeyHash, PrivateKey = this.walletKey, ServiceEndpoint = new Uri("https://redstone.com/test") }; RegistrationToken registrationToken = config.CreateRegistrationToken(this.network); IWalletTransactionHandler walletTransactionHandler = this.node.FullNode.NodeService <IWalletTransactionHandler>(); Transaction transaction = TransactionUtils.BuildTransaction( this.network, walletTransactionHandler, config, registrationToken, WalletName, Account, Password); return(transaction); }
public async Task <IActionResult> RegisterAsync(RegisterServiceNodeRequest request) { try { var registration = new ServiceNodeRegistration(this.network, this.nodeSettings, this.broadcasterManager, this.walletTransactionHandler, this.walletManager, this.serviceNodeManager); Key key = new KeyTool(this.nodeSettings.DataFolder).LoadPrivateKey(); (KeyId collateralPubKeyHash, KeyId rewardPubKeyHash) = GetPubKeyHashes(this.serviceNodeSettings, request.WalletName, request.AccountName); var config = new ServiceNodeRegistrationConfig { ProtocolVersion = (int)ServiceNodeProtocolVersion.INITIAL, Ipv4Address = this.serviceNodeSettings.Ipv4Address ?? IPAddress.None, Ipv6Address = this.serviceNodeSettings.Ipv6Address ?? IPAddress.IPv6None, OnionAddress = null, Port = this.serviceNodeSettings.Port, PrivateKey = key, CollateralPubKeyHash = collateralPubKeyHash, RewardPubKeyHash = rewardPubKeyHash, TxFeeValue = this.serviceNodeSettings.TxFeeValue, TxOutputValue = this.serviceNodeSettings.TxOutputValue, ServiceEndpoint = this.serviceNodeSettings.ServiceEndpoint }; if (!registration.CheckExistingRegistration(config)) { this.logger.LogInformation("{Time} Creating or updating node registration", DateTime.Now); Transaction regTx = await registration.PerformRegistrationAsync(config, request.WalletName, request.Password, request.AccountName); if (regTx != null) { this.logger.LogInformation("{Time} Submitted node registration transaction {TxId} for broadcast", DateTime.Now, regTx.GetHash().ToString()); } else { this.logger.LogInformation("{Time} Unable to broadcast transaction", DateTime.Now); Environment.Exit(0); } return(Ok(new RegisterServiceNodeResponse { CollateralPubKeyHash = collateralPubKeyHash.ToString(), RewardPubKeyHash = rewardPubKeyHash.ToString(), RegistrationTxHash = regTx.GetHash().ToString() })); } else { logger.LogInformation("{Time} Node registration has already been performed", DateTime.Now); return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, "Node registration failed", "Registration has already been performed successfully, you can't do it again.")); } } catch (Exception e) { Console.WriteLine(e); throw; } }