public void CanSerDesTx2() { var tx = Consensus.Tests.tx; var data = Merkle.serialize <Types.Transaction>(tx); var t = Serialization.context.GetSerializer <Types.Transaction>().UnpackSingleObject(data); Assert.IsTrue(t.Equals(tx)); }
public void TestCase() { Types.Block block = Util.GetBlock(null, 0); var data = Merkle.serialize <Types.Block>(block); Types.Block _block = Serialization.context.GetSerializer <Types.Block>().UnpackSingleObject(data); Assert.IsTrue(block.Equals(_block)); }
public void CanSerDesTx() { var p = new TestTransactionPool(); p.Add("test", 1); p.Render(); var test = p.TakeOut("test").Value; var data = Merkle.serialize <Types.Transaction>(test); var t = Serialization.context.GetSerializer <Types.Transaction>().UnpackSingleObject(data); Assert.IsTrue(t.Equals(test)); }
public ActionResult Generate() { if (!Directory.Exists("db")) { Directory.CreateDirectory("db"); } var contractManager = new OracleContractManager(); if (!contractManager.IsSetup) { ViewData["Result"] = false; ViewData["Message"] = contractManager.Message; return(View()); } _StockAPI.Tickers = WebConfigurationManager.AppSettings["tickers"].Split(','); var rawTickers = _StockAPI.FetchResults().Result; var now = DateTime.Now.ToUniversalTime(); var nowTicks = now.Ticks; var items = rawTickers.Select(t => new ContractExamples.Oracle.TickerItem(t.Name, t.Value, nowTicks)); var secret = Convert.FromBase64String(WebConfigurationManager.AppSettings["oracleSecret"]); var commitmentData = ContractExamples.Oracle.commitments(items, secret); var getOutpointsResult = Client.Send <GetContractPointedOutputsResultPayload>(NodeRPCAddress, new GetContractPointedOutputsPayload() { ContractHash = contractManager.ContractAddress.Bytes }).Result; if (!getOutpointsResult.Success || getOutpointsResult.PointedOutputs.Count == 0) { ViewData["Result"] = false; ViewData["Message"] = "Could not find outputs"; return(View()); } var utxos = GetContractPointedOutputsResultPayload.Unpack(getOutpointsResult.PointedOutputs); if (utxos.Count() == 0) { ViewData["Result"] = false; ViewData["Message"] = "Could not find output"; return(View()); } var utxo = utxos.First(); //var serializer = new ContractExamples.FStarCompatibility.DataSerializer(Consensus.Serialization.context); //Consensus.Serialization.context.Serializers.RegisterOverride(serializer); var data = ContractUtilities.DataGenerator.makeOracleMessage(commitmentData.Item2, utxo.Item1); //var data = ContractExamples.QuotedContracts.simplePackOutpoint(utxo.Item1) // .Concat(commitmentData.Item2).ToArray(); //var signiture = Authentication.sign(data, contractManager.PrivateKey); //data = data.Concat(signiture).ToArray(); var sendContractResult = Client.Send <SendContractResultPayload>(NodeRPCAddress, new SendContractPayload() { ContractHash = contractManager.ContractAddress.Bytes, Data = data }).Result; ViewData["Result"] = sendContractResult.Success; if (sendContractResult.Success) { var file = Path.Combine("db", $"{now.ToFileTime()}"); MemoryStream ms = new MemoryStream(); ContractExamples.Oracle.proofMapSerializer.WriteObject(ms, commitmentData.Item1); ms.Position = 0; var sr = new StreamReader(ms); System.IO.File.WriteAllText(Path.ChangeExtension(file, ".data.json"), sr.ReadToEnd()); var outpoint = new Types.Outpoint(sendContractResult.TxHash, 1); // oracle always puts data on output #1 System.IO.File.WriteAllText(Path.ChangeExtension(file, ".outpoint.txt"), Convert.ToBase64String(Merkle.serialize(outpoint))); } else { ViewData["Message"] = "Reason: send result was '" + sendContractResult.Message + "'"; } return(View()); }