Exemplo n.º 1
0
        public static byte[] EncodeRawTransaction(RawTransaction rawTransaction)
        {
            var values  = asRlpValues(rawTransaction);
            var rlpList = new RlpList(values);

            return(RlpEncoder.Encode(rlpList));
        }
Exemplo n.º 2
0
        public IRlpType ToRlpList(RawClause clause)
        {
            var list = new RlpList();

            list.AddRange(new RlpList
            {
                RlpString.Create(clause.To.HexString.HexStringToByteArray()),
                RlpString.Create(clause.Value.AsBytes),
                RlpString.Create(clause.Data.HexStringToByteArray())
            });
            return(list);
        }
Exemplo n.º 3
0
        public RlpTransaction(RawTransaction transaction)
        {
            if (transaction.chainTag == 0)
            {
                throw new ArgumentException("ChainTag is 0");
            }
            ChainTag = RlpString.Create(transaction.chainTag);

            if (transaction.blockRef is null)
            {
                throw new ArgumentException("BlockRef is 0");
            }
            BlockRef = RlpString.Create(UInt64.Parse(transaction.blockRef, System.Globalization.NumberStyles.HexNumber));

            if (transaction.expiration == 0)
            {
                throw new ArgumentException("Expiration is 0");
            }
            Expiration = RlpString.Create(transaction.expiration);


            Clauses = new RlpList();
            Clauses.AddRange(transaction.clauses.Select(ToRlpList));

            GasPriceCoef = transaction.gasPriceCoef == 0
                ? RlpString.Create(RlpString.EMPTY)
                : RlpString.Create(transaction.gasPriceCoef);

            if (transaction.gas == 0)
            {
                throw new ArgumentException("Gas is 0");
            }
            Gas = RlpString.Create(transaction.gas);

            DependsOn = transaction.dependsOn == null
                ? RlpString.Create(RlpString.EMPTY)
                : RlpString.Create(transaction.dependsOn);

            if (transaction.nonce is null)
            {
                throw new ArgumentException("Nonce is null");
            }
            Nonce = RlpString.Create(UInt64.Parse(transaction.nonce));

            RlpList reservedList = null;

            Reserved = reservedList;

            if (transaction.signature != null)
            {
                Signature = RlpString.Create(transaction.signature);
            }
        }
Exemplo n.º 4
0
        private static void FillClauses(RawTransaction rawTransaction, RlpList list)
        {
            var clauses     = list.Values;
            int clausesSize = clauses.Count;
            var rawClause   = new RawClause[clausesSize];

            rawTransaction.Clauses = rawClause;
            for (int clauseIndex = 0; clauseIndex < clausesSize; clauseIndex++)
            {
                var clauseContent = ((RlpList)clauses[clauseIndex]).Values;
                rawClause[clauseIndex] = new RawClause();
                FillOneClause(rawClause, clauseIndex, clauseContent);
            }
        }
Exemplo n.º 5
0
        private static List <RlpType> BuildRlpClausesLIst(RawTransaction rawTransaction)
        {
            var clauses = new List <RlpType>();

            foreach (var clause in rawTransaction.Clauses)
            {
                var rlpClause = new List <RlpType>();
                rlpClause.Add(clause.To == null ? RlpString.Create(RlpString.EMPTY) : RlpString.Create(clause.To));


                rlpClause.Add(clause.Value == null ? RlpString.Create(RlpString.EMPTY) : RlpString.Create(clause.Value));

                rlpClause.Add(clause.Data == null ? RlpString.Create(RlpString.EMPTY) : RlpString.Create(clause.Data));
                var clauseRLP = new RlpList(rlpClause);
                clauses.Add(clauseRLP);
            }
            return(clauses);
        }
Exemplo n.º 6
0
        public RlpList AsRlpValues()
        {
            var rlpList = new RlpList();

            rlpList.AddRange(new List <IRlpType>
            {
                ChainTag,
                BlockRef,
                Expiration,
                Clauses,
                GasPriceCoef,
                Gas,
                DependsOn,
                Nonce,
                Reserved
            });

            if (Signature != null)
            {
                rlpList.Add(Signature);
            }

            return(rlpList);
        }
Exemplo n.º 7
0
        private static List <RlpType> asRlpValues(RawTransaction rawTransaction)
        {
            var result = new List <RlpType>();

            if (rawTransaction.ChainTag == 0)
            {
                throw new ArgumentException("getChainTag is null");
            }
            result.Add(RlpString.Create(rawTransaction.ChainTag));

            if (rawTransaction.BlockRef == null)
            {
                throw new ArgumentException("getBlockRef is null");
            }
            result.Add(RlpString.Create(rawTransaction.BlockRef));

            if (rawTransaction.Expiration == null)
            {
                throw new ArgumentException("getExpiration is null");
            }
            result.Add(RlpString.Create(rawTransaction.Expiration));

            var clauses = BuildRlpClausesLIst(rawTransaction);
            var rlpList = new RlpList(clauses);

            result.Add(rlpList);

            if (rawTransaction.GasPriceCoef == 0)
            {
                result.Add(RlpString.Create(RlpString.EMPTY));
            }
            else
            {
                result.Add(RlpString.Create(rawTransaction.GasPriceCoef));
            }

            if (rawTransaction.Gas == null)
            {
                throw new ArgumentException("getGas is null");
            }
            result.Add(RlpString.Create(rawTransaction.Gas));

            if (rawTransaction.DependsOn == null)
            {
                result.Add(RlpString.Create(RlpString.EMPTY));
            }
            else
            {
                result.Add(RlpString.Create(rawTransaction.DependsOn));
            }

            if (rawTransaction.Nonce == null)
            {
                throw new ArgumentException("getNonce is null");
            }
            result.Add(RlpString.Create(rawTransaction.Nonce));

            if (rawTransaction.Reserved == null)
            {
                var reservedRlp  = new List <RlpType>();
                var reservedList = new RlpList(reservedRlp);
                result.Add(reservedList);
            }
            else
            {
                throw new ArgumentException("reservedList is not supported");
            }

            if (rawTransaction.Signature != null)
            {
                result.Add(RlpString.Create(rawTransaction.Signature));
            }
            return(result);
        }