/// <summary>
        /// 异步 通用合约部署,只返回交易Hash
        /// </summary>
        /// <param name="binCode">合约内容</param>
        /// <returns>交易Hash</returns>
        public async Task <string> DeployContractAsync(string binCode, string abi = null, params object[] values)
        {
            var blockNumber = await GetBlockNumberAsync();

            var resultData = "";
            ConstructorCallEncoder _constructorCallEncoder = new ConstructorCallEncoder();

            if (values == null || values.Length == 0)
            {
                resultData = _constructorCallEncoder.EncodeRequest(binCode, "");
            }

            var des      = new ABIDeserialiser();
            var contract = des.DeserialiseContract(abi);

            if (contract.Constructor == null)
            {
                throw new Exception(
                          "Parameters supplied for a constructor but ABI does not contain a constructor definition");
            }
            resultData = _constructorCallEncoder.EncodeRequest(binCode,
                                                               contract.Constructor.InputParameters, values);

            var transParams = BuildTransactionParams(resultData, blockNumber, "");
            var tx          = BuildRLPTranscation(transParams);

            tx.Sign(new EthECKey(this._privateKey.HexToByteArray(), true));
            var result = await SendRequestAysnc <string>(tx.Data, tx.Signature);

            return(result);
        }
示例#2
0
        public string GetData(string contractByteCode, string abi, params object[] values)
        {
            var contract = abiDeserialiser.DeserialiseContract(abi);

            return(constructorCallEncoder.EncodeRequest(contractByteCode,
                                                        contract.Constructor.InputParameters, values));
        }
示例#3
0
        /// <summary>
        /// 同步 通用合约部署,只返回交易Hash
        /// </summary>
        /// <param name="binCode">合约内容</param>
        /// <returns>交易Hash</returns>
        public string DeployContract(string binCode, string abi = null, params object[] values)
        {
            var blockNumber = GetBlockNumber();
            var resultData  = "";
            ConstructorCallEncoder _constructorCallEncoder = new ConstructorCallEncoder();

            var des      = new ABIDeserialiser();
            var contract = des.DeserialiseContract(abi);

            if (contract.Constructor != null)
            {
                if (values != null)
                {
                    resultData = _constructorCallEncoder.EncodeRequest(binCode,
                                                                       contract.Constructor.InputParameters, values);
                }
                else
                {
                    resultData = _constructorCallEncoder.EncodeRequest(binCode, "");
                }
            }
            else
            {
                resultData = binCode;
            }
            var transParams = BuildTransactionParams(resultData, blockNumber, "");
            var tx          = BuildRLPTranscation(transParams);

            tx.Sign(new EthECKey(this._privateKey.HexToByteArray(), true));
            var result = SendRequest <object>(tx.Data, tx.Signature);

            return(Convert.ToString(result));
        }
        private TransactionInput BuildTransaction(string abi, string contractByteCode, string from, HexBigInteger gas, object[] values)
        {
            var contract    = abiDeserialiser.DeserialiseContract(abi);
            var encodedData = constructorCallEncoder.EncodeRequest(contractByteCode,
                                                                   contract.Constructor.InputParameters, values);
            var transaction = new TransactionInput(encodedData, gas, from);

            return(transaction);
        }
示例#5
0
        public Task <string> SendRequestAsync(string abi, string contractByteCode, string from, HexBigInteger gas,
                                              params object[] values)
        {
            var contract    = abiDeserialiser.DeserialiseContract(abi);
            var encodedData = constructorCallEncoder.EncodeRequest(contractByteCode,
                                                                   contract.Constructor.InputParameters, values);

            return(ethSendTransaction.SendRequestAsync(new TransactionInput(encodedData, gas, @from)));
        }