Esempio n. 1
0
        public void TestRLPEncodeShortString()
        {
            List <byte[]> list = new List <byte[]>();

            list.Add(new byte[] { 0x01, 0x02 });
            list.Add(new byte[] { 0x01, 0x03 });
            var encodeResult = RLPUtils.EncodeMultiple(new byte[] { 0x01, 0x02 }, new byte[] { 0x01, 0x02 }, new byte[] { 0x01, 0x02 }, list, new List <byte[]>(), list);
            var collections  = RLP.Decode(encodeResult) as RLPCollection;

            Assert.Equal("0102", collections[0].RLPData.ToHex());
            Assert.Equal("0102", collections[1].RLPData.ToHex());
            Assert.Equal("0102", collections[2].RLPData.ToHex());
            Assert.Equal(list, (collections[3] as RLPCollection).Select(x => x.RLPData).ToList());
            Assert.Equal(new List <byte[]>(), (collections[4] as RLPCollection).Select(x => x.RLPData).ToList());
            Assert.Equal(list, (collections[5] as RLPCollection).Select(x => x.RLPData).ToList());
        }
Esempio n. 2
0
        public static byte[] EncodeMultTransfer(byte[] origin, byte[] dest, List <byte[]> from, List <byte[]> signatures, byte[] to, byte[] value, List <byte[]> pubkeyHashList)
        {
            int length = RLP.EncodeElement(origin).Length + RLP.EncodeElement(dest).Length + RLPUtils.EncodeList(from.ToArray()).Length + RLPUtils.EncodeList(signatures.ToArray()).Length + RLP.EncodeElement(to).Length + RLP.EncodeElement(value).Length + RLPUtils.EncodeList(pubkeyHashList.ToArray()).Length;

            if (length < 56)
            {
                return(Utils.Combine(new byte[] { (byte)(0xc0 + length) }, RLP.EncodeElement(origin), RLP.EncodeElement(dest), RLP.EncodeList(EncodeElementsBytes(from.ToArray())), RLP.EncodeList(EncodeElementsBytes(signatures.ToArray())), RLP.EncodeElement(to), RLP.EncodeElement(value), RLP.EncodeList(EncodeElementsBytes(pubkeyHashList.ToArray()))));
            }
            else
            {
                Tuple <byte, byte[]> tuple = NumericsUtils.getLengthByte(length);
                return(Utils.Combine(new byte[] { (byte)(0xf7 + tuple.Item1) }, tuple.Item2, RLP.EncodeElement(origin), RLP.EncodeElement(dest), RLP.EncodeList(EncodeElementsBytes(from.ToArray())), RLP.EncodeList(EncodeElementsBytes(signatures.ToArray())), RLP.EncodeElement(to), RLP.EncodeElement(value), RLP.EncodeList(EncodeElementsBytes(pubkeyHashList.ToArray()))));
            }
        }
Esempio n. 3
0
        public static byte[] EncodeMultiple(byte[] a, byte[] b, byte[] c, List <byte[]> d, List <byte[]> e, List <byte[]> f)
        {
            int length = RLP.EncodeElement(a).Length + RLP.EncodeElement(b).Length + RLP.EncodeElement(c).Length + RLPUtils.EncodeList(d.ToArray()).Length + RLPUtils.EncodeList(e.ToArray()).Length + RLPUtils.EncodeList(f.ToArray()).Length;

            if (length < 56)
            {
                return(Utils.Combine(new byte[] { (byte)(0xc0 + length) }, RLP.EncodeElement(a), RLP.EncodeElement(b), RLP.EncodeElement(c), RLP.EncodeList(EncodeElementsBytes(d.ToArray())), RLP.EncodeList(EncodeElementsBytes(e.ToArray())), RLP.EncodeList(EncodeElementsBytes(f.ToArray()))));
            }
            else
            {
                Tuple <byte, byte[]> tuple = NumericsUtils.getLengthByte(length);
                return(Utils.Combine(new byte[] { (byte)(0xf7 + tuple.Item1) }, tuple.Item2, RLP.EncodeElement(a), RLP.EncodeElement(b), RLP.EncodeElement(c), RLP.EncodeList(EncodeElementsBytes(d.ToArray())), RLP.EncodeList(EncodeElementsBytes(e.ToArray())), RLP.EncodeList(EncodeElementsBytes(f.ToArray()))));
            }
        }