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
8 changes: 8 additions & 0 deletions csharp/IotaWalletNet/IotaWalletNet.Application/Account.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using IotaWalletNet.Application.AccountContext.Commands.GenerateAddresses;
using IotaWalletNet.Application.AccountContext.Commands.MintNfts;
using IotaWalletNet.Application.AccountContext.Commands.RequestFromFaucet;
using IotaWalletNet.Application.AccountContext.Commands.SendAmount;
using IotaWalletNet.Application.AccountContext.Commands.SyncAccount;
using IotaWalletNet.Application.AccountContext.Queries.GetBalance;
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Domain.Common.Models.Address;
using IotaWalletNet.Domain.Common.Models.Network;
using IotaWalletNet.Domain.Common.Models.Nft;
using IotaWalletNet.Domain.PlatformInvoke;
using MediatR;
using static IotaWalletNet.Application.AccountContext.Commands.SyncAccount.SyncAccountCommandHandler;
Expand Down Expand Up @@ -37,6 +39,12 @@ public async Task RequestFromFaucetAsync(string address, string url)
await _mediator.Send(new RequestFromFaucetCommand(address, url));
}


public async Task<MintNftsResponse> MintNftsAsync(List<NftOptions> nftsOptions)
{
return await _mediator.Send(new MintNftsCommand(this, Username, nftsOptions));
}

public async Task<GetBalanceResponse> GetBalanceAsync()
{
return await _mediator.Send(new GetBalanceQuery(this, Username));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task<GenerateAddressesResponse> Handle(GenerateAddressesCommand req
}
};

GenerateAddressesData data = new GenerateAddressesData(request.Amount, options);
GenerateAddressesCommandMessageData data = new GenerateAddressesCommandMessageData(request.Amount, options);

