Skip to content

Commit fdc6d45

Browse files
committed
Lab 2
1 parent 084b0f5 commit fdc6d45

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

Common/Solidity/templates/cs-service.ejs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ namespace <%= locals.namespace ? namespace : 'DefaultNamespace' %>
3838
_contract = _web3.Eth.GetContract(ABI, address);
3939
}
4040

41-
public async Task<bool> ExecuteTransactionAsync(Func<I<%= capitalizeFirstLetter(getContractName()) %>Service, Task<string>> func, int timeoutInSeconds = 120)
41+
public async Task<bool> ExecuteTransactionAsync(Func<I<%= capitalizeFirstLetter(getContractName()) %>Service, Task<string>> func, int timeoutInSeconds)
4242
{
43+
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutInSeconds));
44+
4345
string transaction = await func(this);
4446
var receipt = await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction).ConfigureAwait(false);
4547

46-
int count = 0;
47-
while (receipt == null && count < timeoutInSeconds * 2)
48+
while (receipt == null && !cts.IsCancellationRequested)
4849
{
4950
await Task.Delay(500);
5051
receipt = await _web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transaction).ConfigureAwait(false);
51-
count++;
5252
}
5353

5454
return receipt != null;

Lab 2/ConsoleApp/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Threading.Tasks;
3+
using Lab2.SmartContracts;
34
using Nethereum.Web3.Accounts.Managed;
45
using Nethereum.Geth;
5-
using Lab2.SmartContracts;
66
using Nethereum.Hex.HexTypes;
77

88
namespace ConsoleApp
@@ -25,7 +25,7 @@ public static void Main(string[] args)
2525

2626
Console.WriteLine(new string('-', 80));
2727

28-
TestService(senderAddress, password).Wait(60000);
28+
TestService(senderAddress, password).Wait(1000 * 60 * 5); // Wait max 5 minutes
2929

3030
Console.WriteLine(new string('-', 80));
3131
}
@@ -51,14 +51,14 @@ private static async Task TestService(string fromAddress, string password)
5151
ISimpleStorageContractService service = new SimpleStorageContractService(web3, contractAddress);
5252

5353
// TODO 1:
54-
// bool setNumberResult = await service.ExecuteTransactionAsync((srv) => srv.SetNumberAsync(fromAddress, 500));
54+
// bool setNumberResult = await service.ExecuteTransactionAsync(srv => srv.SetNumberAsync(fromAddress, 500));
5555

5656
// TODO 2:
5757
// var getNumberValue = await service.GetNumberCallAsync(fromAddress);
5858
// Console.WriteLine($"The stored number value is '{getNumberValue}'.");
5959

6060
// TODO 3:
61-
// bool setStringResult = await service.ExecuteTransactionAsync((srv) => srv.SetStringAsync(fromAddress, "mstack.nl test"));
61+
// bool setStringResult = await service.ExecuteTransactionAsync(srv => srv.SetStringAsync(fromAddress, "mstack.nl test"));
6262

6363
// TODO 4:
6464
// var getStringValue = await service.GetStringCallAsync(fromAddress);

Lab 2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you have some generic or detailed questions, please feel free to ask these at
1717
## Folder structure
1818

1919
- `Solidity`: folder for the SmartContracts written in Solidity and unit-tests written in javascript.
20-
- `ConsoleApp`: folder for the SmartContracts written in Solidity and unit-tests written in javascript.
20+
- `ConsoleApp`: folder for the ConsoleApp (C#).
2121

2222
## Details
2323

0 commit comments

Comments
 (0)