-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the request builder to maintain the original path and query (#12
- Loading branch information
1 parent
2de0d74
commit 7d8d8f3
Showing
4 changed files
with
80 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using stellar_dotnet_sdk; | ||
using stellar_dotnet_sdk.requests; | ||
using stellar_dotnet_sdk.responses; | ||
|
||
namespace TestConsole | ||
{ | ||
public class Program | ||
{ | ||
//For testing use the following account info, this only exists on test network and may be wiped at any time... | ||
//Public: GAZHWW2NBPDVJ6PEEOZ2X43QV5JUDYS3XN4OWOTBR6WUACTUML2CCJLI | ||
//Secret: SCD74D46TJYXOUXFC5YOA72UTPCCVHK2GRSLKSPRB66VK6UJHQX2Y3R3 | ||
|
||
public static async Task Main(string[] args) | ||
{ | ||
//Network.UseTestNetwork(); | ||
//using (var server = new Server("https://horizon-testnet.stellar.org")) | ||
//{ | ||
// //var friendBot = await server.TestNetFriendBot | ||
// // .FundAccount(KeyPair.Random()) | ||
// // .Execute(); | ||
namespace TestConsole; | ||
|
||
// //await GetLedgerTransactions(server); | ||
// //await ShowAccountTransactions(server); | ||
// ShowTestKeyValue(server); | ||
//} | ||
|
||
|
||
using (var server = new Server("https://horizon.stellar.org")) | ||
{ | ||
Console.WriteLine("-- Streaming All New Ledgers On The Network --"); | ||
await server.Ledgers | ||
.Cursor("now") | ||
.Stream((sender, response) => { ShowOperationResponse(server, sender, response); }) | ||
.Connect(); | ||
} | ||
|
||
Console.ReadLine(); | ||
} | ||
|
||
private static async Task ShowAccountTransactions(Server server) | ||
{ | ||
Console.WriteLine("-- Show Account Transactions (ForAccount) --"); | ||
|
||
var transactions = await server.Transactions | ||
.ForAccount("GAZHWW2NBPDVJ6PEEOZ2X43QV5JUDYS3XN4OWOTBR6WUACTUML2CCJLI") | ||
.Execute(); | ||
public class Program | ||
{ | ||
private const int DefaultFee = 1000000; | ||
|
||
ShowTransactionRecords(transactions.Records); | ||
Console.WriteLine(); | ||
} | ||
public static async Task Main(string[] args) | ||
{ | ||
Network.UsePublicNetwork(); | ||
using var server = new Server("https://horizon.stellar.org"); | ||
|
||
await CreateAccount(server).ConfigureAwait(false); | ||
} | ||
|
||
private static async Task CreateAccount(Server server) | ||
{ | ||
var source = KeyPair.FromSecretSeed("{TO_BE_CONFIGURED}"); | ||
Console.WriteLine("Source account: {TO_BE_CONFIGURED}"); | ||
var destination = KeyPair.Random(); | ||
Console.WriteLine("Destination account: " + destination.AccountId); | ||
|
||
private static async Task GetLedgerTransactions(Server server) | ||
{ | ||
Console.WriteLine("-- Show Ledger Transactions (ForLedger) --"); | ||
// get a list of transactions that occurred in ledger 1400 | ||
var transactions = await server.Transactions | ||
.ForLedger(2365) | ||
.Execute(); | ||
var sourceAccount = await server.Accounts.Account(source.AccountId).ConfigureAwait(false); | ||
var transaction = new TransactionBuilder(sourceAccount) | ||
.SetFee(DefaultFee) | ||
.AddOperation(new CreateAccountOperation.Builder(destination, "1").Build()) | ||
.Build(); | ||
|
||
ShowTransactionRecords(transactions.Records); | ||
Console.WriteLine(); | ||
} | ||
transaction.Sign(source); | ||
|
||
private static void ShowTransactionRecords(List<TransactionResponse> transactions) | ||
var response = await server.SubmitTransaction(transaction).ConfigureAwait(false); | ||
if (response.IsSuccess()) | ||
{ | ||
foreach (var tran in transactions) | ||
ShowTransactionRecord(tran); | ||
Console.WriteLine("Create account response: " + response.Hash); | ||
await DeleteAccount(server, destination, source).ConfigureAwait(false); | ||
} | ||
|
||
private static void ShowTransactionRecord(TransactionResponse tran) | ||
else | ||
{ | ||
Console.WriteLine($"Ledger: {tran.Ledger}, Hash: {tran.Hash}, Fee Paid: {tran.FeeCharged}, Pt:{tran.PagingToken}"); | ||
Console.WriteLine("Create account failed."); | ||
Console.WriteLine("TransactionResultCode: " + response.SubmitTransactionResponseExtras.ExtrasResultCodes.TransactionResultCode ?? "null"); | ||
Console.WriteLine("TransactionResultCodeOperations: " + string.Join(", ", response.SubmitTransactionResponseExtras.ExtrasResultCodes.OperationsResultCodes)); | ||
} | ||
} | ||
|
||
private static async void ShowOperationResponse(Server server, object sender, LedgerResponse lr) | ||
private static async Task DeleteAccount(Server server, KeyPair source, KeyPair destination) | ||
{ | ||
var accountToDelete = await server.Accounts.Account(source.AccountId).ConfigureAwait(false); | ||
var transaction = new TransactionBuilder(accountToDelete) | ||
.SetFee(DefaultFee) | ||
.AddOperation(new AccountMergeOperation.Builder(destination).Build()) | ||
.Build(); | ||
|
||
transaction.Sign(source); | ||
|
||
var feeBumpTransaction = TransactionBuilder.BuildFeeBumpTransaction(destination, transaction, DefaultFee); | ||
|
||
feeBumpTransaction.Sign(destination); | ||
|
||
var response = await server.SubmitTransaction(feeBumpTransaction).ConfigureAwait(false); | ||
if (response.IsSuccess()) | ||
{ | ||
var operationRequestBuilder = server.Operations.ForLedger(lr.Sequence); | ||
var operations = await operationRequestBuilder.Execute(); | ||
|
||
var accts = 0; | ||
var payments = 0; | ||
var offers = 0; | ||
var options = 0; | ||
|
||
foreach (var op in operations.Records) | ||
switch (op.Type) | ||
{ | ||
case "create_account": | ||
accts++; | ||
break; | ||
case "payment": | ||
payments++; | ||
break; | ||
case "manage_offer": | ||
offers++; | ||
break; | ||
case "set_options": | ||
options++; | ||
break; | ||
} | ||
|
||
Console.WriteLine($"id: {lr.Sequence}, tx/ops: {lr.SuccessfulTransactionCount + "/" + lr.OperationCount}, accts: {accts}, payments: {payments}, offers: {offers}, options: {options}"); | ||
Console.WriteLine($"Uri: {((LedgersRequestBuilder)sender).Uri}"); | ||
Console.WriteLine("Delete account response: " + response.Hash); | ||
} | ||
|
||
private static void ShowTestKeyValue(Server server) | ||
else | ||
{ | ||
Console.WriteLine("-- Getting TestKey for Account --"); | ||
|
||
var data = server.Accounts.AccountData("GAZHWW2NBPDVJ6PEEOZ2X43QV5JUDYS3XN4OWOTBR6WUACTUML2CCJLI", "TestKey"); | ||
|
||
var dataResult = data.Result; | ||
|
||
Console.WriteLine("Encoded Value: " + dataResult.Value); | ||
Console.WriteLine("Decoded Value: " + dataResult.ValueDecoded); | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine("Delete account failed."); | ||
Console.WriteLine("TransactionResultCode: " + response.SubmitTransactionResponseExtras.ExtrasResultCodes.TransactionResultCode); | ||
Console.WriteLine("TransactionResultCodeOperations: " + string.Join(", ", response.SubmitTransactionResponseExtras.ExtrasResultCodes.OperationsResultCodes)); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters