/// <inheritdoc /> public async Task <IIotaRepository> CreateAsync(bool remotePoW = false) { string nodeUri; if (remotePoW) { nodeUri = await this.NodeSelector.GetHealthyRemotePoWNodeUriAsync(); } else { nodeUri = await this.NodeSelector.GetHealthyNodeUriAsync(); } var client = new RestIotaClient(new RestClient(nodeUri)); IPoWService powService; if (remotePoW) { powService = new RestPoWService(client); } else { powService = new PoWService(new CpuPearlDiver()); } return(new RestIotaRepository(client, powService)); }
public void TestPowServiceAddsTimeStamps() { var service = new PoWService(new PearlDiverStub()); var result = service.DoPoW(new Hash("BRANCH"), new Hash("TRUNK"), this.bundle.Transactions); foreach (var transaction in result) { Assert.AreEqual(0, transaction.AttachmentTimestampLowerBound); Assert.AreEqual(PoWService.MaxTimestampValue, transaction.AttachmentTimestampUpperBound); var currentTime = Timestamp.UnixSecondsTimestamp * 1000; Assert.IsTrue(transaction.AttachmentTimestamp > currentTime - 10000 && transaction.AttachmentTimestamp < currentTime + 10000); } }
public void TestPowServiceChainsTransactionsCorrectly() { var service = new PoWService(new PearlDiverStub()); var result = service.DoPoW(new Hash("BRANCH"), new Hash("TRUNK"), this.bundle.Transactions); for (var i = 0; i < result.Count; i++) { if (result[i].CurrentIndex == result[i].LastIndex) { Assert.AreEqual(new Hash("BRANCH").Value, result[i].BranchTransaction.Value); Assert.AreEqual(new Hash("TRUNK").Value, result[i].TrunkTransaction.Value); } else { Assert.AreEqual(new Hash("TRUNK").Value, result[i].BranchTransaction.Value); Assert.AreEqual(result[i + 1].Hash.Value, result[i].TrunkTransaction.Value); } } }
public RestIotaRepository Create() { var powService = new PoWService(new CpuPowDiver()); var node = new RestIotaRepository(new RestClient("https://field.carriota.com:443"), powService); if (NoteIsHealthy(node)) { return(node); } foreach (var nodeUri in this.nodeUriList) { node = new RestIotaRepository(new RestClient(nodeUri), powService); if (NoteIsHealthy(node)) { break; } } return(node); }
/// <summary> /// The execute api example. /// </summary> private static void ExecuteApiExample() { var nodeUri = ConfigurationManager.AppSettings["nodeUri"]; // The node URI is saved in the projects App.config ... let's get it var iotaClient = new RestIotaClient(new RestClient(nodeUri)); var powService = new PoWService(new CpuPearlDiver()); // the examples will use the CPU to do PoW for a transaction. // you could also use a remote node for PoW, if the node supports it. Uncomment this line and comment the line above to do so. Don't forget to change the node Uri in App.Config // var powService = new RestPoWService(iotaClient); var repository = new RestIotaRepository( iotaClient, powService); // compose the repository. all these steps would normally be done via DI container (ninject for example) // var factory = new RestIotaRepositoryFactory(); In an async context it is also possible to create a repository via factory as shown here. // var repository = await factory.CreateAsync(); This automatically picks a healthy node. var example = new GetAccountDataExample(repository); // get the example to execute. Change this to any example you want var result = example.Execute(); Console.WriteLine(result); // print the example result to console. Set a breakpoint here if you want to see the result in debug mode. }