/// <summary> /// Take the incoming tx and split it into a list of paged partial tx. /// Inbound tx is in API tx format. Outbound list is also in API tx format, with header info /// repeated on every entry. Note in pages form, it is possible for a tx entry to have only inputs /// or only outputs, with the remainder appearing in later pages. /// </summary> /// <param name="tx">Inbound tx is in API tx format</param> /// <param name="pageSize">number of tx in a page</param> /// <returns>List of paged tx also in API tx format</returns> public static List <JSONNode> ConvertTxToPagedTx(JSONNode tx, int pageSize) { bool deepLogging = false; if (deepLogging) { Msg.Log("ConvertTxToPagedTx: Node In: " + tx.ToString()); } List <JSONNode> txPages = new List <JSONNode>(); // Make a master copy (convert tx to string) string masterStr = tx.ToString(); int masterInputCount = tx["inputs"].Count; int masterOutputCount = tx["out"].Count; int masterTxCount = masterInputCount + masterOutputCount; // How many loops/pages? int loops = masterTxCount / pageSize; int remainder = masterTxCount % pageSize; if (remainder > 0) { loops++; } if (deepLogging) { Msg.Log("ConvertTxToPagedTx: Inputs: " + masterInputCount + " Outputs: " + masterOutputCount + " PageSize: " + pageSize + " Pages: " + loops); } // pi is short for pageIndex (index with page granularity) for (int pi = 0; pi < loops; pi++) { // Make our copy of the master var N = JSON.Parse(masterStr); // Now N is a copy of tx //------------------------------------------------------------ // Removal logic // Page | Removal index // 0 | 0-19 // 1 | 20-39 <<<[eg for page 1 keep only these indices] // 2 | 40-59 // 3 | 60-79 // remove where index < pi * pageSize // or where index > (pi + 1) * pageSize // The removal index works through inputs and outputs //------------------------------------------------------------ var inputs = N["inputs"]; var outputs = N["out"]; // ri is removal index (index with lowest level granularity, ie a single list entry in input or output) for (int ri = 0; ri < masterTxCount; ri++) { if (ri < masterInputCount) { // Input removal - are we eligible for removal? if (ri < (pi * pageSize) || (ri >= (pi + 1) * pageSize)) { inputs[ri]["script"].Value = "DELETEME"; } } else if (ri < (masterInputCount + masterOutputCount)) { // Output removal - eligible for removal? same logic as above if (ri < (pi * pageSize) || (ri >= (pi + 1) * pageSize)) { int localRi = ri - masterInputCount; outputs[localRi]["script"].Value = "DELETEME"; } } else { Debug.LogWarning("SimpleJSONBitStream: removal index higher than expected!"); } } // Ditch the DELETEME nodes in inputs or outputs RemoveTheDeleteMeNodes(N); // Add it to the list txPages.Add(N); } if (deepLogging) { Debug.Log("ConvertTxToPagedTx: Node List Out: Count: " + txPages.Count); foreach (JSONNode j in txPages) { Debug.Log("ConvertTxToPagedTx: Node List Item: " + j.ToString()); } } return(txPages); }
public static string FormatEdgeIdFriendly(JSONNode itemOne, JSONNode itemTwo) { return(itemOne.ToString().Substring(1, 5) + "--" + itemTwo.ToString().Substring(1, 5)); }