示例#1
0
        private void DeserializeRawTransaction(byte[] rawTxnBytes)
        {
            _rawTxnBytes = rawTxnBytes;
            RawTransaction rawTr = RawTransaction.Parser.ParseFrom(_rawTxnBytes);

            ExpirationTimeUnix = rawTr.ExpirationTime;
            ExpirationTime     = rawTr.ExpirationTime.UnixTimeStampToDateTime();

            GasUnitPrice = rawTr.GasUnitPrice;
            MaxGasAmount = rawTr.MaxGasAmount;
            PayloadCase  = (short)rawTr.PayloadCase;

            Sender   = BitConverter.ToString(rawTr.SenderAccount.ToByteArray()).Replace("-", "").ToLower();
            Receiver = BitConverter.ToString(rawTr.Program.Arguments[0]
                                             .Data.ToByteArray()).Replace("-", "").ToLower();
            Amount         = BitConverter.ToUInt64(rawTr.Program.Arguments[1].Data.ToByteArray());
            SequenceNumber = rawTr.SequenceNumber;

            List <CustomTransactionArgument> arguments = new List <CustomTransactionArgument>();

            foreach (var item in rawTr.Program.Arguments)
            {
                var transactionArgument = new CustomTransactionArgument();
                transactionArgument.Data = item.Data.ToByteArray();
                transactionArgument.Type = (short)item.Type;
                arguments.Add(transactionArgument);
            }

            List <byte[]> modules = new List <byte[]>();

            foreach (var item in rawTr.Program.Modules)
            {
                modules.Add(item.ToByteArray());
            }

            Program = new CustomProgram()
            {
                Arguments = arguments,
                Code      = rawTr.Program.Code.ToByteArray(),
                Modules   = modules
            };
        }
        private void DeserializeRawTransaction(byte[] rawTxnBytes)
        {
            _rawTxnBytes = rawTxnBytes;

            int cursor = 0;
            RawTransactionLCS rawTr = _rawTxnBytes.LCDeserialize <RawTransactionLCS>(ref cursor);

            ///TODO
            FirestUint = rawTr.FirstUint;

            ExpirationTimeUnix = rawTr.ExpirationTime;
            ExpirationTime     = rawTr.ExpirationTime.UnixTimeStampToDateTime();

            GasUnitPrice = rawTr.GasUnitPrice;
            MaxGasAmount = rawTr.MaxGasAmount;
            PayloadCase  = rawTr.TransactionPayload.PayloadTypeEnum;

            Sender = rawTr.Sender.Value;

            var programCode = rawTr.TransactionPayload.PayloadTypeEnum;

            //if (Utility.IsPtPOrMint(programCode))
            if (rawTr.TransactionPayload.PayloadTypeEnum ==
                ETransactionPayloadLCS.Program)
            {
                var args = rawTr.TransactionPayload.Program.TransactionArguments.ToArray();
                if (args.Count() == 2 &&
                    args[0].ArgTypeEnum == ETransactionArgumentLCS.Address &&
                    args[1].ArgTypeEnum == ETransactionArgumentLCS.U64)
                {
                    Receiver = args[0].Address.Value;
                    Amount   = args[1].U64;
                }
            }

            SequenceNumber = rawTr.SequenceNumber;

            if (rawTr.TransactionPayload.PayloadTypeEnum ==
                ETransactionPayloadLCS.Script &&
                Utility.IsPtPOrMint(rawTr.TransactionPayload.Script.Code))
            {
                var args = rawTr.TransactionPayload.Script
                           .TransactionArguments.ToArray();
                if (args.Count() == 2 &&
                    args[0].ArgTypeEnum == ETransactionArgumentLCS.Address &&
                    args[1].ArgTypeEnum == ETransactionArgumentLCS.U64)
                {
                    Receiver = args[0].Address.Value;
                    Amount   = args[1].U64;
                }
            }

            if (rawTr.TransactionPayload.PayloadTypeEnum ==
                ETransactionPayloadLCS.Program)
            {
                List <CustomTransactionArgument> arguments =
                    new List <CustomTransactionArgument>();
                foreach (var item in rawTr.TransactionPayload.Program
                         .TransactionArguments)
                {
                    GerArg(arguments, item);
                }

                List <byte[]> modules = new List <byte[]>();

                foreach (var item in rawTr.TransactionPayload.Program.Modules)
                {
                    modules.Add(item);
                }

                Program = new CustomProgram()
                {
                    PayloadType = (ETransactionPayload)rawTr.TransactionPayload
                                  .PayloadTypeEnum,
                    Arguments = arguments,
                    Code      = rawTr.TransactionPayload.Program.Code,
                    Modules   = modules
                };
            }
            else if (rawTr.TransactionPayload.PayloadTypeEnum ==
                     ETransactionPayloadLCS.Script)
            {
                List <CustomTransactionArgument> arguments =
                    new List <CustomTransactionArgument>();
                foreach (var item in rawTr.TransactionPayload.Script
                         .TransactionArguments)
                {
                    GerArg(arguments, item);
                }

                Program = new CustomProgram()
                {
                    PayloadType = (ETransactionPayload)rawTr.TransactionPayload
                                  .PayloadTypeEnum,
                    Arguments = arguments,
                    Code      = rawTr.TransactionPayload.Script.Code
                };
            }
            else if (rawTr.TransactionPayload.PayloadTypeEnum ==
                     ETransactionPayloadLCS.Module)
            {
                List <byte[]> modules = new List <byte[]>();
                modules.Add(rawTr.TransactionPayload.Module.Code);

                Program = new CustomProgram()
                {
                    PayloadType = (ETransactionPayload)rawTr.TransactionPayload
                                  .PayloadTypeEnum,
                    Modules = modules
                };
            }
        }