本文整理汇总了C#中NBitcoin.Op类的典型用法代码示例。如果您正苦于以下问题:C# Op类的具体用法?C# Op怎么用?C# Op使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Op类属于NBitcoin命名空间,在下文中一共展示了Op类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckScriptPubKeyCore
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptPubKeyOps;
if(ops.Length < 1)
return false;
if(ops[0].Code != OpcodeType.OP_RETURN)
return false;
if(scriptPubKey.ToBytes(true).Length > MaxScriptSizeLimit)
return false;
return scriptPubKeyOps.Skip(1).All(o => o.PushData != null && !o.IsInvalid);
}
示例2: CheckScriptPubKeyCore
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptPubKeyOps;
if(ops.Length < 1)
return false;
if(ops[0].Code != OpcodeType.OP_RETURN)
return false;
if(ops.Length == 2)
{
return ops[1].PushData != null && ops[1].PushData.Length <= MAX_OPRETURN_SIZE;
}
return true;
}
示例3: bytes
public const int MAX_OP_RETURN_RELAY = 83; //! bytes (+1 for OP_RETURN, +2 for the pushdata opcodes)
public Script GenerateScriptPubKey(params byte[][] data)
{
if(data == null)
throw new ArgumentNullException("data");
Op[] ops = new Op[data.Length + 1];
ops[0] = OpcodeType.OP_RETURN;
for(int i = 0; i < data.Length; i++)
{
ops[1 + i] = Op.GetPushOp(data[i]);
}
var script = new Script(ops);
if(script.ToBytes(true).Length > MaxScriptSizeLimit)
throw new ArgumentOutOfRangeException("data", "Data in OP_RETURN should have a maximum size of " + MaxScriptSizeLimit + " bytes");
return script;
}
示例4: CheckScriptSigCore
protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
if(!scriptSig.IsPushOnly)
return false;
if(scriptSigOps[0].Code != OpcodeType.OP_0)
return false;
if(scriptSigOps.Length == 1)
return false;
if(!scriptSigOps.Skip(1).All(s => TransactionSignature.ValidLength(s.PushData.Length) || s.Code == OpcodeType.OP_0))
return false;
if(scriptPubKeyOps != null)
{
if(!CheckScriptPubKeyCore(scriptPubKey, scriptPubKeyOps))
return false;
var sigCountExpected = scriptPubKeyOps[0].GetValue();
return sigCountExpected == scriptSigOps.Length + 1;
}
return true;
}
示例5: GenerateWitScript
public WitScript GenerateWitScript(Op[] scriptSig, Script redeemScript)
{
if(redeemScript == null)
throw new ArgumentNullException("redeemScript");
if(scriptSig == null)
throw new ArgumentNullException("scriptSig");
var ops = scriptSig.Concat(new[] { Op.GetPushOp(redeemScript.ToBytes(true)) }).ToArray();
return new WitScript(ops);
}
示例6: GetPushOp
public static Op GetPushOp(byte[] data)
{
Op op = new Op();
op.PushData = data;
if(data.Length == 0)
op.Code = OpcodeType.OP_0;
else if(data.Length == 1 && (byte)1 <= data[0] && data[0] <= (byte)16)
op.Code = (OpcodeType)(data[0] + (byte)OpcodeType.OP_1 - 1);
else if(data.Length == 1 && (byte)0x81 == data[0])
op.Code = OpcodeType.OP_1NEGATE;
else if(0x01 <= data.Length && data.Length <= 0x4b)
op.Code = (OpcodeType)(byte)data.Length;
else if(data.Length <= 0xFF)
op.Code = OpcodeType.OP_PUSHDATA1;
#if !PORTABLE
else if(data.LongLength <= 0xFFFF)
op.Code = OpcodeType.OP_PUSHDATA2;
else if(data.LongLength <= 0xFFFFFFFF)
op.Code = OpcodeType.OP_PUSHDATA4;
#else
else if(data.Length <= 0xFFFF)
op.Code = OpcodeType.OP_PUSHDATA2;
#endif
else
throw new NotSupportedException("Data length should not be bigger than 0xFFFFFFFF");
return op;
}
示例7: CheckScriptPubKeyCore
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
{
return true;
}
示例8: CheckScriptSigCore
protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
return scriptSig.Length == 0;
}
示例9: GenerateScriptSig
public Script GenerateScriptSig(Op[] ops, Script redeemScript)
{
var pushScript = Op.GetPushOp(redeemScript._Script);
return new Script(ops.Concat(new[] { pushScript }));
}
示例10: CheckScriptSigCore
protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
{
var ops = scriptSigOps;
if(ops.Length != 2)
return false;
return ops[0].PushData != null &&
ops[1].PushData != null && PubKey.Check(ops[1].PushData, false);
}
示例11: GenerateScriptSig
public Script GenerateScriptSig(Op[] ops, Script script)
{
var pushScript = Op.GetPushOp(script._Script);
return new Script(ops.Concat(new[] { pushScript }).ToArray());
}
示例12: ReadData
internal static byte[] ReadData(Op op, Stream stream, bool ignoreWrongPush = false)
{
var opcode = op.Code;
uint len = 0;
BitcoinStream bitStream = new BitcoinStream(stream, false);
if(opcode == 0)
return new byte[0];
if((byte)OpcodeType.OP_1 <= (byte)opcode && (byte)opcode <= (byte)OpcodeType.OP_16)
{
return new byte[] { (byte)(opcode - OpcodeType.OP_1 + 1) };
}
if(opcode == OpcodeType.OP_1NEGATE)
{
return new byte[] { 0x81 };
}
if(0x01 <= (byte)opcode && (byte)opcode <= 0x4b)
len = (uint)opcode;
else if(opcode == OpcodeType.OP_PUSHDATA1)
len = bitStream.ReadWrite((byte)0);
else if(opcode == OpcodeType.OP_PUSHDATA2)
len = bitStream.ReadWrite((ushort)0);
else if(opcode == OpcodeType.OP_PUSHDATA4)
len = bitStream.ReadWrite((uint)0);
else
throw new FormatException("Invalid opcode for pushing data : " + opcode);
byte[] data = new byte[len];
var readen = stream.Read(data, 0, data.Length);
if(readen != data.Length && !ignoreWrongPush)
throw new FormatException("Not enough bytes pushed with " + opcode.ToString() + " expected " + len + " but got " + readen);
else if(readen != data.Length)
{
op.IncompleteData = true;
Array.Resize(ref data, readen);
}
return data;
}
示例13: FindAndDelete
internal int FindAndDelete(Op op)
{
return op == null ? 0 : FindAndDelete(o => o.Code == op.Code && Utils.ArrayEqual(o.PushData, op.PushData));
}
示例14: GenerateWitScript
public WitScript GenerateWitScript(Op[] scriptSig, Script redeemScript)
{
if(redeemScript == null)
throw new ArgumentNullException("redeemScript");
if(scriptSig == null)
throw new ArgumentNullException("scriptSig");
return GenerateWitScript(new Script(scriptSig), redeemScript);
}
示例15: Read
public Op Read()
{
var b = Inner.ReadByte();
if(b == -1)
return null;
var opcode = (OpcodeType)b;
if(Op.IsPushCode(opcode))
{
Op op = new Op();
op.Code = opcode;
op.PushData = op.ReadData(Inner);
return op;
}
return new Op()
{
Code = opcode
};
}