Exemplo n.º 1
0
    public async Task MineAndGetReceiptAsync(ulong ping)
    {
        var setPingFunction = contract.GetFunction("setPint");

        Nethereum.Contracts.Event pongEvent = contract.GetEvent("Pong");

        Nethereum.Hex.HexTypes.HexBigInteger estimatedGas = await setPingFunction.EstimateGasAsync(ping);


        Nethereum.RPC.Eth.DTOs.TransactionReceipt receipt = await setPingFunction.SendTransactionAndWaitForReceiptAsync(userAddress, estimatedGas, null, null, ping);

        Debug.Log("receipt: " + receipt.TransactionHash + ", blockNum: " + receipt.BlockNumber.Value);


        var filterInput = pongEvent.CreateFilterInput(new BlockParameter(0), BlockParameter.CreateLatest());
        var logs        = await pongEvent.GetAllChanges <PongEvent>(filterInput);

        foreach (Nethereum.Contracts.EventLog <PongEvent> log in logs)
        {
            Debug.Log("================================");
            Debug.Log("address: " + log.Log.Address);
            Debug.Log("TransactionHash: " + log.Log.TransactionHash);
            Debug.Log("blockNum: " + log.Log.BlockNumber);
            Debug.Log("data: " + log.Log.Data);
            Debug.Log("Pong: " + log.Event.Pong);
        }
    }
Exemplo n.º 2
0
        public async Task <bool> RentBicycleRequestAndWaitForReceiptAsync(Bicycle rental)
        {
            RhodeITDB           db                  = new RhodeITDB();
            bool                rentalResults       = false;
            RentBicycleFunction rentBicycleFunction = new RentBicycleFunction
            {
                BicycleId      = rental.ID,
                DockingStation = rental.DockdeAt,
                FromAddress    = rental.renter,
                Gas            = Variables.gas
            };

            try
            {
                Nethereum.RPC.Eth.DTOs.TransactionReceipt transactionReceipt = await ContractHandler.SendRequestAndWaitForReceiptAsync(rentBicycleFunction, null).ConfigureAwait(false);

                db.StoreTransactionReceipt(new Models.TransactionReceipt {
                    Receipt = transactionReceipt.TransactionHash, Activity = "Rented out bicycle"
                });
                db.StoreUserRide(new Ride {
                    ID = rental.ID, StationName = rental.DockdeAt, Docked = rental.Status, TransactionReceipt = transactionReceipt.TransactionHash
                });
                rentalResults = await UnlockBicycleAsync(rental).ConfigureAwait(false);
            }
            catch (Exception e)
            {
                Console.WriteLine("Something went wrong bicycle rental: " + e.Message);
                return(rentalResults);
            }
            return(rentalResults);
        }
Exemplo n.º 3
0
    public async Task MineAndGetReceiptAsync()
    {
        var setPingFunction = contract.GetFunction("setPint");

        Nethereum.Contracts.Event pongEvent = contract.GetEvent("Pong");

//		var filterAll = await pongEvent.CreateFilterAsync ();
//		Debug.Log ("filterAll: " + filterAll);
//		var filter7 = await pongEvent.CreateFilterAsync(7);

        Nethereum.Hex.HexTypes.HexBigInteger estimatedGas = await setPingFunction.EstimateGasAsync(111);


//		var transactionHash = await setPingFunction.SendTransactionAsync(address, estimatedGas, null,  8);
//		Debug.Log ("transactionHash: " + transactionHash);
        Nethereum.RPC.Eth.DTOs.TransactionReceipt receipt = await setPingFunction.SendTransactionAndWaitForReceiptAsync(address, estimatedGas, null, null, 111);

        Debug.Log("receipt: " + receipt.TransactionHash + ", blockNum: " + receipt.BlockNumber.Value);


//		object[] array = new[] { "9" };
        var filterInput = pongEvent.CreateFilterInput(new BlockParameter(0), BlockParameter.CreateLatest());
        var logs        = await pongEvent.GetAllChanges <PongEvent>(filterInput);

        foreach (Nethereum.Contracts.EventLog <PongEvent> log in logs)
        {
            Debug.Log("================================");
            Debug.Log("address: " + log.Log.Address);
            Debug.Log("TransactionHash: " + log.Log.TransactionHash);
            Debug.Log("blockNum: " + log.Log.BlockNumber);
            Debug.Log("data: " + log.Log.Data);
            Debug.Log("Pong: " + log.Event.Pong);
        }


//		var log = await pongEvent.GetFilterChanges<PongEvent>(filterAll);
//		var log7 = await pongEvent.GetFilterChanges<PongEvent>(filter7);

        Debug.Log("logs: " + logs.Count);
//		Debug.Log("log: " + log.Count);
    }
