Esempio n. 1
0
        /// <summary>
        /// Sends transfer without renew balance
        /// </summary>
        /// <param name="transferItem">The transfer items to send</param>
        /// <param name="addressItems">The address items from which amount is send</param>
        /// <param name="remainderAddress">The remainder where remaind amount is send</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns></returns>
        public async Task <APIResult <TransactionItem[]> > AttachTransferWithoutRenewBalance(TransferItem transferItem, IEnumerable <AddressItem> addressItems, string remainderAddress, CancellationToken cancellationToken)
        {
            var transactionItems       = transferItem.CreateTransactions(remainderAddress, addressItems.ToArray());
            var resultTransactionItems = await AttachTransactions(transactionItems, cancellationToken);

            return(resultTransactionItems);
        }
        public void Transaction_WithPOW_ToTrytes_SerialisesCorrectly()
        {
            // Arrange
            var trunk    = "GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999";
            var branch   = "NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999";
            var transfer = new TransferItem()
            {
                Address = "ASLIEIUJQHMVNHFQEXIDGGRRINZRHXZT9IWMZLRHWDYL9C9A9JSPBZUXJID9YERUQYRVALRVRLQZYSRXW", Message = "TESTMESSAGE", Tag = "MINEIOTADOTCOM", Value = 0
            };

            var trans = transfer.CreateTransactions();

            trans[0].SetAttachmentTime(new DateTime(2018, 01, 12, 0, 0, 0, DateTimeKind.Utc));
            trans[0].SetTimeStamp(new DateTime(2018, 01, 12, 0, 0, 0, DateTimeKind.Utc));
            var tranTrytes = trans.GetTrytes();

            // Act
            var trytesToSend = tranTrytes.DoPow(trunk, branch, 4, 1, CancellationToken.None).Result; // do the pow
            var tran         = new TransactionItem(trytesToSend[0]);

            // Assert
            Assert.AreEqual("ASLIEIUJQHMVNHFQEXIDGGRRINZRHXZT9IWMZLRHWDYL9C9A9JSPBZUXJID9YERUQYRVALRVRLQZYSRXW", tran.Address);
            Assert.AreEqual(0, tran.Value);

            Assert.AreEqual(151575840, tran.Timestamp, tran.Timestamp);
            Assert.AreEqual(1515758400000, tran.AttachmentTimestamp, tran.AttachmentTimestamp);
            Assert.AreEqual(0, tran.CurrentIndex);
            Assert.AreEqual(0, tran.LastIndex);
            Assert.AreEqual("GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999", tran.TrunkTransaction);
            Assert.AreEqual("NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999", tran.BranchTransaction);
            Assert.AreEqual("MINEIOTADOTCOM9999999999999", tran.Tag);
        }
        public void Transaction_ToTrytes_SerialisesCorrectly()
        {
            // Arrange
            var expectedtrytes = "MTWLHBKJJLIRJVEWDPOWHPACMACNTIBTNPLKKTRJHKAA9UAKFH9XCZTDPHIPCXNZ9KQIZCMJXEFUACJXWOZVZHOFYWJMSOSHJYHEBXUIG9TBDMVKSYAUDQAXSDDFPKNHOSETSRNCSSMMMLHGYDQLQWRQWBBOJSWMVXXYIOMI9EXTPJYIQ9GXCLZMKG9UNFKLKRGGJMIMMVGZGBDGRKWBHXCZOMCIRVLBMGXQKXEQKZNMVYHODWXJYYPVUQLLBGCILOYKHBFRUJKIKMKH9RITQOQGLESBZGDDQLCYOUTCRFHJ9ARQYPQLRLOHDEAXEYTM9CCCRWGCJWRGAWYHSHBFXOPNKCVSHDCWPMTSZOUMNOTDWFEDLMSLLMWQBAVAPMPBGZ9HSJOPPFCRPDDUVBCYWKRAWFYVGWJEIQOTXUXSWCWKRQHBWSNZVIOIFFTSQNSOZYEQZJ9NQFERBTITOCPRUQAWAKWIM9MIRKNWVBGXQOIJANCKPOFGEBYCLYNPYMKVBZAYOMKUZJGEQFQIIZLJPZIZMQFDXOUJTAZUEDWZICGDLKCUVNEERXDPAMDEPLUC9NKOAJLQLVIIAVHYHGG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RSVZTOAWV9EYTPCY9TTEKMIJQZSUVVCEDIHCRPTNWVEYNUUN9WXWQYIZUZJFETKSOKOT9CBFNKKRNJXZHHJGOWXHBULQMXMCNSLDHBGBMKHHMNOGFOTXZICOGGRJH9KZ9YDYZJCERMKLOCROVNGSZRKPHZJNAZQSTCUIYCYL9NS9RMKFIGKH9G9SRRZKLVDLNKU9PTEZGUEGGTKRJODNQYGEALTQOOBSOVCEBAZZWITGKMJUQODVKFDNTQSDKDYVBGUJNUIEDMSSOYLWVPAYGJH9ANL9VHGOAHXDKYPOWP9DGMUOBFZKHIMAHOBXMHMGNLVXZQDGYCVLZOEHOYNKKNLKPMAEPTUOBGRXXKBTCPKGNMSHXUDSWQOPRTLVJAFSEXDOMHENM9EMQJHL9DG9LRRMKGHMLTYX9S9EFOYHQLLGMJJEWF9KRYVNAGXFRZCRMCOVMXDYWWPUIKDYPASAECDPFSHFDTGTDNPXD9WZLNOIDLSD9TY9KUDUGVDTTAK9JQTJZU9KFLYD9VXGLBBGMEXASLIEIUJQHMVNHFQEXIDGGRRINZRHXZT9IWMZLRHWDYL9C9A9JSPBZUXJID9YERUQYRVALRVRLQZYSRXWMJLNY9999999999999999999999MINEIOTADOTCOM9999999999999X9DVQYD99C99999999E999999999BHGQLNJGFONXXJLSNEZXACIP9UQGV9HIWKP9X9COQLHBRSWEBSBJECCLLADKBUW9HAKSQZBNJZVIQAHZGFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999MINEIOTADOTCOM9999999999999DBNIZZXJE999999999L99999999XPBFUCTLEMOYKHMTZOKTNLTTHJY";

            // Act
            var transfer = new TransferItem()
            {
                Address = "ASLIEIUJQHMVNHFQEXIDGGRRINZRHXZT9IWMZLRHWDYL9C9A9JSPBZUXJID9YERUQYRVALRVRLQZYSRXW", Message = "TESTMESSAGE", Tag = "MINEIOTADOTCOM", Value = 0
            };
            var tran = transfer.CreateTransactions()[0];

            tran.TrunkTransaction  = "GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999";
            tran.BranchTransaction = "NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999";
            tran.Bundle            = "9BHGQLNJGFONXXJLSNEZXACIP9UQGV9HIWKP9X9COQLHBRSWEBSBJECCLLADKBUW9HAKSQZBNJZVIQAHZ";
            tran.SetTimeStamp(new DateTime(2018, 01, 12, 0, 0, 0, DateTimeKind.Utc));

            var trytesOutput = tran.ToTransactionTrytes();

            // Assert
            Assert.AreEqual("ASLIEIUJQHMVNHFQEXIDGGRRINZRHXZT9IWMZLRHWDYL9C9A9JSPBZUXJID9YERUQYRVALRVRLQZYSRXW", tran.Address);
            Assert.AreEqual(0, tran.Value);
            Assert.AreEqual("MINEIOTADOTCOM9999999999999", tran.Tag);


            Assert.AreEqual("9BHGQLNJGFONXXJLSNEZXACIP9UQGV9HIWKP9X9COQLHBRSWEBSBJECCLLADKBUW9HAKSQZBNJZVIQAHZ", tran.Bundle);
            Assert.AreEqual("GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999", tran.TrunkTransaction);
            Assert.AreEqual("NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999", tran.BranchTransaction);

            Assert.AreEqual(0, tran.LastIndex);
            Assert.AreEqual(0, tran.CurrentIndex);
            Assert.AreEqual(151575840, tran.Timestamp, tran.Timestamp);
            Assert.AreEqual("999999999999999999999999999", tran.Nonce); // Why is this 81 not 27?
        }
        public void Transaction_CanSign_WithoutError()
        {
            // Arrange
            var seed     = "GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999";
            var address1 = Utils.IotaUtils.GenerateAddress(seed, 0);
            var address2 = Utils.IotaUtils.GenerateAddress(seed, 1);
            var pKey     = Utils.Converter.ToTrytes(address1.PrivateKeyTrints);

            var signing       = new Utils.Signing(new Kerl());
            var key1          = signing.Key(Utils.Converter.ToTrits(seed), 0, 2);
            var address1again = Utils.IotaUtils.GenerateAddress(key1, false, CancellationToken.None);

            Assert.AreEqual(address1.Address, address1again);

            var trunk  = "GFZIP9ZXJIJLUBYGTY9LGEDXVBLRCBEOEWYGZKHDLCCGXOVFPZM9MLQRMATDIICUFZRNXDNOBQIBA9999";
            var branch = "NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999";

            var transfer = new TransferItem()
            {
                Address = address2.Address, Message = "TESTMESSAGE", Tag = "MINEIOTADOTCOM", Value = 1
            };

            // Act
            var trans = transfer.CreateTransactions(address1.Address, address1);

            // Assert Pass.
        }
