public static MarshalBinary ( |
||
e | Entry to be marshaled | |
return | byte[] |
/// <summary> /// Caculates the cost of an entry /// </summary> /// <param name="entry"></param> /// <returns></returns> public static sbyte EntryCost(DataStructs.EntryData entry) { var entryBinary = Entries.MarshalBinary(entry); var len = entryBinary.Length - 35; if (len > 10240) { //Error, cannot be larger than 10kb throw new ArgumentException("Parameter cannot exceed 10kb of content", nameof(entry)); } var r = len % 1024; var n = (sbyte)(len / 1024); // Capacity of Entry Payment if (r > 0) { n += 1; } if (n < 1) { n = 1; } return(n); }
/// <summary> /// Second and final step in adding an entry to a chain on the factom blockchain /// </summary> /// <param name="entry">Entry to be added</param> /// <returns>Boolean true/false for success/failure</returns> public static bool RevealEntry(DataStructs.EntryData entry) { var rev = new Reveal(); var marshaledEntry = Entries.MarshalBinary(entry); rev.Entry = Arrays.ByteArrayToHex(marshaledEntry); var req = new RestRequest("/reveal-entry/", Method.POST); var json = JsonConvert.SerializeObject(rev); Console.WriteLine("RE Json = " + json); req.RequestFormat = DataFormat.Json; req.AddParameter("application/json", json, ParameterType.RequestBody); IRestResponse resp = StaticValues.clientWallet.Execute <RestRequest>(req); Console.WriteLine("RevealEntry Resp = " + resp.StatusCode + "|" + resp.StatusCode); if (resp.StatusCode != HttpStatusCode.OK) { throw new FactomEntryException("Entry Reveal Failed. Message: " + resp.ErrorMessage); } return(true); }
/// <summary> /// Second step in committing a new chain. Only run this if CommitChain was successful. /// </summary> /// <param name="c">Chain to be added</param> /// <returns>Boolean true/false for success/failure</returns> public static bool RevealChain(ChainType c) { var r = new Reveal(); var b = Entries.MarshalBinary(c.FirstEntry); r.Entry = Arrays.ByteArrayToHex(b); var json = JsonConvert.SerializeObject(r); var byteJson = Encoding.ASCII.GetBytes(json); var req = new RestRequest("/reveal-chain/", Method.POST); req.RequestFormat = DataFormat.Json; req.AddParameter("application/json", json, ParameterType.RequestBody); var resp = StaticValues.clientWallet.Execute(req); Console.WriteLine("RevealChain Resp = " + resp.StatusCode); //TODO: Remove if (resp.StatusCode != HttpStatusCode.OK) { throw new FactomChainException("Chain Reveal Failed. Message: " + resp.ErrorMessage); } return(true); }