Exemplo n.º 4
0
        public static string[] GetAllRelatedAddresses(this Transaction tx, TransactionReceipt receipt)
        {
            if (tx == null)
            {
                return new string[] { }
            }
            ;

            var uniqueAddresses = new UniqueAddressList()
            {
                tx.From
            };

            if (tx.To.IsNotAnEmptyAddress())
            {
                uniqueAddresses.Add(tx.To);
            }

            if (receipt != null)
            {
                if (receipt.ContractAddress.IsNotAnEmptyAddress())
                {
                    uniqueAddresses.Add(receipt.ContractAddress);
                }

                foreach (var log in tx.GetTransactionLogs(receipt))
                {
                    if (log.Address.IsNotAnEmptyAddress())
                    {
                        uniqueAddresses.Add(log.Address);
                    }
                }
            }

            return(uniqueAddresses.ToArray());
        }
    }
Exemplo n.º 5
0
 public static bool IsForContractCreation(
     this Transaction transaction, TransactionReceipt transactionReceipt)
 {
     return(transaction.To.IsAnEmptyAddress() &&
            transactionReceipt.ContractAddress.IsNotAnEmptyAddress());
 }
Exemplo n.º 6
0
 public static bool IsContractAddressEqual(this TransactionReceipt receipt, string address)
 {
     return(receipt.ContractAddress.EqualsAddress(address));
 }
Exemplo n.º 7
0
 public static bool IsContractAddressEmptyOrEqual(this TransactionReceipt receipt, string contractAddress)
 {
     return(receipt.ContractAddress.IsEmptyOrEqualsAddress(contractAddress));
 }
Exemplo n.º 8
0
 public static bool HasLogs(this TransactionReceipt receipt)
 {
     return(receipt.Logs?.Count > 0);
 }
Exemplo n.º 9
0
 public static bool Failed(this TransactionReceipt receipt)
 {
     return(!receipt.Succeeded());
 }
Exemplo n.º 10
0
 public static bool Succeeded(this TransactionReceipt receipt)
 {
     return(receipt.Status.Value == BigInteger.One);
 }
 public static bool Failed(this TransactionReceipt receipt, bool treatNullStatusAsFailure = TREAT_NULL_STATUS_AS_FAILURE)
 {
     return(receipt.HasErrors() ?? treatNullStatusAsFailure);
 }
 public static bool Succeeded(this TransactionReceipt receipt, bool treatNullStatusAsFailure = TREAT_NULL_STATUS_AS_FAILURE)
 {
     return(!receipt.Failed(treatNullStatusAsFailure));
 }
Exemplo n.º 13
0
        public static IEnumerable <FilterLogVO> GetTransactionLogs(this Transaction transaction, TransactionReceipt receipt)
        {
            for (var i = 0; i < receipt.Logs?.Count; i++)
            {
                if (receipt.Logs[i] is JObject log)
                {
                    var typedLog = log.ToObject <FilterLog>();

                    yield return
                        (new FilterLogVO(transaction, receipt, typedLog));
                }
            }
        }
Exemplo n.º 14
0
 public FilterLogVO(Transaction transaction, TransactionReceipt receipt, FilterLog log)
 {
     Transaction = transaction;
     Receipt     = receipt;
     Log         = log;
 }
Exemplo n.º 15
0
 public virtual bool HasLogs()
 {
     return(TransactionReceipt?.HasLogs() ?? false);
 }