GenerateAddressesCommandMessage message = new GenerateAddressesCommandMessage(request.Username, data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace IotaWalletNet.Application.AccountContext.Commands.GenerateAddresses
{
public class GenerateAddressesCommandMessage : AccountMessage<GenerateAddressesData>
public class GenerateAddressesCommandMessage : AccountMessage<GenerateAddressesCommandMessageData>
{
private const string METHOD_NAME = "generateAddresses";
public GenerateAddressesCommandMessage(string username, GenerateAddressesData methodData)
public GenerateAddressesCommandMessage(string username, GenerateAddressesCommandMessageData methodData)
: base(username, METHOD_NAME, methodData)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace IotaWalletNet.Application.AccountContext.Commands.GenerateAddresses
{
public class GenerateAddressesData
public class GenerateAddressesCommandMessageData
{
public GenerateAddressesData(uint amount, AddressGenerationOptions addressGenerationOptions)
public GenerateAddressesCommandMessageData(uint amount, AddressGenerationOptions addressGenerationOptions)
{
Amount = amount;
AddressGenerationOptions = addressGenerationOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using IotaWalletNet.Application.Common.Interfaces;
using IotaWalletNet.Domain.Common.Models.Nft;
using MediatR;

namespace IotaWalletNet.Application.AccountContext.Commands.MintNfts
{
public class MintNftsCommand : IRequest<MintNftsResponse>
{
public MintNftsCommand(IAccount account, string username, List<NftOptions> nftsOptions)
{
Account = account;
Username = username;
NftsOptions = nftsOptions;
}

public IAccount Account { get; }
public string Username { get; }
public List<NftOptions> NftsOptions { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using IotaWalletNet.Domain.Common.Models.Transaction;
using IotaWalletNet.Domain.PlatformInvoke;
using MediatR;
using Newtonsoft.Json;

namespace IotaWalletNet.Application.AccountContext.Commands.MintNfts
{
public class MintNftsCommandHandler : IRequestHandler<MintNftsCommand, MintNftsResponse>
{
public async Task<MintNftsResponse> Handle(MintNftsCommand request, CancellationToken cancellationToken)
{
MintNftsCommandMessageData data = new MintNftsCommandMessageData(request.NftsOptions, new TransactionOptions());

MintNftsCommandMessage message = new MintNftsCommandMessage(request.Username, data);

string json = JsonConvert.SerializeObject(message);

RustBridgeGenericResponse genericResponse = await request.Account.SendMessageAsync(json);

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

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

namespace IotaWalletNet.Application.AccountContext.Commands.MintNfts
{
public class MintNftsCommandMessage : AccountMessage<MintNftsCommandMessageData>
{
private const string METHOD_NAME = "mintNfts";

public MintNftsCommandMessage(string username, MintNftsCommandMessageData mintNftsCommandMessageData)
: base(username, METHOD_NAME, mintNftsCommandMessageData)
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using IotaWalletNet.Domain.Common.Models.Nft;
using IotaWalletNet.Domain.Common.Models.Transaction;

namespace IotaWalletNet.Application.AccountContext.Commands.MintNfts
{
public class MintNftsCommandMessageData
{
public MintNftsCommandMessageData(List<NftOptions> nftsOptions, TransactionOptions transactionOptions)
{
NftsOptions = nftsOptions;
Options = transactionOptions;
}
public List<NftOptions> NftsOptions { get; set; }
public TransactionOptions Options { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using IotaWalletNet.Domain.Common.Models.Transaction;
using IotaWalletNet.Domain.PlatformInvoke;

namespace IotaWalletNet.Application.AccountContext.Commands.MintNfts
{
public class MintNftsResponse : RustBridgeResponseBase<Transaction>
{


}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using IotaWalletNet.Application.AccountContext.Commands.GenerateAddresses;
using IotaWalletNet.Application.AccountContext.Commands.MintNfts;
using IotaWalletNet.Application.AccountContext.Queries.GetBalance;
using IotaWalletNet.Domain.Common.Interfaces;
using IotaWalletNet.Domain.Common.Models.Address;
using IotaWalletNet.Domain.Common.Models.Network;
using IotaWalletNet.Domain.Common.Models.Nft;
using static IotaWalletNet.Application.AccountContext.Commands.SyncAccount.SyncAccountCommandHandler;

namespace IotaWalletNet.Application.Common.Interfaces
Expand All @@ -20,5 +22,6 @@ public interface IAccount : IRustBridgeCommunicator
Task<GetBalanceResponse> GetBalanceAsync();
Task RequestFromFaucetAsync(string address, string url);
Task<GenerateAddressesResponse> GenerateAddressesAsync(uint numberOfAddresses = 1, NetworkType networkType = default);
Task<MintNftsResponse> MintNftsAsync(List<NftOptions> nftsOptions);
}
}
1 change: 0 additions & 1 deletion csharp/IotaWalletNet/IotaWalletNet.Application/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public async Task<GetAccountsResponse> GetAccountsAsync()
return await _mediator.Send(new GetAccountsQuery(this));
}


public async Task<(GetAccountResponse response, IAccount? account)> GetAccountAsync(string username)
{
GetAccountResponse response = await _mediator.Send(new GetAccountQuery(this, username));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using IotaWalletNet.Domain.PlatformInvoke;
using MediatR;
using Newtonsoft.Json;
using static IotaWalletNet.Application.WalletContext.Queries.GetAccount.GetAccountQueryHandler;

namespace IotaWalletNet.Application.WalletContext.Queries.GetAccounts
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace IotaWalletNet.Main.Common.Extensions
using System.Text;

namespace IotaWalletNet.Domain.Common.Extensions
{
public static class StringExtensions
{
public static bool IsNullOrEmpty(this string? input) => string.IsNullOrEmpty(input);

public static bool IsNotNullAndEmpty(this string? input) => !input.IsNullOrEmpty();

public static string ToHexString(this string input) => "0x" + Convert.ToHexString(Encoding.UTF8.GetBytes(input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
namespace IotaWalletNet.Domain.Common.Models.Nft
{
public class NFTIRC27
{
public string Standard { get; } = "IRC27";

public string Version { get; } = "v1.0";

/// <summary>
/// Mime type
/// </summary>
public string Type { get; set; }
public string NameOfNft { get; }
public string Uri { get; }

public string? CollectionName { get; set; }

public string? IssuerName { get; set; }

public string? Description { get; set; }

/// <summary>
/// address to royalties mapping. Its not encouraged to have total royalties exceed 50%
/// </summary>
public Dictionary<string, decimal> Royalties { get; set; } = new Dictionary<string, decimal>();

/// <summary>
/// Attributes for the item, which will show up on dApps like NFT Marketplaces
/// </summary>
public List<NFTIRC27Attribute> Attributes { get; set; } = new List<NFTIRC27Attribute>();

/// <summary>
/// Attributes for the item, which need not be used publicly
/// </summary>
public List<NFTIRC27Attribute> InternalAttributes { get; set; } = new List<NFTIRC27Attribute>();

/// <summary>
///
/// </summary>
/// <param name="mimeType">Use KnownMimeTypes class to help</param>
public NFTIRC27(string mimeType, string nameOfNft, string uri)
{
Type = mimeType;
NameOfNft = nameOfNft;
Uri = uri;
}

public NFTIRC27 SetDescription(string description)
{
Description = description;
return this;
}

public NFTIRC27 SetCollectionName(string collectionName)
{
CollectionName = collectionName;
return this;
}

public NFTIRC27 SetIssuerName(string issuerName)
{
IssuerName = issuerName;
return this;
}

public NFTIRC27 AddRoyalty(string address, decimal royaltyPercentage)
{
Royalties[address] = royaltyPercentage;

return this;
}

public NFTIRC27 AddAttribute(string traitType, string value)
{
Attributes.Add(new NFTIRC27Attribute(traitType, value));
return this;
}

public NFTIRC27 AddInternalAttribute(string traitType, string value)
{
InternalAttributes.Add(new NFTIRC27Attribute(traitType, value));
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace IotaWalletNet.Domain.Common.Models.Nft
{
public class NFTIRC27Attribute
{
public NFTIRC27Attribute(string traitType, string value)
{
TraitType = traitType;
Value = value;
}

public string TraitType { get; set; }

public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace IotaWalletNet.Domain.Common.Models.Nft
{
public class NftOptions
{
/// <summary>
/// Bech32 encoded address to which the Nft will be minted. Default will use the
/// first address of the account
/// </summary>
public string? Address { get; set; }

/// <summary>
/// Bech32 encoded sender address
/// </summary>
public string? Sender { get; set; }

/// <summary>
/// Hex encoded bytes
/// </summary>
public string? Metadata { get; set; }

/// <summary>
/// Hex encoded bytes
/// </summary>
public string? Tag { get; set; }

/// <summary>
/// Bech32 encoded issuer address
/// </summary>
public string? Issuer { get; set; }

/// <summary>
/// Hex encoded bytes
/// </summary>
public string? ImmutableMetadata { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace IotaWalletNet.Domain.Common.Models.Output
{
public class UtxoInput
{
/// <summary>
/// The transaction id
/// </summary>
public string TransactionId { get; set; }


/// <summary>
/// The output index
/// </summary>
public uint TransactionOutputIndex { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace IotaWalletNet.Domain.Common.Models.Transaction
{
public class TaggedDataPayload
{

public TaggedDataPayload(string tag, string data)
{
Tag = tag;
Data = data;
}


/// <summary>
/// The tag used to categorize the data
/// </summary>
public string Tag { get; set; }

/// <summary>
/// The indexed data
/// </summary>
public string Data { get; set; }
}
}
Loading