/// <inheritdoc /> public async Task <IEventLock?> LockEventForProcessingAsync(EthereumNetwork network, ContractAddress contractAddresses, EventSignature eventSignature, TransactionHash transactionHash, int eventIndex, BlockNumber blockNumber, GasLimit gasUsed, GasPrice gasPrice, EventRetrievalStrategy retrievalStrategy) { var param = new { Network = network.Name, ContractAddress = contractAddresses, EventSignature = eventSignature, TransactionHash = transactionHash, EventIndex = eventIndex, MachineName = this._machineName, BlockNumber = (int)blockNumber.Value, GasUsed = gasUsed, GasPrice = gasPrice, Strategy = retrievalStrategy.GetName() }; return(await this._database.QuerySingleOrDefaultAsync <object, EventLockEntity>(storedProcedure : @"Ethereum.Event_Lock", param : param)); }
/// <summary> /// Return current gasPrice. /// </summary> /// <returns></returns> public GasPrice GetGasPrice() { GasPrice result = new GasPrice(); if (restUtils == null) { restUtils = new RestUtils(); } string resource = string.Format("{0}{1}", API_VERSION, Constant.LINK_GetGasPrice); IRestResponse response = restUtils.Send(API_URL, resource); if (response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK) { try { result = JsonConvert.DeserializeObject <GasPrice>(response.Content); result.message = string.Empty; } catch (Exception ex) { result.message = ex.Message; } } else { result.message = response.ErrorMessage; } return(result); }
/// <summary> /// Updates the newest gas price estimates. /// </summary> /// <param name="value"> The current value of the slider to use to estimate the gas price. </param> private void UpdateGasPriceEstimate(float value) { GasPrice gasPrice = EqualityComparer <GasPrice> .Default.Equals(StandardGasPrice, default(GasPrice)) ? new GasPrice(GasUtils.GetFunctionalGasPrice(10)) : StandardGasPrice; decimal multiplier = decimal.Round((decimal)Mathf.Lerp(0.65f, 1.4f, value) * (decimal)Mathf.Lerp(1f, 4f, value - 0.45f), 2, MidpointRounding.AwayFromZero); onGasPriceChanged?.Invoke(new GasPrice(new BigInteger(multiplier * (decimal)gasPrice.FunctionalGasPrice.Value))); }
public override int GetHashCode() { int hash = 1; if (Hash.Length != 0) { hash ^= Hash.GetHashCode(); } if (From.Length != 0) { hash ^= From.GetHashCode(); } if (To.Length != 0) { hash ^= To.GetHashCode(); } if (Value.Length != 0) { hash ^= Value.GetHashCode(); } if (Nonce != 0UL) { hash ^= Nonce.GetHashCode(); } if (Timestamp != 0L) { hash ^= Timestamp.GetHashCode(); } if (data_ != null) { hash ^= Data.GetHashCode(); } if (ChainId != 0) { hash ^= ChainId.GetHashCode(); } if (GasPrice.Length != 0) { hash ^= GasPrice.GetHashCode(); } if (GasLimit.Length != 0) { hash ^= GasLimit.GetHashCode(); } if (Alg != 0) { hash ^= Alg.GetHashCode(); } if (Sign.Length != 0) { hash ^= Sign.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
/// <summary> /// Updates the gas price estimate given the new GasPrice. /// </summary> /// <param name="gasPrice"> The new GasPrice to set. </param> private void UpdateGasPriceEstimate(GasPrice gasPrice) { TransactionGasPrice = gasPrice; string txFeeText = $"~ {TransactionFee.ToString().LimitEnd(14).TrimEnd('0')}<style=Symbol> ETH</style> | {currencyManager.GetCurrencyFormattedValue(tradableAssetPriceManager.GetPrice("ETH") * TransactionFee)}"; transactionFeeText.text = TransactionFee < lockPRPSPopup.EtherBalance ? txFeeText : "Not enough ETH"; transactionFeeText.color = transactionFeeText.text == "Not enough ETH" ? UIColors.Red : UIColors.White; }
public string ToJsonHex() { var s = "['{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}']"; return(string.Format(s, Nonce.ToHex(), GasPrice.ToHex(), GasLimit.ToHex(), ReceiveAddress.ToHex(), Value.ToHex(), ToHex(Data), Signature.V.ToHex(), Signature.R.ToHex(), Signature.S.ToHex())); }
public string ToJsonHex() { var data = "['" + Nonce.ToHex() + "','" + GasPrice.ToHex() + "','" + GasLimit.ToHex() + "','" + ReceiveAddress.ToHex() + "','" + Value.ToHex() + "','" + ToHex(Data) + "','" + ChainId.ToHex() + "','" + RHash.ToHex() + "','" + SHash.ToHex() + "'"; if (Signature != null) { data = data + ", '" + Signature.V.ToHex() + "', '" + Signature.R.ToHex() + "', '" + Signature.S.ToHex() + "'"; } return(data + "]"); }
public string ToJsonHex() { var data = $"['{Nonce.ToHex()}','{GasPrice.ToHex()}','{GasLimit.ToHex()}','{ReceiveAddress.ToHex()}','{Value.ToHex()}','{ToHex(Data)}','{ChainId.ToHex()}','{RHash.ToHex()}','{SHash.ToHex()}'"; if (Signature != null) { data = data + $", '{Signature.V.ToHex()}', '{Signature.R.ToHex()}', '{Signature.S.ToHex()}'"; } return(data + "]"); }
/// <summary> /// Checks the gas price entered in the gas price field. /// </summary> /// <param name="gasPrice"> The entered gas price. </param> private void CheckGasPriceField(string gasPrice) { decimal price; decimal.TryParse(gasPriceField.Text, out price); enteredGasPrice = new GasPrice(GasUtils.GetFunctionalGasPrice(price)); gasPriceField.Error = string.IsNullOrEmpty(gasPriceField.Text) || price == 0; OnGasChanged?.Invoke(); }
public override int GetHashCode() { unchecked { var hashCode = (From != null ? From.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (To != null ? To.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Hash != null ? Hash.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Value != null ? Value.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Timestamp != null ? Timestamp.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Nonce.GetHashCode(); hashCode = (hashCode * 397) ^ Confirmations.GetHashCode(); hashCode = (hashCode * 397) ^ Block.GetHashCode(); hashCode = (hashCode * 397) ^ (GasPrice != null ? GasPrice.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (GasUsed != null ? GasUsed.GetHashCode() : 0); return(hashCode); } }
public object ToJson() { return(new { hash = Hash.ToJson(), nonce = Nonce.ToJson(), blockHash = BlockHash.ToJson(), blockNumber = BlockNumber.ToJson(), transactionIndex = TransactionIndex.ToJson(), from = From.ToJson(), to = To.ToJson(), value = Value.ToJson(), gasPrice = GasPrice.ToJson(), gas = Gas.ToJson(), input = Data.ToJson(), }); }
protected override void GetAttributes() { attrs.Clear(); attrs.Add("CityId", CityId.ToString()); attrs.Add("ProvinceId", ProvinceId.ToString()); attrs.Add("IndoorTemperature", IndoorTemperature.ToString()); attrs.Add("GraphScale", GraphScale.ToString()); attrs.Add("ActiveTab", ActiveTab.ToString()); attrs.Add("buildingwidth", BuildingOutlineWidth.ToString()); attrs.Add("blockscale", BlockScale.ToString()); attrs.Add("pipeLineScale", PipeLineScale.ToString()); attrs.Add("elecprice", ElecPrice.ToString()); attrs.Add("gasprice", GasPrice.ToString()); if (rasterImageID.IsNull == false) { attrs.Add("rasterImage", rasterImageID.Handle.ToString()); } }
public async Task <Result <GasPrice> > GetGasPriceAsync( bool useCache = true, CancellationToken cancellationToken = default) { if (useCache && _gasPrice != null && DateTime.UtcNow - _gasPriceTimeStampUtc <= TimeSpan.FromMinutes(3)) { return(_gasPrice); } var baseUri = "https://api.etherscan.io/"; var requestUri = $"api?module=gastracker&action=gasoracle&apikey={ApiKey}"; await RequestLimitControl .Wait(cancellationToken) .ConfigureAwait(false); return(await HttpHelper.GetAsyncResult( baseUri : baseUri, requestUri : requestUri, responseHandler : (response, content) => { var json = JsonConvert.DeserializeObject <JObject>(content); _gasPrice = new GasPrice { Low = json["result"].Value <long>("SafeGasPrice"), Average = json["result"].Value <long>("ProposeGasPrice"), High = json["result"].Value <long>("FastGasPrice") }; _gasPriceTimeStampUtc = DateTime.UtcNow; return json.ContainsKey("result") ? new Result <GasPrice>(_gasPrice) : new Result <GasPrice>(new Error(Errors.InvalidResponse, "Invalid response")); }, cancellationToken : cancellationToken) .ConfigureAwait(false)); }
public override int GetHashCode() { unchecked { var hashCode = (Chain != null ? Chain.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (TokenTransfers != null ? TokenTransfers.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Status != null ? Status.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Index; hashCode = (hashCode * 397) ^ (TransactionHash != null ? TransactionHash.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Value.GetHashCode(); hashCode = (hashCode * 397) ^ (FromAddress != null ? FromAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ToAddress != null ? ToAddress.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Date != null ? Date.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (BlockHash != null ? BlockHash.GetHashCode() : 0); hashCode = (hashCode * 397) ^ BlockNumber.GetHashCode(); hashCode = (hashCode * 397) ^ Gas.GetHashCode(); hashCode = (hashCode * 397) ^ GasPrice.GetHashCode(); hashCode = (hashCode * 397) ^ GasUsed.GetHashCode(); hashCode = (hashCode * 397) ^ Nonce.GetHashCode(); hashCode = (hashCode * 397) ^ Confirmations.GetHashCode(); hashCode = (hashCode * 397) ^ (Input != null ? Input.GetHashCode() : 0); return(hashCode); } }
static void Main(string[] args) { // ========================================== // Employee Class // ========================================== var employeeClass = new EmployeeClass(id: 1); employeeClass.FirstName = "Jon"; employeeClass.LastName = "Doe"; Console.WriteLine(); Console.WriteLine("======== Employee Class ========"); Console.WriteLine($"Employee Id: {employeeClass.Id}"); Console.WriteLine($"Employee First Name: {employeeClass.FirstName}"); Console.WriteLine($"Employee Last Name: {employeeClass.LastName}"); // ========================================== // Employee using Init // ========================================== var employeeInit = new EmployeeInit { FirstName = "Jon", LastName = "Doe", Id = 2 }; Console.WriteLine(); Console.WriteLine("======== Employee using Init ========"); Console.WriteLine($"Employee Id: {employeeInit.Id}"); Console.WriteLine($"Employee First Name: {employeeInit.FirstName}"); Console.WriteLine($"Employee Last Name: {employeeInit.LastName}"); // ========================================== // Employee Record // ========================================== var employeeRecord1 = new EmployeeRecord(Id: 3, FirstName: "Jon", LastName: "Doe"); Console.WriteLine(); Console.WriteLine("======== Employee Record 1 ========"); Console.WriteLine($"Employee Id: {employeeRecord1.Id}"); Console.WriteLine($"Employee First Name: {employeeRecord1.FirstName}"); Console.WriteLine($"Employee Last Name: {employeeRecord1.LastName}"); // Using the with keyword to make a copy of the employeeRecord1 and changing only the Id and FirstName properties var employeeRecord2 = employeeRecord1 with { Id = 4, FirstName = "Jane" }; Console.WriteLine(); Console.WriteLine("======== Employee Record 2 ========"); Console.WriteLine($"Employee Id: {employeeRecord2.Id}"); Console.WriteLine($"Employee First Name: {employeeRecord2.FirstName}"); Console.WriteLine($"Employee Last Name: {employeeRecord2.LastName}"); // ========================================== // Compare Record Objects // ========================================== var employeeRecord3 = new EmployeeRecord(Id: 3, FirstName: "Jon", LastName: "Doe"); bool areEqual = employeeRecord1 == employeeRecord3; Console.WriteLine($"Are Records equal? {areEqual}"); // True Console.WriteLine($"Are Hash Code Records equal? {employeeRecord1.GetHashCode() == employeeRecord3.GetHashCode()}"); // True // ========================================== // Compare Class Objects // ========================================== var employeeClass2 = new EmployeeClass(id: 1); employeeClass.FirstName = "Jon"; employeeClass.LastName = "Doe"; Console.WriteLine($"Are Class objects equal? { employeeClass2 == employeeClass}"); // False // ========================================== // Retaional Operators and Pattern Matching // ========================================== // Target Typing Example - Omit the type in a new expression when the created object's type is already known RelationalOperators relationalOperators = new(); Console.WriteLine(); Console.WriteLine("======== Relational Operators ========"); Console.WriteLine($"Is Valid Percentage? {relationalOperators.IsValidPercentage(40)}"); Console.WriteLine($"Is Letter? {relationalOperators.IsLetter('c')}"); Console.WriteLine($"Is Letter or Separator? {relationalOperators.IsLetterOrSeparator('A')}"); Console.WriteLine($"Is Null? {relationalOperators.IsNull(null)}"); Console.WriteLine($"Is Null2? {relationalOperators.IsNull2(null)}"); // ========================================== // Switch Case Example // ========================================== Console.WriteLine(); Console.WriteLine("======== Switch Case Examples ========"); Console.WriteLine($"Direction => {SwitchExamples.GetOrientation()}"); var gasPrice = new GasPrice(1, 4); Console.WriteLine($"Gas price is {SwitchExamples.GetFuelCost(gasPrice)}"); // ========================================== // Target Typing // ========================================== // Instantiate a person object using only the new keyword since the Type is already known. Person person = new("Tony", "Stark"); Console.WriteLine(); Console.WriteLine("======== Target Typing ========"); Console.WriteLine($"First Name: {person.FirstName}"); Console.WriteLine($"Last Name: {person.LastName}"); Console.WriteLine(); var personList = new List <Person> { new ("Tony", "Stark"), new ("Howard", "Stark"), new ("Clint", "Barton"), new ("Captain", "America") }; foreach (var personItem in personList) { Console.WriteLine($"{personItem.FirstName} {personItem.LastName}"); } // ========================================== // Target Typing with Conditional Operators // ========================================== Person p1 = null; Person p2 = null; Person p3 = new("Jon", "Doe"); var somePerson = p1 ?? p2 ?? p3; // if p1 is null use p2, if p2 is null use p3, if neither is null use the first object in the sequence that's not null Console.WriteLine($"Who is {somePerson.FirstName} {somePerson.LastName}?"); } }
/// <summary> /// Updates the estimated gas price based on the current progress of the transaction speed slider. /// </summary> /// <param name="newEstimate"> The new estimated gas price. </param> private void UpdateGasPriceEstimate(GasPrice newEstimate) { estimatedGasPrice = newEstimate; OnGasChanged?.Invoke(); }
private static void EnableTransactions(IServiceCollection services) { services.AddSingleton(TransactionMonitoringConfiguration()); IGasPriceLimitConfiguration gasPriceLimitConfiguration = new GasPriceLimitConfiguration(maximumExpeditedGasPrice: GasPrice.FromGwei(2m), maximumGasPrice: GasPrice.FromGwei(2m)); EthereumTransactionsSetup.Configure <RecommendationsBasedGasPricePolicy>(gasLimitPolicy: GasLimitPolicy(), transactionSpeedUpPolicy: new DefaultTransactionSpeedUpPolicy(gweiToIncreaseBy: 10m), services: services, gasPriceLimitConfiguration: gasPriceLimitConfiguration, recommendationsBasedGasPricePolicyConfiguration: RecommendationsBasedGasPricePolicyConfiguration()); EthereumTransactionsServiceSetup.Configure(services); }
public static decimal GetFuelCost(GasPrice price) => price.MaxPrice switch { 1 or 2 => 1.00m,
/// <summary> /// Updates all IGasPriceObservableBase with the gas prices required. /// </summary> /// <typeparam name="T"> The type of the gas price observable which inherits IGasPriceObservableBase. </typeparam> /// <param name="gasPriceVariable"> The variable which should get the value of the gas price. </param> /// <param name="gasPriceValue"> The newest gas price value. </param> /// <param name="updateObservableAction"> Action to call on each observable. </param> private void UpdateObservable <T>(ref GasPrice gasPriceVariable, GasPrice gasPriceValue, Action <T> updateObservableAction) where T : IGasPriceObservableBase { gasPriceVariable = gasPriceValue; observables.OfType <T>().ToList().SafeForEach(updateObservableAction); }