public static async Task <string> GetDeploymentReport(this WonkaEthEngineInitialization poEthEngineInit)
        {
            StringBuilder report = new StringBuilder("Contracts deployed successfully!\n");

            report.Append("Wonka Contract deployed to: (" + poEthEngineInit.RulesEngineContractAddress + ")\n");
            report.Append("Registry Contract deployed to: (" + poEthEngineInit.RegistryContractAddress + ")\n");
            report.Append("Test Storage Contract deployed to: (" + poEthEngineInit.StorageContractAddress + ")\n\n");
            report.Append("RuleTree (" + poEthEngineInit.Engine.RulesEngine.RuleTreeRoot.Description + ") was serialized succesfully to the Wonka Contract!");

            var EngineContractHandler =
                GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RulesEngineContractAddress);

            var GetAttrNumOutput =
                await
                EngineContractHandler
                .QueryDeserializingToObjectAsync <GetNumberOfAttributesFunction, GetNumberOfAttributesOutputDTO>(new GetNumberOfAttributesFunction(), null)
                .ConfigureAwait(false);

            // Placed a wait, just for good measure
            System.Threading.Thread.Sleep(2000);

            report.Append("\n\nNumber of Attributes Deployed to Wonka Contract: [" + (uint)GetAttrNumOutput.ReturnValue1 + "].\n\n");

            string sCurrValsReport = await poEthEngineInit.GetCurrValuesReport().ConfigureAwait(false);

            report.Append(sCurrValsReport);

            return(report.ToString());
        }
        /// <summary>
        ///
        /// This method will use Nethereum to call upon (or create) an instance of the Ethgine contract and
        /// to create a RuleTree that will be owned by the Sender.
        ///
        /// <returns>Indicates whether or not the RuleTree was created to the blockchain</returns>
        /// </summary>
        public static bool Serialize(this WonkaEthEngineInitialization poEngineInitData)
        {
            bool bResult = false;

            if ((poEngineInitData != null) && (poEngineInitData.Engine != null) && (poEngineInitData.Engine.RulesEngine != null))
            {
                if (poEngineInitData.Engine.RulesEngine.RefEnvHandle != null)
                {
                    bResult =
                        poEngineInitData.Engine.RulesEngine.RefEnvHandle.Serialize(poEngineInitData.EthRuleTreeOwnerAddress,
                                                                                   poEngineInitData.EthPassword,
                                                                                   poEngineInitData.EthSenderAddress,
                                                                                   poEngineInitData.RulesEngineContractAddress,
                                                                                   poEngineInitData.RulesEngineABI,
                                                                                   poEngineInitData.Web3HttpUrl);

                    if (bResult)
                    {
                        bResult =
                            poEngineInitData.Engine.RulesEngine.Serialize(poEngineInitData.EthRuleTreeOwnerAddress,
                                                                          poEngineInitData.EthPassword,
                                                                          poEngineInitData.EthSenderAddress,
                                                                          poEngineInitData.RulesEngineContractAddress,
                                                                          poEngineInitData.RulesEngineABI,
                                                                          poEngineInitData.RulesEngineContractAddress,
                                                                          poEngineInitData.Web3HttpUrl);
                    }
                }
            }

            return(bResult);
        }
        public static async Task <string> GetCurrValuesReport(this WonkaEthEngineInitialization poEthEngineInit)
        {
            Wonka.MetaData.WonkaRefEnvironment RefEnv = Wonka.MetaData.WonkaRefEnvironment.GetInstance();

            StringBuilder report = new StringBuilder("Below are current Attr values on Storage Contract (pulled via Wonka Engine Contract):\n");

            report.Append("-----------------------------------\n");

            ASCIIEncoding asciiEncoding = new ASCIIEncoding();

            var EngineContractHandler =
                GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RulesEngineContractAddress);

            var ValOnRecordFunction =
                new GetValueOnRecordFunction()
            {
                Ruler = poEthEngineInit.EthSenderAddress
            };

            foreach (var TempAttr in RefEnv.AttrCache)
            {
                ValOnRecordFunction.Key = asciiEncoding.GetBytes(TempAttr.AttrName);

                var GetAttrValOutput =
                    await
                    EngineContractHandler
                    .QueryDeserializingToObjectAsync <GetValueOnRecordFunction, GetValueOnRecordOutputDTO>(ValOnRecordFunction, null)
                    .ConfigureAwait(false);

                report.Append("Value of Attr(" + TempAttr.AttrName + ") : [" + GetAttrValOutput.ReturnValue1 + "].\n");
            }

            return(report.ToString());
        }
        public static async Task <string> ExecuteOnChain(this WonkaEthEngineInitialization poEthEngineInit)
        {
            StringBuilder EngineReport = new StringBuilder();

            /**
            ** Classic Way
            **
            ** var EngineContractHandler =
            **      GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RulesEngineContractAddress);
            **
            ** var ExecWithReportFunction =
            **      new ExecuteWithReportFunction() { Ruler = poEthEngineInit.EthSenderAddress };
            **
            ** var EWRTrxReceipt = await EngineContractHandler.SendRequestAndWaitForReceiptAsync(ExecWithReportFunction, null).ConfigureAwait(false);
            **/

            ProgressBarValues.ExecuteProgressBar = 12;

            var Report = new Wonka.Eth.Extensions.RuleTreeReport();

            ProgressBarValues.ExecuteProgressBar = 25;

            await poEthEngineInit.Engine.RulesEngine.ExecuteOnChainAsync(poEthEngineInit, Report).ConfigureAwait(false);

            ProgressBarValues.ExecuteProgressBar = 50;

            string sPrettyPrintReport = await Report.PrettyPrint(poEthEngineInit).ConfigureAwait(false);

            EngineReport.Append(sPrettyPrintReport);

            ProgressBarValues.ExecuteProgressBar = 75;

            return(EngineReport.ToString());
        }
        /// <summary>
        ///
        /// This method will use Nethereum to call upon (or create) an instance of the Ethgine contract and
        /// to create a RuleTree that will be owned by the Sender.
        ///
        /// <returns>Indicates whether or not the RuleTree was created to the blockchain</returns>
        /// </summary>
        public static async Task <bool> SerializeAsync(this WonkaEthEngineInitialization poEngineInitData)
        {
            bool bResult = false;

            if ((poEngineInitData != null) && (poEngineInitData.Engine != null) && (poEngineInitData.Engine.RulesEngine != null))
            {
                if (poEngineInitData.Engine.RulesEngine.RefEnvHandle != null)
                {
                    bResult =
                        await poEngineInitData.Engine.RulesEngine.RefEnvHandle.SerializeAsync(poEngineInitData.EthRuleTreeOwnerAddress,
                                                                                              poEngineInitData.EthPassword,
                                                                                              poEngineInitData.EthSenderAddress,
                                                                                              poEngineInitData.RulesEngineContractAddress,
                                                                                              poEngineInitData.RulesEngineABI,
                                                                                              poEngineInitData.Web3HttpUrl).ConfigureAwait(false);

                    if (bResult)
                    {
                        bResult =
                            await poEngineInitData.Engine.RulesEngine.SerializeAsync(poEngineInitData.EthRuleTreeOwnerAddress,
                                                                                     poEngineInitData.EthPassword,
                                                                                     poEngineInitData.EthSenderAddress,
                                                                                     poEngineInitData.RulesEngineContractAddress,
                                                                                     poEngineInitData.RulesEngineABI,
                                                                                     poEngineInitData.RulesEngineContractAddress,
                                                                                     poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                    }
                }
            }

            return(bResult);
        }
 public static Dictionary <string, WonkaBizSource> InitializeTokenOpMap(this WonkaEthEngineInitialization poEngInitData)
 {
     return(WonkaEthCustomRuleTokenExtensions.InitializeTokenOperationsMap(poEngInitData.EthSenderAddress,
                                                                           poEngInitData.EthPassword,
                                                                           poEngInitData.ERC20ContractAddress,
                                                                           poEngInitData.ERC721ContractAddress,
                                                                           poEngInitData.Web3HttpUrl));
 }
        /// <summary>
        ///
        /// This method will deploy all contracts needed to run Wonka on-chain, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> DeployContractsClassicAsync(this WonkaEthEngineInitialization poEngineInitData)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                var account = new Account(poEngineInitData.EthPassword);

                Nethereum.Web3.Web3 web3 = null;
                if (!String.IsNullOrEmpty(poEngineInitData.Web3HttpUrl))
                {
                    web3 = new Nethereum.Web3.Web3(account, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    web3 = new Nethereum.Web3.Web3(account);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RulesEngineContractAddress))
                {
                    var EngineDeployment = new Autogen.WonkaEngine.WonkaEngineDeploymentClassic();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_ENGINE_CONTRACT_GAS_COST);

                    poEngineInitData.RulesEngineContractAddress =
                        await EngineDeployment.DeployContractAsync(web3, poEngineInitData.RulesEngineABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RegistryContractAddress))
                {
                    var RegistryDeployment = new Autogen.WonkaRegistry.WonkaRegistryDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.RegistryContractAddress =
                        await RegistryDeployment.DeployContractAsync(web3, poEngineInitData.RegistryContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.StorageContractAddress))
                {
                    var TestContractDeployment = new Autogen.WonkaTestContract.WonkaTestContractDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.StorageContractAddress =
                        await TestContractDeployment.DeployContractAsync(web3, poEngineInitData.StorageContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }
            }

            return(bResult);
        }
        public static async Task <bool> OwnsRuleTree(this WonkaEthEngineInitialization poEthEngineInit, string psRuleTreeOwner)
        {
            var EngineContractHandler =
                GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RulesEngineContractAddress);

            var OwnsRuleTreeOutput =
                await
                EngineContractHandler
                .QueryDeserializingToObjectAsync <HasRuleTreeFunction, HasRuleTreeOutputDTO>(new HasRuleTreeFunction()
            {
                Ruler = psRuleTreeOwner
            }, null)
                .ConfigureAwait(false);

            return(OwnsRuleTreeOutput.ReturnValue1);
        }
