public void ShouldGetBundle() { var iotaApi = new IotaAPI { IotaClient = new IotaClient(Provider) }; GetBundleResponse gbr = iotaApi.GetBundle(TEST_HASH); Assert.IsNotNull(gbr, "GetBundleResponse should not return null on failure"); }
/// <summary> /// /// </summary> /// <param name="tailTransactionHash"></param> /// <param name="depth"></param> /// <param name="minWeightMagnitude"></param> /// <param name="reference"></param> /// <returns></returns> public ReplayBundleResponse ReplayBundle(string tailTransactionHash, int depth, int minWeightMagnitude, string reference) { if (!InputValidator.IsHash(tailTransactionHash)) { throw new ArgumentException(Constants.INVALID_TAIL_HASH_INPUT_ERROR); } var stopWatch = Stopwatch.StartNew(); GetBundleResponse bundleResponse = GetBundle(tailTransactionHash); Bundle bundle = new Bundle(bundleResponse.Transactions, bundleResponse.Transactions.Count); return(ReplayBundle(bundle, depth, minWeightMagnitude, reference, stopWatch)); }
/// <summary> /// /// </summary> /// <param name="inclusionStates"></param> /// <param name="addresses"></param> /// <returns></returns> public Bundle[] BundlesFromAddresses(bool inclusionStates, params string[] addresses) { List <Transaction> trxs = FindTransactionObjectsByAddresses(addresses); // set of tail transactions List <string> tailTransactions = new List <string>(); List <string> nonTailBundleHashes = new List <string>(); foreach (var trx in trxs) { // Sort tail and nonTails if (trx.CurrentIndex == 0) { tailTransactions.Add(trx.CurlHash()); } else { if (nonTailBundleHashes.IndexOf(trx.Bundle) == -1) { nonTailBundleHashes.Add(trx.Bundle); } } } List <Transaction> bundleObjects = FindTransactionObjectsByBundle(nonTailBundleHashes.ToArray()); foreach (var trx in bundleObjects) { // Sort tail and nonTails if (trx.CurrentIndex == 0) { var hash = trx.CurlHash(); if (tailTransactions.IndexOf(hash) == -1) { tailTransactions.Add(hash); } } } List <Bundle> finalBundles = new List <Bundle>(); var tailTxArray = tailTransactions.ToArray(); // If inclusionStates, get the confirmation status // of the tail transactions, and thus the bundles GetInclusionStatesResponse gisr = null; if (tailTxArray.Length != 0 && inclusionStates) { gisr = GetLatestInclusion(tailTxArray); if (gisr?.States == null || gisr.States.Count == 0) { throw new IllegalStateException(Constants.GET_INCLUSION_STATE_RESPONSE_ERROR); } } GetInclusionStatesResponse finalInclusionStates = gisr; try { Parallel.ForEach(tailTxArray, tailTx => { try { GetBundleResponse bundleResponse = GetBundle(tailTx); Bundle gbr = new Bundle(bundleResponse.Transactions, bundleResponse.Transactions.Count); if (gbr.Transactions != null) { if (inclusionStates) { bool thisInclusion = false; if (finalInclusionStates != null) { thisInclusion = finalInclusionStates.States[tailTxArray.ToList().IndexOf(tailTx)]; } foreach (var t in gbr.Transactions) { t.Persistence = thisInclusion; } } finalBundles.Add(gbr); } // If error returned from getBundle, simply ignore it because the bundle was most likely incorrect } catch (ArgumentException) { Log.Warn(Constants.GET_BUNDLE_RESPONSE_ERROR); } }); } catch (AggregateException) { return(null); } finalBundles.Sort(); Bundle[] returnValue = new Bundle[finalBundles.Count]; for (int i = 0; i < finalBundles.Count; i++) { returnValue[i] = new Bundle(finalBundles[i].Transactions, finalBundles[i].Transactions.Count); } return(returnValue); }