private Bundle TraverseBundle(string trunkTx, string bundleHash, Bundle bundle) { var gtr = IotaClient.GetTrytes(trunkTx); if (gtr != null) { if (gtr.Trytes.Count == 0) { throw new ArgumentException(Constants.INVALID_BUNDLE_ERROR); } Transaction trx = new Transaction(gtr.Trytes[0]); if (trx.Bundle == null) { throw new ArgumentException(Constants.INVALID_TRYTES_INPUT_ERROR); } // If first transaction to search is not a tail, return error if (bundleHash == null && trx.CurrentIndex != 0) { throw new ArgumentException(Constants.INVALID_TAIL_HASH_INPUT_ERROR); } // If no bundle hash, define it if (bundleHash == null) { bundleHash = trx.Bundle; } // If different bundle hash, return with bundle if (!bundleHash.Equals(trx.Bundle, StringComparison.Ordinal)) { bundle.Length = bundle.Transactions.Count; return(bundle); } // If only one bundle element, return if (trx.LastIndex == 0 && trx.CurrentIndex == 0) { return(new Bundle(new List <Transaction> { trx }, 1)); } // Define new trunkTransaction for search trunkTx = trx.TrunkTransaction; // Add transaction object to bundle bundle.Transactions.Add(trx); // Continue traversing with new trunkTx return(TraverseBundle(trunkTx, bundleHash, bundle)); } throw new ArgumentException(Constants.GET_TRYTES_RESPONSE_ERROR); }
/// <summary> /// /// </summary> /// <param name="hashes"></param> /// <returns></returns> public List <Transaction> FindTransactionObjectsByHashes(string[] hashes) { if (!InputValidator.IsArrayOfHashes(hashes)) { throw new IllegalStateException("Not an Array of Hashes: " + hashes); } var trytesResponse = IotaClient.GetTrytes(hashes); var trxs = new List <Transaction>(); foreach (var tryte in trytesResponse.Trytes) { trxs.Add(new Transaction(tryte)); } return(trxs); }