private static bool TryParseOD(string str, Network network, out string?whyFailure, out OutputDescriptor?result, bool requireCheckSum = false, ISigningRepository?repo = null) { if (network is null) { throw new ArgumentNullException(nameof(network)); } if (str == null) { throw new ArgumentNullException(nameof(str)); } str = str.Replace(" ", ""); result = null; whyFailure = null; var checkSplit = str.Split('#'); if (checkSplit.Length > 2) { whyFailure = "Multiple '#'s Symbols"; return(false); } if (checkSplit.Length == 1 && requireCheckSum) { whyFailure = "Missing checksum"; return(false); } if (checkSplit.Length == 2) { str = checkSplit[0]; if (checkSplit[1].Length != 8) { whyFailure = "Invalid length of Checksum"; return(false); } var realCheckSum = OutputDescriptor.GetCheckSum(str); if (realCheckSum != checkSplit[1]) { whyFailure = $"CheckSum mismatch. Expected: {checkSplit[1]}; Actual: {realCheckSum}"; return(false); } } var res = POutputDescriptor(repo, network).TryParse(str, network); if (!res.IsSuccess) { whyFailure = res.Description; return(false); } result = res.Value; if (result is OutputDescriptor.Multi multi && multi.PkProviders.Count > 3) { whyFailure = "You can not have more than 3 pubkeys in top level multisig."; return(false); } return(true); }
internal WSH(OutputDescriptor inner, Network network) : base(network) { if (inner == null) { throw new ArgumentNullException(nameof(inner)); } if (inner.IsTopLevelOnly() || inner is WSH) { throw new ArgumentException($"{inner} can not be inner element for WSH"); } Inner = inner; }
internal static P PMulti(ISigningRepository?repo, bool onlyCompressed, uint?maxN = null) => from name in Parse.String("sortedmulti").XOr(Parse.String("multi")).Text() let isSorted = name.StartsWith("sorted") from _l in Parse.Char('(') from m in Parse.Digit.XMany().Text().Then(d => Parse.TryConvert(d.Trim(), UInt32.Parse)) where m != 0 from _c in Parse.Char(',') from pkProviders in PPubKeyProvider(repo, onlyCompressed).DelimitedBy(Parse.Char(',')) where m <= pkProviders.Count() from _r in Parse.Char(')') where !maxN.HasValue || pkProviders.Count() <= maxN select OutputDescriptor.NewMulti(m, pkProviders, isSorted);
internal static P PRaw(ISigningRepository?repo) { var PScript = ( from _n in Parse.String("raw") from inner in SurroundedByBrackets from sc in Parse.TryConvert(inner, str => Script.FromHex(str)) select sc ).InjectRepository(repo); return(PScript.Select(s => OutputDescriptor.NewRaw(s))); }
internal SH(OutputDescriptor inner) { if (inner == null) { throw new ArgumentNullException(nameof(inner)); } if (inner.IsTopLevelOnly()) { throw new ArgumentException($"{inner} can not be inner element for SH"); } Inner = inner; }
internal static P PAddr(Network n) => from _n in Parse.String("addr") from inner in SurroundedByBrackets from addr in PTryConvertAddr(inner, n) select OutputDescriptor.NewAddr(addr, n);