Exemplo n.º 1
0
        public static KeyValuePair <BaseTransaction, int> Deserialize(IEnumerable <byte> payload)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            SmartContractTransaction result = new SmartContractTransaction();
            int currentStartIndex           = 0;

            result.Version    = BitConverter.ToUInt32(payload.Take(4).ToArray(), 0);
            result.Category   = (TransactionCategories)payload.ElementAt(4);
            currentStartIndex = 5;
            var fromCompactSize = CompactSize.Deserialize(payload.Skip(currentStartIndex).ToArray()); // FROM

            currentStartIndex += fromCompactSize.Value;
            if (fromCompactSize.Key.Size > 0)
            {
                result.From        = payload.Skip(currentStartIndex).Take((int)fromCompactSize.Key.Size);
                currentStartIndex += (int)fromCompactSize.Key.Size;
            }

            var toCompactSize = CompactSize.Deserialize(payload.Skip(currentStartIndex).ToArray()); // TO

            currentStartIndex += toCompactSize.Value;
            if (toCompactSize.Key.Size > 0)
            {
                result.To          = payload.Skip(currentStartIndex).Take((int)toCompactSize.Key.Size);
                currentStartIndex += (int)toCompactSize.Key.Size;
            }

            var dataCompactSize = CompactSize.Deserialize(payload.Skip(currentStartIndex).ToArray()); // DATA

            currentStartIndex += dataCompactSize.Value;
            if (dataCompactSize.Key.Size > 0)
            {
                result.Data        = payload.Skip(currentStartIndex).Take((int)dataCompactSize.Key.Size);
                currentStartIndex += (int)dataCompactSize.Key.Size;
            }

            result.Gas         = BitConverter.ToDouble(payload.Skip(currentStartIndex).Take(8).ToArray(), 0);
            currentStartIndex += 8;
            result.GasPrice    = BitConverter.ToDouble(payload.Skip(currentStartIndex).Take(8).ToArray(), 0);
            currentStartIndex += 8;
            result.Value       = BitConverter.ToDouble(payload.Skip(currentStartIndex).Take(8).ToArray(), 0);
            currentStartIndex += 8;
            result.Nonce       = BitConverter.ToInt32(payload.Skip(currentStartIndex).Take(4).ToArray(), 0);
            currentStartIndex += 4;
            result.LockTime    = BitConverter.ToUInt32(payload.Skip(currentStartIndex).Take(4).ToArray(), 0);
            currentStartIndex += 4;
            return(new KeyValuePair <BaseTransaction, int>(result, currentStartIndex));
        }
Exemplo n.º 2
0
        public static KeyValuePair <BaseTransaction, int> Deserialize(IEnumerable <byte> payload)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }

            var type = (TransactionCategories)payload.ElementAt(4);

            switch (type)
            {
            case TransactionCategories.Monetary:
                return(BcBaseTransaction.Deserialize(payload));

            case TransactionCategories.SmartContract:
                return(SmartContractTransaction.Deserialize(payload));
            }

            return(default(KeyValuePair <BaseTransaction, int>));
        }