示例#9
0
        private async Task <bool> InitEngineAsync(bool pbInitChainEnv)
        {
            bool bResult = false;

            moEthEngineInit = new WonkaEthEngineInitialization();

            moEthEngineInit.Engine.MetadataSource       = moMetadataSource;
            moEthEngineInit.Engine.RulesMarkupXml       = msRulesContents;
            moEthEngineInit.Engine.DotNetRetrieveMethod = RetrieveValueMethod;
            moEthEngineInit.EthSenderAddress            = moEthEngineInit.EthRuleTreeOwnerAddress = msSenderAddress;
            moEthEngineInit.EthPassword          = msPassword;
            moEthEngineInit.ERC20ContractAddress = msContractAddress;

            if (!String.IsNullOrEmpty(msWeb3HttpUrl))
            {
                moEthEngineInit.Web3HttpUrl = msWeb3HttpUrl;
            }

            if ((moSourceMap == null) || (moSourceMap.Count <= 0))
            {
                moSourceMap = GetDefaultSourceMap();
            }

            moEthEngineInit.Engine.RulesEngine =
                new WonkaEthRulesEngine(new StringBuilder(msRulesContents),
                                        moSourceMap,
                                        moEthEngineInit,
                                        moMetadataSource,
                                        false);

            await moEthEngineInit.InitEngineAsync().ConfigureAwait(false);

            /*
             * NOTE: Not needed for now
             *          // Serialize the data domain to the blockchain
             *          if (pbInitChainEnv)
             * {
             *                  await moEthEngineInit.SerializeAsync().ConfigureAwait(false);
             * }
             */

            return(bResult);
        }
        public static async Task <bool> Deploy(this WonkaEthEngineInitialization poEthEngineInit)
        {
            ProgressBarValues.DeployProgressBar = 25;

            poEthEngineInit.StorageContractABI    = Wonka.Eth.Autogen.WonkaTestContract.WonkaTestContractDeployment.ABI;
            poEthEngineInit.StorageGetterMethod   = "getAttrValueBytes32";
            poEthEngineInit.StorageSetterMethod   = "setAttrValueBytes32";
            poEthEngineInit.UsingStorageContract  = true;
            poEthEngineInit.UsingTrxStateContract = false;

            await poEthEngineInit.InitEngineAsync(false).ConfigureAwait(false);

            ProgressBarValues.DeployProgressBar = 50;

            // Serialize the data domain to the blockchain
            await poEthEngineInit.SerializeAsync().ConfigureAwait(false);

            ProgressBarValues.DeployProgressBar = 75;

            return(true);
        }
