コード例 #1
0
 void dapp_EmitParam(ThinNeo.ScriptBuilder sb, MyJson.IJsonNode param)
 {
     if (param is MyJson.JsonNode_ValueNumber)//bool 或小整数
     {
         sb.EmitParamJson(param);
     }
     else if (param is MyJson.JsonNode_Array)
     {
         var list = param.AsList();
         for (var i = list.Count - 1; i >= 0; i--)
         {
             dapp_EmitParam(sb, list[i]);
         }
         sb.EmitPushNumber(param.AsList().Count);
         sb.Emit(ThinNeo.VM.OpCode.PACK);
     }
     else if (param is MyJson.JsonNode_ValueString)//复杂格式
     {
         var str   = param.AsString();
         var bytes = dapp_getCallParam(str);
         sb.EmitPushBytes(bytes);
     }
     else
     {
         throw new Exception("should not pass a {}");
     }
 }
コード例 #2
0
            public static ResultItem FromJson(string type, MyJson.IJsonNode value)
            {
                ResultItem item = new ResultItem();

                if (type == "Array")
                {
                    item.subItem = new ResultItem[value.AsList().Count];
                    for (var i = 0; i < item.subItem.Length; i++)
                    {
                        var subjson = value.AsList()[i].AsDict();
                        var subtype = subjson["type"].AsString();
                        item.subItem[i] = FromJson(subtype, subjson["value"]);
                    }
                }
                else if (type == "ByteArray")
                {
                    item.data = ThinNeo.Helper.HexString2Bytes(value.AsString());
                }
                else if (type == "Integer")
                {
                    item.data = System.Numerics.BigInteger.Parse(value.AsString()).ToByteArray();
                }
                else if (type == "Boolean")
                {
                    if (value.AsBool())
                    {
                        item.data = new byte[1] {
                            0x01
                        }
                    }
                    ;
                    else
                    {
                        item.data = new byte[0];
                    }
                }
                else if (type == "String")
                {
                    item.data = System.Text.Encoding.UTF8.GetBytes(value.AsString());
                }
                else
                {
                    throw new Exception("not support type:" + type);
                }
                return(item);
            }
コード例 #3
0
 public ScriptBuilder EmitParamJson(MyJson.IJsonNode param)
 {
     if (param is MyJson.JsonNode_ValueNumber)//bool 或小整数
     {
         var num = param as MyJson.JsonNode_ValueNumber;
         if (num.isBool)
         {
             this.EmitPushBool(num.AsBool());
         }
         else
         {
             this.EmitPushNumber(num.AsInt());
         }
     }
     else if (param is MyJson.JsonNode_Array)
     {
         var list = param.AsList();
         for (var i = list.Count - 1; i >= 0; i--)
         {
             EmitParamJson(list[i]);
         }
         this.EmitPushNumber(param.AsList().Count);
         this.Emit(ThinNeo.OpCode.PACK);
     }
     else if (param is MyJson.JsonNode_ValueString)//复杂格式
     {
         var str   = param.AsString();
         var bytes = GetParamBytes(str);
         this.EmitPushBytes(bytes);
     }
     else
     {
         throw new Exception("should not pass a {}");
     }
     return(this);
 }
コード例 #4
0
        MyJson.JsonNode_Object getJsonResult(MyJson.JsonNode_Array json, string pos)
        {
            var pp = pos.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);

            if (pp[0] == "result")
            {
                MyJson.IJsonNode value = json;

                for (var i = 1; i < pp.Length; i++)
                {
                    if (value is MyJson.JsonNode_Object && value.AsDict()["type"].AsString() == "Array")
                    {
                        value = value.AsDict()["value"];
                    }
                    var index = int.Parse(pp[i]);
                    value = value.AsList()[index];
                }
                return(value.AsDict());
            }
            return(null);
        }
コード例 #5
0
 public ScriptBuilder EmitParamJson(MyJson.IJsonNode param)
 {
     if (param is MyJson.JsonNode_ValueNumber)//bool 或小整数
     {
         var num = param as MyJson.JsonNode_ValueNumber;
         if (num.isBool)
         {
             this.EmitPushBool(num.AsBool());
         }
         else
         {
             this.EmitPushNumber(num.AsInt());
         }
     }
     else if (param is MyJson.JsonNode_Array)
     {
         var list = param.AsList();
         for (var i = list.Count - 1; i >= 0; i--)
         {
             EmitParamJson(list[i]);
         }
         this.EmitPushNumber(param.AsList().Count);
         this.Emit(ThinNeo.VM.OpCode.PACK);
     }
     else if (param is MyJson.JsonNode_ValueString)//复杂格式
     {
         var str = param.AsString();
         if (str[0] != '(')
         {
             throw new Exception("must start with:(str) or (hex) or (hexrev) or (int) or (addr)");
         }
         if (str.IndexOf("(str)") == 0)
         {
             this.EmitPushString(str.Substring(5));
         }
         else if (str.IndexOf("(int)") == 0)
         {
             var num = System.Numerics.BigInteger.Parse(str.Substring(5));
             this.EmitPushNumber(num);
         }
         else if (str.IndexOf("(hex)") == 0)
         {
             var hex = ThinNeo.Helper.HexString2Bytes(str.Substring(5));
             this.EmitPushBytes(hex);
         }
         else if (str.IndexOf("(hexrev)") == 0)
         {
             var hex = ThinNeo.Helper.HexString2Bytes(str.Substring(8));
             this.EmitPushBytes(hex.Reverse().ToArray());
         }
         else if (str.IndexOf("(addr)") == 0)
         {
             var addr = (str.Substring(6));
             var hex  = ThinNeo.Helper.GetPublicKeyHashFromAddress(addr);
             this.EmitPushBytes(hex);
         }
         else
         {
             throw new Exception("must start with:(str) or (hex) or (hexbig) or (int)");
         }
     }
     else
     {
         throw new Exception("should not pass a {}");
     }
     return(this);
 }