public WonkaCQSTest(string psSenderAddress, string psPassword, string psContractAddress = null) { var TmpAssembly = Assembly.GetExecutingAssembly(); // Read the ABI of the Ethereum contract for the Wonka rules engine and holds our data record using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi"))) { msAbiWonka = AbiReader.ReadToEnd(); } // Read the XML markup that lists the business rules (i.e., the RuleTree) using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.SimpleAccountCheck.xml"))) { msRulesContents = RulesReader.ReadToEnd(); } // Using the metadata source, we create an instance of a defined data domain WonkaRefEnvironment RefEnv = WonkaRefEnvironment.CreateInstance(false, moMetadataSource); msSenderAddress = psSenderAddress; msPassword = psPassword; if (psContractAddress == null) { msContractAddress = DeployContract(); } else { msContractAddress = psContractAddress; } // Finally we serialize the data domain to the blockchain RefEnv.Serialize(msSenderAddress, msPassword, msSenderAddress, msContractAddress, msAbiWonka); }
// This constructor will be called in the case that we wish to initialize the framework // with configuration files that will be accessed through IPFS public WonkaCQSOrchTest(StringBuilder psPeerKeyId, string psRulesMarkupFile, string psRulesInitFile, string psRegistryInitFile) { moAttrSourceMap = new Dictionary <string, WonkaBizSource>(); moCustomOpMap = new Dictionary <string, WonkaBizSource>(); var TmpAssembly = Assembly.GetExecutingAssembly(); WonkaRefEnvironment RefEnv = WonkaRefEnvironment.CreateInstance(false, moMetadataSource); Wonka.IpfsW.WonkaIpfsEnvironment IpfsEnv = Wonka.IpfsW.WonkaIpfsEnvironment.CreateInstance(); // Read the XML markup that lists the business rules msRulesContents = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRulesMarkupFile); // Read the configuration file that contains all the initialization details regarding the rules engine // (like addresses of contracts, senders, passwords, etc.) string sInitXml = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRulesInitFile); if (!String.IsNullOrEmpty(sInitXml)) { System.Xml.Serialization.XmlSerializer WonkaEthSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthInitialization), new System.Xml.Serialization.XmlRootAttribute("Wonka.EthInitialization")); Wonka.Eth.Init.WonkaEthInitialization WonkaInit = WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitXml)) as Wonka.Eth.Init.WonkaEthInitialization; WonkaInit.RetrieveEmbeddedResources(TmpAssembly); moOrchInitData = WonkaInit.TransformIntoOrchestrationInit(moMetadataSource); System.Console.WriteLine("Number of custom operators: (" + WonkaInit.CustomOperatorList.Length + ")."); } // Read the configuration file that contains all the initialization details regarding the rules registry // (like Ruletree info, Grove info, etc.) string sInitRegistryXml = IpfsEnv.GetFile(psPeerKeyId.ToString(), psRegistryInitFile); if (!String.IsNullOrEmpty(sInitRegistryXml)) { System.Xml.Serialization.XmlSerializer WonkaEthSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthRegistryInitialization), new System.Xml.Serialization.XmlRootAttribute("Wonka.EthRegistryInitialization")); moWonkaRegistryInit = WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitRegistryXml)) as Wonka.Eth.Init.WonkaEthRegistryInitialization; moWonkaRegistryInit.RetrieveEmbeddedResources(TmpAssembly); } #region Set Class Member Variables msSenderAddress = moOrchInitData.BlockchainEngine.SenderAddress; msPassword = moOrchInitData.BlockchainEngine.Password; if (moOrchInitData.BlockchainEngine.ContractAddress == null) { msWonkaContractAddress = DeployWonkaContract(); } else { msWonkaContractAddress = moOrchInitData.BlockchainEngine.ContractAddress; } if (moOrchInitData.DefaultBlockchainDataSource.ContractAddress == null) { msOrchContractAddress = DeployOrchestrationContract(); } else { msOrchContractAddress = moOrchInitData.DefaultBlockchainDataSource.ContractAddress; } msAbiWonka = moOrchInitData.BlockchainEngine.ContractABI; msAbiOrchContract = moOrchInitData.DefaultBlockchainDataSource.ContractABI; moDefaultSource = new WonkaBizSource(moOrchInitData.DefaultBlockchainDataSource.SourceId, moOrchInitData.DefaultBlockchainDataSource.SenderAddress, moOrchInitData.DefaultBlockchainDataSource.Password, moOrchInitData.DefaultBlockchainDataSource.ContractAddress, moOrchInitData.DefaultBlockchainDataSource.ContractABI, moOrchInitData.DefaultBlockchainDataSource.MethodName, moOrchInitData.DefaultBlockchainDataSource.SetterMethodName, RetrieveValueMethod); // 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) { moAttrSourceMap[TempAttr.AttrName] = moDefaultSource; } // Here a mapping is created, where each Custom Operator points to a specific contract and its "implementation" method // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type moCustomOpMap = moOrchInitData.BlockchainCustomOpFunctions; #endregion Wonka.Eth.Contracts.WonkaRuleTreeRegistry WonkaRegistry = Wonka.Eth.Contracts.WonkaRuleTreeRegistry.CreateInstance(moWonkaRegistryInit.BlockchainRegistry.ContractSender, moWonkaRegistryInit.BlockchainRegistry.ContractPassword, moWonkaRegistryInit.BlockchainRegistry.ContractAddress, moWonkaRegistryInit.BlockchainRegistry.ContractABI, moWonkaRegistryInit.Web3HttpUrl); RefEnv.Serialize(moOrchInitData.BlockchainEngineOwner, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka, moOrchInitData.Web3HttpUrl); }
// This constructor will be called in the case that we wish to initialize the framework // with configuration files locally (embedded resources, local filesystem, etc.) public WonkaCQSOrchTest() { moAttrSourceMap = new Dictionary <string, WonkaBizSource>(); moCustomOpMap = new Dictionary <string, WonkaBizSource>(); var TmpAssembly = Assembly.GetExecutingAssembly(); // Using the metadata source, we create an instance of a defined data domain WonkaRefEnvironment RefEnv = WonkaRefEnvironment.CreateInstance(false, moMetadataSource); // Read the XML markup that lists the business rules (i.e., the RuleTree) using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.xml"))) { msRulesContents = RulesReader.ReadToEnd(); } // Read the configuration file that contains all the initialization details regarding the rules engine // (like addresses of contracts, senders, passwords, etc.) using (var XmlReader = new System.IO.StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.init.xml"))) { string sInitXml = XmlReader.ReadToEnd(); // We deserialize/parse the contents of the config file System.Xml.Serialization.XmlSerializer WonkaEthSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthInitialization), new System.Xml.Serialization.XmlRootAttribute("Wonka.EthInitialization")); Wonka.Eth.Init.WonkaEthInitialization WonkaInit = WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitXml)) as Wonka.Eth.Init.WonkaEthInitialization; // Here, any embeddeded resources mentioned in the config file (instead of simple file URLs) are accessed here WonkaInit.RetrieveEmbeddedResources(TmpAssembly); // The initialization data is transformed into a structure used by the Wonka.Eth namespace moOrchInitData = WonkaInit.TransformIntoOrchestrationInit(moMetadataSource); System.Console.WriteLine("Number of custom operators: (" + WonkaInit.CustomOperatorList.Length + ")."); } // Read the configuration file that contains all the initialization details regarding the rules registry // (like Ruletree info, Grove info, etc.) - this information will allow us to add our RuleTree to the // Registry so that it can be discovered by users and so it can be added to a Grove (where it can be executed // as a member of a collection) using (var XmlReader = new System.IO.StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaRegistry.init.xml"))) { string sInitRegistryXml = XmlReader.ReadToEnd(); // We deserialize/parse the contents of the config file System.Xml.Serialization.XmlSerializer WonkaEthSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Wonka.Eth.Init.WonkaEthRegistryInitialization), new System.Xml.Serialization.XmlRootAttribute("Wonka.EthRegistryInitialization")); moWonkaRegistryInit = WonkaEthSerializer.Deserialize(new System.IO.StringReader(sInitRegistryXml)) as Wonka.Eth.Init.WonkaEthRegistryInitialization; // Here, any embeddeded resources mentioned in the config file (instead of simple file URLs) are accessed here moWonkaRegistryInit.RetrieveEmbeddedResources(TmpAssembly); } // Here, we save all data from the config files to member properties // This region and the usage of member properties isn't necessary, but it's useful for debugging #region Set Class Member Variables msSenderAddress = moOrchInitData.BlockchainEngine.SenderAddress; msPassword = moOrchInitData.BlockchainEngine.Password; if (moOrchInitData.BlockchainEngine.ContractAddress == null) { msWonkaContractAddress = DeployWonkaContract(); } else { msWonkaContractAddress = moOrchInitData.BlockchainEngine.ContractAddress; } if (moOrchInitData.DefaultBlockchainDataSource.ContractAddress == null) { msOrchContractAddress = DeployOrchestrationContract(); } else { msOrchContractAddress = moOrchInitData.DefaultBlockchainDataSource.ContractAddress; } msAbiWonka = moOrchInitData.BlockchainEngine.ContractABI; msAbiOrchContract = moOrchInitData.DefaultBlockchainDataSource.ContractABI; moDefaultSource = new WonkaBizSource(moOrchInitData.DefaultBlockchainDataSource.SourceId, moOrchInitData.DefaultBlockchainDataSource.SenderAddress, moOrchInitData.DefaultBlockchainDataSource.Password, moOrchInitData.DefaultBlockchainDataSource.ContractAddress, moOrchInitData.DefaultBlockchainDataSource.ContractABI, moOrchInitData.DefaultBlockchainDataSource.MethodName, moOrchInitData.DefaultBlockchainDataSource.SetterMethodName, RetrieveValueMethod); foreach (WonkaRefAttr TempAttr in RefEnv.AttrCache) { moAttrSourceMap[TempAttr.AttrName] = moDefaultSource; } moCustomOpMap = moOrchInitData.BlockchainCustomOpFunctions; #endregion // We initialize the proxy that will be used to communicate with the Registry on the blockchain Wonka.Eth.Contracts.WonkaRuleTreeRegistry WonkaRegistry = Wonka.Eth.Contracts.WonkaRuleTreeRegistry.CreateInstance(moWonkaRegistryInit.BlockchainRegistry.ContractSender, moWonkaRegistryInit.BlockchainRegistry.ContractPassword, moWonkaRegistryInit.BlockchainRegistry.ContractAddress, moWonkaRegistryInit.BlockchainRegistry.ContractABI, moWonkaRegistryInit.Web3HttpUrl); // Here, the data domain is serialized to the blockchain for use by the RuleTree(s) RefEnv.Serialize(moOrchInitData.BlockchainEngineOwner, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka, moOrchInitData.Web3HttpUrl); }
// This constructor will be called in the case that we wish to initialize the framework // with provided parameters public WonkaCQSOrchTest(string psSenderAddress, string psPassword, string psWonkaContractAddress, string psOrchContractAddress) { var TmpAssembly = Assembly.GetExecutingAssembly(); moAttrSourceMap = new Dictionary <string, WonkaBizSource>(); moCustomOpMap = new Dictionary <string, WonkaBizSource>(); // Read the ABI of the Ethereum contract for the Wonka rules engine using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.WonkaEngine.abi"))) { msAbiWonka = AbiReader.ReadToEnd(); } // Read the ABI of the Ethereum contract that will demonstrate both our Custom Operator functionality and our Orchestration functionality using (var AbiReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.OrchTest.abi"))) { msAbiOrchContract = AbiReader.ReadToEnd(); } // Read the XML markup that lists the business rules using (var RulesReader = new StreamReader(TmpAssembly.GetManifestResourceStream("WonkaSystem.TestData.VATCalculationExample.xml"))) { msRulesContents = RulesReader.ReadToEnd(); } // Using the metadata source, we create an instance of a defined data domain WonkaRefEnvironment RefEnv = WonkaRefEnvironment.CreateInstance(false, moMetadataSource); msSenderAddress = psSenderAddress; msPassword = psPassword; moMetadataSource = new WonkaMetadataTestSource(); if (psWonkaContractAddress == null) { msWonkaContractAddress = DeployWonkaContract(); } else { msWonkaContractAddress = psWonkaContractAddress; } if (psOrchContractAddress == null) { msOrchContractAddress = DeployOrchestrationContract(); } else { msOrchContractAddress = psOrchContractAddress; } // Serialize the data domain to the blockchain RefEnv.Serialize(msSenderAddress, msPassword, msSenderAddress, msWonkaContractAddress, msAbiWonka); moDefaultSource = new WonkaBizSource(CONST_ORCH_CONTRACT_MARKUP_ID, msSenderAddress, msPassword, psOrchContractAddress, msAbiOrchContract, CONST_ORCH_CONTRACT_GET_METHOD, CONST_ORCH_CONTRACT_SET_METHOD, RetrieveValueMethod); // 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) { moAttrSourceMap[TempAttr.AttrName] = moDefaultSource; } Dictionary <string, WonkaBizSource> CustomOpSourceMap = new Dictionary <string, WonkaBizSource>(); // Here a mapping is created, where each Custom Operator points to a specific contract and its "implementation" method // - the class that contains this information (contract, accessors, etc.) is of the WonkaBreSource type WonkaBizSource CustomOpSource = new WonkaBizSource(CONST_CUSTOM_OP_MARKUP_ID, msSenderAddress, msPassword, psOrchContractAddress, msAbiOrchContract, LookupVATDenominator, CONST_CUSTOM_OP_CONTRACT_METHOD); moCustomOpMap[CONST_CUSTOM_OP_MARKUP_ID] = CustomOpSource; }