コード例 #1
0
        public ContractABI DeserialiseContract(string abi)
        {
            var            convertor   = new ExpandoObjectConverter();
            var            contract    = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(abi, convertor);
            var            functions   = new List <FunctionABI>();
            var            events      = new List <EventABI>();
            ConstructorABI constructor = null;

            foreach (IDictionary <string, object> element in contract)
            {
                if ((string)element["type"] == "function")
                {
                    functions.Add(BuildFunction(element));
                }
                if ((string)element["type"] == "event")
                {
                    events.Add(BuildEvent(element));
                }
                if ((string)element["type"] == "constructor")
                {
                    constructor = BuildConstructor(element);
                }
            }

            var contractABI = new ContractABI();

            contractABI.Functions   = functions.ToArray();
            contractABI.Constructor = constructor;
            contractABI.Events      = events.ToArray();

            return(contractABI);
        }
コード例 #2
0
        public ConstructorABI BuildConstructor(IDictionary <string, object> constructor)
        {
            var constructorABI = new ConstructorABI();

            constructorABI.InputParameters = BuildFunctionParameters((List <object>)constructor["inputs"]);
            return(constructorABI);
        }
コード例 #3
0
        public string GenerateMethods(string contractName, ConstructorABI constructor)
        {
            var messageType         = _contractDeploymentCQSMessageModel.GetContractDeploymentMessageTypeName(contractName);
            var messageVariableName =
                _contractDeploymentCQSMessageModel.GetContractDeploymentMessageVariableName(contractName);

            var sendRequestReceipt =
                $@"{SpaceUtils.TwoTabs}public Task<TransactionReceipt> DeployContractAndWaitForReceiptAsync(Web3 web3, {messageType} {messageVariableName}, CancellationTokenSource cancellationTokenSource = null)
{SpaceUtils.TwoTabs}{{
{SpaceUtils.ThreeTabs} web3.Eth.GetContractDeploymentHandler<{messageType}>().SendRequestAndWaitForReceiptAsync({messageVariableName}, cancellationTokenSource);
{SpaceUtils.TwoTabs}}}";


            var sendRequest =
                $@"{SpaceUtils.TwoTabs}public Task<string> DeployContractAsync(Web3 web3, {messageType} {messageVariableName})
{SpaceUtils.TwoTabs}{{
{SpaceUtils.ThreeTabs} web3.Eth.GetContractDeploymentHandler<{messageType}>().SendRequestAsync({messageVariableName});
{SpaceUtils.TwoTabs}}}";

            var sendRequestContract =
                $@"{SpaceUtils.TwoTabs}public Task<string> DeployContractAndGetServiceAsyc(Web3 web3, {messageType} {messageVariableName}, CancellationTokenSource cancellationTokenSource = null)
{SpaceUtils.TwoTabs}{{
{SpaceUtils.ThreeTabs} web3.Eth.GetContractDeploymentHandler<{messageType}>().SendRequestAsync({messageVariableName});
{SpaceUtils.TwoTabs}}}";

            return(null);
        }
コード例 #4
0
        private ContractABI DeserialiseContractBody(List <IDictionary <string, object> > contract)
        {
            var            functions   = new List <FunctionABI>();
            var            events      = new List <EventABI>();
            ConstructorABI constructor = null;

            foreach (IDictionary <string, object> element in contract)
            {
                if ((string)element["type"] == "function")
                {
                    functions.Add(BuildFunction(element));
                }
                if ((string)element["type"] == "event")
                {
                    events.Add(BuildEvent(element));
                }
                if ((string)element["type"] == "constructor")
                {
                    constructor = BuildConstructor(element);
                }
            }

            var contractABI = new ContractABI();

            contractABI.Functions   = functions.ToArray();
            contractABI.Constructor = constructor;
            contractABI.Events      = events.ToArray();

            return(contractABI);
        }
 public ContractDeploymentCQSMessageModel(ConstructorABI constructorABI, string @namespace, string byteCode, string contractName)
     : base(@namespace, contractName, "Deployment")
 {
     ConstructorABI = constructorABI;
     ByteCode       = byteCode;
     InitisialiseNamespaceDependencies();
 }
        static ContractDeploymentCQSMessageGenerator CreateGenerator()
        {
            var constructorAbi = new ConstructorABI {
                InputParameters = new[] { new ParameterABI("uint256", "totalSupply") }
            };

            return(new ContractDeploymentCQSMessageGenerator(
                       constructorAbi, namespaceName: "DefaultNamespace", byteCode: "0x123456789", contractName: "StandardContract", codeGenLanguage: CodeGenLanguage.CSharp));
        }
