Beispiel #1
0
 public GasTests()
 {
     _vechainClient = new VeChainClient
     {
         ServerUri = new Uri(Environment.GetEnvironmentVariable("VECHAIN_TESTNET_URL") ?? "https://sync-testnet.vechain.org")
     };
 }
Beispiel #2
0
 public BlockTest()
 {
     _vechainClient = new VeChainClient();
     _vechainClient.SetBlockchainAddress("https://sync-testnet.vechain.org");
 }
        /// <summary>
        /// Calculates the execution gas cost of a transaction by submitting it to the contract on the client
        /// instance of the blockchain.
        /// </summary>
        /// <param name="transaction">The Transaction for which the cost is calculated</param>
        /// <param name="client"></param>
        /// <returns>The execution gas cost of the transaction</returns>
        public static async Task <ulong> CalculateExecutionGasCost(this Transaction transaction, VeChainClient client)
        {
            var callResults = await client.ExecuteAddressCode(transaction.clauses);

            return((ulong)callResults.Sum(result => (decimal)result.gasUsed));
        }
        /// <summary>
        /// Transfer the transaction to the blockchain to be included in the next block.
        /// </summary>
        /// <param name="rawTransaction">The transaction to be included in the blockchain</param>
        /// <param name="client">The client that determines the interaction with the blockchain</param>
        /// <returns>The result of the transfer</returns>
        public static async Task <TransferResult> Transfer(this RawTransaction rawTransaction, VeChainClient client)
        {
            if (rawTransaction?.signature == null)
            {
                throw new ArgumentException("Unsigned transaction can not be sent");
            }

            var bytes = rawTransaction.Encode();

            var transactionString = bytes.ByteArrayToString(StringType.Hex | StringType.ZeroLowerX);

            return(await client.SendTransaction(bytes));
        }
        /// <summary>
        /// Calculates the gas usage of a rawTransaction by combining the intrinsic gas cost with
        /// the cost of a test run interacting with a potential contract
        /// <param name="transaction">The rawTransaction for which the cost is calculated</param>
        /// <returns>The total gas cost of a transaction</returns>
        public static async Task <ulong> CalculateTotalGasCost(this Transaction transaction, VeChainClient client)
        {
            var executionCost = await transaction.CalculateExecutionGasCost(client);

            var intrinsicCost = transaction.CalculateIntrinsicGasCost();

            return(executionCost + intrinsicCost);
        }