示例#11
0
        private WonkaEthRulesEngine AssembleWonkaEthEngine(string psWonkaRules)
        {
            refEnvHandle =
                WonkaRefEnvironment.CreateInstance(false, metadataSource);

            string sContractAddr  = "";
            string sContractABI   = "";
            string sGetMethodName = "";
            string sSetMethodName = "";

            WonkaBizSource.RetrieveDataMethod retrieveMethod = null;

            var SourceMap = new Dictionary <string, WonkaBizSource>();

            foreach (var TmpAttr in refEnvHandle.AttrCache)
            {
                var TmpSource =
                    new WonkaBizSource(TmpAttr.AttrName,
                                       CONST_ACCT_PUBLIC_KEY,
                                       CONST_ACCT_PASSWORD,
                                       sContractAddr,
                                       sContractABI,
                                       sGetMethodName,
                                       sSetMethodName,
                                       retrieveMethod);

                SourceMap[TmpAttr.AttrName] = TmpSource;
            }

            WonkaEthEngineInitialization EngineInit =
                new WonkaEthEngineInitialization()
            {
                EthSenderAddress = CONST_ACCT_PUBLIC_KEY,
                EthPassword      = CONST_ACCT_PASSWORD,
                Web3HttpUrl      = CONST_TEST_INFURA_URL
            };

            return(new WonkaEthRulesEngine(new StringBuilder(psWonkaRules), SourceMap, EngineInit, metadataSource, false));
        }
