Exemple #1
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);
        }
Exemple #2
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);
            }
        }
        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);
        }
        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);
        }