Skip to content

Commit c40719b

Browse files
authored
Merge pull request #139 from IOTA-NET/67-feat-sendmicrotransaction
67 feat sendmicrotransaction
2 parents 7f6f44b + 6110d56 commit c40719b

File tree

17 files changed

+347
-8
lines changed

17 files changed

+347
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ For more examples, see the [Examples](https://github.com/wireless90/IotaWallet.N
166166
- [x] MintNativeTokens
167167
- [x] MintNfts
168168
- [x] RequestFromFaucet
169+
- [x] SendAmount
170+
- [x] SendMicroAmount
169171
- [x] SendNativeTokens
170172
- [x] SendNfts
171173
- [x] SyncAccount

csharp/IotaWalletNet/IotaWalletNet.Application/Account.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using IotaWalletNet.Application.AccountContext.Commands.MintNfts;
1111
using IotaWalletNet.Application.AccountContext.Commands.RequestFromFaucet;
1212
using IotaWalletNet.Application.AccountContext.Commands.SendAmount;
13+
using IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount;
1314
using IotaWalletNet.Application.AccountContext.Commands.SendNativeTokens;
1415
using IotaWalletNet.Application.AccountContext.Commands.SendNfts;
1516
using IotaWalletNet.Application.AccountContext.Commands.SyncAccount;
@@ -53,6 +54,11 @@ public Account(IMediator mediator, string username, IWallet wallet)
5354
public IWallet Wallet { get; }
5455

5556

57+
public async Task<SendMicroAmountResponse> SendMicroAmountAsync(List<AddressWithMicroAmount> addressWithMicroAmounts, TaggedDataPayload? taggedDataPayload = null)
58+
{
59+
return await _mediator.Send(new SendMicroAmountCommand(addressWithMicroAmounts, taggedDataPayload, Username, this));
60+
}
61+
5662
public async Task<DestroyFoundryResponse> DestroyFoundryAsync(string foundryId)
5763
{
5864
return await _mediator.Send(new DestroyFoundryCommand(foundryId, Username, this));
@@ -174,6 +180,8 @@ public async Task<SendAmountResponse> SendAmountAsync(List<AddressWithAmount> ad
174180

175181
public SendAmountBuilder SendAmountUsingBuilder() => new SendAmountBuilder(_mediator, this, Username);
176182

183+
public SendMicroAmountBuilder SendMicroAmountUsingBuilder() => new SendMicroAmountBuilder(_mediator, this, Username);
184+
177185
public async Task<SyncAccountResponse> SyncAccountAsync()
178186
{
179187
return await _mediator.Send(new SyncAccountCommand(this, Username));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using IotaWalletNet.Application.Common.Interfaces;
2+
using IotaWalletNet.Domain.Common.Models.Address;
3+
using IotaWalletNet.Domain.Common.Models.Transaction.PayloadTypes;
4+
using MediatR;
5+
6+
namespace IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount
7+
{
8+
public class SendMicroAmountCommand : IRequest<SendMicroAmountResponse>
9+
{
10+
public SendMicroAmountCommand(List<AddressWithMicroAmount> addressesWithMicroAmount, TaggedDataPayload? taggedDataPayload, string username, IAccount account)
11+
{
12+
AddressesWithMicroAmount = addressesWithMicroAmount;
13+
Username = username;
14+
Account = account;
15+
TaggedDataPayload = taggedDataPayload;
16+
}
17+
18+
public List<AddressWithMicroAmount> AddressesWithMicroAmount { get; set; }
19+
20+
public TaggedDataPayload? TaggedDataPayload { get; set; }
21+
22+
public string Username { get; set; }
23+
24+
public IAccount Account { get; set; }
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using IotaWalletNet.Domain.Common.Models.Transaction;
2+
using IotaWalletNet.Domain.PlatformInvoke;
3+
using MediatR;
4+
using Newtonsoft.Json;
5+
6+
namespace IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount
7+
{
8+
public class SendMicroAmountCommandHandler : IRequestHandler<SendMicroAmountCommand, SendMicroAmountResponse>
9+
{
10+
public async Task<SendMicroAmountResponse> Handle(SendMicroAmountCommand request, CancellationToken cancellationToken)
11+
{
12+
SendMicroAmountCommandMessageData messageData = new SendMicroAmountCommandMessageData(request.AddressesWithMicroAmount, new TransactionOptions() { TaggedDataPayload = request.TaggedDataPayload });
13+
SendMicroAmountCommandMessage message = new SendMicroAmountCommandMessage(request.Username, messageData);
14+
string messageJson = JsonConvert.SerializeObject(message);
15+
16+
RustBridgeGenericResponse genericResponse = await request.Account.SendMessageAsync(messageJson);
17+
18+
SendMicroAmountResponse response = genericResponse.As<SendMicroAmountResponse>()!;
19+
20+
return response;
21+
}
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using IotaWalletNet.Domain.Common.Models;
2+
3+
namespace IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount
4+
{
5+
public class SendMicroAmountCommandMessage : AccountMessage<SendMicroAmountCommandMessageData>
6+
{
7+
private const string METHOD_NAME = "sendMicroTransaction";
8+
public SendMicroAmountCommandMessage(string username, SendMicroAmountCommandMessageData? methodData)
9+
: base(username, METHOD_NAME, methodData)
10+
{
11+
}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using IotaWalletNet.Domain.Common.Models.Address;
2+
using IotaWalletNet.Domain.Common.Models.Transaction;
3+
4+
namespace IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount
5+
{
6+
public class SendMicroAmountCommandMessageData
7+
{
8+
public SendMicroAmountCommandMessageData(List<AddressWithMicroAmount> addressesWithMicroAmount, TransactionOptions options)
9+
{
10+
AddressesWithMicroAmount = addressesWithMicroAmount;
11+
Options = options;
12+
}
13+
14+
public List<AddressWithMicroAmount> AddressesWithMicroAmount { get; set; }
15+
16+
public TransactionOptions Options { get; set; }
17+
}
18+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using IotaWalletNet.Domain.Common.Models.Transaction;
2+
using IotaWalletNet.Domain.PlatformInvoke;
3+
4+
namespace IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount
5+
{
6+
public class SendMicroAmountResponse : RustBridgeResponseBase<Transaction>
7+
{
8+
9+
}
10+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount;
2+
using IotaWalletNet.Application.Common.Interfaces;
3+
using IotaWalletNet.Domain.Common.Models.Address;
4+
using IotaWalletNet.Domain.Common.Models.Transaction.PayloadTypes;
5+
using MediatR;
6+
7+
namespace IotaWalletNet.Application.Common.Builders
8+
{
9+
public class SendMicroAmountBuilder
10+
{
11+
private readonly List<AddressWithMicroAmount> _addressWithMicroAmounts;
12+
private readonly IMediator _mediator;
13+
private readonly IAccount _account;
14+
private readonly string _username;
15+
private TaggedDataPayload? _taggedDataPayload;
16+
17+
public SendMicroAmountBuilder(IMediator mediator, IAccount account, string username)
18+
{
19+
_addressWithMicroAmounts = new List<AddressWithMicroAmount>();
20+
_mediator = mediator;
21+
_account = account;
22+
_username = username;
23+
}
24+
25+
public SendMicroAmountBuilder AddAddressAndAmount(string receiverAddress, ulong amountInGlow, ulong expirationInSeconds)
26+
{
27+
AddressWithMicroAmount addressWithMicroAmount = new AddressWithMicroAmount(receiverAddress, amountInGlow.ToString(), expirationInSeconds);
28+
_addressWithMicroAmounts.Add(addressWithMicroAmount);
29+
30+
return this;
31+
}
32+
33+
public SendMicroAmountBuilder SetTaggedDataPayload(string tag, string data)
34+
{
35+
_taggedDataPayload = new TaggedDataPayload(tag, data);
36+
return this;
37+
}
38+
public async Task<SendMicroAmountResponse> SendMicroAmountAsync()
39+
{
40+
return await _mediator.Send(new SendMicroAmountCommand(_addressWithMicroAmounts, _taggedDataPayload, _username, _account));
41+
}
42+
}
43+
}

csharp/IotaWalletNet/IotaWalletNet.Application/Common/Interfaces/IAccount.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using IotaWalletNet.Application.AccountContext.Commands.MintNativeTokens;
1010
using IotaWalletNet.Application.AccountContext.Commands.MintNfts;
1111
using IotaWalletNet.Application.AccountContext.Commands.SendAmount;
12+
using IotaWalletNet.Application.AccountContext.Commands.SendMicroAmount;
1213
using IotaWalletNet.Application.AccountContext.Commands.SendNativeTokens;
1314
using IotaWalletNet.Application.AccountContext.Commands.SendNfts;
1415
using IotaWalletNet.Application.AccountContext.Commands.SyncAccount;
@@ -66,5 +67,7 @@ public interface IAccount : IRustBridgeCommunicator
6667
Task<GetFoundryOutputResponse> GetFoundryOutputAsync(string tokenId);
6768
Task<DestroyFoundryResponse> DestroyFoundryAsync(string foundryId);
6869
SendAmountBuilder SendAmountUsingBuilder();
70+
Task<SendMicroAmountResponse> SendMicroAmountAsync(List<AddressWithMicroAmount> addressWithMicroAmounts, TaggedDataPayload? taggedDataPayload = null);
71+
SendMicroAmountBuilder SendMicroAmountUsingBuilder();
6972
}
7073
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace IotaWalletNet.Domain.Common.Models.Address
2+
{
3+
public class AddressWithMicroAmount
4+
{
5+
public AddressWithMicroAmount(string address, string amount, ulong expiration, string? returnAddress = null)
6+
{
7+
Address = address;
8+
Amount = amount;
9+
ReturnAddress = returnAddress;
10+
Expiration = expiration;
11+
}
12+
13+
public string Address { get; set; }
14+
15+
public string Amount { get; set; }
16+
17+
public string? ReturnAddress { get; set; }
18+
19+
public ulong Expiration { get; set; }
20+
}
21+
22+
23+
}

0 commit comments

Comments
 (0)