Esempio n. 1
0
        public async Task <string> CreateAsync(
            string task_uuid,
            string pid, string psn,
            string tenant_id,
            string start_date_time, string end_date_time,
            string start_date_time_local, string end_date_time_local,
            BigInteger?nonce = null)
        {
            _logger.LogDebug("FDBC_Nethereum.SmartContracts.Policy.CreateAsync({task_uuid})", task_uuid);

            string sender_address    = _settings.default_sender_address;
            string contract_abi      = _settings.policy_contract_abi;
            string contract_bytecode = _settings.policy_contract_bytecode;

            ////====================================
            //// deploy contract
            var from     = sender_address;
            var gasLimit = new HexBigInteger(4700000);
            var wei      = new HexBigInteger(0);

            object[] values = new object[] {
                task_uuid,
                pid, psn,
                tenant_id,
                start_date_time, end_date_time,
                start_date_time_local, end_date_time_local
            };


            string tx_hash = "";

            if (nonce != null)
            {
                string data = web3geth.Eth.DeployContract.GetData(contract_bytecode, contract_abi, values);
                Nethereum.Signer.Transaction signable_transcation = new Nethereum.Signer.Transaction(
                    to: null, amount: wei, nonce: (BigInteger)nonce,
                    gasPrice: Nethereum.Signer.Transaction.DEFAULT_GAS_PRICE,
                    gasLimit: gasLimit.Value,
                    data: data
                    );

                tx_hash = await _blockchain_manager.SignAndSendRawTransaction(signable_transcation);
            }
            else
            {
                tx_hash = await web3geth.Eth.DeployContract.SendRequestAsync(
                    abi : contract_abi,
                    contractByteCode : contract_bytecode,
                    from : from,
                    gas : gasLimit,
                    value : wei,
                    values : values);
            }

            return(tx_hash);
        }