Esempio n. 5
0
        /// <summary>
        /// Finds reminder and creates transaction items
        /// </summary>
        /// <param name="transferItem"></param>
        /// <param name="seed"></param>
        /// <param name="addressItems"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <TransactionItem[]> CreateTransactions(TransferItem transferItem, string seed, IEnumerable <AddressItem> addressItems, CancellationToken cancellationToken)
        {
            addressItems = addressItems.Where(b => b.Balance > 0).ToArray();
            var reminderAddressItem = await FindReminderAddress(seed, addressItems.Max(a => a.Index) + 1, cancellationToken);

            var transactionItems = transferItem.CreateTransactions(reminderAddressItem.Address, addressItems.ToArray());

            return(transactionItems);
        }
Esempio n. 6
0
        public async Task <string> ApproveTransaction(string transactionHash, ApproveTransactionType approveType)
        {
            var api = CreateIotaClient();
            //var address = await api.GetAddress(TestSeed2, 8);

            var emptyAddress = IotaUtils.GenerateRandomTrytes(81); // "".Pad(81);

            var transfer = new TransferItem()
            {
                Address = emptyAddress,
                Value   = 0,
                Message = "",
                Tag     = ""
            };

            while (true)
            {
                try
                {
                    CancellationTokenSource cts = new CancellationTokenSource();

                    var transactions    = transfer.CreateTransactions();
                    var trytesToPow     = transactions.GetTrytes().Single();
                    var toApproveResult = await api.IriApi.GetTransactionsToApprove(9);

                    var toApprove = toApproveResult.Result;

                    var diver = new PowDiver();
                    cts.CancelAfter(20000);
                    var trunk  = toApprove.TrunkTransaction;
                    var branch = toApprove.BranchTransaction;

                    if (approveType == ApproveTransactionType.Trunk)
                    {
                        trunk = transactionHash;
                    }
                    else
                    {
                        branch = transactionHash;
                    }

                    var trytesToSend = await diver.DoPow(trytesToPow.SetApproveTransactions(trunk, branch), 15, cts.Token);

                    await api.IriApi.BroadcastTransactions(trytesToSend);

                    await api.IriApi.StoreTransactions(trytesToSend);

                    var transaction = new TransactionItem(trytesToSend);

                    return(transaction.Hash);
                }
                catch (OperationCanceledException)
                {
                    continue;
                }
            }
        }
