Beispiel #1
0
        /// <summary>
        /// Transactions can be identified by root hash of the transaction merkle tree (this) or by its position in the block transactions merkle tree.
        /// Every transaction hash is unique for the whole chain. Collision could in theory happen, chances are 67148E-63%.
        /// </summary>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <param name="index">The index of the <see cref="Transaction" /> in a <see cref="Block" /></param>
        /// <returns>The <see cref="Transaction" /> (if it exists).</returns>
        public async Task <Transaction> GetTransactionByBlockNumberAndIndex(BigInteger blockNumber, int index)
        {
            string jsonResponse = await _in3.SendRpc(EthGetTransactionByBlockNumberAndIndex,
                                                     new object[] { BlockParameter.AsString(blockNumber), BlockParameter.AsString(index) });

            return(RpcHandler.From <Transaction>(jsonResponse));
        }
Beispiel #2
0
        /// <summary>
        /// Retrieve the of uncle of a block for the given <paramref name="blockNumber" /> and a position. Uncle blocks are valid blocks and are mined in a genuine manner, but get rejected from the main blockchain.
        /// </summary>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <param name="position">Position of the block.</param>
        /// <returns>The uncle block.</returns>
        public async Task <Block> GetUncleByBlockNumberAndIndex(BigInteger blockNumber, int position)
        {
            string jsonResponse = await _in3.SendRpc(EthGetUncleByBlockNumberAndIndex,
                                                     new object[] { BlockParameter.AsString(blockNumber), DataTypeConverter.BigIntToPrefixedHex(position) });

            return(RpcHandler.From <TransactionBlock>(jsonResponse));
        }
Beispiel #3
0
        /// <summary>
        /// Transactions can be identified by root hash of the transaction merkle tree (this) or by its position in the block transactions merkle tree.
        /// Every transaction hash is unique for the whole chain. Collision could in theory happen, chances are 67148E-63%.
        /// See also <see cref="Eth1.Api.GetTransactionByBlockNumberAndIndex" />.
        /// </summary>
        /// <param name="blockHash">Desired block hash.</param>
        /// <param name="index">The index of the <see cref="Transaction" /> in a <see cref="Block" /></param>
        /// <returns>The <see cref="Transaction" /> (if it exists).</returns>
        public async Task <Transaction> GetTransactionByBlockHashAndIndex(String blockHash, int index)
        {
            string jsonResponse = await _in3.SendRpc(EthGetTransactionByBlockHashAndIndex,
                                                     new object[] { blockHash, BlockParameter.AsString(index) });

            return(RpcHandler.From <Transaction>(jsonResponse));
        }
Beispiel #4
0
        /// <summary>
        /// Stored value in designed position at a given <paramref name="address" />. Storage can be used to store a smart contract state, constructor or just any data.
        /// Each contract consists of a EVM bytecode handling the execution and a storage to save the state of the contract.
        /// </summary>
        /// <param name="address">Ethereum account address.</param>
        /// <param name="position">Position index, 0x0 up to 100.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>Stored value in designed position.</returns>
        public async Task <string> GetStorageAt(string address, BigInteger position, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthGetStorageAt, new object[] {
                address, DataTypeConverter.BigIntToPrefixedHex(position), BlockParameter.AsString(blockNumber)
            });

            return(RpcHandler.From <string>(jsonResponse));
        }
Beispiel #5
0
        /// <summary>
        /// Blocks can be identified by sequential number in which it was mined, or root hash of the block merkle tree <see cref="Eth1.Api.GetBlockByHash" />.
        /// </summary>
        /// <param name="blockNumber">Desired block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <param name="shouldIncludeTransactions">If <see langword="true"/>, returns the full transaction objects, otherwise only its hashes. The default value is <see langword="true"/>.</param>
        /// <returns>The <see cref="Block" /> of the requested <b>blockNumber</b> (if exists).</returns>
        /// <remarks>
        /// <para>
        /// Returning <see cref="Block" /> must be cast to <see cref="TransactionBlock" /> or <see cref="TransactionHashBlock" /> to access the transaction data.
        /// </para>
        /// </remarks>
        /// <example>
        ///   <code>
        ///   TransactionBlock latest = (TransactionBlock) _client.Eth1.GetBlockByNumber(BlockParameter.Latest, true);
        ///   TransactionHashBlock earliest = (TransactionHashBlock) _client.Eth1.GetBlockByNumber(BlockParameter.Earliest, false);
        ///   </code>
        /// </example>
        public async Task <Block> GetBlockByNumber(BigInteger blockNumber, bool shouldIncludeTransactions = true)
        {
            string jsonResponse = await _in3.SendRpc(EthGetBlockByNumber,
                                                     new object[] { BlockParameter.AsString(blockNumber), shouldIncludeTransactions });

            if (shouldIncludeTransactions)
            {
                return(RpcHandler.From <TransactionBlock>(jsonResponse));
            }
            else
            {
                return(RpcHandler.From <TransactionHashBlock>(jsonResponse));
            }
        }
