Esempio n. 1
0
        public static Serializer Create(TxData obj)
        {
            obj = (TxData)obj.Clone();
            if (obj.TransactionType is int || obj.TransactionType is TransactionType)
            {
                var transactionType = (TransactionType)obj.TransactionType;
                if (!Enum.IsDefined(typeof(TransactionType), transactionType))
                {
                    throw new InvalidOperationException("Invalid transaction type!");
                }

                obj.TransactionType = transactionType.ToString();
            }

            List <List <object> > typedef = null;

            if (obj.TransactionType is string transactionTypeStr)
            {
                TransactionType transactionType;
                if (!Enum.TryParse(transactionTypeStr, out transactionType))
                {
                    throw new InvalidOperationException("Invalid transaction type!");
                }

                obj.TransactionType = (int)transactionType;
                typedef             = _transactionTypeMetas[transactionType];
            }
            else
            {
                throw new InvalidOperationException("Object to be serialized must contain either TransactionType, LedgerEntryType or AffectedNodes.");
            }

            var so = new Serializer();

            so.Serialize(typedef, obj);
            return(so);
        }
Esempio n. 2
0
 private void Serialize(List <List <object> > typedef, TxData obj)
 {
     SerializedTypeHelper.STObject.Serialize(this, obj, true);
 }