Ejemplo n.º 1
0
        public void TestEncodeEmptyString()
        {
            string test     = "";
            string expected = "80";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 2
0
        public void TestEncodeEmptyStringList()
        {
            string[] test     = new string[0];
            string   expected = "c0";
            string   result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 3
0
        public void TestEncodeLongString()
        {
            string test     = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
            string expected = "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 请求发送RPC交易
        /// </summary>
        /// <typeparam name="TResult">返回结果</typeparam>
        /// <param name="txData">交易数据(rlp)</param>
        /// <param name="txSignature">交易签名</param>
        /// <returns>返回交易结果</returns>
        protected TResult SendRequest <TResult>(byte[][] txData, EthECDSASignature txSignature) where TResult : class, new()
        {
            var rlpSignedEncoded = RLPEncoder.EncodeSigned(new SignedData(txData, txSignature), 10).ToHex();
            var request          = new RpcRequestMessage(this._requestId, JsonRPCAPIConfig.SendRawTransaction, new object[] { this._requestObjectId, rlpSignedEncoded });
            var result           = HttpUtils.RpcPost <TResult>(this._url, request);

            return(result);
        }
Ejemplo n.º 5
0
        public void TestEncodeMediumInteger()
        {
            int    test     = 1024;
            string expected = "820400";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 6
0
        public void TestEncodeBigInteger()
        {
            UInt64 test     = 18446744073709551615;
            string expected = "88ffffffffffffffff";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 7
0
        public void TestEncodeZero()
        {
            int    test     = 0;
            string expected = "80";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 8
0
        public void TestEncodeLowInteger()
        {
            int    test     = 15;
            string expected = "0f";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 9
0
        public void TestEncodeShortStringList()
        {
            string[] test     = new string[] { "dog", "god", "cat" };
            string   expected = "cc83646f6783676f6483636174";
            string   result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 10
0
        public void TestEncodeMultiList()
        {
            Object[] test     = new Object[] { 1, new Object[] { "cat" }, "dog", new Object[] { 2 } };
            string   expected = "cc01c48363617483646f67c102";
            string   result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 11
0
        public void TestEncodeSingleCharacter()
        {
            string test     = "d";
            string expected = "64";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 12
0
        public void TestEncodeSingleString()
        {
            string test     = "dog";
            string expected = "83646f67";
            string result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 13
0
        public void TestEncodeTwoListsOfEmptyLists()
        {
            Object[] test     = new Object[] { new Object[] { }, new Object[] { new Object[] { } }, new Object[] { new Object[] { }, new Object[] { new Object[] { } } } };
            string   expected = "c7c0c1c0c3c0c1c0";
            string   result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 异步请求发送RPC交易
        /// </summary>
        /// <typeparam name="TResult">返回结果</typeparam>
        /// <param name="txData">交易数据(rlp)</param>
        /// <param name="txSignature">交易签名</param>
        /// <returns>返回交易结果</returns>
        protected async Task <TResult> SendRequestAysnc <TResult>(byte[][] txData, EthECDSASignature txSignature)
        {
            var rlpSignedEncoded = RLPEncoder.EncodeSigned(new SignedData(txData, txSignature), 10).ToHex();
            var request          = new RpcRequest(this._requestId, JsonRPCAPIConfig.SendRawTransaction, new object[] { this._requestObjectId, rlpSignedEncoded });
            var response         = await _rpcClient.SendRequestAsync <TResult>(request);

            return(response);
        }
Ejemplo n.º 15
0
        public void TestEncodeArrayOfEmptyStrings()
        {
            string[] test     = new string[] { };
            string   expected = "c0";
            string   result   = RLPEncoder.Encode(test).ToHex();

            Assert.AreEqual(result, expected);
        }
Ejemplo n.º 16
0
        public void TestEncodeLengthHigherThan55()
        {
            int Length = 56;
            int Offset = 192;

            byte[] expected      = new byte[] { 0xf8, 0x38 };
            byte[] EncodedLength = RLPEncoder.EncodeLength(Length, Offset);
            Assert.AreEqual(expected.ToHex(), EncodedLength.ToHex());
        }
Ejemplo n.º 17
0
        public void TestEncodeLengthLowerThan56()
        {
            int Length = 1;
            int Offset = 128;

            byte[] expected      = new byte[] { (byte)0x81 };
            byte[] EncodedLength = RLPEncoder.EncodeLength(Length, Offset);
            Assert.AreEqual(expected.ToHex(), EncodedLength.ToHex());
        }
Ejemplo n.º 18
0
        private string GetPrivateSignedTransaction(string txnSigned)
        {
            if (PrivateFor != null && PrivateFor.Count > 0)
            {
                var signedData = RLPDecoder.DecodeSigned(txnSigned.HexToByteArray(), 6);

                if (signedData.V[0] == 28)
                {
                    signedData.V[0] = 38;
                }
                else
                {
                    signedData.V[0] = 37;
                }

                return(RLPEncoder.EncodeSigned(signedData, 6).ToHex());
            }

            return(txnSigned);
        }
Ejemplo n.º 19
0
 public void TestEncodeNull()
 {
     byte[] result = RLPEncoder.Encode(null);
 }