Esempio n. 7
0
        public async Task DoPowAndSendTransactionWithValueTest()
        {
            var api       = CreateIotaClient();
            var addresses = await api.GetAddresses(TestSeed, 104, 3, CancellationToken.None);

            var transfer = new TransferItem()
            {
                Address = addresses[1].Address,
                Value   = 10000000,
                Message = "MESSAGETESTVALUEPOW",
                Tag     = "TAGTESTVALUEPOW"
            };

            while (true)
            {
                try
                {
                    CancellationTokenSource cts = new CancellationTokenSource();

                    var transactionItems  = transfer.CreateTransactions(addresses[2].Address, addresses.First());
                    var transactionTrytes = transactionItems.GetTrytes();
                    var toApproveResult   = await api.IriApi.GetTransactionsToApprove(9);

                    var toApprove = toApproveResult.Result;

                    var trunk  = toApprove.TrunkTransaction;
                    var branch = toApprove.BranchTransaction;

                    var trytesToSend = await transactionTrytes.DoPow(trunk, branch, 15, cts.Token);

                    await api.IriApi.BroadcastTransactions(trytesToSend);

                    await api.IriApi.StoreTransactions(trytesToSend);

                    var firstTrytes = trytesToSend.Last();

                    var transactionItem            = new TransactionItem(firstTrytes);
                    var rebroadcastTransactionHash = await Rebroadcast(firstTrytes);

                    break;
                }
                catch (AggregateException)
                {
                    continue;
                }
            }
        }