コード例 #7
0
        public ContractDeploymentCQSMessageGeneratorTests()
        {
            var constructorAbi = new ConstructorABI {
                InputParameters = new[] { new ParameterABI("uint256", "totalSupply") }
            };

            _contractDeploymentCqsMessageGenerator = new ContractDeploymentCQSMessageGenerator(
                constructorAbi, namespaceName: "DefaultNamespace", byteCode: "0x123456789", contractName: "StandardContract");
        }
コード例 #8
0
        public ConstructorABI ExtractConstructorABI(string signature, string name, string parameters)
        {
            var constructor = new ConstructorABI();

            constructor.InputParameters = new List <Parameter>().ToArray();
            if (!string.IsNullOrEmpty(parameters))
            {
                constructor.InputParameters = ExtractParameters(parameters).ToArray();
            }
            return(constructor);
        }
コード例 #9
0
        public void GeneratesExpectedProtoBufferContent()
        {
            var constructorAbi = new ConstructorABI()
            {
                InputParameters = new[]
                {
                    new ParameterABI("bytes32", "ownerId", 1)
                }
            };

            var functionAbi1 = new FunctionABI("recordHousePurchase", false)
            {
                InputParameters = new[]
                {
                    new ParameterABI("bytes32", "propertyId", 1),
                    new ParameterABI("bytes32", "buyerId", 2),
                    new ParameterABI("uint32", "date", 3),
                    new ParameterABI("uint32", "price", 4),
                },
                OutputParameters = new[]
                {
                    new ParameterABI("uint"),
                }
            };

            var eventAbi1 = new EventABI("HousePurchased")
            {
                InputParameters = new[]
                {
                    new ParameterABI("int32", "purchaseId", 1),
                    new ParameterABI("bytes32", "propertyId", 2),
                    new ParameterABI("bytes32", "buyerId", 3),
                    new ParameterABI("uint32", "date", 4),
                    new ParameterABI("uint32", "price", 5),
                }
            };

            var contractABI = new ContractABI
            {
                Constructor = constructorAbi,
                Functions   = new[] { functionAbi1 },
                Events      = new[] { eventAbi1 }
            };

            var generator = new ContractABIToProtoGenerator(contractABI, "Proxy.Ethereum.Samples.HousePurchase", "HousePurchase");
            var actualProtoFileContent = generator.GenerateFileContent();

            var expectedContent = GetExpectedProtoContent("ContractABIToProto.01.proto");

            Assert.Equal(expectedContent, actualProtoFileContent);
        }
