async Task <T> ExecuteContract <T>(params object[] values) { var web3 = new Web3(_providerUrl); var unlockAccountResult = await web3.Personal.UnlockAccount.SendRequestAsync(_senderAddress, _password, _unlockAccountDuration); return(await web3.Eth.GetContract(ZenCsScriptCore.Decode(_abi), _contractAddress).GetFunction(_functionName).CallAsync <T>(values)); }
// Parse "result" tags and create assembly for dynamically getting results from elements, that are then input args to smart contract function void InitializeScript(Hashtable elements, IPlugin element) { lock (_syncCsScript) { if (_scripts == null) { string sFunctions = string.Empty; foreach (string args in Regex.Split(ZenCsScriptCore.Decode(element.GetElementProperty("SCTRANSACTION_PARAMETERS")), "¨")) { if (!string.IsNullOrEmpty(args)) { sFunctions += ZenCsScriptCore.GetFunction("return " + args + ";"); } } _scripts = ZenCsScriptCore.Initialize(sFunctions, elements, element, Path.Combine("tmp", "SmartContractTransaction", element.ID + ".zen"), ParentBoard, element.GetElementProperty("PRINT_CODE") == "1"); } } }
/** * Second in series of element callbacks. * Save visual element properties, parse and prepare dynamic calls for CONTRACT_PARAMS property */ public void OnNodeInit(Hashtable elements, IPlugin element) { // Provider url ("http://localhost:8545") _providerUrl = element.GetElementProperty("PROVIDER_URL"); // Message value ("0"). Number of wei sent with the message. _messageValue = element.GetElementProperty("MESSAGE_VALUE"); // Default gas value. ("290000") _defaultGas = string.IsNullOrEmpty(element.GetElementProperty("DEFAUT_GAS")) ? "290000" : element.GetElementProperty("DEFAUT_GAS"); // Smart contract address ("0x97a93e68fa58513facb2b702a97597cab97afd6f") _contractAddress = element.GetElementProperty("SMART_CONTRACT_ADDRESS"); // Smart contract ABI ([{""constant"":false,""inputs"":[{""name"":""tvConsumption"",""type"":""int256""}, // {""name"":""washingMachineConsumption"",""type"":""int256""}],""name"":""saveConsumptions"",""outputs"":[], // ""payable"":false,""stateMutability"":""nonpayable"",""type"":""function""},{""constant"":false,""inputs"":[], // ""name"":""getConsumptions"",""outputs"":[{""name"":""sumConsumption"",""type"":""int256""}],""payable"":false, // ""stateMutability"":""nonpayable"",""type"":""function""},{""inputs"":[{""name"":""tvConsumption"",""type"":""int256""}, // {""name"":""washingMachineConsumption"",""type"":""int256""}],""payable"":false,""stateMutability"":""nonpayable"", // ""type"":""constructor""}]) _abi = ZenCsScriptCore.Decode(element.GetElementProperty("ABI")); // Name of smart contract function to be called ("saveConsumptions") _functionName = element.GetElementProperty("FUNCTION_NAME"); // Get private key from keystore file var json = File.OpenText(element.GetElementProperty("KEYSTORE_FILE")).ReadToEnd(); var service = new KeyStoreService(); _privateKey = service.DecryptKeyStoreFromJson(element.GetElementProperty("KEYSTORE_FILE_PASSWORD"), json).ToHex(); _address = service.GetAddressFromKeyStore(json); // Parse result tags (<result>Element Id</result>) defined by user and dynamically create assembly that will query element results. InitializeScript(elements, element); }