Example #1
0
 public static AddressItem[] GetAddressItems(this ContentCollectionModel <AddressItemModel> content)
 {
     return(content.GetAddressModels().GetAddressItems());
 }
Example #2
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);
            }
        }