public object Post(DeployContracts request)
        {
            // Deploy the library contract and await until the transaction has been mined
            TransactionHash libTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.LIB.abi,
                AppModelConfig.LIB.bytecode,
                request.SigningPrivateKey,
                null);
            TransactionResult libTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = libTransactionHash.Hash
            });

            // Deploy the trust contract and await until the transaction has been mined
            TransactionHash trustTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.TRUST.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.TRUST.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                null);
            TransactionResult trustTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = trustTransactionHash.Hash
            });

            // Deploy the pool contract
            TransactionHash poolTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.POOL.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.POOL.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult poolTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = poolTransactionHash.Hash
            });

            // Deploy the bond contract
            TransactionHash bondTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.BOND.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.BOND.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult bondTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = bondTransactionHash.Hash
            });

            // Deploy the bank contract
            TransactionHash bankTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.BANK.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.BANK.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult bankTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = bankTransactionHash.Hash
            });

            // Deploy the policy contract
            TransactionHash policyTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.POLICY.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.POLICY.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult policyTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = policyTransactionHash.Hash
            });

            // Deploy the claim contract
            TransactionHash settlementTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.SETTLEMENT.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.SETTLEMENT.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult settlementTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = settlementTransactionHash.Hash
            });

            // Deploy the adjustor contract
            TransactionHash adjustorTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.ADJUSTOR.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.ADJUSTOR.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult adjustorTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = adjustorTransactionHash.Hash
            });

            // Deploy the timer contract
            TransactionHash timerTransactionHash = AppServices.createSignDeployContract(
                AppModelConfig.TIMER.abi,
                AppModelConfig.linkContractBytecode(AppModelConfig.TIMER.bytecode, "Lib", libTransResult.ContractAddress),
                request.SigningPrivateKey,
                trustTransResult.ContractAddress);
            TransactionResult timerTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = timerTransactionHash.Hash
            });

            // Submit and return the transaction hash of the broadcasted transaction
            TransactionHash initEcosytemHash = AppServices.createSignPublishTransaction(
                AppModelConfig.TRUST.abi,
                trustTransResult.ContractAddress,
                request.SigningPrivateKey,
                "initEcosystem",
                poolTransResult.ContractAddress,            // pool
                bondTransResult.ContractAddress,            // bond
                bankTransResult.ContractAddress,            // bank
                policyTransResult.ContractAddress,          // policy
                settlementTransResult.ContractAddress,      // settlement
                adjustorTransResult.ContractAddress,        // adjustor
                timerTransResult.ContractAddress,           // timer
                request.IsWinterTime
                );

            // Get the transaction result
            TransactionResult initTransResult = (TransactionResult)Get(new GetReceipt {
                TransactionHash = initEcosytemHash.Hash
            });

            // Return the addresses of the newly created contracts
            return(new EcosystemContractAddresses {
                TrustContractAdr = trustTransResult.ContractAddress,
                PoolContractAdr = poolTransResult.ContractAddress,
                BondContractAdr = bondTransResult.ContractAddress,
                BankContractAdr = bankTransResult.ContractAddress,
                PolicyContractAdr = policyTransResult.ContractAddress,
                SettlementContractAdr = settlementTransResult.ContractAddress,
                AdjustorContractAdr = adjustorTransResult.ContractAddress,
                TimerContractAdr = timerTransResult.ContractAddress
            });
        }
Exemplo n.º 2
0
        public object Get(GetPolicyLogs request)
        {
            // Retrieve the block parameters
            (BlockParameter fromBlock, BlockParameter toBlock) = AppServices.getBlockParameterConfiguration(request.FromBlock, request.ToBlock,
                                                                                                            (request.Hash.IsEmpty() == true) && (request.Owner.IsEmpty() == true) && (request.Info.IsEmpty() == true));

            // Create the filter variables for selecting only the requested log entries
            object[] ft1 = (request.Hash.IsEmpty() == true ? null : new object[] { request.Hash.HexToByteArray() });
            object[] ft2 = (request.Owner.IsEmpty() == true ? null : new object[] { request.Owner });
            object[] ft3 = (request.Info.IsEmpty() == true ? null : new object[1]);

            // Adjust the filterinpu for ft3 if a value has been provided
            if (request.Info.IsEmpty() == false)
            {
                if (request.Info.HasHexPrefix() == true)
                {
                    ft3[0] = request.Info.HexToByteArray();
                }
                else if (uint.TryParse(request.Info, out uint val) == true)
                {
                    ft3[0] = val.ToString("X64").EnsureHexPrefix().HexToByteArray();
                }
            }

            // Retrieve the contract info
            var contract = AppServices.web3.Eth.GetContract(AppModelConfig.POLICY.abi, AppServices.GetEcosystemAdr(request.ContractAdr).PolicyContractAdr);

            // Create the filter input to extract the requested log entries
            var filterInput = contract.GetEvent("LogPolicy").CreateFilterInput(filterTopic1: ft1, filterTopic2: ft2, filterTopic3: ft3, fromBlock: fromBlock, toBlock: toBlock);

            // Extract all the logs as specified by the filter input
            var res = AppServices.web3.Eth.Filters.GetLogs.SendRequestAsync(filterInput).Result;

            // Create the return instance
            var logs = new PolicyLogs()
            {
                EventLogs = new List <PolicyEventLog>()
            };

            // Interate through all the returned logs and add them to the logs list
            for (int i = res.Length - 1; i >= 0; i--)
            {
                var log = new PolicyEventLog();
                log.BlockNumber = Convert.ToUInt64(res[i].BlockNumber.HexValue, 16);
                log.Hash        = res[i].Topics[1].ToString();
                log.Owner       = AppModelConfig.getAdrFromString32(res[i].Topics[2].ToString());
                log.Timestamp   = Convert.ToUInt64(res[i].Data.Substring(2 + 0 * 64, 64), 16);
                log.State       = (PolicyState)Convert.ToInt32(res[i].Data.Substring(2 + 1 * 64, 64), 16);

                if (AppModelConfig.isEmptyHash(res[i].Topics[3].ToString()) == true)
                {
                    log.Info = "";
                }
                else if (res[i].Topics[3].ToString().StartsWith("0x000000") == true)
                {
                    log.Info = Convert.ToInt64(res[i].Topics[3].ToString(), 16).ToString();
                }
                else
                {
                    log.Info = res[i].Topics[3].ToString();
                }
                logs.EventLogs.Add(log);
            }

            // Return the list of Policy logs
            return(logs);
        }