Beispiel #1
0
        public Block GetBlockByNumber(int blockNumber, BlockTag blockTag, bool returnFullObject)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getBlockByNumber);

            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToHexString());
            }

            rpcRequest.AddParam(returnFullObject);
            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);
            var json      = JsonConvert.SerializeObject(rpcResult.Result);
            var block     = JsonConvert.DeserializeObject <Block>(json);

            return(block);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the number of transactions sent from an address.
        /// </summary>
        /// <param name="address">address</param>
        /// <param name="blockTag">Block Param</param>
        /// <param name="blockNumber">integer block number,</param>
        /// <returns>integer of the number of transactions send from this address.</returns>
        public long GetTransactionCount(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getTransactionCount);

            rpcRequest.AddParam(address);

            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToString());
            }

            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);
            var balance   = Convert.ToInt64(rpcResult.Result, 16);

            return(balance);
        }
 public Filter(string fromBlock = null, string toBlock = null,BlockTag from = BlockTag.Earliest, BlockTag to = BlockTag.Pending, string address = null, string[] topics = null)
 {
     FromBlock = fromBlock ?? from.ToJsonMethodName();
     ToBlock = toBlock ?? to.ToJsonMethodName();
     Address = address;
     Topics = topics;
 }
Beispiel #4
0
        /// <summary>
        /// Returns the balance of the account of given address.
        /// </summary>
        /// <param name="address">address to check for balance.</param>
        /// <param name="blockTag"> integer block number</param>
        /// <param name="blockNumber">Block param</param>
        /// <returns></returns>
        public BigInteger GetBalance(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getBalance);

            rpcRequest.AddParam(address);
            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToString());
            }

            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);

            if (rpcResult.Result == null)
            {
                return(0);
            }

            string value   = rpcResult.Result.ToString();
            var    balance = value.ToBigInteger();

            return(balance);
        }
Beispiel #5
0
 public Filter(string fromBlock = null, string toBlock = null, BlockTag from = BlockTag.Earliest, BlockTag to = BlockTag.Pending, string address = null, string[] topics = null)
 {
     FromBlock = fromBlock ?? from.ToJsonMethodName();
     ToBlock   = toBlock ?? to.ToJsonMethodName();
     Address   = address;
     Topics    = topics;
 }
Beispiel #6
0
        /// <summary>
        /// Returns code at a given address.
        /// </summary>
        /// <param name="address">address</param>
        /// <param name="blockTag"></param>
        /// <param name="blockNumber">integer block number,</param>
        /// <returns></returns>
        public string GetCode(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getCode);

            rpcRequest.AddParam(address);

            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToHexString());
            };
            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);

            return(rpcResult.Result);
        }
        /// <summary>
        /// Returns the number of transactions sent from an address.
        /// </summary>
        /// <param name="address">address</param>
        /// <param name="blockTag">Block Param</param>
        /// <param name="blockNumber">integer block number,</param>
        /// <returns>integer of the number of transactions send from this address.</returns>
        public long GetTransactionCount(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getTransactionCount);
            rpcRequest.AddParam(address);

            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToString());
            }

            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);
            var balance = Convert.ToInt64(rpcResult.Result, 16);
            return balance;
        }
        /// <summary>
        /// Returns code at a given address.
        /// </summary>
        /// <param name="address">address</param>
        /// <param name="blockTag"></param>
        /// <param name="blockNumber">integer block number,</param>
        /// <returns></returns>
        public string GetCode(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getCode);
            rpcRequest.AddParam(address);

            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToHexString());
            };
            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);

            return rpcResult.Result;
        }
        public Block GetBlockByNumber(int blockNumber, BlockTag blockTag, bool returnFullObject)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getBlockByNumber);
            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToHexString());
            }

            rpcRequest.AddParam(returnFullObject);
            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);
            var json = JsonConvert.SerializeObject(rpcResult.Result);
            var block = JsonConvert.DeserializeObject<Block>(json);
            return block;
        }
        /// <summary>
        /// Returns the balance of the account of given address.
        /// </summary>
        /// <param name="address">address to check for balance.</param>
        /// <param name="blockTag"> integer block number</param>
        /// <param name="blockNumber">Block param</param>
        /// <returns></returns>
        public BigInteger GetBalance(string address, BlockTag blockTag = BlockTag.Quantity, int blockNumber = -1)
        {
            var rpcRequest = new RpcRequest(RpcMethod.eth_getBalance);
            rpcRequest.AddParam(address);
            if (blockTag != BlockTag.Quantity && blockNumber > -1)
            {
                throw new Exception("Balance tag and block number cannot both be provided, chose either");
            }

            if (blockTag != BlockTag.Quantity)
            {
                rpcRequest.AddParam(blockTag.ToJsonMethodName());
            }
            else
            {
                rpcRequest.AddParam(blockNumber.ToString());
            }

            var rpcResult = new RpcConnector().MakeRequest(rpcRequest);

            if (rpcResult.Result == null)
            {
                return 0;
            }

            string value = rpcResult.Result.ToString();
            var balance = value.ToBigInteger();

            return balance;
        }