Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public ConstructorABI BuildConstructor(IDictionary <string, object> constructor)
        {
            var constructorABI = new ConstructorABI();

            constructorABI.InputParameters = BuildFunctionParameters((List <object>)constructor["inputs"]);
            return(constructorABI);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
        public ContractDeploymentCQSMessageGeneratorTests()
        {
            var constructorAbi = new ConstructorABI {
                InputParameters = new[] { new ParameterABI("uint256", "totalSupply") }
            };

            _contractDeploymentCqsMessageGenerator = new ContractDeploymentCQSMessageGenerator(
                constructorAbi, namespaceName: "DefaultNamespace", byteCode: "0x123456789", contractName: "StandardContract");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
        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)}
}}
");
        }
        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);
        }
        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}}}");
        }
 public string GenerateClass(ConstructorABI abi, string byteCode, string contractName)
 {
     return(template.GenerateClass(abi, byteCode, contractName));
 }
Ejemplo n.º 14
0
 public ConstructorABI BuildConstructor(dynamic constructor)
 {
     var constructorABI = new ConstructorABI();
     constructorABI.InputParameters = BuildFunctionParameters(constructor.inputs);
     return constructorABI;
 }
Ejemplo n.º 15
0
 public ConstructorABI BuildConstructor(IDictionary<string, object> constructor)
 {
     var constructorABI = new ConstructorABI();
     constructorABI.InputParameters = BuildFunctionParameters((List<object>) constructor["inputs"]);
     return constructorABI;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 17
0
 public ConstructorABIToProtoGenerator(ConstructorABI constructorABI, string name)
 {
     ClassModel    = new ConstructorABIToProtoModel(constructorABI, name, "CreateRequest");
     ClassTemplate = new ConstructorABIToProtoTemplate(ClassModel);
 }
 public ConstructorABIToProtoModel(ConstructorABI constructorABI, string name, string classNameSuffix) : base("", name, classNameSuffix)
 {
     ConstructorAbi  = constructorABI;
     CodeGenLanguage = CodeGenLanguage.Proto;
 }