Beispiel #6
0
        internal Rpc.LogFilter ToRPc()
        {
            Rpc.LogFilter result = new Rpc.LogFilter();
            if (FromBlock != null)
            {
                result.FromBlock = BlockParameter.AsString(FromBlock.Value);
            }
            if (ToBlock != null)
            {
                result.ToBlock = BlockParameter.AsString(ToBlock.Value);
            }
            result.Address   = Address;
            result.Topics    = Topics;
            result.BlockHash = BlockHash;

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Gas estimation for transaction. Used to fill transaction.gas field. Check RawTransaction docs for more on gas.
        /// </summary>
        /// <param name="request">The transaction request whose cost will be estimated.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>Estimated gas in Wei.</returns>
        public async Task <long> EstimateGas(TransactionRequest request, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthEstimateGas, new object[] { await MapTransactionToRpc(request), BlockParameter.AsString(blockNumber) });

            return((long)DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse)));
        }
Beispiel #8
0
        /// <summary>
        /// Calls a smart-contract method. Will be executed locally by Incubed's EVM or signed and sent over to save the state changes.
        /// Check https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api for more.
        /// </summary>
        /// <param name="request">The transaction request to be processed.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>Ddecoded result. If only one return value is expected the Object will be returned, if not an array of objects will be the result.</returns>
        public async Task <object> Call(TransactionRequest request, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthCall, new object[] { await MapTransactionToRpc(request), BlockParameter.AsString(blockNumber) });

            if (request.IsFunctionInvocation())
            {
                return(await AbiDecode(request.Function, RpcHandler.From <string>(jsonResponse)));
            }

            return(RpcHandler.From <object>(jsonResponse));
        }
Beispiel #9
0
        /// <summary>
        /// Retrieve the total of uncles of a block for the given <paramref name="blockNumber" />. Uncle blocks are valid and are mined in a genuine manner, but get rejected from the main blockchain.
        /// See <see cref="Eth1.Api.GetUncleCountByBlockHash" />.
        /// </summary>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>The number of uncles in a block.</returns>
        public async Task <long> GetUncleCountByBlockNumber(BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthGetUncleCountByBlockNumber, new object[] { BlockParameter.AsString(blockNumber) });

            return(Convert.ToInt64(RpcHandler.From <string>(jsonResponse), 16));
        }
Beispiel #10
0
        /// <summary>
        /// Number of transactions mined from this <paramref name="address" />. Used to set transaction nonce.
        /// Nonce is a value that will make a transaction fail in case it is different from (transaction count + 1).
        /// It exists to mitigate replay attacks.
        /// </summary>
        /// <param name="address">Ethereum account address.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>Number of transactions mined from this address.</returns>
        public async Task <long> GetTransactionCount(string address, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthGetTransactionCount, new object[] { address, BlockParameter.AsString(blockNumber) });

            return(Convert.ToInt64(RpcHandler.From <string>(jsonResponse), 16));
        }
Beispiel #11
0
        /// <summary>
        /// Smart-Contract bytecode in hexadecimal. If the account is a simple wallet the function will return '0x'.
        /// </summary>
        /// <param name="address">Ethereum address.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>Smart-Contract bytecode in hexadecimal.</returns>
        public async Task <string> GetCode(string address, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthGetCode, new object[] { address, BlockParameter.AsString(blockNumber) });

            return(RpcHandler.From <string>(jsonResponse));
        }
Beispiel #12
0
        /// <summary>
        /// Returns the balance of the account of given <paramref name="address" />.
        /// </summary>
        /// <param name="address">Address to check for balance.</param>
        /// <param name="blockNumber">Block number or <see cref="BlockParameter.Latest" /> or <see cref="BlockParameter.Earliest" />.</param>
        /// <returns>The current balance in wei.</returns>
        public async Task <BigInteger> GetBalance(string address, BigInteger blockNumber)
        {
            string jsonResponse = await _in3.SendRpc(EthGetBalance, new object[] { address, BlockParameter.AsString(blockNumber) });

            return(DataTypeConverter.HexStringToBigint(RpcHandler.From <string>(jsonResponse)));
        }