Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Finding an IOTA node");
            INodeFinder nodeFinder = new IotaDanceNodeFinder();
            var         node       = nodeFinder.FindNodes().Result.First();

            Console.WriteLine($"Creating transfer now. This may take a few seconds.");

            // We'll create out 2 transactions.
            var transaction1 = new TransactionItem("FAKEADDRESS9999999999999999999999999999999999999999999999999999999999999999999999", 0, "BEEFROG")
            {
                SignatureFragment = BeeFrog.Iota.Api.Utils.Converter.AsciiToTrytes("Message part 1")
            };

            var transaction2 = new TransactionItem("FAKEADDRESS9999999999999999999999999999999999999999999999999999999999999999999999", 0, "BEEFROG")
            {
                SignatureFragment = BeeFrog.Iota.Api.Utils.Converter.AsciiToTrytes("Message part 2")
            };

            // Create an array and bundle the transactions together.
            var trans = new TransactionItem[] { transaction1, transaction2 };

            trans.FinalizeBundleHash(new Curl());

            // Now we can send them.
            var api       = new IotaApi(node.Url);
            var apiResult = api.AttachTransactions(trans, CancellationToken.None).Result;

            if (apiResult.Successful)
            {
                var transaction = apiResult.Result;
                Console.WriteLine($"Your transaction bundle is: {transaction[0].Bundle}");
            }
            else
            {
                Console.WriteLine($"{apiResult.ErrorMessage} Exception: {apiResult.ExceptionInfo}");
            }

            Console.WriteLine($"Press any key to close");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        private static void Promote(IotaApi api, string hash)
        {
            while (true)
            {
                Console.WriteLine("Waiting 60 seconds before promoting. Press any key to stop.");
                for (int i = 0; i < 240; i++)
                {
                    if (i % 4 == 0)
                    {
                        Console.Write(".");
                    }

                    Thread.Sleep(250);
                    if (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                        return;
                    }
                }

                var states = api.IriApi.GetInclusionStates(new[] { hash }).Result;
                if (states.Successful && states.Result.Any() && states.Result[0])
                {
                    Console.WriteLine("Your transaction has been confirmed!");
                    return;
                }

                var consistencyResponse = api.IriApi.CheckConsistency(hash, hash).Result;
                if (consistencyResponse.Successful)
                {
                    if (consistencyResponse.Result == false)
                    {
                        Console.WriteLine("Your transaction needs to be re-attached!");
                        var response = api.GetTransactionItems(hash).Result;
                        if (response.Successful)
                        {
                            Console.WriteLine("Re-attaching!");
                            var reattachResponse = api.AttachTransactions(response.Result, CancellationToken.None).Result;
                            if (reattachResponse.Successful)
                            {
                                hash = reattachResponse.Result[0].Hash;
                                Console.WriteLine("Success! Your new hash is:" + hash);
                                continue;
                            }
                            else
                            {
                                Console.WriteLine($"Re-attach Failed! Reason: {reattachResponse.ErrorMessage} Exception:{reattachResponse.ExceptionInfo}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Get Transaction Failed! Reason: {response.ErrorMessage} Exception:{response.ExceptionInfo}");
                        }
                    }

                    Console.WriteLine(" Promoting.");
                    var promoteResponse = api.PromoteTransaction(hash, CancellationToken.None).Result;
                    if (promoteResponse.Successful)
                    {
                        Console.WriteLine(promoteResponse.Result.Hash);
                    }
                    else
                    {
                        Console.WriteLine($"Promotion failed!! Reason: {promoteResponse.ErrorMessage} Exception:{promoteResponse.ExceptionInfo}");
                    }
                }
                else
                {
                    Console.WriteLine($"CheckConsistency failed! Reason: {consistencyResponse.ErrorMessage} Exception:{consistencyResponse.ExceptionInfo}");
                }
            }
        }