public void Fetch(BigInteger from, BigInteger to) { EthUtils.RunSync(() => processor.ExecuteAsync( startAtBlockNumberIfNotProcessed: from, toBlockNumber: (to != BigInteger.Zero) ? to : from, cancellationToken: cancellationToken) ); }
public List <EventLog <TransferEventDTO> > GetTransferEvents(string contract, HexBigInteger start, HexBigInteger end) { var transferEventHandler = GetWeb3Client().Eth.GetEvent <TransferEventDTO>(contract); var filter = transferEventHandler.CreateFilterInput( fromBlock: new BlockParameter(start), toBlock: new BlockParameter(end)); var logs = EthUtils.RunSync(() => transferEventHandler.GetAllChanges(filter)); return(logs); }
public TransactionReceipt GetTransactionReceipt(string tx) { TransactionReceipt receipt = null; if (!tx.StartsWith("0x")) { tx = "0x" + tx.ToLower(); } receipt = EthUtils.RunSync(() => GetWeb3Client().Eth.Transactions.GetTransactionReceipt.SendRequestAsync(tx)); return(receipt); }
public EthTransferResult TryTransferAsset(string platform, string symbol, string toAddress, decimal amount, int decimals, out string result) { if (symbol.Equals("ETH", StringComparison.InvariantCultureIgnoreCase) || symbol.Equals("BNB", StringComparison.InvariantCultureIgnoreCase)) { var bytes = Nexus.GetOracleReader().Read <byte[]>(DateTime.Now, Domain.DomainExtensions.GetOracleFeeURL(platform)); var fees = Phantasma.Numerics.BigInteger.FromUnsignedArray(bytes, true); var gasPrice = Numerics.UnitConversion.ToDecimal(fees / _settings.Oracle.EthGasLimit, 9); result = EthUtils.RunSync(() => GetWeb3Client().Eth.GetEtherTransferService() .TransferEtherAsync(toAddress, amount, gasPrice, _settings.Oracle.EthGasLimit)); return(EthTransferResult.Success); } else { var nativeAsset = false; if (symbol == DomainSettings.StakingTokenSymbol || symbol == DomainSettings.FuelTokenSymbol) { nativeAsset = true; } var hash = Nexus.GetTokenPlatformHash(symbol, platform, Nexus.RootStorage); if (hash.IsNull) { result = null; return(EthTransferResult.Failure); } var contractAddress = hash.ToString().Substring(0, 40); if (string.IsNullOrEmpty(contractAddress)) { result = null; return(EthTransferResult.Failure); } string outTransactionHash = null; if (nativeAsset) { var swapIn = new SwapInFunction() { Source = _account.Address, Target = toAddress, Amount = Nethereum.Util.UnitConversion.Convert.ToWei(amount, decimals) }; var swapInHandler = GetWeb3Client().Eth.GetContractTransactionHandler <SwapInFunction>(); swapIn.Gas = _settings.Oracle.EthGasLimit; var bytes = Nexus.GetOracleReader().Read <byte[]>(DateTime.Now, Domain.DomainExtensions. GetOracleFeeURL(platform)); var fees = Phantasma.Numerics.BigInteger.FromUnsignedArray(bytes, true); swapIn.GasPrice = System.Numerics.BigInteger.Parse(fees.ToString()) / swapIn.Gas; outTransactionHash = EthUtils.RunSync(() => swapInHandler .SendRequestAsync(contractAddress, swapIn)); } else { var transferHandler = GetWeb3Client().Eth.GetContractTransactionHandler <TransferFunction>(); var transfer = new TransferFunction() { To = toAddress, TokenAmount = Nethereum.Util.UnitConversion.Convert.ToWei(amount, decimals) }; outTransactionHash = EthUtils.RunSync(() => transferHandler .SendRequestAndWaitForReceiptAsync(contractAddress, transfer)).TransactionHash; } result = outTransactionHash; return(EthTransferResult.Success); } }
public Transaction GetTransaction(string tx) { var transaction = EthUtils.RunSync(() => GetWeb3Client().Eth.Transactions.GetTransactionByHash.SendRequestAsync(tx)); return(transaction); }
public BlockWithTransactions GetBlock(string hash) { return(EthUtils.RunSync(() => GetWeb3Client().Eth.Blocks.GetBlockWithTransactionsByHash.SendRequestAsync(hash))); }
public BlockWithTransactions GetBlock(HexBigInteger height) { return(EthUtils.RunSync(() => GetWeb3Client().Eth.Blocks.GetBlockWithTransactionsByNumber .SendRequestAsync(new BlockParameter(height)))); }