public void TestToUnsignedEnvelopeXdrWithSignatures() { var network = new Network("Standalone Network ; February 2017"); var source = KeyPair.FromSecretSeed(network.NetworkId); var txSource = KeyPair.Random(); var account = new Account(txSource, 7); var destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); var amount = "2000"; var asset = new AssetTypeNative(); var tx = new TransactionBuilder(account) .SetFee(100) .AddTimeBounds(new TimeBounds(0, 0)) .AddOperation( new PaymentOperation.Builder(destination, asset, amount).Build()) .AddMemo(new MemoText("Happy birthday!")) .Build(); tx.Sign(KeyPair.Random()); try { tx.ToUnsignedEnvelopeXdr(); } catch (Exception e) { Assert.AreEqual(e.Message, "Transaction must not be signed. Use ToEnvelopeXDR."); } }
public void TestChangeTrustOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); Asset asset = new AssetTypeNative(); var limit = "922337203685.4775807"; var operation = new ChangeTrustOperation.Builder(asset, limit) .SetSourceAccount(source) .Build(); var xdr = operation.ToXdr(); var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr); Assert.AreEqual(9223372036854775807L, xdr.Body.ChangeTrustOp.Limit.InnerValue); Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); Assert.IsTrue(parsedOperation.Asset is AssetTypeNative); Assert.AreEqual(limit, parsedOperation.Limit); Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); Assert.AreEqual( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=", operation.ToXdrBase64()); }
public void TestSignatureBaseNoNetwork() { var network = new Network("Standalone Network ; February 2017"); var source = KeyPair.FromSecretSeed(network.NetworkId); var txSource = new MuxedAccountMed25519(source, 0); var account = new Account(txSource, 7); var destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); var amount = "2000"; var asset = new AssetTypeNative(); var tx = new TransactionBuilder(account) .SetFee(100) .AddTimeBounds(new TimeBounds(0, 0)) .AddOperation( new PaymentOperation.Builder(destination, asset, amount).Build()) .AddMemo(new MemoText("Happy birthday!")) .Build(); try { tx.SignatureBase(null); } catch (Exception e) { Assert.IsNotNull(e); } }
public void TestPaymentOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); Asset asset = new AssetTypeNative(); var amount = "1000"; var operation = new PaymentOperation.Builder(destination, asset, amount) .SetSourceAccount(source) .Build(); var xdr = operation.ToXdr(); var parsedOperation = (PaymentOperation)Operation.FromXdr(xdr); Assert.AreEqual(10000000000L, xdr.Body.PaymentOp.Amount.InnerValue); Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); Assert.IsTrue(parsedOperation.Asset is AssetTypeNative); Assert.AreEqual(amount, parsedOperation.Amount); Assert.AreEqual( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA=", operation.ToXdrBase64()); }
public void TestCreatePassiveOfferOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); Asset selling = new AssetTypeNative(); var buying = Asset.CreateNonNativeAsset("USD", issuer); var amount = "0.00001"; var price = "2.93850088"; // n=36731261 d=12500000 var priceObj = Price.FromString(price); var operation = new CreatePassiveOfferOperation.Builder(selling, buying, amount, price) .SetSourceAccount(source) .Build(); var xdr = operation.ToXdr(); var parsedOperation = (CreatePassiveOfferOperation)Operation.FromXdr(xdr); Assert.AreEqual(100L, xdr.Body.CreatePassiveOfferOp.Amount.InnerValue); Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); Assert.IsTrue(parsedOperation.Buying.Equals(buying)); Assert.AreEqual(amount, parsedOperation.Amount); Assert.AreEqual(price, parsedOperation.Price); Assert.AreEqual(priceObj.Numerator, 36731261); Assert.AreEqual(priceObj.Denominator, 12500000); Assert.AreEqual( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg", operation.ToXdrBase64()); }
public void TestAssetTypeNative() { var asset = new AssetTypeNative(); var thisXdr = asset.ToXdr(); var parsedAsset = Asset.FromXdr(thisXdr); Assert.IsTrue(parsedAsset is AssetTypeNative); }
public async Task <bool> SubmitTransaction(string exchangeAccount, string destinationAddress, int amountLumens) { // Update transaction state to 'sending' so it won't be resubmitted in case of the failure. var customerId = DB.CustomerId(exchangeAccount); DB.UpdateTransactionState(customerId, destinationAddress, amountLumens, "sending"); try { // Check if the destination address exists var destinationKeyPair = KeyPair.FromAccountId(destinationAddress); // If so, continue by submitting a transaction to the destination Asset asset = new AssetTypeNative(); KeyPair sourceKeypair = KeyPair.FromSecretSeed(BaseAccountSecret); AccountResponse sourceAccountResponse = await server.Accounts.Account(sourceKeypair); Account sourceAccount = new Account(sourceAccountResponse.KeyPair, sourceAccountResponse.SequenceNumber); PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, amountLumens.ToString()).SetSourceAccount(sourceAccount.KeyPair).Build(); Transaction transact = new Transaction.Builder(sourceAccount).AddOperation(operation).Build(); // Sign the transaction transact.Sign(sourceKeypair); //Try to send the transaction try { await server.SubmitTransaction(transact); } catch (Exception exception) { Console.WriteLine("Send Transaction Failed:" + exception.Message); } } catch (Exception e) { Console.WriteLine("Account does not exist:" + e.Message); }; try { // Submit the transaction created DB.UpdateTransactionState(customerId, destinationAddress, amountLumens, "done"); } catch (Exception e) { // set transaction state to 'error' DB.UpdateTransactionState(customerId, destinationAddress, amountLumens, "error"); Console.WriteLine("error:" + e.Message); } return(true); }
public async Task <bool> ActivateUserAccount(string accountId, string secretSeed) { //Set network and server Network.UseTestNetwork(); Server server = new Server("https://horizon-testnet.stellar.org"); var sourceKeyPair = KeyPair.FromSecretSeed(DistributionAccount.SecretSeed); //Destination keypair from the account id KeyPair destinationKeyPair = KeyPair.FromAccountId(accountId); AccountResponse sourceAccountResponse = await server.Accounts.Account(DistributionAccount.PublicKey); //Create source account object Account sourceAccount = new Account(DistributionAccount.PublicKey, sourceAccountResponse.SequenceNumber); Asset asset = new AssetTypeNative(); var operationStartSponsor = new BeginSponsoringFutureReservesOperation.Builder(destinationKeyPair) .SetSourceAccount(sourceKeyPair) .Build(); //Create payment operation CreateAccountOperation operation = new CreateAccountOperation.Builder(destinationKeyPair, "0").SetSourceAccount(sourceAccount.KeyPair).Build(); var sponsoredSource = KeyPair.FromSecretSeed(secretSeed); var operationEndSponsoring = new EndSponsoringFutureReservesOperation.Builder() .SetSourceAccount(sponsoredSource) .Build(); Transaction transaction = new TransactionBuilder(sourceAccount) .SetFee(100) .AddOperation(operationStartSponsor) .AddOperation(operation) .AddOperation(operationEndSponsoring) .Build(); //Sign Transaction transaction.Sign(sourceKeyPair); transaction.Sign(sponsoredSource); try { var response = await server.SubmitTransaction(transaction); return(response.IsSuccess()); } catch (Exception exception) { return(false); } }
private async void RunAsync() { Server server = UStellarManager.GetServer(); KeyPair sourceKeyPair = KeyPair.FromSecretSeed(source); //Check if the destination account exists in the server. Log("Checking if destination account exists in server", 0); await server.Accounts.Account(destination); Log("Done"); //Load up to date information in source account await server.Accounts.Account(sourceKeyPair.AccountId); AccountResponse sourceAccountResponse = await server.Accounts.Account(sourceKeyPair.AccountId); Account sourceAccount = new Account(sourceAccountResponse.AccountId, sourceAccountResponse.SequenceNumber); //Create the Asset to send and put the amount we are going to send. Asset asset = new AssetTypeNative(); string amount = "1"; PaymentOperation operation = new PaymentOperation.Builder(KeyPair.FromAccountId(destination), asset, amount).SetSourceAccount(sourceAccount.KeyPair).Build(); Transaction transaction = new Transaction.Builder(sourceAccount).AddOperation(operation).Build(); //Sign Transaction Log("Signing Transaction", 2); transaction.Sign(KeyPair.FromSecretSeed(source)); Log("Done"); //Try to send the transaction try { Log("Sending Transaction", 2); await server.SubmitTransaction(transaction); Log("Success!", 1); } catch (Exception exception) { Log("Something went wrong", 2); Log("Exception: " + exception.Message, 1); // If the result is unknown (no response body, timeout etc.) we simply resubmit // already built transaction: // SubmitTransactionResponse response = server.submitTransaction(transaction); } }
public void TestPathPaymentStrictReceiveOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); Asset sendAsset = new AssetTypeNative(); var sendMax = "0.0001"; Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); var destAmount = "0.0001"; Asset[] path = { new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) }; var operation = new PathPaymentStrictReceiveOperation.Builder( sendAsset, sendMax, destination, destAsset, destAmount) .SetPath(path) .SetSourceAccount(source) .Build(); var xdr = operation.ToXdr(); var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr); Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue); Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue); Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); Assert.AreEqual(sendMax, parsedOperation.SendMax); Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); Assert.AreEqual(destAmount, parsedOperation.DestAmount); Assert.AreEqual(path.Length, parsedOperation.Path.Length); Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); Assert.AreEqual( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", operation.ToXdrBase64()); }
public void TestTransactionFeeOverflow() { var source = KeyPair.Random(); var txSource = new MuxedAccountMed25519(source, 0); var account = new Account(txSource, 7); var destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); var amount = "2000"; var asset = new AssetTypeNative(); Assert.ThrowsException <OverflowException>(() => { var tx = new TransactionBuilder(account) .SetFee(UInt32.MaxValue) .AddTimeBounds(new TimeBounds(0, 0)) .AddOperation( new PaymentOperation.Builder(destination, asset, amount).Build()) .AddOperation( new PaymentOperation.Builder(destination, asset, amount).Build()) .Build(); }); }
public void Initialize() { BaseFee = 100; NetworkPassphrase = "Standalone Network ; February 2017"; Network = new Network(NetworkPassphrase); InnerSource = KeyPair.FromSecretSeed(Network.NetworkId); InnerAccount = new Account(InnerSource.AccountId, 7); Destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); Amount = "2000.0000000"; Asset = new AssetTypeNative(); InnerTransaction = new TransactionBuilder(InnerAccount) .SetFee(100) .AddTimeBounds(new TimeBounds(0, 0)) .AddOperation( new PaymentOperation.Builder(Destination, Asset, Amount) .Build()) .AddMemo(new MemoText("Happy birthday!")) .Build(); InnerTransaction.Sign(InnerSource, Network); FeeSource = KeyPair.FromSecretSeed("SB7ZMPZB3YMMK5CUWENXVLZWBK4KYX4YU5JBXQNZSK2DP2Q7V3LVTO5V"); Transaction = TransactionBuilder.BuildFeeBumpTransaction(FeeSource, InnerTransaction, 100); }
public void TestTransactionWithMuxedAccount() { var network = new Network("Standalone Network ; February 2017"); var source = KeyPair.FromSecretSeed(network.NetworkId); var txSource = new MuxedAccountMed25519(source, 0); var account = new Account(txSource, 7); var destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); var amount = "2000"; var asset = new AssetTypeNative(); var tx = new TransactionBuilder(account) .SetFee(100) .AddTimeBounds(new TimeBounds(0, 0)) .AddOperation( new PaymentOperation.Builder(destination, asset, amount).Build()) .AddMemo(new MemoText("Happy birthday!")) .Build(); var xdr = tx.ToUnsignedEnvelopeXdrBase64(); var back = TransactionBuilder.FromEnvelopeXdr(xdr) as Transaction; Assert.IsNotNull(back); Assert.AreEqual(txSource.Address, back.SourceAccount.Address); }
public void TestManageOfferOperation() { // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); Asset selling = new AssetTypeNative(); var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); var amount = "0.00001"; var price = "0.85334384"; // n=5333399 d=6250000 var priceObj = Price.FromString(price); long offerId = 1; var operation = new ManageOfferOperation.Builder(selling, buying, amount, price) .SetOfferId(offerId) .SetSourceAccount(source) .Build(); Assert.AreEqual( "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", operation.ToXdrBase64()); }
public async Task TestCheckOtherOperationTypes() { var accountId = "GAYHAAKPAQLMGIJYMIWPDWCGUCQ5LAWY4Q7Q3IKSP57O7GUPD3NEOSEA"; var destinations = new string[] { "GASGNGGXDNJE5C2O7LDCATIVYSSTZKB24SHYS6F4RQT4M4IGNYXB4TIV", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB", "GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ", }; var native = new AssetTypeNative(); var gbp = Asset.CreateNonNativeAsset("GBP", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"); var eur = Asset.CreateNonNativeAsset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL"); var operations = new Operation[] { new AccountMergeOperation.Builder(KeyPair.FromAccountId(destinations[0])).Build(), new PathPaymentStrictSendOperation.Builder(native, "5.00", KeyPair.FromAccountId(destinations[1]), native, "5.00") .SetPath(new[] { gbp, eur }) .Build(), new PathPaymentStrictReceiveOperation.Builder(native, "5.00", KeyPair.FromAccountId(destinations[2]), native, "5.00") .SetPath(new[] { gbp, eur }) .Build(), new ChangeTrustOperation.Builder(gbp, "10000").Build(), }; When() .Returns(ServerTest.ResponseMessage(HttpStatusCode.OK, BuildAccountResponse(accountId))) .Returns(ServerTest.ResponseMessage(HttpStatusCode.OK, BuildAccountResponse(destinations[0]))) .Returns(ServerTest.ResponseMessage(HttpStatusCode.OK, BuildAccountResponse(destinations[1]))) .Returns(ServerTest.ResponseMessage(HttpStatusCode.OK, BuildAccountResponse(destinations[2]))); var tx = BuildTransaction(accountId, operations, Memo.None()); await _server.CheckMemoRequired(tx); }
// [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}")); }
public async Task <string> BuildTransactionAsync(Guid operationId, AddressBalance from, string toAddress, string memoText, long amount) { var fromKeyPair = KeyPair.FromAccountId(from.Address); var fromAccount = new Account(fromKeyPair, from.Sequence); var toKeyPair = KeyPair.FromAccountId(toAddress); var transferableBalance = from.Balance - from.MinBalance; Operation operation; if (await _horizonService.AccountExists(toAddress)) { if (amount <= transferableBalance) { var asset = new AssetTypeNative(); operation = new PaymentOperation.Builder(toKeyPair, asset, Operation.FromXdrAmount(amount)) .SetSourceAccount(fromKeyPair) .Build(); } else if (!_balanceService.IsDepositBaseAddress(from.Address)) { operation = new AccountMergeOperation.Builder(toKeyPair) .SetSourceAccount(fromKeyPair) .Build(); } else { throw new BusinessException($"It isn't allowed to merge the entire balance from the deposit base into another account! Transfer less funds. transferable={transferableBalance}"); } } else { if (amount <= transferableBalance) { operation = new CreateAccountOperation.Builder(toKeyPair, Operation.FromXdrAmount(amount)) .SetSourceAccount(fromKeyPair) .Build(); } else { throw new BusinessException($"It isn't possible to merge the entire balance into an unused account! Use a destination in existance. transferable={transferableBalance}"); } } var builder = new TransactionBuilder(fromAccount) .AddOperation(operation) .SetFee(_appSettings.StellarApiService.OperationFee); if (!string.IsNullOrWhiteSpace(memoText)) { var memo = new MemoText(memoText); builder = builder.AddMemo(memo); } var tx = builder.Build(); var xdr = tx.ToUnsignedEnvelopeXdr(TransactionBase.TransactionXdrVersion.V1); var expirationDate = (DateTime.UtcNow + _transactionExpirationTime); var maxUnixTimeDouble = expirationDate.ToUnixTime() / 1000;//ms to seconds var maxTimeUnix = (ulong)maxUnixTimeDouble; xdr.V1.Tx.TimeBounds = new TimeBounds() { MaxTime = new TimePoint(new Uint64(maxTimeUnix)), MinTime = new TimePoint(new Uint64(0)), }; var writer = new XdrDataOutputStream(); stellar_dotnet_sdk.xdr.TransactionEnvelope.Encode(writer, xdr); var xdrBase64 = Convert.ToBase64String(writer.ToArray()); _log.Info("Transaction has been built", new { OperationId = operationId, From = from, To = toAddress, Memo = memoText, Amount = amount, Fee = tx.Fee, Sequence = tx.SequenceNumber, MaxTimeUnix = maxTimeUnix }); var build = new TxBuild { OperationId = operationId, XdrBase64 = xdrBase64 }; await _buildRepository.AddAsync(build); return(xdrBase64); }
public async Task SendNativeAssets() { //Set network and server Network network = new Network("Test SDF Network ; September 2015"); Server server = new Server("https://horizon-testnet.stellar.org"); KeyPair keypair = KeyPair.Random(); Network.UseTestNetwork(); var sourceaccID = keypair.AccountId; using (var server1 = new Server("https://horizon-testnet.stellar.org")) { var friendBot = await server.TestNetFriendBot .FundAccount(sourceaccID) .Execute().ConfigureAwait(true); } //Source keypair from the secret seed KeyPair sourceKeypair = KeyPair.FromSecretSeed(keypair.SecretSeed); var SourceaccTest = await server.Accounts.Account(sourceaccID); //Load source account data AccountResponse sourceAccountResponse = await server.Accounts.Account(sourceKeypair.AccountId); //Create source account object Account sourceAccount = new Account(sourceKeypair.AccountId, sourceAccountResponse.SequenceNumber); //Create asset object with specific amount //You can use native or non native ones. Asset asset = new AssetTypeNative(); string amount = "30"; //Load des account data AccountResponse descAccountResponse = await server.Accounts.Account("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT"); //Destination keypair from the account id KeyPair destinationKeyPair = KeyPair.FromAccountId("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT"); var transactions = await server.Transactions .ForAccount("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT") .Execute().ConfigureAwait(true); var abc = new TransactionResponse(); var test = new test.MyTestApp(); test.Main(); var tranDetail = server.Transactions.ForAccount("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT").Cursor("now"); var paymentDetail = server.Payments.ForAccount("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT"); //paymentDetail.Stream(operationres); //OnhresholdReached?.Invoke(this, new OperationResponse()); Program1 abcd = new Program1(); abcd.OnhresholdReached += Abcd_OnhresholdReached; abcd.OnhresholdReached += new EventHandler <OperationResponse>(this.Abcd_OnhresholdReached); var OperateDetail = server.Operations.ForAccount("GDLRM2QFV7GOOAZDELHFCC5RBRMX4NAZNBSTAKG6NGO4CFODY5PSCYWT"); //Create payment operation PaymentOperation operation = new PaymentOperation.Builder(destinationKeyPair, asset, amount).SetSourceAccount(sourceAccount.KeyPair).Build(); //Create transaction and add the payment operation we created Transaction transaction = new Transaction.Builder(sourceAccount).AddOperation(operation).Build(); //Sign Transaction transaction.Sign(sourceKeypair); //Try to send the transaction try { Console.WriteLine("Sending Transaction"); await server.SubmitTransaction(transaction).ConfigureAwait(true); Console.WriteLine("Success!"); } catch (Exception exception) { Console.WriteLine("Send Transaction Failed"); Console.WriteLine("Exception: " + exception.Message); } }
/// Generates a multi-signed transaction /// and transfer amount to a 3rd account, if signed correctly public async Task MultiSigTransfer() { // Horizon settings Network.UseTestNetwork(); Server server = new Server(HorizonUrl); // master account Console.WriteLine("Generating key pairs..."); KeyPair masterKeyPair = KeyPair.FromSecretSeed(MasterSecret); AccountResponse masterAccountResponse = await server.Accounts.Account(masterKeyPair); Account masterAccount = new Account(masterAccountResponse.KeyPair, masterAccountResponse.SequenceNumber); // generating keypairs KeyPair signerKeyPair = KeyPair.FromAccountId(SignerAccount); KeyPair signerSecretKeyPair = KeyPair.FromSecretSeed(SignerSecret);; KeyPair destinationKeyPair = KeyPair.FromAccountId(DestinationAccount); var signerKey = stellar_dotnet_sdk.Signer.Ed25519PublicKey(signerKeyPair); // set signer operation SetOptionsOperation signerOperation = new SetOptionsOperation.Builder().SetSigner(signerKey, 1).Build(); // set flag // for clearing flags -> SetOptionsOperation flagOperation = new SetOptionsOperation.Builder().SetClearFlags(1).Build(); SetOptionsOperation flagOperation = new SetOptionsOperation.Builder().SetSetFlags(1).Build(); // set medium threshold SetOptionsOperation thresholdOperation = new SetOptionsOperation.Builder().SetMediumThreshold(2).Build(); // payment operation string amountToTransfer = "35"; Asset asset = new AssetTypeNative(); PaymentOperation paymentOperation = new PaymentOperation.Builder(destinationKeyPair, asset, amountToTransfer).SetSourceAccount(masterKeyPair).Build(); // create transaction Transaction transaction = new Transaction.Builder(masterAccount) .AddOperation(flagOperation) .AddOperation(thresholdOperation) .AddOperation(signerOperation) .AddOperation(paymentOperation) .Build(); // sign Transaction transaction.Sign(masterKeyPair); transaction.Sign(signerSecretKeyPair); // try to send transaction try { Console.WriteLine("Sending Transaction..."); await server.SubmitTransaction(transaction); Console.WriteLine("Success!"); await this.GetBalance(MasterAccount); await this.GetBalance(SignerAccount); await this.GetBalance(DestinationAccount); } catch (Exception exception) { Console.WriteLine("Send Transaction Failed"); Console.WriteLine("Exception: " + exception.Message); } }