Esempio n. 8
0
        public async Task SendVeryEmptyTransactionTest()
        {
            var api = CreateIotaClient();

            var emptyAddress = IotaUtils.GenerateRandomTrytes(81); // "".Pad(81);

            var transfer = new TransferItem()
            {
                Address = emptyAddress,
                Value   = 0,
                Message = null,
                Tag     = null
            };

            while (true)
            {
                try
                {
                    CancellationTokenSource cts = new CancellationTokenSource();

                    var transactions    = transfer.CreateTransactions();
                    var trytesToPow     = transactions.GetTrytes().Single();
                    var toApproveResult = await api.IriApi.GetTransactionsToApprove(9);

                    var toApprove = toApproveResult.Result;
                    var diver     = new PowDiver();
                    //cts.CancelAfter(15000);
                    var trunk  = toApprove.TrunkTransaction;
                    var branch = toApprove.BranchTransaction;


                    var trytesToSend = await diver.DoPow(trytesToPow.SetApproveTransactions(trunk, branch), 15, cts.Token);

                    await api.IriApi.BroadcastTransactions(trytesToSend);

                    await api.IriApi.StoreTransactions(trytesToSend);

                    var transaction = new TransactionItem(trytesToSend);
                }
                catch (OperationCanceledException)
                {
                    continue;
                }
            }
        }
