private static List <Recipient> GetRecipients(IServiceNodeRegistrationConfig registrationConfig, RegistrationToken registrationToken) { byte[] tokenBytes = registrationToken.GetRegistrationTokenBytes(registrationConfig.PrivateKey); byte[] markerBytes = Encoding.UTF8.GetBytes(RegistrationToken.Marker); var recipients = new List <Recipient> { new Recipient { Amount = registrationConfig.TxOutputValue, ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(markerBytes) } }; recipients.AddRange(BlockChainDataConversions.BytesToPubKeys(tokenBytes).Select(pk => new Recipient { Amount = registrationConfig.TxOutputValue, ScriptPubKey = pk.ScriptPubKey })); if (!recipients.Any()) { throw new Exception("ERROR: No recipients for registration transaction, cannot proceed"); } return(recipients); }
public async Task <Transaction> PerformRegistrationAsync( IServiceNodeRegistrationConfig registrationConfig, string walletName, string walletPassword, string accountName) { Transaction transaction = null; try { RegistrationToken registrationToken = registrationConfig.CreateRegistrationToken(this.network); transaction = TransactionUtils.BuildTransaction(this.network, this.walletTransactionHandler, registrationConfig, registrationToken, walletName, accountName, walletPassword); await this.broadcasterManager.BroadcastTransactionAsync(transaction).ConfigureAwait(false); } catch (Exception e) { Console.WriteLine("ERROR: Unable to broadcast registration transaction"); Console.WriteLine(e); } return(transaction); }
public static Transaction BuildTransaction( Network network, IWalletTransactionHandler walletTransactionHandler, IServiceNodeRegistrationConfig registrationConfig, RegistrationToken registrationToken, string walletName, string accountName, string password) { var accountReference = new WalletAccountReference() { AccountName = accountName, WalletName = walletName }; var context = new TransactionBuildContext(network) { AccountReference = accountReference, Recipients = GetRecipients(registrationConfig, registrationToken), Shuffle = false, Sign = true, OverrideFeeRate = new FeeRate(registrationConfig.TxFeeValue), WalletPassword = password }; context.TransactionBuilder.CoinSelector = new DefaultCoinSelector { GroupByScriptPubKey = false }; Transaction transaction = walletTransactionHandler.BuildTransaction(context); return(transaction); }
public bool CheckExistingRegistration(IServiceNodeRegistrationConfig registrationConfig) { // In order to determine if the registration sequence has been performed // before, and to see if a previous performance is still valid, interrogate // the service node manager IServiceNode serviceNode = this.serviceNodeManager.GetByServerId(registrationConfig.CollateralPubKeyHash.ToString()); // If no service matching node then registration definitely needs to be done if (serviceNode == null) { return(false); } // Now check config against existing service node RegistrationToken registrationToken = serviceNode.RegistrationRecord.Token; // IPv4 if (registrationConfig.Ipv4Address == null && registrationToken.Ipv4Addr != null) { return(false); } if (registrationConfig.Ipv4Address != null && registrationToken.Ipv4Addr == null) { return(false); } if (registrationConfig.Ipv4Address != null && registrationToken.Ipv4Addr != null && !registrationConfig.Ipv4Address.Equals(registrationToken.Ipv4Addr)) { return(false); } // IPv6 if (registrationConfig.Ipv6Address == null && registrationToken.Ipv6Addr != null) { return(false); } if (registrationConfig.Ipv6Address != null && registrationToken.Ipv6Addr == null) { return(false); } if (registrationConfig.Ipv6Address != null && registrationToken.Ipv6Addr != null && !registrationConfig.Ipv6Address.Equals(registrationToken.Ipv6Addr)) { return(false); } // Onion if (registrationConfig.OnionAddress != registrationToken.OnionAddress) { return(false); } if (registrationConfig.Port != registrationToken.Port) { return(false); } if (registrationConfig.CollateralPubKeyHash != registrationToken.CollateralPubKeyHash) { return(false); } if (registrationConfig.RewardPubKeyHash != registrationToken.RewardPubKeyHash) { return(false); } if (registrationConfig.ServiceEndpoint != registrationToken.ServiceEndpoint) { return(false); } // TODO: Check if transaction is actually confirmed on the blockchain? return(true); }