public void TestAssetTypeCreditAlphaNum12() { var code = "TESTTEST"; var issuer = KeyPair.Random(); var asset = new AssetTypeCreditAlphaNum12(code, issuer); var thisXdr = asset.ToXdr(); var parsedAsset = (AssetTypeCreditAlphaNum12)Asset.FromXdr(thisXdr); Assert.AreEqual(code, asset.Code); Assert.AreEqual(issuer.AccountId, parsedAsset.Issuer.AccountId); }
async Task GetCoinsFromIssuer(string asset_code, double amount) { Network network = new Network("Public Global Stellar Network ; September 2015"); Server server = new Server("https://horizon.stellar.org"); Network.UsePublicNetwork(); KeyPair issuerKeypair = KeyPair.FromSecretSeed("SEED"); KeyPair destinationKeyPair = KeyPair.FromAccountId("PUBLIC"); AccountResponse issuerAccountResponse = null; var t = Task.Run(async() => { issuerAccountResponse = await server.Accounts.Account(issuerKeypair); }); t.Wait(); Account issuerAccount = new Account(issuerAccountResponse.KeyPair, issuerAccountResponse.SequenceNumber); Asset asset = new AssetTypeCreditAlphaNum12(asset_code, issuerKeypair); PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, amount.ToString()).SetSourceAccount(issuerAccount.KeyPair).Build(); Transaction transaction = new Transaction.Builder(issuerAccount).AddOperation(operation).Build(); //Try to send the transaction try { transaction.Sign(issuerKeypair); var tSign = Task.Run(async() => { await server.SubmitTransaction(transaction); }); tSign.Wait(); } catch (Exception exception) { Console.WriteLine("Send Transaction Failed"); Console.WriteLine("Exception: " + exception.Message); } }
public async Task <string> SendVoteToken(string pubKey, string secretKey, string memo) { //Set network and server Network.UseTestNetwork(); Server server = new Server("https://horizon-testnet.stellar.org"); var source = KeyPair.FromSecretSeed(secretKey); AccountResponse sourceAccountResponse = await server.Accounts.Account(source.AccountId); //Create source account object Account sourceAccount = new Account(source.AccountId, sourceAccountResponse.SequenceNumber); Asset asset = new AssetTypeCreditAlphaNum12(this.VoteToken, IssueAccount.PublicKey); //Create payment operation PaymentOperation operation = new PaymentOperation.Builder(KeyPair.FromAccountId(DistributionAccount.PublicKey), asset, "1").SetSourceAccount(sourceAccount.KeyPair).Build(); Transaction innerTransaction = new TransactionBuilder(sourceAccount) .SetFee(100) .AddOperation(operation) .AddMemo(new MemoText(memo)) .Build(); innerTransaction.Sign(source); var feeSource = KeyPair.FromSecretSeed(DistributionAccount.SecretSeed); var finalTx = TransactionBuilder.BuildFeeBumpTransaction(feeSource, innerTransaction, 100); finalTx.Sign(feeSource); //Try to send the transaction try { var response = await this.SubmitTransaction(finalTx.ToEnvelopeXdrBase64()); var hash = response.Hash; return(hash); } catch (Exception exception) { return(string.Empty); } }
public async Task <bool> SendVoteTokenToUser(string destinationAddress) { //Set network and server Network.UseTestNetwork(); Server server = new Server("https://horizon-testnet.stellar.org"); //Sender var senderSource = KeyPair.FromSecretSeed(DistributionAccount.SecretSeed); //Destination keypair from the account id KeyPair destinationKeyPair = KeyPair.FromAccountId(destinationAddress); AccountResponse sourceAccountResponse = await server.Accounts.Account(senderSource.AccountId); //Create source account object Account sourceAccount = new Account(senderSource.AccountId, sourceAccountResponse.SequenceNumber); Asset asset = new AssetTypeCreditAlphaNum12(this.VoteToken, IssueAccount.PublicKey); //Create payment operation PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, "1").SetSourceAccount(sourceAccount.KeyPair).Build(); //Create transaction and add the payment operation we created Transaction transaction = new TransactionBuilder(sourceAccount).AddOperation(operation).Build(); //Sign Transaction transaction.Sign(senderSource); //Try to send the transaction try { var response = await server.SubmitTransaction(transaction); return(response.IsSuccess()); } catch (Exception exception) { return(false); } }
async Task CreateSurveyAsset(string asset_code) { Network network = new Network("Public Global Stellar Network ; September 2015"); Server server = new Server("https://horizon.stellar.org"); Network.UsePublicNetwork(); KeyPair issuerKeypair = KeyPair.FromAccountId("SEED"); KeyPair destinationKeyPair = KeyPair.FromSecretSeed("PUBLIC"); AccountResponse destinationAccountResponse = null; var t = Task.Run(async() => { destinationAccountResponse = await server.Accounts.Account(destinationKeyPair); }); t.Wait(); Account destinationAccount = new Account(destinationAccountResponse.KeyPair, destinationAccountResponse.SequenceNumber); Asset asset = new AssetTypeCreditAlphaNum12(asset_code, issuerKeypair); ChangeTrustOperation operation = new ChangeTrustOperation.Builder(asset, "100000000000").Build(); Transaction transaction = new Transaction.Builder(destinationAccount).AddOperation(operation).Build(); try { transaction.Sign(destinationKeyPair); var tSign = Task.Run(async() => { await server.SubmitTransaction(transaction); }); tSign.Wait(); // await GetCoinsFromIssuer(asset_code,100); } catch (Exception exception) { Console.WriteLine("Send Transaction Failed"); Console.WriteLine("Exception: " + exception.Message); } }
// [ValidateAntiForgeryToken] public async Task <string> Create([Bind("ID,TokenName,Amount,Destination,SendStart")] Send send) { send.Destination = send.Destination.ToUpper(); send.TokenName = send.TokenName.ToUpper(); if (send.Destination[0] != 'G' || send.Destination.Length != 56) { ModelState.AddModelError("Address", "Address is not in a proper format (begins with a G and is 56 characters long"); } string[] tokenNames = { "XLM", "SECOND", "MINUTE", "HOUR", "DAY", "WEEK", "MONTH", "YEAR", "MASLOW1", "MASLOW2", "MASLOW3", "MASLOW4", "MASLOW5" }; if (!(tokenNames.Contains(send.TokenName))) { ModelState.AddModelError("TokenName", "Token is not supported."); } if (!(send.Amount > 0)) { ModelState.AddModelError("Amount", "The amount sent has to be a positive integer."); } Network.UsePublicNetwork(); var server = new Server("https://horizon.stellar.org"); KeyPair source = KeyPair.FromSecretSeed(Environment.GetEnvironmentVariable("SECRET_KEY_" + send.TokenName)); KeyPair destination = KeyPair.FromAccountId(send.Destination); send.Source = Environment.GetEnvironmentVariable("SECRET_KEY_" + send.TokenName); await server.Accounts.Account(destination); AccountResponse sourceAccount = await server.Accounts.Account(source); var sendingAccountPubKey = Environment.GetEnvironmentVariable("PUBLIC_KEY_" + send.TokenName); AccountsRequestBuilder accReqBuilder = new AccountsRequestBuilder(new Uri("https://horizon.stellar.org/accounts/" + sendingAccountPubKey)); var accountResponse = await accReqBuilder.Account(new Uri("https://horizon.stellar.org/accounts/" + sendingAccountPubKey)); Asset tst; if (send.TokenName == "XLM") { // TODO implement this in the future tst = new AssetTypeNative(); // https://elucidsoft.github.io/dotnet-stellar-sdk/api/stellar_dotnetcore_sdk.AssetTypeNative.html } else if (send.TokenName.Length <= 4) { tst = new AssetTypeCreditAlphaNum4(send.TokenName, KeyPair.FromAccountId(Environment.GetEnvironmentVariable("ISSUER_KEY_" + send.TokenName))); } else { tst = new AssetTypeCreditAlphaNum12(send.TokenName, KeyPair.FromAccountId(Environment.GetEnvironmentVariable("ISSUER_KEY_" + send.TokenName))); } Transaction transaction = new Transaction.Builder(new stellar_dotnetcore_sdk.Account(KeyPair.FromAccountId(sendingAccountPubKey), accountResponse.SequenceNumber)) .AddOperation(new PaymentOperation.Builder(destination, tst, Convert.ToString(send.Amount)).Build()) .AddMemo(Memo.Text("Test Transaction")) .Build(); transaction.Sign(source); string status = ""; try { if (ModelState.IsValid) { SubmitTransactionResponse response = await server.SubmitTransaction(transaction); status += "Success!"; return(HtmlEncoder.Default.Encode($"SendsController POST CREATE {status} 1 {source} 2 3 4 ")); } } catch (Exception e) { status += "ERROR" + e.Message; } return(HtmlEncoder.Default.Encode($"INVALID {send.ID}, {send.TokenName}")); }