public static async Task <MultisigTransactionIdentifiers> SubmitTransactionAsync(Web3 web3, string contractAddress, string destination, BigInteger value, string data, BigInteger gas, BigInteger gasPrice)
        {
            IContractTransactionHandler <SubmitTransactionFunction> submitHandler = web3.Eth.GetContractTransactionHandler <SubmitTransactionFunction>();

            var submitTransactionFunctionMessage = new SubmitTransactionFunction()
            {
                Destination = destination,
                Value       = value,
                Data        = Encoders.Hex.DecodeData(data),
                Gas         = gas,
                GasPrice    = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            TransactionReceipt submitTransactionReceipt = await submitHandler.SendRequestAndWaitForReceiptAsync(contractAddress, submitTransactionFunctionMessage).ConfigureAwait(false);

            EventLog <SubmissionEventDTO> submission = submitTransactionReceipt.DecodeAllEvents <SubmissionEventDTO>().FirstOrDefault();

            // Use -1 as an error indicator.
            if (submission == null)
            {
                return new MultisigTransactionIdentifiers()
                       {
                           TransactionId = BigInteger.MinusOne
                       }
            }
            ;

            return(new MultisigTransactionIdentifiers()
            {
                TransactionHash = submitTransactionReceipt.TransactionHash, TransactionId = submission.Event.TransactionId
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows to execute a Safe transaction confirmed by required number of owners and then pays the account that submitted the transaction.
        /// </summary>
        /// <remarks>Note: The fees are always transferred, even if the user transaction fails.</remarks>
        /// <param name="web3">Instance of the web3 client to execute the function against.</param>
        /// <param name="proxyContract">The address of the Gnosis Safe proxy deployment that owns the wrapped STRAX contract.</param>
        /// <param name="wrappedStraxContract">The address of the wrapped STRAX ERC20 contract.</param>
        /// <param name="value">The Ether value of the transaction, if applicable. For ERC20 transfers this is 0.</param>
        /// <param name="data">The ABI-encoded data of the transaction, e.g. if a contract method is being called. For ERC20 transfers this will be set.</param>
        /// <param name="safeTxGas">Gas that should be used for the Safe transaction.</param>
        /// <param name="baseGas">Gas costs that are independent of the transaction execution (e.g. base transaction fee, signature check, payment of the refund).</param>
        /// <param name="gasPrice">Gas price that should be used for the payment calculation.</param>
        /// <param name="signatureCount">The number of packed signatures included.</param>
        /// <param name="signatures">Packed signature data ({bytes32 r}{bytes32 s}{uint8 v}).</param>
        /// <returns>The transaction hash of the execution transaction.</returns>
        public static async Task <string> ExecTransactionAsync(Web3 web3, string proxyContract, string wrappedStraxContract, BigInteger value, string data, BigInteger safeTxGas, BigInteger baseGas, BigInteger gasPrice, int signatureCount, byte[] signatures)
        {
            // These parameters are supplied to the function hardcoded:
            // @param operation Operation type of Safe transaction. The Safe supports CALL (uint8 = 0), DELEGATECALL (uint8 = 1) and CREATE (uint8 = 2).
            // @param gasToken Token address (or 0 if ETH) that is used for the payment.
            // @param refundReceiver Address of receiver of gas payment (or 0 if tx.origin).

            IContractTransactionHandler <ExecTransactionFunction> execHandler = web3.Eth.GetContractTransactionHandler <ExecTransactionFunction>();

            var execTransactionFunctionMessage = new ExecTransactionFunction()
            {
                To             = proxyContract,
                Value          = value,
                Data           = Encoders.Hex.DecodeData(data),
                Operation      = 0, // CALL
                SafeTxGas      = safeTxGas,
                BaseGas        = baseGas,
                GasPrice       = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei),
                GasToken       = ETHClient.ZeroAddress,
                RefundReceiver = ETHClient.ZeroAddress,
                Signatures     = signatures
            };

            TransactionReceipt execTransactionReceipt = await execHandler.SendRequestAndWaitForReceiptAsync(proxyContract, execTransactionFunctionMessage).ConfigureAwait(false);

            return(execTransactionReceipt.TransactionHash);
        }
Exemplo n.º 3
0
        public async Task <TransactionReceipt> Handle(CreateTemplateRequest aCreateTemplateRequest, CancellationToken aCancellationToken)
        {
            IContractTransactionHandler <CreateTemplateRequest> contractTransactionHandler =
                Web3ContractManager.Web3.Eth.GetContractTransactionHandler <CreateTemplateRequest>();

            HexBigInteger gasEstimate =
                await contractTransactionHandler.EstimateGasAsync(EthereumSettings.NftCreatorAddress, aCreateTemplateRequest);

            aCreateTemplateRequest.Gas = gasEstimate;
            return(await contractTransactionHandler
                   .SendRequestAndWaitForReceiptAsync(EthereumSettings.NftCreatorAddress, aCreateTemplateRequest));
        }
Exemplo n.º 4
0
        public static async Task <string> TransferOwnershipAsync(Web3 web3, string contractAddress, string newOwner)
        {
            IContractTransactionHandler <TransferOwnershipFunction> transferHandler = web3.Eth.GetContractTransactionHandler <TransferOwnershipFunction>();

            var transfer = new TransferOwnershipFunction()
            {
                NewOwner = newOwner
            };

            TransactionReceipt transactionTransferReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transfer).ConfigureAwait(false);

            return(transactionTransferReceipt.TransactionHash);
        }
        /// <summary>
        /// Normally the final mandatory confirmation will automatically call the execute.
        /// This is provided in case it has to be called again due to an error condition.
        /// </summary>
        public static async Task <string> ExecuteTransactionAsync(Web3 web3, string contractAddress, BigInteger transactionId, BigInteger gas, BigInteger gasPrice)
        {
            IContractTransactionHandler <ExecuteTransactionFunction> executionHandler = web3.Eth.GetContractTransactionHandler <ExecuteTransactionFunction>();

            var executeTransactionFunctionMessage = new ExecuteTransactionFunction()
            {
                TransactionId = transactionId,
                Gas           = gas,
                GasPrice      = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            TransactionReceipt executeTransactionReceipt = await executionHandler.SendRequestAndWaitForReceiptAsync(contractAddress, executeTransactionFunctionMessage).ConfigureAwait(false);

            return(executeTransactionReceipt.TransactionHash);
        }
Exemplo n.º 6
0
        public static async Task <string> TransferAsync(Web3 web3, string contractAddress, string recipient, BigInteger amount, BigInteger gas, BigInteger gasPrice)
        {
            IContractTransactionHandler <TransferFunction> transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>();

            var transfer = new TransferFunction()
            {
                To          = recipient,
                TokenAmount = amount,
                Gas         = gas,
                GasPrice    = Web3.Convert.ToWei(gasPrice, UnitConversion.EthUnit.Gwei)
            };

            TransactionReceipt transactionTransferReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transfer).ConfigureAwait(false);

            return(transactionTransferReceipt.TransactionHash);
        }
        /// <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");
            }
        }