示例#12
0
        public void Execute()
        {
            // Using the metadata source, we create an instance of a defined data domain
            WonkaRefEnvironment RefEnv =
                WonkaRefEnvironment.CreateInstance(false, moMetadataSource);

            var sWeb3Url       = "https://mainnet.infura.io/v3/7238211010344719ad14a89db874158c";
            var sSenderAddress = "0x12890D2cce102216644c59daE5baed380d84830c";
            var sPassword      = "******";
            var sERC20Address  = "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2";

            // To test whether the data domain has been created, we pull back one attribute
            WonkaRefAttr AccountStsAttr   = RefEnv.GetAttributeByAttrName("AccountStatus");
            WonkaRefAttr AuditRvwFlagAttr = RefEnv.GetAttributeByAttrName("AuditReviewFlag");

            Dictionary <string, WonkaBizSource> SourceMap = new Dictionary <string, WonkaBizSource>();

            /*
             * WonkaBizSource DefaultSource =
             *  new WonkaBizSource(sContractSourceId, msSenderAddress, msPassword, sContractAddress, sContractAbi, sOrchGetterMethod, sOrchSetterMethod, RetrieveValueMethod);
             */

            WonkaBizSource DefaultSource =
                new WonkaBizSource("", "", "", "", null);

            // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
            // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
            foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache)
            {
                SourceMap[TempAttr.AttrName] = DefaultSource;
            }

            var WonkaEthEngInit =
                new WonkaEthEngineInitialization()
            {
                EthSenderAddress      = sSenderAddress,
                EthPassword           = sPassword,
                ERC20ContractAddress  = sERC20Address,
                ERC721ContractAddress = "",
                Web3HttpUrl           = sWeb3Url
            };

            // Creating an instance of the rules engine using our rules and the metadata
            WonkaBizRulesEngine RulesEngine =
                new WonkaEthRulesEngine(new StringBuilder(msRulesContents), SourceMap, WonkaEthEngInit, moMetadataSource);

            // Gets a predefined data record that will be our analog for new data coming into the system
            WonkaProduct NewProduct = GetNewProduct();

            // Check that the data has been populated correctly on the "new" record
            string sStatusValueBefore = GetAttributeValue(NewProduct, AccountStsAttr);

            // RulesEngine.GetCurrentProductDelegate = GetOldProduct;

            // Validate the new record using our rules engine and its initialized RuleTree
            Wonka.BizRulesEngine.Reporting.WonkaBizRuleTreeReport Report = RulesEngine.Validate(NewProduct);

            // Now retrieve the AccountStatus value and see if the rules have altered it (which should
            // not be the case)
            string sStatusValueAfter  = GetAttributeValue(NewProduct, AccountStsAttr);
            string sAuditRvwFlagAfter = GetAttributeValue(NewProduct, AuditRvwFlagAttr);

            if (Report.GetRuleSetFailureCount() > 0)
            {
                throw new Exception("Oh heavens to Betsy! Something bad happened!");
            }
        }
        public static async Task <string> PrettyPrint(this Wonka.Eth.Extensions.RuleTreeReport poReport, WonkaEthEngineInitialization poEthEngineInit)
        {
            StringBuilder PrettyPrintReport = new StringBuilder();

            int nRSFailedCount = poReport.GetRuleSetSevereFailureCount();

            if (nRSFailedCount == 0)
            {
                PrettyPrintReport.Append("Engine completed successfully!\n\n");
            }
            else
            {
                PrettyPrintReport.Append("Engine failed, with [" + nRSFailedCount + "] 'severe' leaf RuleSets having failed.\n\n");
                PrettyPrintReport.Append("Failed 'severe' RuleSets: [" + String.Join(',', poReport.RuleSetFailures) + "]\n\n");
            }

            string sCurrValsReport = await poEthEngineInit.GetCurrValuesReport().ConfigureAwait(false);

            PrettyPrintReport.Append(sCurrValsReport);

            return(PrettyPrintReport.ToString());
        }
        public static async Task <string> AddToRegistry(this WonkaEthEngineInitialization poEthEngineInit, string psGroveId, string psGroveDesc)
        {
            var bytesTreeId  = ASCIIEncoding.ASCII.GetBytes(poEthEngineInit.Engine.RulesEngine.DetermineRuleTreeChainID());
            var bytesGroveId = ASCIIEncoding.ASCII.GetBytes(psGroveId);

            var RegistryContractHandler =
                GetWeb3(poEthEngineInit.EthPassword, poEthEngineInit.Web3HttpUrl).Eth.GetContractHandler(poEthEngineInit.RegistryContractAddress);

            BigInteger CreationTime = new BigInteger(DateTime.Now.ToEpochTime());

            // Add Grove to the Registry first
            try
            {
                var AddGroveFunction
                    = new AddRuleGroveFunction()
                    {
                    GroveId = bytesGroveId, Desc = psGroveDesc, GroveOwner = poEthEngineInit.EthSenderAddress, CreateTime = CreationTime
                    };

                var addGroveToRegReceipt =
                    await RegistryContractHandler.SendRequestAndWaitForReceiptAsync(AddGroveFunction, null).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                // NOTE: Should be addressed in the future
            }

            // Add RuleTree to the Registry next
            List <byte[]> bytesOpList = new List <byte[]>();

            poEthEngineInit.Engine.RulesEngine.CustomOpMap.Keys.ToList().ForEach(x => bytesOpList.Add(ASCIIEncoding.ASCII.GetBytes(x)));

            var AddRuleTreeFunction
                = new AddRuleTreeIndexFunction()
                {
                RsId          = bytesTreeId,
                Desc          = "General Description",
                RuleTreeGrpId = bytesGroveId,
                GrpIdx        = 1,
                Ruler         = poEthEngineInit.EthSenderAddress,
                Host          = "",
                Attributes    = new List <byte[]>(),
                Associates    = new List <string>(),
                MinCost       = poEthEngineInit.Engine.RulesEngine.CalculateMinGasEstimate(),
                MaxCost       = poEthEngineInit.Engine.RulesEngine.CalculateMaxGasEstimate(),
                Ops           = bytesOpList,
                CreateTime    = CreationTime
                };

            var addTreeToRegReceipt =
                await RegistryContractHandler.SendRequestAndWaitForReceiptAsync(AddRuleTreeFunction, null).ConfigureAwait(false);

            /**
            ** NOTE: Not needed for now
            **
            ** // Add RuleTree to the Grove in the Registry
            ** var AddToRegistryFunction =
            **      new AddRuleTreeToGroveFunction() { GroveId = bytesGroveId, TreeId = bytesTreeId };
            **
            ** var addTreeToGroveReceipt =
            **      await RegistryContractHandler.SendRequestAndWaitForReceiptAsync(AddToRegistryFunction, null).ConfigureAwait(false);
            **/

            return(addTreeToRegReceipt.TransactionHash);
        }
