Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IotaWalletNet.Application.Common.Options;
using IotaWalletNet.Application.WalletContext.Commands.CreateAccount;
using IotaWalletNet.Application.WalletContext.Commands.StoreMnemonic;
using IotaWalletNet.Application.WalletContext.Commands.VerifyMnemonic;
using IotaWalletNet.Application.WalletContext.Queries.GetNewMnemonic;
Expand All @@ -12,7 +13,7 @@ public interface IWallet : IRustBridgeCommunicator, IDisposable
SecretManagerOptionsBuilder ConfigureSecretManagerOptions();
WalletOptionsBuilder ConfigureWalletOptions();
IWallet ThenInitialize();
Task<(string response, IAccount? account)> CreateAccountAsync(string username);
Task<(CreateAccountResponse response, IAccount? account)> CreateAccountAsync(string username);
Task<(string response, IAccount? account)> GetAccountAsync(string username);
Task<string> GetAccountsAsync();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Domain.Common.Models.Coin;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using static IotaWalletNet.Application.Common.Options.WalletOptions;
Expand Down Expand Up @@ -39,11 +40,7 @@ public class WalletOptions

public int CoinType { get; set; } = (int)TypeOfCoin.Shimmer;

public enum TypeOfCoin : int
{
Iota = 4218,
Shimmer = 4219,
}


public WalletOptions()
{
Expand Down
7 changes: 3 additions & 4 deletions csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public async Task<VerifyMnemonicResponse> VerifyMnemonicAsync(string mnemonic)
}