Esempio n. 9
0
        public async Task SendEmptyTransferWithPowTest()
        {
            var api     = CreateIotaClient();
            var address = await api.GetAddress(TestSeed2, 20);

            var transfer = new TransferItem()
            {
                Address = address.Address,
                Value   = 0,
                Message = "THEMESSAGETEST",
                Tag     = "THETAGTEST"
            };

            while (true)
            {
                try
                {
                    Console.WriteLine("Do pow and send");
                    CancellationTokenSource cts = new CancellationTokenSource();

                    var transactions    = transfer.CreateTransactions();
                    var trytesToPow     = transactions.GetTrytes().Single();
                    var toApproveResult = await api.IriApi.GetTransactionsToApprove(9);

                    var toApprove = toApproveResult.Result;
                    var diver     = new PowDiver();
                    cts.CancelAfter(15000); //
                    var trytesToSend = await diver.DoPow(trytesToPow.SetApproveTransactions(toApprove.TrunkTransaction, toApprove.BranchTransaction), 15, cts.Token);

                    //Thread.Sleep(200000);
                    await api.IriApi.BroadcastTransactions(trytesToSend);

                    await api.IriApi.StoreTransactions(trytesToSend);

                    var transaction = new TransactionItem(trytesToSend);

                    break;
                }
                catch (OperationCanceledException)
                {
                    continue;
                }
            }
        }
        public async Task CreateTransaction_WothPOW_BundleHasCreatedCorrectly()
        {
            var nonceSeeker  = new LocalNonceSeeker(5);
            var transferItem = new TransferItem()
            {
                Address = "S9XDEUXLTPUKULJXMV9IUKBMLGRHLXPCIMWFE9UHIGQGJEZSJRPYFBDSNNSMDEHBSTUEGAGBX9QZNKDNY", Tag = "TEST"
            };
            var transactions = transferItem.CreateTransactions();

            transactions[0].SetTimeStamp(new DateTime(2018, 2, 5, 14, 28, 0));
            transactions[0].SetAttachmentTime(new DateTime(2018, 2, 5, 14, 28, 0));
            transactions.FinalizeAndNormalizeBundleHash(new Crypto.Kerl());

            var transactionTrytes = transactions.GetTrytes();

            var trunk  = "MEFHCNF9JEMCAHURCCO9BCGLNKVWJZIHQN9AZJPBHBEVVOZTWEPRLLUDVNWHHUGSHRPXZXUUVSHVA9999";
            var branch = "NYXCW9DAGWKXQXUL9OUIIJYJFDOBLEB9LGTNWMCNADXPJVGECZ9SKVRTOXSNNXRHPP9QMCXSWRLU99999";

            var trytesToSend = await nonceSeeker.SearchNonce(transactionTrytes, trunk, branch, CancellationToken.None);

            Assert.IsTrue(ValidBundle_SingleItem(trytesToSend[0]));
        }
Esempio n. 11
0
        /// <summary>
        /// Sends transfer without money
        /// </summary>
        /// <param name="api"></param>
        /// <param name="transferItem">Transfer item</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns></returns>
        public static Task <APIResult <TransactionItem[]> > AttachTransfer(this IotaApi api, TransferItem transferItem, CancellationToken cancellationToken)
        {
            var transactionItems = transferItem.CreateTransactions();

            return(api.AttachTransactions(transactionItems, cancellationToken));
        }
Esempio n. 12
0
        public async Task SendTransfer(NewSendModel sendModel, CancelSyncModel syncModel)
        {
            var addressModels = sendModel.Addresses.ToArray();

            if (addressModels == null || addressModels.Length == 0)
            {
                addressModels = addressesModel.GetAddressModels();
            }

            var addressItems = addressModels.Select(a => a.Tag).OfType <AddressItem>().ToArray();
            var api          = CreateIotaClient();

            long value = 0;

            if (sendModel.Value.HasValue)
            {
                value = (long)Convert.ChangeType(sendModel.Value.Value, typeof(long)); // long.Parse(sendModel.Value.ToString());
            }
            if (value < 0)
            {
                throw new Exception("Value cannot be less than zero");
            }

            var addressToSend = sendModel.Address;

            addressToSend = IotaExtensions.ValidateAddress(addressToSend);
            if (addressToSend.Length == 90)
            {
                addressToSend = Borlay.Iota.Library.Utils.Checksum.RemoveChecksum(addressToSend);
            }


            var transfer = new TransferItem()
            {
                Address = addressToSend,
                Value   = value,
                Tag     = sendModel.MessageTag,
                Message = sendModel.Message
            };

            if (value > 0)
            {
                syncModel.Text = "Renew the balances";
                await api.RenewAddresses(addressItems);

                var filteredAddressItems = addressItems.FilterBalance(value).ToArray();
                var filterReminder       = filteredAddressItems.Select(a => a.Address).ToList();
                filterReminder.Add(addressToSend);

                syncModel.Text = "Searching for the remainder";
                var remainderAddressItem = await GetRemainder(filterReminder.ToArray(), syncModel.Token);


                var transactions = transfer.CreateTransactions(remainderAddressItem.Address, filteredAddressItems).ToArray();
                await SendTransactions(transactions, syncModel, true);
            }
            else
            {
                var transactions = transfer.CreateTransactions().ToArray();
                await SendTransactions(transactions, syncModel, false);
            }
        }