Example #1
0
        public ActionResult TokenGenerator()
        {
            var createTokenGenerator = new CreateTokenGenerator();

            createTokenGenerator.Destination.SetValue(Request["destination"]);

            if (createTokenGenerator.Invalid)
            {
                return(View("TokenGenerator", createTokenGenerator));
            }
            else
            {
                try
                {
                    var secureTokenParameters = new ContractExamples.QuotedContracts.SecureTokenParameters(
                        createTokenGenerator.Destination.Address.Bytes);

                    //var contract = ContractExamples.QuotedContracts.secureTokenFactory(secureTokenParameters);
                    //var contractCode = ContractExamples.Execution.quotedToString(contract);
                    var tpl = Utils.GetTemplate("SecureToken");

                    var metadata     = new { contractType = "securetoken", destination = Convert.ToBase64String(secureTokenParameters.destination) };
                    var jsonHeader   = "//" + JsonConvert.SerializeObject(metadata);
                    var contractCode = tpl.Replace("__ADDRESS__", Convert.ToBase64String(secureTokenParameters.destination));
                    contractCode += "\n" + jsonHeader;

                    var code         = Utils.Dos2Unix(contractCode);
                    var contractHash = Consensus.Merkle.innerHash(Encoding.ASCII.GetBytes(contractCode));

                    ViewBag.Code = code;
                    ViewBag.Hash = Convert.ToBase64String(contractHash);

                    var file = $"{HttpServerUtility.UrlTokenEncode(contractHash)}";

                    Directory.CreateDirectory(Path.Combine("db", "contracts"));
                    Directory.CreateDirectory(Path.Combine("db", "asset-metadata"));

                    if (!System.IO.File.Exists(file))
                    {
                        System.IO.File.WriteAllText(Path.ChangeExtension(Path.Combine("db", "contracts", file), ".txt"), contractCode);
                    }

                    System.IO.File.WriteAllText(Path.ChangeExtension(Path.Combine("db", "asset-metadata", file), ".json"), JsonConvert.SerializeObject(new AssetMetadata()
                    {
                        name = Request["assetName"]
                    }));
                }
                catch (Exception e)
                {
                    ViewBag.Message = "Error creating contract: " + e.Message;
                }

                return(View("Result"));
            }
        }
Example #2
0
        public ActionResult FromTemplate(string id)
        {
            object model = null;

            switch (id)
            {
            case "CallOption":
                var createCallOption = new CreateCallOption();
                //               var oracleStatus = GetOracleStatus().Result;

                //               if (oracleStatus == null)
                //               {
                //	createCallOption.OracleErrorMessage = "Oracle not operatable";
                //}

                var oracleContractManager = new ContractsDiscovery.Web.App_Code.OracleContractManager();

                if (oracleContractManager.IsSetup)
                {
                    createCallOption.Oracle.SetValue(oracleContractManager.ContractAddress.ToString());
                }
                else
                {
                    createCallOption.OracleErrorMessage = oracleContractManager.Message;
                }

                //createCallOption.OracleServiceUrl = WebConfigurationManager.AppSettings["oracleService"];
                createCallOption.Tickers.AddRange(new List <String>(WebConfigurationManager.AppSettings["tickers"].Split(',')));

                model = createCallOption;
                break;

            case "TokenGenerator":
                model = new CreateTokenGenerator();
                break;

            case "Oracle":
                model = new CreateOracle();
                break;
            }

            return(View(id, model));
        }