private bool ReadScript(Script script) { var bytes = script.ToBytes(true); if(bytes.Length == 0 || bytes[0] != (byte)OpcodeType.OP_RETURN) return false; foreach(var op in script.ToOps()) { if(op.PushData != null && !op.IsInvalid) { if(ReadData(op.PushData)) return true; } } return false; }
private Script AssertCompressed(Script script, int expectedSize) { var compressor = new ScriptCompressor(script); var compressed = compressor.ToBytes(); Assert.Equal(expectedSize, compressed.Length); compressor = new ScriptCompressor(); compressor.ReadWrite(compressed); AssertEx.CollectionEquals(compressor.GetScript().ToBytes(), script.ToBytes()); var compressed2 = compressor.ToBytes(); AssertEx.CollectionEquals(compressed, compressed2); return compressor.GetScript(); }
void ReplaceRedeemScript(TxIn input, Script redeemScript) { ScriptEvaluationContext ctx = new ScriptEvaluationContext(); ctx.ScriptVerify = ScriptVerify.StrictEnc; ctx.EvalScript(input.ScriptSig, new Transaction(), 0); var stack = ctx.Stack; Assert.True(stack.Count > 0); stack.Pop(); stack.Push(redeemScript.ToBytes()); input.ScriptSig = PushAll(stack); }
public override bool CanGenerateScriptSig(Script scriptPubKey) { return scriptPubKey.Length == 1 && scriptPubKey.ToBytes(true)[0] == (byte)OpcodeType.OP_TRUE; }