示例#15
0
        /// <summary>
        ///
        /// This method will initialize an instance of the Wonka.Net engine, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> InitEngineAsync(this WonkaEthEngineInitialization poEngineInitData, bool pbRequireRetrieveValueMethod = true)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                if (pbRequireRetrieveValueMethod && (EngineProps.DotNetRetrieveMethod == null))
                {
                    throw new WonkaEthInitException("ERROR!  Retrieve method not provided for the Wonka.NET engine.", poEngineInitData);
                }

                if (EngineProps.MetadataSource == null)
                {
                    throw new WonkaEthInitException("ERROR!  No metadata source has been provided.", poEngineInitData);
                }

                // Using the metadata source, we create an instance of a defined data domain
                WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, EngineProps.MetadataSource);

                // The old version of deployment, pushing out a contract with all methods (i.e., library)
                // bool bDeploySuccess = poEngineInitData.DeployContractsClassicAsync().Result;

                // The new version of deployment, pushing out the contract with a link to a library
                bool bDeploySuccess = poEngineInitData.DeployContractsAsync().Result;

                if (bDeploySuccess)
                {
                    if ((EngineProps.SourceMap == null) || (EngineProps.SourceMap.Count == 0))
                    {
                        EngineProps.SourceMap = new Dictionary <string, WonkaBizSource>();

                        // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
                        // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
                        foreach (WonkaRefAttr TempAttr in WonkaRefEnv.AttrCache)
                        {
                            WonkaBizSource TempSource =
                                new WonkaBizSource(poEngineInitData.StorageDefaultSourceId,
                                                   poEngineInitData.EthSenderAddress,
                                                   poEngineInitData.EthPassword,
                                                   poEngineInitData.StorageContractAddress,
                                                   poEngineInitData.StorageContractABI,
                                                   poEngineInitData.StorageGetterMethod,
                                                   poEngineInitData.StorageSetterMethod,
                                                   EngineProps.DotNetRetrieveMethod);

                            EngineProps.SourceMap[TempAttr.AttrName] = TempSource;
                        }
                    }

                    EngineProps.RulesEngine =
                        new WonkaBizRulesEngine(new StringBuilder(EngineProps.RulesMarkupXml), EngineProps.SourceMap, EngineProps.MetadataSource);

                    EngineProps.RulesEngine.DefaultSource = poEngineInitData.StorageDefaultSourceId;

                    //NOTE: These Ethereum ops will not currently execute correctly within .NET during Async mode, since the Wonka.NET must then also be refactored to execute in Async
                    //EngineProps.RulesEngine.SetDefaultStdOps(poEngineInitData.EthPassword, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    throw new Exception("ERROR!  Deployment of Wonka contracts has failed!");
                }
            }

            return(bResult);
        }