public async Task<(string response, IAccount? account)> CreateAccountAsync(string username)
public async Task<(CreateAccountResponse response, IAccount? account)> CreateAccountAsync(string username)
{

string response = await _mediator.Send(new CreateAccountCommand(this, username));
CreateAccountResponse response = await _mediator.Send(new CreateAccountCommand(this, username));

if (response.Contains("\"alias\":"))
if (response.IsSuccess())
{

IAccount account = new Account(_mediator, username, this);
Expand All @@ -100,7 +100,6 @@ public async Task<VerifyMnemonicResponse> VerifyMnemonicAsync(string mnemonic)
else
{
return (response, null);

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace IotaWalletNet.Application.WalletContext.Commands.CreateAccount
{
public class CreateAccountCommand : IRequest<string>
public class CreateAccountCommand : IRequest<CreateAccountResponse>
{
public CreateAccountCommand(IWallet wallet, string username)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using IotaWalletNet.Domain.PlatformInvoke;
using IotaWalletNet.Application.WalletContext.Queries.GetNewMnemonic;
using IotaWalletNet.Domain.Common.Models.Account;
using IotaWalletNet.Domain.PlatformInvoke;
using MediatR;
using Newtonsoft.Json;

namespace IotaWalletNet.Application.WalletContext.Commands.CreateAccount
{
public class CreateAccountCommandHandler : IRequestHandler<CreateAccountCommand, string>
public class CreateAccountCommandHandler : IRequestHandler<CreateAccountCommand, CreateAccountResponse>
{
public async Task<string> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
public async Task<CreateAccountResponse> Handle(CreateAccountCommand request, CancellationToken cancellationToken)
{
CreateAccountCommandMessage message = new CreateAccountCommandMessage(request.Username);
string json = JsonConvert.SerializeObject(message);

RustBridgeGenericResponse response = await request.Wallet.SendMessageAsync(json);
RustBridgeGenericResponse genericResponse = await request.Wallet.SendMessageAsync(json);

return "";
CreateAccountResponse response = genericResponse.IsSuccess
? genericResponse.As<CreateAccountResponse>()!
: new CreateAccountResponse() { Error = genericResponse.As<RustBridgeResponseError>(), Type = "error" };


return response;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using IotaWalletNet.Domain.Common.Models.Account;
using IotaWalletNet.Domain.PlatformInvoke;

namespace IotaWalletNet.Application.WalletContext.Commands.CreateAccount
{
public class CreateAccountResponse : RustBridgeResponseBase<AccountMeta>
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public async Task<GetNewMnemonicResponse> Handle(GetNewMnemonicQuery request, Ca
RustBridgeGenericResponse genericResponse = await request.Wallet.SendMessageAsync(json);

GetNewMnemonicResponse response = genericResponse.IsSuccess
? genericResponse.As<GetNewMnemonicResponse>()!
: new GetNewMnemonicResponse() { Error = genericResponse.As<RustBridgeResponseError>(), Type = "error" };
? genericResponse.As<GetNewMnemonicResponse>()!
: new GetNewMnemonicResponse() { Error = genericResponse.As<RustBridgeResponseError>(), Type = "error" };

return response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using IotaWalletNet.Domain.Common.Models.Address;
using IotaWalletNet.Domain.Common.Models.Coin;
using IotaWalletNet.Domain.Common.Models.Output;

namespace IotaWalletNet.Domain.Common.Models.Account
{
public class AccountMeta
{
public int Index { get; set; }

public TypeOfCoin CoinType { get; set; }

public string Alias { get; set; } = string.Empty;

public List<AccountAddress> PublicAddresses { get; set; } = new List<AccountAddress>();
public List<AccountAddress> InternalAddresses { get; set; } = new List<AccountAddress>();

public List<AddressWithUnspentOutputs> AddressesWithUnspentOutputs { get; set; } = new List<AddressWithUnspentOutputs>();

public Dictionary<string, OutputData> Outputs { get; set; } = new Dictionary<string, OutputData>();

/// <summary>
/// Output IDs of unspent outputs that are currently used as input for transactions
/// </summary>
public HashSet<string> LockedOutputs { get; set; } = new HashSet<string>();

public Dictionary<string, OutputData> UnspentOutputs { get; set; } = new Dictionary<string, OutputData>();


//public List<string> Transactions { get; set; } = new List<string>();

public HashSet<string> PendingTransactions { get; set; } = new HashSet<string>();


}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace IotaWalletNet.Domain.Common.Models.Address
{
public class AddressInformation
public class AccountAddress
{
public AccountAddress(string address)
{
Address = address;
}

public string Address { get; set; }
public int KeyIndex { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace IotaWalletNet.Domain.Common.Models.Address
{
public class AddressWithUnspentOutputs
{
public AddressWithUnspentOutputs(string address)
{
Address = address;
}

public string Address { get; set; }

public int KeyIndex { get; set; }

public bool Internal { get; set; }

public List<string> OutputIds { get; set; } = new List<string>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace IotaWalletNet.Domain.Common.Models.Coin
{
public enum TypeOfCoin : int
{
Iota = 4218,
Shimmer = 4219,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Security.Principal;

namespace IotaWalletNet.Domain.Common.Models.Output
{
/// <summary>
/// An output with Metadata
/// </summary>
public class OutputData
{
public OutputData(string outputId)
{
OutputId = outputId;
}

/// <summary>
/// The identifier of an Output
/// </summary>
public string OutputId { get; set; }

/// <summary>
/// If an output is spent
/// </summary>
public bool IsSpent { get; set; }

public string NetworkId { get; set; }

public bool Remainder { get; set; }

//addresstypes not mapped
//outputtypes not mapped

/// <summary>
/// The metadata of the output
/// </summary>
public OutputMetadata Metadata { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace IotaWalletNet.Domain.Common.Models.Output
{
public class OutputMetadata
{

/**
* The block id the output was contained in.
*/
public string? BlockId { get; set; }

/**
* The transaction id for the output.
*/
public string? TransactionId { get; set; }

/**
* The index for the output.
*/
public uint OutputIndex { get; set; }
/**
* Is the output spent.
*/
public bool IsSpent { get; set; }
/**
* The milestone index at which this output was spent.
*/
public uint MilestoneIndexSpent { get; set; }

/**
* The milestone timestamp this output was spent.
*/
public uint MilestoneTimestampSpent { get; set; }

/**
* The transaction id for the output.
*/
public string? TransactionIdSpent { get; set; }

/**
* The milestone index at which this output was booked into the ledger.
*/
public uint MilestoneIndexBooked { get; set; }

/**
* The milestone timestamp this output was booked in the ledger.
*/
public uint MilestoneTimestampBooked { get; set; }

/**
* The ledger index at which these output was available at.
*/
public uint LedgerIndex { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace IotaWalletNet.Domain.Common.Models.Output
{
public class OutputTypeToClaim
{
public const string None = "None";
public const string MicroTransactions = "MicroTransactions";
public const string NativeTokens = "NativeTokens";
public const string Nfts = "Nfts";
public const string All = "All";

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public abstract class RustBridgeResponseBase<TPayload>
public TPayload? Payload { get; set; }

public RustBridgeResponseError? Error { get; set; }

public bool IsSuccess() => Error == null;
}

public abstract class RustBridgeResponseBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using IotaWalletNet.Application.Common.Extensions;
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Application.Common.Options;
using IotaWalletNet.Domain.Common.Models.Coin;
using IotaWalletNet.Main.Common.Extensions;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -25,7 +26,7 @@ public static async Task Run()
//Build wallet using a fluent-style configuration api
wallet = wallet
.ConfigureWalletOptions()
.SetCoinType(WalletOptions.TypeOfCoin.Shimmer)
.SetCoinType(TypeOfCoin.Shimmer)
.SetStoragePath("./walletdb")
.ThenBuild()
.ConfigureClientOptions()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using IotaWalletNet.Application.Common.Extensions;
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Application.Common.Options;
using IotaWalletNet.Application.WalletContext.Commands.CreateAccount;
using IotaWalletNet.Application.WalletContext.Commands.StoreMnemonic;
using IotaWalletNet.Application.WalletContext.Queries.GetNewMnemonic;
using IotaWalletNet.Domain.Common.Models.Coin;
using IotaWalletNet.Main.Common.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
Expand All @@ -29,7 +31,7 @@ public async static Task Run()
//Build wallet using a fluent-style configuration api
wallet = wallet
.ConfigureWalletOptions()
.SetCoinType(WalletOptions.TypeOfCoin.Shimmer)
.SetCoinType(TypeOfCoin.Shimmer)
.SetStoragePath("./walletdb")
.ThenBuild()
.ConfigureClientOptions()
Expand All @@ -53,13 +55,13 @@ public async static Task Run()
StoreMnemonicResponse storeMnemonicResponse = await wallet.StoreMnemonicAsync(newMnemonic);
Console.WriteLine($"StoreMnemonicAsync: {JsonConvert.SerializeObject(storeMnemonicResponse)}");

string response;
CreateAccountResponse response;
//Let's create 2 accounts, with usernames cookiemonster and elmo
(response, IAccount? cookieMonsterAccount) = await wallet.CreateAccountAsync("cookiemonster");
Console.WriteLine($"CreateAccountAsync: {response.PrettyJson()}");
Console.WriteLine($"CreateAccountAsync: {JsonConvert.SerializeObject(response)}");

(response, IAccount? elmoAccount) = await wallet.CreateAccountAsync("elmo");
Console.WriteLine($"CreateAccountAsync: {response.PrettyJson()}");
Console.WriteLine($"CreateAccountAsync: {JsonConvert.SerializeObject(response)}");

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using IotaWalletNet.Application.Common.Extensions;
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Application.Common.Options;
using IotaWalletNet.Domain.Common.Models.Coin;
using IotaWalletNet.Domain.Common.Models.Network;
using IotaWalletNet.Main.Common.Extensions;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -27,7 +28,7 @@ public static async Task Run()
//Build wallet using a fluent-style configuration api
wallet = wallet
.ConfigureWalletOptions()
.SetCoinType(WalletOptions.TypeOfCoin.Shimmer)
.SetCoinType(TypeOfCoin.Shimmer)
.SetStoragePath("./walletdb")
.ThenBuild()
.ConfigureClientOptions()
Expand Down
Loading