Esempio n. 1
0
        public async Task <WithdrawInfo> WithdrawEth(string withdrawHash, string recipient, decimal amount, string symbol)
        {
            Contract           contract = web3.Eth.GetContract(abi, contractAddress);
            TransactionReceipt receipt  = null;

            try
            {
                if (symbol == "ETH")
                {
                    Function withdrawEth = contract.GetFunction("withdrawEth");
                    Log.Warning("Sending ETH Withdrawal...");
                    receipt = await withdrawEth.SendTransactionAndWaitForReceiptAsync(account.Address,             // Sender
                                                                                      new HexBigInteger(900000),   // Gas
                                                                                      null,
                                                                                      null,
                                                                                      withdrawHash,     // WithdrawHash
                                                                                      recipient,        // Recipient
                                                                                      account.Address,  // Sender
                                                                                      Web3Geth.Convert.ToWei(amount));
                }
                else
                if (symbol == "TBRL")
                {
                    Function withdrawERC20 = contract.GetFunction("withdrawERC20");
                    Log.Warning("Sending TBRL Withdrawal...");
                    receipt = await withdrawERC20.SendTransactionAndWaitForReceiptAsync(account.Address,            // Sender
                                                                                        new HexBigInteger(900000),  // Gas
                                                                                        null,
                                                                                        null,
                                                                                        withdrawHash,    // WithdrawHash
                                                                                        recipient,       // Recipient
                                                                                        account.Address, // Sender
                                                                                        Web3Geth.Convert.ToWei(amount),
                                                                                        "0x7a094dfD89893d204436Bf331a51d80F5C48a2Eb");
                }

                if (receipt != null)
                {
                    if (receipt.HasErrors() != null && ((bool)receipt.HasErrors()))
                    {
                        Log.Error("Withdrawal Error, Hash: " + withdrawHash);
                    }
                    else
                    {
                        Log.Warning("Withdrawal Success: " + withdrawHash);
                    }

                    return(new WithdrawInfo()
                    {
                        Asset = symbol, HashStr = withdrawHash, TxHash = receipt.TransactionHash, Timestamp = DateTime.Now, BlockNumber = receipt.BlockNumber.HexValue
                    });
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }

            return(null);
        }
Esempio n. 2
0
    private void DebugTransactionReceipt(TransactionReceipt receipt)
    {
        string hasErrors = receipt.HasErrors().HasValue ? receipt.HasErrors().Value.ToString() : "???";

        Debug.Log("TransactionHash: " + receipt.TransactionHash);
        Debug.Log("HasErrors: " + hasErrors);
        Debug.Log("Status: " + receipt.Status.Value.ToString());
        Debug.Log("Logs: " + receipt.Logs);
        //foreach(var log in receipt.Logs)
    }
Esempio n. 3
0
    //public List<Galleass3D.Contracts.Timber.ContractDefinition.MintEventDTO> TimberMintEvents = new List<Galleass3D.Contracts.Timber.ContractDefinition.MintEventDTO>();
    //public List<Galleass3D.Contracts.Copper.ContractDefinition.MintEventDTO> CopperMintEvents = new List<Galleass3D.Contracts.Copper.ContractDefinition.MintEventDTO>();



    //LandGenerated


    public string GetDescriptiveText()
    {
        StringBuilder sb = new StringBuilder();

        string hasErrors = TransactionReceipt.HasErrors().HasValue ? TransactionReceipt.HasErrors().Value.ToString() : "???";

        sb.AppendLine(TransactionReceipt.TransactionHash);
        sb.AppendLine("Contract:" + ContractName);
        sb.AppendLine("HasErrors:" + hasErrors);
        sb.AppendLine("Status:" + TransactionReceipt.Status.Value.ToString());
        sb.AppendLine("Logs:" + TransactionReceipt.Logs);

        return(sb.ToString());
    }
Esempio n. 4
0
        public void ShouldCheckForNewupdate()
        {
            string lookupContractAddress = "0xa454963c7a6dcbdcd0d3fb281f4e67262fb71586";
            string ncContractAddress     = "0x5f51f49e25b2ba1acc779066a2614eb70a9093a0";
            string rpc = Environment.GetEnvironmentVariable("TEST_RPC") ?? "http://localhost:8545";
            string validatorAddress      = "0xc3681dfe99730eb45154208cba7b0df7e705f305";
            string fileToPersistBlockNum = Path.GetTempFileName();

            ResetToSnapshot(rpc);

            // no new update should be seen
            ContractWrapper cw        = new ContractWrapper(lookupContractAddress, rpc, validatorAddress, new MockLogger(), "test", _keyjson, fileToPersistBlockNum);
            bool            hasUpdate = cw.HasNewUpdate().Result;

            hasUpdate.Should().Be(false);


            // Send an update
            // prepare RPC connection to play some tx

            string  contractOwnerPk = "ae29ab491cf53d8b63f281cc5eecdbbac4a992b2a4bf483bacae66dfff0740f0";
            Account account         = new Account(contractOwnerPk);

            // create a web 3 instance
            Web3 web3 = new Web3(account, rpc);

            // hook up to the contract and event
            ContractHandler contractHandler = web3.Eth.GetContractHandler(ncContractAddress);

            // contract gets primed with by ganache start
            // const valAddr = "0xc3681dfe99730eb45154208cba7b0df7e705f305"; // first addr in ganache
            // contract.updateValidator(valAddr, '0x123456', 'parity/parity:v2.3.3', '0x123456', 'https://chainspec', true);

            TransactionReceipt confirmResponse = contractHandler.SendRequestAndWaitForReceiptAsync(new UpdateValidatorFunction
            {
                DockerSha        = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x23 },
                DockerName       = "parity/parity:v2.3.4",
                ChainspecSha     = new byte[] { 0x0, 0x1, 0x2, 0x3, 0x23 },
                ChainspecUrl     = "https://example.com" + new Random().Next(),
                IsSigning        = true,
                ValidatorAddress = validatorAddress
            }).Result;


            bool?hasErrors = confirmResponse.HasErrors();

            if (hasErrors.HasValue && hasErrors.Value)
            {
                throw new ContractException("Unable to confirm update");
            }

            // now an update should be seen
            bool hasUpdate2Nd = cw.HasNewUpdate().Result;

            hasUpdate2Nd.Should().Be(true);
        }
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <returns></returns>
        /// <exception cref="T:src.Contract.ContractException">Thrown if the transaction can not be completed</exception>
        public async Task ConfirmUpdate()
        {
            IContractTransactionHandler <ConfirmUpdateFunction> updateTxHandler = _web3.Eth.GetContractTransactionHandler <ConfirmUpdateFunction>();
            ConfirmUpdateFunction updateTx = new ConfirmUpdateFunction
            {
                FromAddress = _validatorAddress,
                Gas         = new BigInteger(500000)
            };

            TransactionReceipt confirmResponse = await updateTxHandler.SendRequestAndWaitForReceiptAsync(_ncContractAddress, updateTx);

            bool?hasErrors = confirmResponse.HasErrors();

            if (hasErrors.HasValue && hasErrors.Value)
            {
                throw new ContractException("Unable to confirm update");
            }
        }
        /// <summary>
        /// Continuously checks the transaction receipt until it is found, and calls the respective event.
        /// </summary>
        /// <param name="sender"> Sender object. </param>
        /// <param name="eventArgs"> Timer event arguments. </param>
        private async void CheckTransactionReceipt(object sender, ElapsedEventArgs eventArgs)
        {
            EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt(NetworkProvider.GetWeb3().Client);
            TransactionReceipt       receipt = await ethGetTransactionReceipt.SendRequestAsync(txHash);

            if (receipt == null)
            {
                return;
            }

            if (receipt.HasErrors() == true || receipt.Status.Value == 0)
            {
                OnTransactionFail?.Invoke();
            }
            else
            {
                OnTransactionSuccess?.Invoke();
            }

            timer.Stop();
        }