コード例 #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
ファイル: MyJsonCompress.cs プロジェクト: zhangf911/LSharp
 static void PackJson(System.IO.Stream stream, MyJson.IJsonNode node, IList <string> pubdict, IList <string> localdict, bool riseDictByKey, bool riseDictByString)
 {
     if (node is MyJson.JsonNode_ValueString)
     {
         string v = node.AsString();
         if (riseDictByString && v != null && v.Length > 1 && pubdict.Contains(v) == false)
         {
             pubdict.Add(v);
         }
         PackJsonString(stream, v, pubdict, localdict, riseDictByString);
     }
     else if (node is MyJson.JsonNode_ValueNumber)
     {
         PackJsonNumber(stream, node as MyJson.JsonNode_ValueNumber);
     }
     else if (node is MyJson.JsonNode_Array)
     {
         PackJsonArray(stream, node as MyJson.JsonNode_Array, pubdict, localdict, riseDictByKey, riseDictByString);
     }
     else if (node is MyJson.JsonNode_Object)
     {
         PackJsonObject(stream, node as MyJson.JsonNode_Object, pubdict, localdict, riseDictByKey, riseDictByString);
     }
 }
コード例 #4
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);
 }
コード例 #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);
 }