/// <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));
        }
Пример #2
0
        public static RestIotaRepository GenerateNode(bool doRemotePoW, string nodeUri)
        {
            var iotaClient = new RestIotaClient(new RestClient(nodeUri));

            return(doRemotePoW
               ? new RestIotaRepository(iotaClient, new RestPoWService(iotaClient))
               : new RestIotaRepository(iotaClient, new PoWService(new CpuPearlDiver())));
        }
Пример #3
0
        public TangleMessenger(Seed seed, int minWeightMagnitude = 9)
        {
            this.seed      = seed;
            this.MinWeight = minWeightMagnitude;
            var iotaClient = new RestIotaClient(new RestClient("https://nodes.testnet.iota.org:443"));

            this.repository = new RestIotaRepository(iotaClient, new PoWService(new CpuPearlDiver()));
        }
        /// <summary>
        /// Creates the repository for a single node
        /// </summary>
        /// <param name="uri">Node Uri</param>
        /// <param name="powType">"Where" to do the proof of work</param>
        /// <param name="timeout">Timeout for node calls</param>
        /// <returns>
        /// The iota repository
        /// </returns>
        /// <exception>
        /// Throws an UriFormatException if the node uri is invalid
        /// </exception>
        public static RestIotaRepository Create(string uri, PoWType powType = PoWType.Local, int timeout = 5000)
        {
            var client = new RestIotaClient(new RestClient(uri)
            {
                Timeout = timeout
            });

            return(new RestIotaRepository(client, ResolvePoWType(powType, client)));
        }
Пример #5
0
        /// <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.
        }