コード例 #10
0
        public string GenerateFullClass(ConstructorABI constructorABI, string namespaceName, string byteCode, string contractName)
        {
            return
                ($@"using System;
using System.Threading.Tasks;
using System.Numerics;
using Nethereum.Hex.HexTypes;
using Nethereum.ABI.FunctionEncoding.Attributes;
namespace {namespaceName}
{{
{GenerateClass(constructorABI, byteCode, contractName)}
}}
");
        }
コード例 #11
0
        public ContractABI DeserialiseABI(string abi)
        {
            var expandoObjectConverter = new ExpandoObjectConverter();
            var dictionaryList         = JsonConvert.DeserializeObject <List <IDictionary <string, object> > >(abi, expandoObjectConverter);
            var functionAbiList        = new List <FunctionABI>();
            var eventAbiList           = new List <EventABI>();
            var errorAbiList           = new List <ErrorABI>();
            var constructorAbi         = new ConstructorABI();
            var contractAbi            = new ContractABI();

            foreach (IDictionary <string, object> dictionary in dictionaryList)
            {
                if ((string)dictionary["type"] == "function")
                {
                    functionAbiList.Add(this.BuildFunction(dictionary, contractAbi));
                }
                if ((string)dictionary["type"] == "event")
                {
                    eventAbiList.Add(this.BuildEvent(dictionary, contractAbi));
                }
                if ((string)dictionary["type"] == "error")
                {
                    errorAbiList.Add(this.BuildError(dictionary, contractAbi));
                }
                if ((string)dictionary["type"] == "constructor")
                {
                    constructorAbi = this.BuildConstructor(dictionary);
                }
            }

            contractAbi.Functions   = functionAbiList.ToArray();
            contractAbi.Constructor = constructorAbi;
            contractAbi.Events      = eventAbiList.ToArray();
            contractAbi.Errors      = errorAbiList.ToArray();



            var structs = _structDeserialiser.GetStructsFromAbi(abi);

            contractAbi.Structs = structs;
            _structDeserialiser.SetTupleTypeSameAsNameIfRequired(contractAbi);

            return(contractAbi);
        }
コード例 #12
0
        public string GenerateClass(ConstructorABI constructorABI, string byteCode, string contractName)
        {
            var typeName = _contractDeploymentCQSMessageModel.GetContractDeploymentMessageTypeName(contractName);

            return
                ($@"{SpaceUtils.OneTab}public class {typeName}:ContractDeploymentMessage
{SpaceUtils.OneTab}{{
{SpaceUtils.TwoTabs}
{SpaceUtils.TwoTabs}public static string BYTECODE = ""{byteCode}"";
{SpaceUtils.TwoTabs}
{SpaceUtils.TwoTabs}public {typeName}():base(BYTECODE)
{SpaceUtils.TwoTabs}{{
{SpaceUtils.TwoTabs}}}
{SpaceUtils.TwoTabs}
{SpaceUtils.TwoTabs}public {typeName}(string byteCode):base(byteCode)
{SpaceUtils.TwoTabs}{{
{SpaceUtils.TwoTabs}}}
{SpaceUtils.TwoTabs}
{_parameterABIFunctionDTOTemplate.GenerateAllProperties(constructorABI.InputParameters)}
{SpaceUtils.OneTab}}}");
        }
コード例 #13
0
 public string GenerateClass(ConstructorABI abi, string byteCode, string contractName)
 {
     return(template.GenerateClass(abi, byteCode, contractName));
 }
コード例 #14
0
 public ConstructorABI BuildConstructor(dynamic constructor)
 {
     var constructorABI = new ConstructorABI();
     constructorABI.InputParameters = BuildFunctionParameters(constructor.inputs);
     return constructorABI;
 }
コード例 #15
0
 public ConstructorABI BuildConstructor(IDictionary<string, object> constructor)
 {
     var constructorABI = new ConstructorABI();
     constructorABI.InputParameters = BuildFunctionParameters((List<object>) constructor["inputs"]);
     return constructorABI;
 }
コード例 #16
0
 public ContractDeploymentCQSMessageGenerator(ConstructorABI abi, string namespaceName, string byteCode, string contractName, CodeGenLanguage codeGenLanguage)
 {
     ClassModel = new ContractDeploymentCQSMessageModel(abi, namespaceName, byteCode, contractName);
     ClassModel.CodeGenLanguage = codeGenLanguage;
     InitialiseTemplate(codeGenLanguage);
 }
コード例 #17
0
 public ConstructorABIToProtoGenerator(ConstructorABI constructorABI, string name)
 {
     ClassModel    = new ConstructorABIToProtoModel(constructorABI, name, "CreateRequest");
     ClassTemplate = new ConstructorABIToProtoTemplate(ClassModel);
 }
コード例 #18
0
 public ConstructorABIToProtoModel(ConstructorABI constructorABI, string name, string classNameSuffix) : base("", name, classNameSuffix)
 {
     ConstructorAbi  = constructorABI;
     CodeGenLanguage = CodeGenLanguage.Proto;
 }