Exemplo n.º 8
0
        public async Task <MintNftResponse> Handle(MintNftRequest aMintNftRequest, CancellationToken aCancellationToken)
        {
            IContractTransactionHandler <MintNftRequest> contractTransactionHandler =
                Web3ContractManager.Web3.Eth.GetContractTransactionHandler <MintNftRequest>();

            HexBigInteger gasEstimate =
                await contractTransactionHandler.EstimateGasAsync(EthereumSettings.NftCreatorAddress, aMintNftRequest);

            aMintNftRequest.Gas = gasEstimate;
            TransactionReceipt transactionReceipt = await contractTransactionHandler
                                                    .SendRequestAndWaitForReceiptAsync(EthereumSettings.NftCreatorAddress, aMintNftRequest);

            List <EventLog <MintNftEventDto> > mintNftEventDtos = transactionReceipt.DecodeAllEvents <MintNftEventDto>();

            return(new MintNftResponse
            {
                MintNftEventDto = mintNftEventDtos.FirstOrDefault()?.Event,
                TransactionReceipt = transactionReceipt
            });
        }
Exemplo n.º 9
0
 public static async Task <TransactionReceipt> asyncTransferAmount(string contractAddress, TransferFunction transfer, IContractTransactionHandler <TransferFunction> deploymentHandler)
 {
     return(await deploymentHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transfer));
 }