示例#16
0
        /// <summary>
        ///
        /// This method will deploy all contracts needed to run Wonka on-chain, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> DeployContractsAsync(this WonkaEthEngineInitialization poEngineInitData)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                var account = new Account(poEngineInitData.EthPassword);

                Nethereum.Web3.Web3 web3 = null;
                if (!String.IsNullOrEmpty(poEngineInitData.Web3HttpUrl))
                {
                    web3 = new Nethereum.Web3.Web3(account, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    web3 = new Nethereum.Web3.Web3(account);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RulesEngineContractAddress))
                {
                    var WonkaLibABI         = Autogen.WonkaLibrary.WonkaLibraryDeployment.ABI;
                    var WonkaLibPlaceHolder = Autogen.WonkaLibrary.WonkaLibraryDeployment.PLACEHOLDER_KEY;

                    var EngineDeployment = new Autogen.WonkaEngine.WonkaEngineDeploymentClassic();

                    var WonkaLibDeployment = new Autogen.WonkaLibrary.WonkaLibraryDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_ENGINE_CONTRACT_GAS_COST);

                    // Deploy the library contract first
                    var LibraryContractAddress =
                        await WonkaLibDeployment.DeployContractAsync(web3, WonkaLibABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);

                    var libraryMapping =
                        new ByteCodeLibrary()
                    {
                        Address = LibraryContractAddress, PlaceholderKey = WonkaLibPlaceHolder
                    };

                    // Link main contract byte code with the library, in preparation for deployment
                    var contractByteCode = Autogen.WonkaEngine.WonkaEngineDeployment.BYTECODE;
                    var libraryMappings  = new ByteCodeLibrary[] { libraryMapping };
                    var libraryLinker    = new ByteCodeLibraryLinker();

                    var contractByteCodeLinked = libraryLinker.LinkByteCode(contractByteCode, libraryMappings);

                    // Deploy linked contract
                    var DeployEngineReceipt
                        = await web3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(contractByteCodeLinked, poEngineInitData.EthSenderAddress, nDeployGas, null, null, null).ConfigureAwait(false);

                    poEngineInitData.RulesEngineContractAddress = DeployEngineReceipt.ContractAddress;
                }

                if (String.IsNullOrEmpty(poEngineInitData.RegistryContractAddress))
                {
                    var RegistryDeployment = new Autogen.WonkaRegistry.WonkaRegistryDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.RegistryContractAddress =
                        await RegistryDeployment.DeployContractAsync(web3, poEngineInitData.RegistryContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.StorageContractAddress))
                {
                    var TestContractDeployment = new Autogen.WonkaTestContract.WonkaTestContractDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.StorageContractAddress =
                        await TestContractDeployment.DeployContractAsync(web3, poEngineInitData.StorageContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }
            }

            return(bResult);
        }
        /// <summary>
        ///
        /// This method will initialize an instance of the Wonka.Net engine, using all the data provided.
        ///
        /// <returns>None</returns>
        /// </summary>
        public static async Task <bool> InitEngineAsync(this WonkaEthEngineInitialization poEngineInitData, bool pbRequireRetrieveValueMethod = true)
        {
            bool bResult = true;

            var EngineProps = poEngineInitData.Engine;

            if (EngineProps == null)
            {
                throw new Exception("ERROR!  No engine properties provided.");
            }

            if ((EngineProps.RulesEngine == null) && !String.IsNullOrEmpty(EngineProps.RulesMarkupXml))
            {
                if (pbRequireRetrieveValueMethod && (EngineProps.DotNetRetrieveMethod == null))
                {
                    throw new WonkaEthInitException("ERROR!  Retrieve method not provided for the Wonka.NET engine.", poEngineInitData);
                }

                if (EngineProps.MetadataSource == null)
                {
                    throw new WonkaEthInitException("ERROR!  No metadata source has been provided.", poEngineInitData);
                }

                // Using the metadata source, we create an instance of a defined data domain
                WonkaRefEnvironment WonkaRefEnv = WonkaRefEnvironment.CreateInstance(false, EngineProps.MetadataSource);

                var account = new Account(poEngineInitData.EthPassword);

                Nethereum.Web3.Web3 web3 = null;
                if (!String.IsNullOrEmpty(poEngineInitData.Web3HttpUrl))
                {
                    web3 = new Nethereum.Web3.Web3(account, poEngineInitData.Web3HttpUrl);
                }
                else
                {
                    web3 = new Nethereum.Web3.Web3(account);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RulesEngineContractAddress))
                {
                    var EngineDeployment = new Autogen.WonkaEngine.WonkaEngineDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_ENGINE_CONTRACT_GAS_COST);

                    poEngineInitData.RulesEngineContractAddress =
                        await EngineDeployment.DeployContractAsync(web3, poEngineInitData.RulesEngineABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.RegistryContractAddress))
                {
                    var RegistryDeployment = new Autogen.WonkaRegistry.WonkaRegistryDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.RegistryContractAddress =
                        await RegistryDeployment.DeployContractAsync(web3, poEngineInitData.RegistryContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if (String.IsNullOrEmpty(poEngineInitData.StorageContractAddress))
                {
                    var TestContractDeployment = new Autogen.WonkaTestContract.WonkaTestContractDeployment();

                    HexBigInteger nDeployGas = new HexBigInteger(CONST_DEPLOY_DEFAULT_CONTRACT_GAS_COST);

                    poEngineInitData.StorageContractAddress =
                        await TestContractDeployment.DeployContractAsync(web3, poEngineInitData.StorageContractABI, poEngineInitData.EthSenderAddress, nDeployGas, poEngineInitData.Web3HttpUrl).ConfigureAwait(false);
                }

                if ((EngineProps.SourceMap == null) || (EngineProps.SourceMap.Count == 0))
                {
                    EngineProps.SourceMap = new Dictionary <string, WonkaBizSource>();

                    // Here a mapping is created, where each Attribute points to a specific contract and its "accessor" methods
                    // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type
                    foreach (WonkaRefAttr TempAttr in WonkaRefEnv.AttrCache)
                    {
                        WonkaBizSource TempSource =
                            new WonkaBizSource(poEngineInitData.StorageDefaultSourceId,
                                               poEngineInitData.EthSenderAddress,
                                               poEngineInitData.EthPassword,
                                               poEngineInitData.StorageContractAddress,
                                               poEngineInitData.StorageContractABI,
                                               poEngineInitData.StorageGetterMethod,
                                               poEngineInitData.StorageSetterMethod,
                                               EngineProps.DotNetRetrieveMethod);

                        EngineProps.SourceMap[TempAttr.AttrName] = TempSource;
                    }
                }

                EngineProps.RulesEngine =
                    new WonkaBizRulesEngine(new StringBuilder(EngineProps.RulesMarkupXml), EngineProps.SourceMap, EngineProps.MetadataSource);

                EngineProps.RulesEngine.DefaultSource = poEngineInitData.StorageDefaultSourceId;

                //NOTE: These Ethereum ops will not currently execute correctly within .NET during Async mode, since the Wonka.NET must then also be refactored to execute in Async
                //EngineProps.RulesEngine.SetDefaultStdOps(poEngineInitData.EthPassword, poEngineInitData.Web3HttpUrl);
            }

            return(bResult);
        }