/// <summary> /// Estimates the signed serialize size of an unsigned transaction, assuming all /// inputs spend P2PKH outputs. The estimate is a worst case, so the actual /// serialize size after signing should always be less than or equal to this value. /// </summary> /// <param name="inputCount">Number of P2PKH outputs the transaction will redeem</param> /// <param name="outputs">Transaction output array</param> /// <param name="addChangeOutput">Add the serialize size for an additional P2PKH change output</param> /// <returns>Estimated signed serialize size of the transaction</returns> public static int EstimateSerializeSize(int inputCount, Output[] outputs, bool addChangeOutput) { if (outputs == null) throw new ArgumentNullException(nameof(outputs)); var changeSize = 0; var outputCount = outputs.Length; if (addChangeOutput) { changeSize = PayToPubKeyHashOutputSize; outputCount++; } return 12 + (2 * CompactInt.SerializeSize((ulong)inputCount)) + CompactInt.SerializeSize((ulong)outputCount) + inputCount * RedeemPayToPubKeyHashInputSize + outputs.Sum(o => o.SerializeSize) + changeSize; }