public static Script GenerateScriptSig(OffchainScriptParams scriptParams) { List <Op> ops = new List <Op>(); ops.AddRange(scriptParams.Pushes.Select(Op.GetPushOp)); ops.Add(scriptParams.IsMultisig ? OpcodeType.OP_1 : OpcodeType.OP_0); ops.Add(Op.GetPushOp(scriptParams.RedeemScript)); return(new Script(ops)); }
public static OffchainScriptParams ExtractScriptSigParameters(Script script) { var ops = script.ToOps().ToArray(); var scriptParams = new OffchainScriptParams(); scriptParams.IsMultisig = ops.Length == 5 && ops[3].Code == OpcodeType.OP_1; var signCnt = scriptParams.IsMultisig ? 3 : 1; scriptParams.Pushes = ops.Take(signCnt).Select(o => o.PushData).ToArray(); scriptParams.RedeemScript = ops[ops.Length - 1].PushData; return(scriptParams); }