public static string ForgeEntrypoint(string value) { string res = ""; if (EntrypointTags.ContainsKey(value)) { res += EntrypointTags[value].ToString("X2"); } else { res += "ff"; res += Forge.ForgeArray(Encoding.Default.GetBytes(value).ToHexString()); } return(res); }
public static string ForgeMicheline(JToken data) { string res = ""; if (data is JArray) { res += "02"; res += Forge.ForgeArray(string.Concat(data.Select(item => ForgeMicheline(item)))); } else if (data is JObject) { if (data["prim"] != null) { var args_len = data["args"]?.Count() ?? 0; var annots_len = data["annots"]?.Count() ?? 0; res += LenTags[args_len][annots_len > 0]; res += PrimTags[data["prim"].ToString()]; if (args_len > 0) { string args = string.Concat(data["args"].Select(item => ForgeMicheline(item))); if (args_len < 3) { res += args; } else { res += Forge.ForgeArray(args); } } if (annots_len > 0) { res += Forge.ForgeArray(string.Join(" ", data["annots"])); } else if (args_len == 3) { res += new string('0', 8); } } else if (data["bytes"] != null) { res += "0A"; res += Forge.ForgeArray(data["bytes"].ToString()); } else if (data["int"] != null) { res += "00"; res += ForgeMicheint(BigInteger.Parse(data["int"].Value <string>())); } else if (data["string"] != null) { res += "01"; res += Forge.ForgeArray(Encoding.Default.GetBytes(data["string"].Value <string>()).ToHexString()); } else { throw new Exception($"Michelson forge error"); } } else { throw new Exception($"Michelson forge error"); } return(res); }