Exemplo n.º 1
0
                static byte[] CreateSignatureRedeemScript(DevWalletAccount account)
                {
                    var key = account.GetKey();

                    if (key == null)
                    {
                        throw new Exception("DevWalletAccount missing key");
                    }

                    using var sb = new Neo.VM.ScriptBuilder();
                    sb.EmitPush(key.PublicKey.EncodePoint(true));
                    sb.Emit(Neo.VM.OpCode.CHECKSIG);
                    return(sb.ToArray());
                }
Exemplo n.º 2
0
 public static ScriptBuilder EmitPush(this ScriptBuilder sb, ISerializable data)
 {
     return(sb.EmitPush(data.ToArray()));
 }
Exemplo n.º 3
0
        public static ScriptBuilder EmitPush(this ScriptBuilder sb, object obj)
        {
            switch (obj)
            {
            case bool data:
                sb.EmitPush(data);
                break;

            case byte[] data:
                sb.EmitPush(data);
                break;

            case string data:
                sb.EmitPush(data);
                break;

            case BigInteger data:
                sb.EmitPush(data);
                break;

            case ISerializable data:
                sb.EmitPush(data);
                break;

            case sbyte data:
                sb.EmitPush(data);
                break;

            case byte data:
                sb.EmitPush(data);
                break;

            case short data:
                sb.EmitPush(data);
                break;

            case ushort data:
                sb.EmitPush(data);
                break;

            case int data:
                sb.EmitPush(data);
                break;

            case uint data:
                sb.EmitPush(data);
                break;

            case long data:
                sb.EmitPush(data);
                break;

            case ulong data:
                sb.EmitPush(data);
                break;

            case Enum data:
                sb.EmitPush(BigInteger.Parse(data.ToString("d")));
                break;

            case null:
                sb.Emit(OpCode.PUSHNULL);
                break;

            default:
                throw new ArgumentException();
            }
            return(sb);
        }
Exemplo n.º 4
0
Arquivo: Helper.cs Projeto: lcmfq/neo
        public static ScriptBuilder EmitPush(this ScriptBuilder sb, ContractParameter parameter)
        {
            if (parameter.Value is null)
            {
                sb.Emit(OpCode.PUSHNULL);
            }
            else
            {
                switch (parameter.Type)
                {
                case ContractParameterType.Signature:
                case ContractParameterType.ByteArray:
                    sb.EmitPush((byte[])parameter.Value);
                    break;

                case ContractParameterType.Boolean:
                    sb.EmitPush((bool)parameter.Value);
                    break;

                case ContractParameterType.Integer:
                    if (parameter.Value is BigInteger bi)
                    {
                        sb.EmitPush(bi);
                    }
                    else
                    {
                        sb.EmitPush((BigInteger)typeof(BigInteger).GetConstructor(new[] { parameter.Value.GetType() }).Invoke(new[] { parameter.Value }));
                    }
                    break;

                case ContractParameterType.Hash160:
                    sb.EmitPush((UInt160)parameter.Value);
                    break;

                case ContractParameterType.Hash256:
                    sb.EmitPush((UInt256)parameter.Value);
                    break;

                case ContractParameterType.PublicKey:
                    sb.EmitPush((ECPoint)parameter.Value);
                    break;

                case ContractParameterType.String:
                    sb.EmitPush((string)parameter.Value);
                    break;

                case ContractParameterType.Array:
                {
                    IList <ContractParameter> parameters = (IList <ContractParameter>)parameter.Value;
                    for (int i = parameters.Count - 1; i >= 0; i--)
                    {
                        sb.EmitPush(parameters[i]);
                    }
                    sb.EmitPush(parameters.Count);
                    sb.Emit(OpCode.PACK);
                }
                break;

                default:
                    throw new ArgumentException();
                }
            }
            return(sb);
        }
Exemplo n.º 5
0
 public static ScriptBuilder EmitAppCall(this ScriptBuilder sb, UInt160 scriptHash, bool useTailCall = false)
 {
     return(sb.EmitAppCall(scriptHash.ToArray(), useTailCall));
 }
Exemplo n.º 6
0
 public static ScriptBuilder EmitSysCall(this ScriptBuilder sb, uint method, params object[] args)
 {
     for (int i = args.Length - 1; i >= 0; i--)
         EmitPush(sb, args[i]);
     return sb.EmitSysCall(method);
 }
Exemplo n.º 7
0
 public static ScriptBuilder Emit(this ScriptBuilder sb, params OpCode[] ops)
 {
     foreach (OpCode op in ops)
         sb.Emit(op);
     return sb;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Emits the opcodes for calling a contract dynamically.
 /// </summary>
 /// <param name="builder">The <see cref="ScriptBuilder"/> to be used.</param>
 /// <param name="scriptHash">The hash of the contract to be called.</param>
 /// <param name="method">The method to be called in the contract.</param>
 /// <param name="args">The arguments for calling the contract.</param>
 /// <returns>The same instance as <paramref name="builder"/>.</returns>
 public static ScriptBuilder EmitDynamicCall(this ScriptBuilder builder, UInt160 scriptHash, string method, params object[] args)
 {
     return(EmitDynamicCall(builder, scriptHash, method, CallFlags.All, args));
 }
Exemplo n.º 9
0
 public static ScriptBuilder EmitDynamicCall(this ScriptBuilder sb, UInt160 scriptHash, string operation, params object[] args)
 {
     return(EmitDynamicCall(sb, scriptHash, operation, CallFlags.All, args));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Generate scripts to call a specific method from a specific contract.
 /// </summary>
 /// <param name="scriptHash">contract script hash</param>
 /// <param name="operation">contract operation</param>
 /// <param name="args">operation arguments</param>
 /// <returns></returns>
 public static byte[] MakeScript(this UInt160 scriptHash, string operation, params object[] args)
 {
     using ScriptBuilder sb = new ScriptBuilder();
     sb.EmitDynamicCall(scriptHash, operation, args);
     return(sb.ToArray());
 }