private static async Task <SubmitTransactionResponse> SendAllowKinTrustOperation(KeyPair account, AccountResponse accountResponse) { ChangeTrustOperation.Builder changeTrustOperationBuilder = new ChangeTrustOperation.Builder((AssetTypeCreditAlphaNum)_kinAsset, TRUST_NO_LIMIT_VALUE).SetSourceAccount(account); ChangeTrustOperation changeTrustOperation = changeTrustOperationBuilder.Build(); Transaction.Builder allowKinTrustTransaction = new Transaction.Builder(new Account(account, accountResponse.SequenceNumber)).AddOperation(changeTrustOperation); allowKinTrustTransaction.AddMemo(new MemoText("1-chancity")); Transaction transaction = allowKinTrustTransaction.Build(); transaction.Sign(account); return(await _server.SubmitTransaction(transaction).ConfigureAwait(false)); }
static async Task <Transaction> BuildTransaction(KeyPair keyPair, double amount, string appendedMemo = "") { amount = amount / 100; var destinationKeyPair = KeyPair.FromAccountId("GDL6CWJER7TOXIWMFTOLVUZU4GKT547OCTNPOTXISJGI4SSOPEQTC3HT"); PaymentOperation.Builder paymentOperationBuilder = new PaymentOperation.Builder(destinationKeyPair, _asset, amount.ToString(CultureInfo.InvariantCulture)) .SetSourceAccount(keyPair); PaymentOperation paymentOperation = paymentOperationBuilder.Build(); var accountResponse = await _server.Accounts.Account(keyPair); Transaction.Builder paymentTransaction = new Transaction.Builder(new Account(keyPair, accountResponse.SequenceNumber)).AddOperation(paymentOperation); paymentTransaction.AddMemo(new MemoText($"1-rced-{appendedMemo}")); var transaction = paymentTransaction.Build(); transaction.Sign(keyPair); return(transaction); }
private async Task <SubmitTransactionResponse> GetCreateAccountTransaction(string destinationAddress) { KeyPair destinationKeyPair = KeyPair.FromAccountId(destinationAddress); AccountResponse sourceAccount = null; AccountResponse destinationAccount = null; try { sourceAccount = await GetAccount(_keyPair).ConfigureAwait(false); destinationAccount = await GetAccount(destinationKeyPair).ConfigureAwait(false); } catch (Exception ex) {} if (sourceAccount == null) { throw new Exception("Source account doesn't exists"); } if (destinationAccount != null) { throw new Exception("Account already exists"); } CreateAccountOperation.Builder createAccountOperationBuilder = new CreateAccountOperation.Builder(destinationKeyPair, "0"); createAccountOperationBuilder.SetSourceAccount(_keyPair); Transaction.Builder transactionBuilder = new Transaction.Builder(new Account(_keyPair, sourceAccount.SequenceNumber)); transactionBuilder.AddOperation(createAccountOperationBuilder.Build()); transactionBuilder.AddMemo(new MemoText($"1-{_app_id}")); Transaction transaction = transactionBuilder.Build(); transaction.Sign(_keyPair); return(await _server.SubmitTransaction(transaction).ConfigureAwait(false)); }
private async Task <SubmitTransactionResponse> SendPaymentOperation(KeyPair sourceKeyPair, KeyPair destinationKeyPair, AccountResponse sourceAccount, double amount, string marketPlaceOrderId = null) { PaymentOperation.Builder paymentOperationBuilder = new PaymentOperation.Builder(destinationKeyPair, _kinAsset, amount.ToString(CultureInfo.InvariantCulture)) .SetSourceAccount(sourceKeyPair); PaymentOperation paymentOperation = paymentOperationBuilder.Build(); Transaction.Builder paymentTransaction = new Transaction.Builder(new Account(sourceKeyPair, sourceAccount.SequenceNumber)).AddOperation( paymentOperation); string toAppend = string.IsNullOrEmpty(marketPlaceOrderId) ? "p2p" : marketPlaceOrderId; paymentTransaction.AddMemo(new MemoText($"1-test-{toAppend}")); Transaction transaction = paymentTransaction.Build(); transaction.Sign(sourceKeyPair); return(await _server.SubmitTransaction(transaction).ConfigureAwait(false)); }
public ITransactionBuilder SetMemo(string memo) { _transactionBuilder.AddMemo(new MemoText(memo)); return(this); }
public static async void Payout(decimal InflationAmount) { Network.UseTestNetwork(); //Get the number of votes you have var votes = GetTotalVotes(); //Get the accounts that voted for you and what you owe them var accounts = GetVoterAccounts(InflationAmount, votes); decimal sum = 0; decimal percentage = 0; KeyPair PoolSource = KeyPair.FromSecretSeed(Configuration["INFLATION_POOL_SECRET"]); //KeyPair PoolSource = KeyPair.FromSecretSeed(Environment.GetEnvironmentVariable("INFLATION_POOL_SECRET")); AccountResponse sourceAccount = await server.Accounts.Account(PoolSource); var sequenceNumber = sourceAccount.SequenceNumber; Account PoolAccount = new Account(PoolSource, sequenceNumber); Transaction.Builder BatchTransaction = new Transaction.Builder(PoolAccount); List <Transaction> Transactions = new List <Transaction>(); int batch = 0; foreach (var account in accounts) { //we can only have 100 operations per transaction, this means we need to split up our payouts every 100 people //Rounding down because we're greedy pigs that want to keep every last stroop var payout = RoundDown(account.Payout, 7); var payoutPercent = RoundDown(account.Percentage, 7); //Create the payment operation, we are pulling the 100 stroop fee out of the receipients end. //The lowest amount a voting account could possibly contain is 1 lumen //1 lumen will earn 0.0001923 lumens per week, so we don't have to worry about the fee being larger than a potential earning! var operation = new PaymentOperation.Builder(KeyPair.FromAccountId(account.AccountId), new AssetTypeNative(), (payout - .0000100m).ToString()) .SetSourceAccount(PoolSource) .Build(); BatchTransaction.AddOperation(operation); Console.WriteLine($" Account: {account.AccountId} Earned: {payout}XLM (%{payoutPercent})"); //totalling up our payout/percentages sum += payout; percentage += payoutPercent; if (batch == 99 || account.Equals(accounts.LastOrDefault())) { //This batch is full! we sign it with a memo and our private key and add it to the list of to be processed outgoing transactions. var t = BatchTransaction.AddMemo(Memo.Text($"Sample Memo")).Build(); t.Sign(PoolSource); Transactions.Add(t); BatchTransaction = new Transaction.Builder(PoolAccount); } //Reset the batch batch = batch == 99 ? 0 : ++batch; } Console.WriteLine("Submitting batches to the stellar network..."); foreach (var t in Transactions) { //Submit each transaction to the network Console.WriteLine($"Submitting batch: {Transactions.IndexOf(t) + 1}..."); var response = await server.SubmitTransaction(t); Console.WriteLine($"Batch submitted."); //Console.WriteLine($"Envelope XDR is:"); //Console.WriteLine($"{response.EnvelopeXdr}"); } Console.WriteLine($"Payed out: {sum} (%{percentage})"); //Exists the console app after it has found inflation and payed out. Console.WriteLine("Exiting"); Environment.Exit(0); }