public static Types.Script ParseAddress(string address, string prefix) { (string hrp, int[] data) = ConvertAddress.Decode(address); if (hrp != prefix) { throw new Exception($"Invalid prefix! Expected: {prefix}, actual: {hrp}"); } if (data[0] == 1) { if (data.Length < 2) { throw new Exception("Invalid payload length!"); } string codeHash; string hashType; if (data[1] == SecpShortId) { codeHash = SecpCodeHash; hashType = SecpHashType; } else if (data[1] == MultisigShortId) { codeHash = MultisigCodeHash; hashType = MultisigHashType; } else { throw new Exception("Short address format error!"); } return(new Types.Script() { CodeHash = codeHash, HashType = hashType, Args = IntsToHex(data.Skip(2).ToArray()) }); } else if (data[0] == 2 || data[0] == 4) { if (data.Length < 33) { throw new Exception("Invalid payload length!"); } return(new Types.Script() { CodeHash = IntsToHex(data.Skip(1).Take(32).ToArray()), HashType = data[0] == 2 ? "data" : "type", Args = IntsToHex(data.Skip(33).ToArray()) }); } throw new Exception($"Invalid payload format type: {data[0]}"); }