Пример #1
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));
        }
Пример #2
0
 internal static string AsString(BigInteger block)
 {
     if (block == Latest)
     {
         return("latest");
     }
     if (block == Earliest || block < -1)
     {
         return("earliest");
     }
     return(DataTypeConverter.BigIntToPrefixedHex(block));
 }
Пример #3
0
        public void BigIntToPrefixedHex()
        {
            BigInteger n1 = -3482395934534543;
            BigInteger n2 = 0;
            BigInteger n3 = 15;
            BigInteger n4 = 17;

            Assert.That(DataTypeConverter.BigIntToPrefixedHex(n1), Is.EqualTo("-0xC5F387CA52B8F"));
            Assert.That(DataTypeConverter.BigIntToPrefixedHex(n2), Is.EqualTo("0x0"));
            Assert.That(DataTypeConverter.BigIntToPrefixedHex(n3), Is.EqualTo("0xF"));
            Assert.That(DataTypeConverter.BigIntToPrefixedHex(n4), Is.EqualTo("0x11"));
        }
Пример #4
0
        // For sure this should not be here at all. As soon as there is a decoupled way to abiEncode, got to extract this to a wrapper (e.g.: adapter or a factory method on TransactionRpc itself.
        private async Task <Rpc.Transaction> MapTransactionToRpc(TransactionRequest tx)
        {
            Rpc.Transaction result = new Rpc.Transaction();

            result.Data = tx.Data == null || tx.Data.Length < 2 ? "0x" : tx.Data;
            if (!String.IsNullOrEmpty(tx.Function))
            {
                string fnData = await AbiEncode(tx.Function, tx.Params);

                if (fnData != null && fnData.Length > 2 && fnData.StartsWith("0x"))
                {
                    result.Data += fnData.Substring(2 + (result.Data.Length > 2 ? 8 : 0));
                }
            }

            result.To   = tx.To;
            result.From = tx.From;
            if (tx.Value.HasValue)
            {
                result.Value = DataTypeConverter.BigIntToPrefixedHex(tx.Value.Value);
            }

            if (tx.Nonce.HasValue)
            {
                result.Nonce = DataTypeConverter.BigIntToPrefixedHex(tx.Nonce.Value);
            }

            if (tx.Gas.HasValue)
            {
                result.Gas = DataTypeConverter.BigIntToPrefixedHex(tx.Gas.Value);
            }

            if (tx.GasPrice.HasValue)
            {
                result.GasPrice = DataTypeConverter.BigIntToPrefixedHex(tx.GasPrice.Value);
            }

            if (result.Data == null || result.Data.Length < 2)
            {
                result.Data = "0x";
            }
            else
            {
                result.Data = DataTypeConverter.AddHexPrefixer(result.Data);
            }

            return(result);
        }
Пример #5
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));
        }
Пример #6
0
        /// <summary>
        /// Retrieve the logs for a certain filter. Logs marks changes of state on the blockchain for events. Equivalent to <see cref="Eth1.Api.GetFilterChangesFromLogs" />.
        /// </summary>
        /// <param name="filterId">Id returned during the filter creation.</param>
        /// <returns>Array of logs which occurred since last poll.</returns>
        /// <remarks>
        /// <para>Since the return is the <see langword="Log[]" /> since last poll, executing this multiple times changes the state making this a "non-idempotent" getter.</para>
        /// </remarks>
        public async Task <Log[]> GetFilterLogs(long filterId)
        {
            string jsonResponse = await _in3.SendRpc(EthGetFilterLogs, new object[] { DataTypeConverter.BigIntToPrefixedHex((BigInteger)filterId) });

            return(RpcHandler.From <Log[]>(jsonResponse));
        }
Пример #7
0
        /// <summary>
        /// Uninstalls a previously created filter.
        /// </summary>
        /// <param name="filterId">The filter id returned by <see cref="Eth1.Api.NewBlockFilter" />.</param>
        /// <returns>The result of the operation, <see langword="true" /> on success or <see langword="false" /> on failure.</returns>
        public async Task <bool> UninstallFilter(long filterId)
        {
            string jsonResponse = await _in3.SendRpc(EthUninstallFilter, new object[] { DataTypeConverter.BigIntToPrefixedHex(filterId) });

            return(RpcHandler.From <bool>(jsonResponse));
        }