public void shouldNotGetInclusionStates() { GetInclusionStatesResponse res = iotaApi.GetInclusionStates(new[] { TEST_ADDRESS_WITH_CHECKSUM }, new[] { "DNSBRJWNOVUCQPILOQIFDKBFJMVOTGHLIMLLRXOHFTJZGRHJUEDAOWXQRYGDI9KHYFGYDWQJZKX999999" }); Assert.IsNotNull(res.States); }
public void shouldGetInclusionStates() { GetInclusionStatesResponse res = iotaApi.GetInclusionStates( new[] { "DBPECSH9YLSSTQDGERUHJBBJTKVUDBMTJLG9WPHBINGHIFOSJMDJLARTVOXXWEFQJLLBINOHCZGYFSMUEXWPPMTOFW" }, new[] { iotaApi.GetNodeInfo().LatestSolidSubtangleMilestone }); Assert.IsNotNull(res.States); }
public void shouldGetLastInclusionState() { GetInclusionStatesResponse res = iotaClient.GetLatestInclusion(new string[] { TEST_HASH }); Assert.IsNotNull(res.States); }
public void ShouldGetLastInclusionState() { var iotaApi = new IotaAPI { IotaClient = new IotaClient(Provider) }; GetInclusionStatesResponse res = iotaApi.GetLatestInclusion(new[] { TEST_HASH }); Assert.IsNotNull(res.States, "States should be an array of booleans"); Assert.IsTrue(res.States[0], "Hash should have been seen as confirmed"); }
private Bundle[] BundlesFromAddresses(string[] addresses, bool inclusionStates) { var trxs = FindTransactionObjects(addresses); // set of tail transactions var tailTransactions = new List <string>(); var nonTailBundleHashes = new List <string>(); foreach (var trx in trxs) { // Sort tail and nonTails if (trx.CurrentIndex == 0) { tailTransactions.Add(trx.Hash); } else { if (nonTailBundleHashes.IndexOf(trx.Bundle) == -1) { nonTailBundleHashes.Add(trx.Bundle); } } } var bundleObjects = FindTransactionObjectsByBundle(nonTailBundleHashes.ToArray()); foreach (var trx in bundleObjects) { // Sort tail and nonTails if (trx.CurrentIndex == 0) { if (tailTransactions.IndexOf(trx.Hash) == -1) { tailTransactions.Add(trx.Hash); } } } var 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 (inclusionStates) { try { gisr = GetLatestInclusion(tailTxArray); } catch (IllegalAccessError) { // suppress exception (the check is done below) } if (gisr == null || gisr.States == null || gisr.States.Count == 0) { throw new ArgumentException("Inclusion states not found"); } } var finalInclusionStates = gisr; Parallel.ForEach(tailTransactions, param => { try { var b = GetBundle(param); if (inclusionStates) { var thisInclusion = finalInclusionStates != null && finalInclusionStates.States[tailTxArray.ToList().IndexOf(param)]; foreach (var t in b.Transactions) { t.Persistance = thisInclusion; } } finalBundles.Add(b); } catch (System.Exception ex) { Console.WriteLine("Bundle error: " + ex.Message); } }); finalBundles.Sort(); var returnValue = new Bundle[finalBundles.Count]; for (var i = 0; i < finalBundles.Count; i++) { returnValue[i] = new Bundle(finalBundles[i].Transactions, finalBundles[i].Transactions.Count); } return(returnValue); }
/// <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); }