public static string forge_entrypoint(string value) { string res = ""; if (entrypoint_tags.ContainsKey(value)) { res += entrypoint_tags[value].ToString("X2"); } else { res += "ff"; res += Forge.forge_array(Encoding.Default.GetBytes(value).ToHexString()); } return(res); }
public async Task <bool> AutoFillOperations(Atomex.Tezos tezos, JObject head, JArray operations, bool defaultFee = true) { var runResults = await RunOperations(head, operations) .ConfigureAwait(false); foreach (var result in runResults.SelectToken("contents")) { decimal gas = 0, storage_diff = 0, size = 0, fee = 0; var metaData = result["metadata"]; var operationResult = metaData?["operation_result"]; if (operationResult?["status"]?.ToString() == "applied") { try { gas = tezos.GasReserve + operationResult?["consumed_gas"]?.Value <decimal>() ?? 0; gas += metaData ?.SelectToken("internal_operation_results") ?.Sum(res => res["result"]?["consumed_gas"]?.Value <decimal>() ?? 0) ?? 0; //storage = operationResult?["storage_size"]?.Value<decimal>() ?? 0; storage_diff = operationResult?["paid_storage_size_diff"]?.Value <decimal>() ?? 0; storage_diff += tezos.ActivationStorage * (operationResult?["allocated_destination_contract"]?.ToString() == "True" ? 1 : 0); storage_diff += tezos.ActivationStorage * metaData?["internal_operation_results"] ?.Where(res => res["result"]?["allocated_destination_contract"]?.ToString() == "True") .Count() ?? 0; storage_diff += metaData ?.SelectToken("internal_operation_results") ?.Sum(res => res["result"]?["paid_storage_size_diff"]?.Value <decimal>() ?? 0) ?? 0; var op = operations .Children <JObject>() .FirstOrDefault(o => o["counter"] != null && o["counter"].ToString() == result["counter"].ToString()); op["gas_limit"] = gas.ToString(); op["storage_limit"] = storage_diff.ToString(); JToken forgedOpLocal = Forge.ForgeOperationsLocal(null, op); ///Checking for local and node forging results equality //JToken forgedOp = await ForgeOperations(head, op); //if (forgedOpLocal.ToString() != forgedOp.ToString().Substring((int)tezos.HeadSizeInBytes * 2)) // Log.Error("Local operation forge result differs from remote"); //process the error size = forgedOpLocal.ToString().Length / 2 + Math.Ceiling((tezos.HeadSizeInBytes + tezos.SigSizeInBytes) / operations.Count); fee = tezos.MinimalFee + tezos.MinimalNanotezPerByte * size + (long)Math.Ceiling(tezos.MinimalNanotezPerGasUnit * gas) + 1; if (defaultFee) { op["fee"] = fee.ToString(); } } catch (Exception ex) { Log.Error("Transaction autofilling error: " + ex.Message.ToString()); //process the error return(false); } } else { Log.Error("Transaction running failed: "); //process the error Log.Error(result.ToString()); return(false); } } return(true); }
public static string forge_micheline(JToken data) { string res = ""; if (data is JArray) { res += "02"; res += Forge.forge_array(string.Concat(data.Select(item => forge_micheline(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 += len_tags[args_len][annots_len > 0]; res += prim_tags[data["prim"].ToString()]; if (args_len > 0) { string args = string.Concat(data["args"].Select(item => forge_micheline(item))); if (args_len < 3) { res += args; } else { res += Forge.forge_array(args); } } if (annots_len > 0) { res += Forge.forge_array(string.Join(" ", data["annots"])); } else if (args_len == 3) { res += new string('0', 8); } } else if (data["bytes"] != null) { res += "0A"; res += Forge.forge_array(data["bytes"].ToString()); } else if (data["int"] != null) { res += "00"; res += forge_int(data["int"].Value <int>()); } else if (data["string"] != null) { res += "01"; res += Forge.forge_array(Encoding.Default.GetBytes(data["string"].Value <string>()).ToHexString()); } else { throw new Exception($"Michelson forge error"); } } else { throw new Exception($"Michelson forge error"); } return(res); }