Esempio n. 1
0
        public object Get(GetPolicyList request)
        {
            // Get the contract for the Policy by specifying the Policy address
            var contract = AppServices.web3.Eth.GetContract(AppModelConfig.POLICY.abi, AppServices.GetEcosystemAdr(request.ContractAdr).PolicyContractAdr);

            // Create the Policy list object and initialise
            PolicyList list = new PolicyList()
            {
                Items = new List <PolicyDetail>()
            };

            // If no Policy Owner Address has been specified return all the Policys starting from lastIdx in decending order
            if (request.Owner.IsEmpty() == true)
            {
                // Get the metadata info for the first, next and count of Policys
                list.Info = contract.GetFunction("hashMap").CallDeserializingToObjectAsync <ListInfo>().Result;
                // Create the idx to continue the search from
                int lastIdx = (request.FromIdx != 0 ? (int)request.FromIdx :(int)list.Info.CountAllItems);
                // Define the lower bound
                int lowerBoundIdx = Math.Max(0, lastIdx -
                                             (request.MaxEntries != 0 ? (int)request.MaxEntries : (int)AppModelConfig.defaultNumberEntriesForLazyLoading));
                // Iterate through all the possilbe Policy entries
                for (int i = lastIdx; i > lowerBoundIdx; i--)
                {
                    string PolicyHash = AppModelConfig.convertToHex(contract.GetFunction("get").CallAsync <byte[]>(i).Result);
                    // Add the PolicyDetails to the list if a valid hash has been returned
                    if (AppModelConfig.isEmptyHash(PolicyHash) == false)
                    {
                        var Policy = contract.GetFunction("dataStorage").CallDeserializingToObjectAsync <PolicyDetail>(PolicyHash.HexToByteArray()).Result;
                        Policy.Hash = PolicyHash;
                        list.Items.Add(Policy);
                    }
                }
            }
            else
            {
                // Get all the log files that match the Policy owner's address specified
                List <PolicyEventLog> logs = ((PolicyLogs)this.Get(
                                                  new GetPolicyLogs {
                    ContractAdr = request.ContractAdr, Owner = request.Owner
                })).EventLogs;
                // Filter the list only for Created state entries and sort it with timestamp desc
                var filteredList = logs.GroupBy(x => x.Hash).Select(x => x.FirstOrDefault()).ToList().OrderByDescending(o => o.Timestamp).ToList();
                // Iterate through the list
                for (int i = 0; i < filteredList.Count; i++)
                {
                    var Policy = contract.GetFunction("dataStorage").CallDeserializingToObjectAsync <PolicyDetail>(filteredList[i].Hash.HexToByteArray()).Result;
                    Policy.Hash = filteredList[i].Hash;
                    list.Items.Add(Policy);
                }
            }

            // Return the Policy list
            return(list);
        }
