public object Post(ProcessBankPaymentAdvice request) { // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.BANK, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr, request.SigningPrivateKey, "processPaymentAdvice", request.AdviceIdx, request.BankTransactionIdx )); }
public object Post(CreateSettlement request) { // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.SETTLEMENT.abi, AppServices.GetEcosystemAdr(request.ContractAdr).SettlementContractAdr, request.SigningPrivateKey, "createSettlement", request.AdjustorHash.HexToByteArray(), (AppModelConfig.isEmptyHash(request.PolicyHash) ? AppModelConfig.EMPTY_HASH.HexToByteArray() : request.PolicyHash.HexToByteArray()), (AppModelConfig.isEmptyHash(request.DocumentHash) ? AppModelConfig.EMPTY_HASH.HexToByteArray() : request.DocumentHash.HexToByteArray()) )); }
public object Put(SetExpectedSettlementAmount request) { // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.SETTLEMENT.abi, AppServices.GetEcosystemAdr(request.ContractAdr).SettlementContractAdr, request.SigningPrivateKey, "setExpectedSettlementAmount", request.SettlementHash.HexToByteArray(), request.AdjustorHash.HexToByteArray(), request.ExpectedSettlementAmount )); }
public object Post(CreateAdjustor request) { // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.TRUST, AppServices.GetEcosystemAdr(request.ContractAdr).TrustContractAdr, request.SigningPrivateKey, "createAdjustor", request.Owner, request.SettlementApprovalAmount, request.PolicyRiskPointLimit, request.ServiceAgreementHash.HexToByteArray() )); }
public object Get(GetBondLogs 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(); else ft3[0] = AppModelConfig.convertToHex64(request.Info).HexToByteArray(); } // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.BOND.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BondContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogBond").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 BondLogs() { EventLogs = new List<BondEventLog>() }; // 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 BondEventLog(); 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 = (BondState)Convert.ToInt32(res[i].Data.Substring(2 + 1 * 64,64), 16); if (AppModelConfig.isEmptyHash(log.Hash)) log.Info = AppModelConfig.FromHexString(res[i].Topics[3].ToString()); else if ((log.State == BondState.SecuredReferenceBond) || (log.State == BondState.LockedReferenceBond)) log.Info = res[i].Topics[3].ToString().EnsureHexPrefix(); else log.Info = Convert.ToInt64(res[i].Topics[3].ToString(), 16).ToString(); logs.EventLogs.Add(log); } // Return the list of bond logs return logs; }
public object Put(PingTimer request) { string timerContractAdr = AppServices.GetEcosystemAdr(request.ContractAdr).TimerContractAdr; // Activate or deactivate the auto ping scheduling functionality AppServices.configureTimerPing(timerContractAdr, request.SigningPrivateKey, request.AutoSchedulePingDuration); // Submit and return the transaction hash of the broadcasted ping transaction return(AppServices.createSignPublishTransaction( AppModelConfig.TIMER.abi, timerContractAdr, request.SigningPrivateKey, "ping" )); }
public object Put(UpdatePolicy request) { // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.POLICY.abi, AppServices.GetEcosystemAdr(request.ContractAdr).PolicyContractAdr, request.SigningPrivateKey, "updatePolicy", request.AdjustorHash.HexToByteArray(), request.PolicyHash.HexToByteArray(), request.DocumentHash.HexToByteArray(), request.RiskPoints )); }
public object Get(GetBankLogs request) { // Retrieve the block parameters (BlockParameter fromBlock, BlockParameter toBlock) = AppServices.getBlockParameterConfiguration(request.FromBlock, request.ToBlock, (request.Success == SuccessFilter.All) && (request.InternalReferenceHash.IsEmpty() == true)); // Create the filter variables for selecting only the requested log entries object[] ft1 = (request.InternalReferenceHash.IsEmpty() == true ? null : new object[] { request.InternalReferenceHash.HexToByteArray() }); object[] ft2 = { (uint)request.AccountType }; object[] ft3 = (request.Success == SuccessFilter.All ? null : (request.Success == SuccessFilter.Positive ? new object[] { true } : new object[] { false })); // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.BANK.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogBank").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 BankLogs() { EventLogs = new List <BankEventLog>() }; // 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 BankEventLog(); log.BlockNumber = Convert.ToUInt64(res[i].BlockNumber.HexValue, 16); log.InternalReferenceHash = res[i].Topics[1].ToString(); log.AccountType = (AccountType)Convert.ToUInt64(res[i].Topics[2].ToString(), 16); log.Success = res[i].Topics[3].ToString().EndsWith("1"); log.PaymentAccountHash = res[i].Data.Substring(2 + 0 * 64, 64).EnsureHexPrefix(); log.PaymentSubject = res[i].Data.Substring(2 + 1 * 64, 64).EnsureHexPrefix().StartsWith("0x000000") ? Convert.ToUInt64(res[i].Data.Substring(2 + 1 * 64, 64), 16).ToString() : res[i].Data.Substring(2 + 1 * 64, 64).EnsureHexPrefix(); log.Info = AppModelConfig.isEmptyHash(res[i].Data.Substring(2 + 2 * 64, 64).EnsureHexPrefix()) ? "0x0" : AppModelConfig.FromHexString(res[i].Data.Substring(2 + 2 * 64, 64)); log.Timestamp = Convert.ToUInt64(res[i].Data.Substring(2 + 3 * 64, 64), 16); log.TransactionType = (TransactionType)Convert.ToUInt64(res[i].Data.Substring(2 + 4 * 64, 64), 16); log.Amount = Convert.ToUInt64(res[i].Data.Substring(2 + 5 * 64, 64), 16); logs.EventLogs.Add(log); } // Return the list of bond logs return(logs); }
public object Get(GetSettlementLogs request) { // Return the requested log file entries return(new SettlementLogs() { Logs = new LogParser <SettlementLog>().parseLogs( AppModelConfig.SETTLEMENT, AppServices.GetEcosystemAdr(request.ContractAdr).SettlementContractAdr, "LogSettlement", (request.SettlementHash.IsEmpty() == true ? null : new object[] { request.SettlementHash.HexToByteArray() }), (request.AdjustorHash.IsEmpty() == true ? null : new object[] { request.AdjustorHash.HexToByteArray() }), (request.Info.IsEmpty() == true ? null : new object[] { request.Info.HexToByteArray() }), request.FromBlock, request.ToBlock, (request.SettlementHash.IsEmpty() == true) && (request.AdjustorHash.IsEmpty() == true) && (request.Info.IsEmpty() == true) ) }); }
public object Get(GetBankLogs request) { // Return the requested log file entries return(new BankLogs() { Logs = new LogParser <BankLog>().parseLogs( AppModelConfig.BANK, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr, "LogBank", (request.InternalReferenceHash.IsEmpty() == true ? null : new object[] { request.InternalReferenceHash.HexToByteArray() }), new object[] { (uint)request.AccountType }, (request.Success == SuccessFilter.All ? null : (request.Success == SuccessFilter.Positive ? new object[] { true } : new object[] { false })), request.FromBlock, request.ToBlock, (request.Success == SuccessFilter.All) && (request.InternalReferenceHash.IsEmpty() == true) ) }); }
public object Get(GetAdjustorLogs request) { // Return the requested log file entries return(new AdjustorLogs() { Logs = new LogParser <AdjustorLog>().parseLogs( AppModelConfig.ADJUSTOR, AppServices.GetEcosystemAdr(request.ContractAdr).AdjustorContractAdr, "LogAdjustor", (request.Hash.IsEmpty() == true ? null : new object[] { request.Hash.HexToByteArray() }), (request.Owner.IsEmpty() == true ? null : new object[] { request.Owner }), (request.Info.IsEmpty() == true ? null : new object[1]), request.FromBlock, request.ToBlock, (request.Hash.IsEmpty() == true) && (request.Owner.IsEmpty() == true) && (request.Info.IsEmpty() == true) ) }); }
// ******************************************************************************************** // *** TRUST // ******************************************************************************************** public object Get(GetTrustLogs request) { // Return the requested log file entries return(new TrustLogs() { Logs = new LogParser <TrustLog>().parseLogs( AppModelConfig.TRUST, AppServices.GetEcosystemAdr(request.ContractAdr).TrustContractAdr, "LogTrust", (request.Subject.IsEmpty() == true ? null : new object[] { AppModelConfig.convertToHex64(request.Subject).HexToByteArray() }), (request.Address.IsEmpty() == true ? null : new object[] { request.Address }), (request.Info.IsEmpty() == true ? null : new object[] { AppModelConfig.convertToHex64(request.Info).HexToByteArray() }), request.FromBlock, request.ToBlock, (request.Subject.IsEmpty() == true) && (request.Address.IsEmpty() == true) && (request.Info.IsEmpty() == true) ) }); }
public object Get(GetEcosystemLogs request) { // Return the requested log file entries return(new EcosystemLogs() { Logs = new LogParser <EcosystemLog>().parseLogs( AppModelConfig.POOL, AppServices.GetEcosystemAdr(request.ContractAdr).PoolContractAdr, "LogPool", (request.Subject.IsEmpty() == true ? null : new object[] { AppModelConfig.convertToHex64(request.Subject).HexToByteArray() }), (request.Day == 0 ? null : new object[] { request.Day }), (request.Value == 0 ? null : new object[] { request.Value }), request.FromBlock, request.ToBlock, (request.Subject.IsEmpty() == true) && (request.Day == 0) && (request.Value == 0) ) }); }
public object Get(GetEcosystemLogs request) { // Retrieve the block parameters (BlockParameter fromBlock, BlockParameter toBlock) = AppServices.getBlockParameterConfiguration(request.FromBlock, request.ToBlock, (request.Subject.IsEmpty() == true) && (request.Day == 0) && (request.Value == 0)); // Create the filter variables for selecting only the requested log entries object[] ft1 = (request.Subject.IsEmpty() == true ? null : new object[] { AppModelConfig.convertToHex64(request.Subject).HexToByteArray() }); object[] ft2 = (request.Day == 0 ? null : new object[] { request.Day }); object[] ft3 = (request.Value == 0 ? null : new object[] { request.Value }); // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.POOL.abi, AppServices.GetEcosystemAdr(request.ContractAdr).PoolContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogPool").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 EcosystemLogs() { EventLogs = new List <EcosystemEventLog>() }; // Interate through all the returned logs and add them to the logs list for (int i = res.Length - 1; i >= 0; i--) { logs.EventLogs.Add(new EcosystemEventLog() { BlockNumber = Convert.ToUInt64(res[i].BlockNumber.HexValue, 16), Subject = AppModelConfig.FromHexString(res[i].Topics[1].ToString()), Day = Convert.ToUInt64(res[i].Topics[2].ToString(), 16), Value = Convert.ToUInt64(res[i].Topics[3].ToString(), 16), Timestamp = Convert.ToUInt64(res[i].Data.Substring(2 + 0 * 64, 64), 16) }); } // Return the list of bond logs return(logs); }
public object Post(ProcessBankAccountCredit request) { // Convert the payment subject to a hash if it is a valid number if (uint.TryParse(request.PaymentSubject, out uint val) == true) { request.PaymentSubject = val.ToString("X64").EnsureHexPrefix(); } // Submit and return the transaction hash of the broadcasted transaction return(AppServices.createSignPublishTransaction( AppModelConfig.BANK.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr, request.SigningPrivateKey, "processAccountCredit", request.BankTransactionIdx, (ulong)request.AccountType, request.PaymentAccountHashSender.HexToByteArray(), request.PaymentSubject.HexToByteArray(), request.CreditAmount )); }
public object Get(GetBankPaymentAdviceList request) { // Get the contract for the Bank by specifying the bank address var contract = AppServices.web3.Eth.GetContract(AppModelConfig.BANK.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr); // Create a new return instance for Bank Metadata and set the Bank contract address uint countPaymentAdvice = contract.GetFunction("countPaymentAdviceEntries").CallAsync <uint>().Result; // Create the bond list object and initialise PaymentAdviceList list = new PaymentAdviceList() { Items = new List <PaymentAdviceDetail>() }; // Iterate through all the payment advice entries available according to count for (uint i = 0; i < countPaymentAdvice; i++) { // Call the payment advice from the specified idx PaymentAdviceDetail advice = contract.GetFunction("bankPaymentAdvice").CallDeserializingToObjectAsync <PaymentAdviceDetail>(i).Result; // Verify the payment advice returned has not already been processed (check the payment amount) if (advice.Amount > 0) { // Set the Advice index advice.Idx = i; // Convert the payment subject if applicable if (advice.PaymentSubject.StartsWith("0x000000") == true) { advice.PaymentSubject = Convert.ToUInt64(advice.PaymentSubject.RemoveHexPrefix(), 16).ToString(); } // Add advice to the list list.Items.Add(advice); } } // Return the list of all outstanding payment advice return(list); }
// ******************************************************************************************** // *** HOSTING ENVIRONMENT AND CONFIGURATION SETUP // ******************************************************************************************** public object Get(HostingEnvironmentSetup request) { // Returns the configured hosting environment details return(new HostingEnvironment { ApiServiceHostingEnvironmentName = AppModelConfig.hostingEnvironment.EnvironmentName, MaxWaitDurationForTransactionReceipt = AppModelConfig.maxWaitDurationForTransactionReceipt, DefaultNumberEntriesForLazyLoading = AppModelConfig.defaultNumberEntriesForLazyLoading, DefaultBlockRangeForEventLogLoading = AppModelConfig.defaultBlockRangeForEventLogLoading, Web3UrlEndpoint = AppModelConfig.WEB3_URL_ENDPOINT, AutoSchedulePingDuration = AppServices.getPingTimerInterval(), ExternalAccessInterfaceAbi = AppModelConfig.EXTACCESSI.abi, InternalAccessInterfaceAbi = AppModelConfig.INTACCESSI.abi, SetupInterfaceAbi = AppModelConfig.SETUPI.abi, LibraryAbi = AppModelConfig.LIB.abi, PoolAbi = AppModelConfig.POOL.abi, BondAbi = AppModelConfig.BOND.abi, BankAbi = AppModelConfig.BANK.abi, PolicyAbi = AppModelConfig.POLICY.abi, SettlementAbi = AppModelConfig.SETTLEMENT.abi, AdjustorAbi = AppModelConfig.ADJUSTOR.abi, TimerAbi = AppModelConfig.TIMER.abi, TrustAbi = AppModelConfig.TRUST.abi }); }
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 }); }
public object Get(GetPolicy 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); // PolicyListEntry entry = contract.GetFunction("get").CallDeserializingToObjectAsync<PolicyListEntry>(i).Result; // If no Policy hash has been provided as part of the request get the corresponding hash that belongs to the provided idx if (request.Hash.IsEmpty() == true) { request.Hash = AppModelConfig.convertToHex(contract.GetFunction("get").CallAsync <byte[]>(request.Idx).Result); } // Retrieve the Policy details from the Blockchain PolicyDetail Policy = contract.GetFunction("dataStorage").CallDeserializingToObjectAsync <PolicyDetail>(request.Hash.HexToByteArray()).Result; // Set the Policy hash to the requested has as specified in the request Policy.Hash = request.Hash; Policy.EventLogs = new List <PolicyEventLog>(); // If Policy hash is set retrieve the logs for the Policy if (AppModelConfig.isEmptyHash(Policy.Hash) == false) { Policy.EventLogs = ((PolicyLogs)this.Get( new GetPolicyLogs { ContractAdr = request.ContractAdr, Hash = request.Hash })).EventLogs; // Just for the Policy specific event logs reverse the order to have the events in ascending order Policy.EventLogs.Reverse(); } // Return the Policy return(Policy); }
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); }
public object Get(GetTimerNotifications request) { // Maximal duration that can be specified to retrive notifications for (24 hours) ulong maxDuration = 3600 * 24; // Get the contract for the Bond by specifying the bond address var contract = AppServices.web3.Eth.GetContract(AppModelConfig.TIMER.abi, AppServices.GetEcosystemAdr(request.ContractAdr).TimerContractAdr); // Get the current time from the blockchain from the timer contract ulong currentTimeEPOCH = contract.GetFunction("getBlockchainEPOCHTime").CallAsync <ulong>().Result; // Get the inception date of the timer contract ulong timerInceptionEPOCH = contract.GetFunction("TIMER_INCEPTION_DATE").CallAsync <ulong>().Result; // If both from and to time parameter are provided ensure that they are at least the value of the timer inception EPOCH if (((request.FromTime != 0) && (request.FromTime < timerInceptionEPOCH)) || ((request.ToTime != 0) && (request.ToTime < timerInceptionEPOCH))) { throw new HttpError(HttpStatusCode.NotAcceptable, AppModelConfig.TransactionProcessingError, AppModelConfig.TransactionProcessingErrorMessage); } // If no time parameter is provided if ((request.FromTime == 0 && request.ToTime == 0)) { request.FromTime = currentTimeEPOCH; request.ToTime = currentTimeEPOCH + maxDuration; } // If only the From time is not provided set it based on the to time provided else if (request.FromTime == 0) { request.FromTime = request.ToTime - maxDuration; } // If only the To time is not provided set it based on the from time provided else if (request.ToTime == 0) { request.ToTime = request.FromTime + maxDuration; } // If both from and to time is provided ensure they are valid (to is greater than from) and within max duration allowed else if ((request.FromTime + maxDuration < request.ToTime) || (request.FromTime > request.ToTime)) { throw new HttpError(HttpStatusCode.NotAcceptable, AppModelConfig.TransactionProcessingError, AppModelConfig.TransactionProcessingErrorMessage); } TimerNotifications notifications = new TimerNotifications { NotificationEntries = new List <TimerNotificationEntry>() }; ulong fromTime_10_S = request.FromTime / 10; ulong toTime_10_S = request.ToTime / 10; // 100 second loop interation for (ulong i_100_S = fromTime_10_S / 10; i_100_S <= toTime_10_S / 10; i_100_S++) { // Verify it this interval has entries if (contract.GetFunction("timeIntervalHasEntries").CallAsync <bool>(i_100_S).Result == true) { // Iterate throught the 10 slots within this 100 second itervall for (ulong j_10_S = i_100_S * 10; j_10_S < (i_100_S + 1) * 10; j_10_S++) { // Get the number of entries for this 10 second slot ulong countEntries = contract.GetFunction("getTimerNotificationCount").CallAsync <ulong>(j_10_S).Result; // Iterate through every entry in a slot for (uint k = 0; k < countEntries; k++) { // Verify if the entry is within from and to before adding it to the list if ((j_10_S >= fromTime_10_S) && (j_10_S <= toTime_10_S)) { var entry = contract.GetFunction("notification").CallDeserializingToObjectAsync <TimerNotificationEntry>(j_10_S, k).Result; entry.Timestamp = j_10_S * 10; notifications.NotificationEntries.Add(entry); } } } } } // Return all the notifications return(notifications); }
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); }
public object Get(GetEcosystemContractAddresses request) { return(AppServices.GetEcosystemAdr(request.ContractAdr)); }
// ******************************************************************************************** // *** ECOSYSTEM // ******************************************************************************************** public object Get(GetEcosystemStatus 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 EcosystemStatus status = new EcosystemStatus(); // Load the trust contract to retrieve the external access interface duration for pre-authorisation var contract = AppServices.web3.Eth.GetContract(AppModelConfig.POOL.abi, adr.PoolContractAdr); status.currentPoolDay = contract.GetFunction("currentPoolDay").CallAsync <ulong>().Result; status.isWinterTime = contract.GetFunction("isWinterTime").CallAsync <bool>().Result; status.daylightSavingScheduled = contract.GetFunction("daylightSavingScheduled").CallAsync <bool>().Result; // Bank account balances status.WC_Bal_FA_Cu = contract.GetFunction("WC_Bal_FA_Cu").CallAsync <ulong>().Result; status.WC_Bal_BA_Cu = contract.GetFunction("WC_Bal_BA_Cu").CallAsync <ulong>().Result; status.WC_Bal_PA_Cu = contract.GetFunction("WC_Bal_PA_Cu").CallAsync <ulong>().Result; // Variables used by the Insurance Pool during overnight processing only status.overwriteWcExpenses = contract.GetFunction("overwriteWcExpenses").CallAsync <bool>().Result; status.WC_Exp_Cu = contract.GetFunction("WC_Exp_Cu").CallAsync <ulong>().Result; // Pool variables as defined in the model status.WC_Locked_Cu = contract.GetFunction("WC_Locked_Cu").CallAsync <ulong>().Result; status.WC_Bond_Cu = contract.GetFunction("WC_Bond_Cu").CallAsync <ulong>().Result; status.WC_Transit_Cu = contract.GetFunction("WC_Transit_Cu").CallAsync <ulong>().Result; status.B_Yield_Ppb = contract.GetFunction("B_Yield_Ppb").CallAsync <ulong>().Result; status.B_Gradient_Ppq = contract.GetFunction("B_Gradient_Ppq").CallAsync <ulong>().Result; // Flag to indicate if the bond yield accelleration is operational (and scheduled by the timer) status.bondYieldAccellerationScheduled = contract.GetFunction("bondYieldAccellerationScheduled").CallAsync <bool>().Result; status.bondYieldAccelerationThreshold = contract.GetFunction("bondYieldAccelerationThreshold").CallAsync <ulong>().Result; // Load the bond contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.BOND.abi, adr.BondContractAdr); status.BondListInfo = contract.GetFunction("hashMap").CallDeserializingToObjectAsync <ListInfo>().Result; // Load the policy contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.POLICY.abi, adr.PolicyContractAdr); status.totalIssuedPolicyRiskPoints = contract.GetFunction("totalIssuedPolicyRiskPoints").CallAsync <ulong>().Result; status.PolicyListInfo = contract.GetFunction("hashMap").CallDeserializingToObjectAsync <ListInfo>().Result; // Load the adjustor contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.ADJUSTOR.abi, adr.AdjustorContractAdr); status.AdjustorListInfo = contract.GetFunction("hashMap").CallDeserializingToObjectAsync <ListInfo>().Result; // Load the settlement contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.SETTLEMENT.abi, adr.SettlementContractAdr); status.SettlementListInfo = contract.GetFunction("hashMap").CallDeserializingToObjectAsync <ListInfo>().Result; // Load the bank contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.BANK.abi, adr.BankContractAdr); status.fundingAccountPaymentsTracking_Cu = contract.GetFunction("fundingAccountPaymentsTracking_Cu").CallAsync <ulong>().Result; // Load the timer contract contract = AppServices.web3.Eth.GetContract(AppModelConfig.TIMER.abi, adr.TimerContractAdr); status.lastPingExececution = contract.GetFunction("lastPingExec_10_S").CallAsync <ulong>().Result * 10; return(status); }