/// <summary> /// Generates an addresses and gets transactions and balances /// </summary> /// <param name="seed">Seed</param> /// <param name="index">Address index to start</param> /// <param name="count">Address count to generate</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns></returns> public async Task <AddressItem[]> GetAddresses(string seed, int index, int count, CancellationToken cancellationToken) { InputValidator.CheckIfValidSeed(seed); seed = InputValidator.PadSeedIfNecessary(seed); var tasks = new List <Task <AddressItem> >(); for (var i = index; i < count + index; i++) { var task = GenerateAddressAsync(seed, i, cancellationToken); tasks.Add(task); } var addressItems = await Task.WhenAll(tasks); cancellationToken.ThrowIfCancellationRequested(); var renewBalances = addressItems.Where(a => a.TransactionCount > 0).ToArray(); if (renewBalances.Length > 0) { await RenewBalances(renewBalances); } return(addressItems.ToArray()); }
/// <summary> /// Gets the transfers which are associated with a seed. /// The transfers are determined by either calculating deterministically which addresses were already used, /// or by providing a list of indexes to get the transfers from. /// </summary> /// <param name="seed">tryte-encoded seed. It should be noted that this seed is not transferred</param> /// <param name="inclusionStates">If True, it gets the inclusion states of the transfers.</param> /// <param name="security"></param> /// <param name="start">the address start index</param> /// <param name="end">the address end index</param> /// <returns>An Array of Bundle object that represent the transfers</returns> public Bundle[] GetTransfers(string seed, int security, int?start, int?end, bool inclusionStates = false) { InputValidator.CheckIfValidSeed(seed); seed = InputValidator.PadSeedIfNecessary(seed); if (!start.HasValue) { start = 0; } if (!end.HasValue) { end = 0; } // If start value bigger than end, return error // or if difference between end and start is bigger than 500 keys if (start.Value > end.Value || end.Value > start + 500) { throw new System.Exception("Invalid inputs provided: start, end"); } // first call findTransactions // If a transaction is non tail, get the tail transactions associated with it // add it to the list of tail transactions var addresses = GetNewAddress(seed, security, start.Value, false, end.Value, true); var bundles = BundlesFromAddresses(addresses, inclusionStates); return(bundles); }
/// <summary> /// Generates and address and gets transactions and balance /// </summary> /// <param name="seed">Seed</param> /// <param name="index">Address index</param> /// <returns></returns> public async Task <AddressItem> GetAddress(string seed, int index) { InputValidator.CheckIfValidSeed(seed); seed = InputValidator.PadSeedIfNecessary(seed); var addressItem = await GenerateAddressAsync(seed, index, CancellationToken.None); await iriApi.RenewBalances(addressItem); return(addressItem); }
/// <summary> /// Gets all possible inputs of a seed and returns them with the total balance. /// This is either done deterministically (by genearating all addresses until findTransactions is empty and doing /// getBalances), /// or by providing a key range to use for searching through. /// </summary> /// <param name="seed">Tryte-encoded seed. It should be noted that this seed is not transferred</param> /// <param name="security">The Security level of private key / seed.</param> /// <param name="start">Starting key index</param> /// <param name="end">Ending key index</param> /// <param name="threshold">The minimum threshold of accumulated balances from the inputs that is required</param> /// <returns>The inputs (see <see cref="Input" />) </returns> public Inputs GetInputs(string seed, int security, int start, int end, long threshold) { InputValidator.CheckIfValidSeed(seed); seed = InputValidator.PadSeedIfNecessary(seed); if (security < 1) { throw new ArgumentException("invalid security level provided"); } // If start value bigger than end, return error if (start > end) { throw new ArgumentException("start must be smaller than end", nameof(start)); } // or if difference between end and start is bigger than 500 keys if (end - start > 500) { throw new ArgumentException("total number of keys exceeded 500"); } // Case 1: start and end // // If start and end is defined by the user, simply iterate through the keys // and call getBalances if (end != 0) { var allAddresses = new string[end - start]; for (var i = start; i < end; i++) { var address = IotaApiUtils.NewAddress(seed, security, i, false, _curl); allAddresses[i] = address; } return(GetBalanceAndFormat(allAddresses, threshold, start, security)); } // Case 2: iterate till threshold || end // // Either start from index: 0 or start (if defined) until threshold is reached. // Calls getNewAddress and deterministically generates and returns all addresses // We then do getBalance, format the output and return it var addresses = GetNewAddress(seed, security, start, false, 0, true); return(GetBalanceAndFormat(addresses, threshold, start, security)); }