Esempio n. 2
0
        public object Get(GetEcosystemConfiguration request)
        {
            // Using the request's contract address provided, retrieve all the ecosystem's addresses to get the pool address
            EcosystemContractAddresses adr = AppServices.GetEcosystemAdr(request.ContractAdr);

            // Create the return instance
            EcosystemConfiguration setup = new EcosystemConfiguration();

            // Load the trust contract to retrieve the external access interface duration for pre-authorisation
            var contract = AppServices.web3.Eth.GetContract(AppModelConfig.EXTACCESSI.abi, adr.TrustContractAdr);

            // Pre-authorisation duration for external authentication
            setup.EXT_ACCESS_PRE_AUTH_DURATION_SEC = contract.GetFunction("EXT_ACCESS_PRE_AUTH_DURATION_SEC").CallAsync <ulong>().Result;

            // Get the contract for the Pool by specifying the pool address
            contract        = AppServices.web3.Eth.GetContract(AppModelConfig.SETUPI.abi, adr.PoolContractAdr);
            setup.POOL_NAME = contract.GetFunction("POOL_NAME").CallAsync <string>().Result;

            // Constants used by the Insurance Pool
            setup.WC_POOL_TARGET_TIME_SEC           = contract.GetFunction("WC_POOL_TARGET_TIME_SEC").CallAsync <ulong>().Result;
            setup.DURATION_TO_BOND_MATURITY_SEC     = contract.GetFunction("DURATION_TO_BOND_MATURITY_SEC").CallAsync <ulong>().Result;
            setup.DURATION_BOND_LOCK_NEXT_STATE_SEC = contract.GetFunction("DURATION_BOND_LOCK_NEXT_STATE_SEC").CallAsync <ulong>().Result;
            setup.DURATION_WC_EXPENSE_HISTORY_DAYS  = contract.GetFunction("DURATION_WC_EXPENSE_HISTORY_DAYS").CallAsync <ulong>().Result;

            // Yield constants
            setup.YAC_PER_INTERVAL_PPB      = contract.GetFunction("YAC_PER_INTERVAL_PPB").CallAsync <ulong>().Result;
            setup.YAC_INTERVAL_DURATION_SEC = contract.GetFunction("YAC_INTERVAL_DURATION_SEC").CallAsync <ulong>().Result;
            setup.YAC_EXPENSE_THRESHOLD_PPT = contract.GetFunction("YAC_EXPENSE_THRESHOLD_PPT").CallAsync <ulong>().Result;
            setup.MIN_YIELD_PPB             = contract.GetFunction("MIN_YIELD_PPB").CallAsync <ulong>().Result;
            setup.MAX_YIELD_PPB             = contract.GetFunction("MAX_YIELD_PPB").CallAsync <ulong>().Result;

            // Bond constants
            setup.MIN_BOND_PRINCIPAL_CU = contract.GetFunction("MIN_BOND_PRINCIPAL_CU").CallAsync <ulong>().Result;
            setup.MAX_BOND_PRINCIPAL_CU = contract.GetFunction("MAX_BOND_PRINCIPAL_CU").CallAsync <ulong>().Result;
            setup.BOND_REQUIRED_SECURITY_REFERENCE_PPT = contract.GetFunction("BOND_REQUIRED_SECURITY_REFERENCE_PPT").CallAsync <ulong>().Result;

            // Policy constants
            setup.MIN_POLICY_CREDIT_CU = contract.GetFunction("MIN_POLICY_CREDIT_CU").CallAsync <ulong>().Result;
            setup.MAX_POLICY_CREDIT_CU = contract.GetFunction("MAX_POLICY_CREDIT_CU").CallAsync <ulong>().Result;
            setup.MAX_DURATION_POLICY_RECONCILIATION_DAYS = contract.GetFunction("MAX_DURATION_POLICY_RECONCILIATION_DAYS").CallAsync <ulong>().Result;
            setup.POLICY_RECONCILIATION_SAFETY_MARGIN     = contract.GetFunction("POLICY_RECONCILIATION_SAFETY_MARGIN").CallAsync <ulong>().Result;
            setup.MIN_DURATION_POLICY_PAUSED_DAY          = contract.GetFunction("MIN_DURATION_POLICY_PAUSED_DAY").CallAsync <ulong>().Result;
            setup.MAX_DURATION_POLICY_PAUSED_DAY          = contract.GetFunction("MAX_DURATION_POLICY_PAUSED_DAY").CallAsync <ulong>().Result;
            setup.DURATION_POLICY_POST_LAPSED_DAY         = contract.GetFunction("DURATION_POLICY_POST_LAPSED_DAY").CallAsync <ulong>().Result;
            setup.MAX_DURATION_POLICY_LAPSED_DAY          = contract.GetFunction("MAX_DURATION_POLICY_LAPSED_DAY").CallAsync <ulong>().Result;

            // Pool processing costants
            setup.POOL_DAILY_PROCESSING_OFFSET_SEC    = contract.GetFunction("POOL_DAILY_PROCESSING_OFFSET_SEC").CallAsync <ulong>().Result;
            setup.POOL_DAYLIGHT_SAVING_ADJUSTMENT_SEC = contract.GetFunction("POOL_DAYLIGHT_SAVING_ADJUSTMENT_SEC").CallAsync <ulong>().Result;
            setup.POOL_TIME_ZONE_OFFSET = contract.GetFunction("POOL_TIME_ZONE_OFFSET").CallAsync <long>().Result;

            // Operator and Trust fees
            setup.POOL_OPERATOR_FEE_PPT = contract.GetFunction("POOL_OPERATOR_FEE_PPT").CallAsync <ulong>().Result;
            setup.TRUST_FEE_PPT         = contract.GetFunction("TRUST_FEE_PPT").CallAsync <ulong>().Result;

            // Hashes of the bank account owner and bank account number (sha3(accountOwner, accountNumber))
            setup.PREMIUM_ACCOUNT_PAYMENT_HASH    = AppModelConfig.convertToHex(contract.GetFunction("PREMIUM_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.BOND_ACCOUNT_PAYMENT_HASH       = AppModelConfig.convertToHex(contract.GetFunction("BOND_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.FUNDING_ACCOUNT_PAYMENT_HASH    = AppModelConfig.convertToHex(contract.GetFunction("FUNDING_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.TRUST_ACCOUNT_PAYMENT_HASH      = AppModelConfig.convertToHex(contract.GetFunction("TRUST_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.OPERATOR_ACCOUNT_PAYMENT_HASH   = AppModelConfig.convertToHex(contract.GetFunction("OPERATOR_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.SETTLEMENT_ACCOUNT_PAYMENT_HASH = AppModelConfig.convertToHex(contract.GetFunction("SETTLEMENT_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);
            setup.ADJUSTOR_ACCOUNT_PAYMENT_HASH   = AppModelConfig.convertToHex(contract.GetFunction("ADJUSTOR_ACCOUNT_PAYMENT_HASH").CallAsync <string>().Result);

            return(setup);
        }