-
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.
Upgraded to .NET 8 with additional improvements (#15)
- Upgraded to .NET 8 and C# 12. - Updated names (namespaces, classes, variables, directories,..) to comply with C# standard. - Reorganized classes. - Refactored operation response classes. - Refactored effect response classes. - Refactored Result classes. - Added missing result classes. - Improved operation classes. - Refactored JSON converters. - Removed Operation builder classes. - Updated XDR schemes to latest version. - Refactored ClaimAtom classes and added missing unit tests. - Refactored utility classes in Tests project.
- Loading branch information
Showing
1,617 changed files
with
35,584 additions
and
39,264 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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using StellarDotnetSdk.Accounts; | ||
using StellarDotnetSdk.Operations; | ||
using StellarDotnetSdk.Transactions; | ||
using SysConsole = System.Console; | ||
|
||
namespace StellarDotnetSdk.Console; | ||
|
||
public static class Program | ||
{ | ||
private const int DefaultFee = 1000000; | ||
|
||
public static async Task Main(string[] args) | ||
{ | ||
// Network.UsePublicNetwork(); | ||
using var server = new Server("https://horizon-testnet.stellar.org"); | ||
|
||
var paymentsWithoutTransactions = await server.Payments.Execute().ConfigureAwait(false); | ||
var paymentsWithTransactions = await server.Payments.IncludeTransaction().Execute().ConfigureAwait(false); | ||
|
||
await CreateAccount(server).ConfigureAwait(false); | ||
|
||
SysConsole.ReadLine(); | ||
} | ||
|
||
private static async Task CreateAccount(Server server) | ||
{ | ||
var source = KeyPair.FromSecretSeed("SDR4PTKMR5TAQQCL3RI2MLXXSXQDIR7DCAONQNQP6UCDZCD4OVRWXUHI"); | ||
SysConsole.WriteLine("Source account: {TO_BE_CONFIGURED}"); | ||
var destination = KeyPair.Random(); | ||
SysConsole.WriteLine("Destination account: " + destination.AccountId); | ||
|
||
var sourceAccount = await server.Accounts.Account(source.AccountId).ConfigureAwait(false); | ||
var transaction = new TransactionBuilder(sourceAccount) | ||
.SetFee(DefaultFee) | ||
.AddOperation(new CreateAccountOperation(destination, "1")) | ||
.Build(); | ||
|
||
transaction.Sign(source); | ||
|
||
var response = await server.SubmitTransaction(transaction).ConfigureAwait(false); | ||
if (response.IsSuccess) | ||
{ | ||
SysConsole.WriteLine("Create account response: " + response.Hash); | ||
await DeleteAccount(server, destination, source).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
SysConsole.WriteLine("Create account failed."); | ||
SysConsole.WriteLine("TransactionResultCode: " + | ||
response.SubmitTransactionResponseExtras.ExtrasResultCodes.TransactionResultCode ?? "null"); | ||
SysConsole.WriteLine("TransactionResultCodeOperations: " + string.Join(", ", | ||
response.SubmitTransactionResponseExtras.ExtrasResultCodes.OperationsResultCodes)); | ||
} | ||
} | ||
|
||
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(destination)) | ||
.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) | ||
{ | ||
SysConsole.WriteLine("Delete account response: " + response.Hash); | ||
} | ||
else | ||
{ | ||
SysConsole.WriteLine("Delete account failed."); | ||
SysConsole.WriteLine("TransactionResultCode: " + | ||
response.SubmitTransactionResponseExtras.ExtrasResultCodes.TransactionResultCode); | ||
SysConsole.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<AssemblyName>StellarDotnetSdk.Console</AssemblyName> | ||
<RootNamespace>StellarDotnetSdk.Console</RootNamespace> | ||
<LangVersion>12</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\StellarDotnetSdk\StellarDotnetSdk.csproj"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NSec.Cryptography" Version="22.4.0"/> | ||
</ItemGroup> | ||
|
||
</Project> |
32 changes: 16 additions & 16 deletions
32
stellar-dotnet-sdk-test/AccountFlagTest.cs → ...tnetSdk.Tests/Accounts/AccountFlagTest.cs
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,17 +1,17 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
|
||
namespace stellar_dotnet_sdk_test; | ||
|
||
[TestClass] | ||
public class AccountFlagTest | ||
{ | ||
[TestMethod] | ||
public void TestValues() | ||
{ | ||
Assert.AreEqual(1, (int)AccountFlag.AUTH_REQUIRED_FLAG); | ||
Assert.AreEqual(2, (int)AccountFlag.AUTH_REVOCABLE_FLAG); | ||
Assert.AreEqual(4, (int)AccountFlag.AUTH_IMMUTABLE_FLAG); | ||
Assert.AreEqual(8, (int)AccountFlag.AUTH_CLAWBACK_FLAG); | ||
} | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using StellarDotnetSdk.Accounts; | ||
|
||
namespace StellarDotnetSdk.Tests.Accounts; | ||
|
||
[TestClass] | ||
public class AccountFlagTest | ||
{ | ||
[TestMethod] | ||
public void TestValues() | ||
{ | ||
Assert.AreEqual(1, (int)AccountFlag.AUTH_REQUIRED_FLAG); | ||
Assert.AreEqual(2, (int)AccountFlag.AUTH_REVOCABLE_FLAG); | ||
Assert.AreEqual(4, (int)AccountFlag.AUTH_IMMUTABLE_FLAG); | ||
Assert.AreEqual(8, (int)AccountFlag.AUTH_CLAWBACK_FLAG); | ||
} | ||
} |
135 changes: 67 additions & 68 deletions
135
stellar-dotnet-sdk-test/AccountTest.cs → ...arDotnetSdk.Tests/Accounts/AccountTest.cs
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,69 +1,68 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
|
||
namespace stellar_dotnet_sdk_test; | ||
|
||
[TestClass] | ||
public class AccountTest | ||
{ | ||
[TestMethod] | ||
public void TestNullArguments() | ||
{ | ||
Assert.ThrowsException<ArgumentNullException>(() => new Account((string)null, 10L)); | ||
Assert.ThrowsException<ArgumentNullException>(() => new Account(KeyPair.Random().AccountId, null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestWithStringArgumentIsKeyPair() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var account = new Account(keypair.Address, 7); | ||
Assert.AreEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
} | ||
|
||
[TestMethod] | ||
public void TestWithMuxedAccount() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var muxed = new MuxedAccountMed25519(keypair, 10); | ||
var account = new Account(muxed, 7); | ||
Assert.AreNotEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.AccountId, muxed.AccountId); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetIncrementedSequenceNumber() | ||
{ | ||
var random = KeyPair.Random(); | ||
var account = new Account(random.AccountId, 100L); | ||
long incremented; | ||
incremented = account.IncrementedSequenceNumber; | ||
Assert.AreEqual(100L, account.SequenceNumber); | ||
Assert.AreEqual(101L, incremented); | ||
incremented = account.IncrementedSequenceNumber; | ||
Assert.AreEqual(100L, account.SequenceNumber); | ||
Assert.AreEqual(101L, incremented); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIncrementSequenceNumber() | ||
{ | ||
var random = KeyPair.Random(); | ||
var account = new Account(random.AccountId, 100L); | ||
account.IncrementSequenceNumber(); | ||
Assert.AreEqual(account.SequenceNumber, 101L); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetters() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var account = new Account(keypair.AccountId, 100L); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.SequenceNumber, 100L); | ||
} | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using StellarDotnetSdk.Accounts; | ||
|
||
namespace StellarDotnetSdk.Tests.Accounts; | ||
|
||
[TestClass] | ||
public class AccountTest | ||
{ | ||
[TestMethod] | ||
public void TestNullArguments() | ||
{ | ||
Assert.ThrowsException<ArgumentNullException>(() => new Account((string)null, 10L)); | ||
Check warning on line 13 in StellarDotnetSdk.Tests/Accounts/AccountTest.cs GitHub Actions / pack_and_test
|
||
Assert.ThrowsException<ArgumentNullException>(() => new Account(KeyPair.Random().AccountId, null)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestWithStringArgumentIsKeyPair() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var account = new Account(keypair.Address, 7); | ||
Assert.AreEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
} | ||
|
||
[TestMethod] | ||
public void TestWithMuxedAccount() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var muxed = new MuxedAccountMed25519(keypair, 10); | ||
var account = new Account(muxed, 7); | ||
Assert.AreNotEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.AccountId, muxed.AccountId); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetIncrementedSequenceNumber() | ||
{ | ||
var random = KeyPair.Random(); | ||
var account = new Account(random.AccountId, 100L); | ||
var incremented = account.IncrementedSequenceNumber; | ||
Assert.AreEqual(100L, account.SequenceNumber); | ||
Assert.AreEqual(101L, incremented); | ||
incremented = account.IncrementedSequenceNumber; | ||
Assert.AreEqual(100L, account.SequenceNumber); | ||
Assert.AreEqual(101L, incremented); | ||
} | ||
|
||
[TestMethod] | ||
public void TestIncrementSequenceNumber() | ||
{ | ||
var random = KeyPair.Random(); | ||
var account = new Account(random.AccountId, 100L); | ||
account.IncrementSequenceNumber(); | ||
Assert.AreEqual(account.SequenceNumber, 101L); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetters() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var account = new Account(keypair.AccountId, 100L); | ||
Assert.AreEqual(account.KeyPair.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.AccountId, keypair.AccountId); | ||
Assert.AreEqual(account.SequenceNumber, 100L); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
stellar-dotnet-sdk-test/KeyPairBIP39Tests.cs → ...etSdk.Tests/Accounts/KeyPairBIP39Tests.cs
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
Oops, something went wrong.