Esempio n. 1
0
 public static ResourceReceipt CopyReceipt(ReceiptCapsule origin)
 {
     return(new ResourceReceipt(origin.Receipt));
 }
Esempio n. 2
0
        public static TransactionInfoCapsule BuildInstance(TransactionCapsule transaction, BlockCapsule block, TransactionTrace trace)
        {
            TransactionInfo result  = new TransactionInfo();
            ReceiptCapsule  receipt = trace.Receipt;

            result.Result = TransactionInfo.Types.code.Sucess;
            if (trace.RuntimeError.IsNotNullOrEmpty() ||
                trace.Result.Exception != null)
            {
                result.Result     = TransactionInfo.Types.code.Failed;
                result.ResMessage = ByteString.CopyFromUtf8(trace.RuntimeError);
            }

            result.Id = ByteString.CopyFrom(transaction.Id.Hash);
            ProgramResult program_result = trace.Result;

            long fee = program_result.TransactionResult.Fee
                       + receipt.EnergyFee
                       + receipt.NetFee
                       + receipt.MultiSignFee;


            result.Fee = fee;
            result.ContractResult.Add(ByteString.CopyFrom(program_result.HReturn));
            result.ContractAddress               = ByteString.CopyFrom(program_result.ContractAddress);
            result.UnfreezeAmount                = program_result.TransactionResult.UnfreezeAmount;
            result.AssetIssueID                  = program_result.TransactionResult.AssetIssueID;
            result.ExchangeId                    = program_result.TransactionResult.ExchangeId;
            result.WithdrawAmount                = program_result.TransactionResult.WithdrawAmount;
            result.ExchangeReceivedAmount        = program_result.TransactionResult.ExchangeReceivedAmount;
            result.ExchangeInjectAnotherAmount   = program_result.TransactionResult.ExchangeInjectAnotherAmount;
            result.ExchangeWithdrawAnotherAmount = program_result.TransactionResult.ExchangeWithdrawAnotherAmount;

            List <TransactionInfo.Types.Log> logs = new List <TransactionInfo.Types.Log>();

            program_result.LogInfos.ForEach(info => logs.Add(LogInfo.BuildLog(info)));
            result.Log.AddRange(logs);

            if (block != null)
            {
                result.BlockNumber    = block.Instance.BlockHeader.RawData.Number;
                result.BlockTimeStamp = block.Instance.BlockHeader.RawData.Timestamp;
            }

            result.Receipt = receipt.Receipt;

            if (Args.Instance.VM.SaveInternalTx == true && program_result.InternalTransactions != null)
            {
                foreach (var tx in program_result.InternalTransactions)
                {
                    Protocol.InternalTransaction internal_transaction = new Protocol.InternalTransaction();
                    internal_transaction.Hash              = ByteString.CopyFrom(tx.Hash);
                    internal_transaction.CallerAddress     = ByteString.CopyFrom(tx.SendAddress);
                    internal_transaction.TransferToAddress = ByteString.CopyFrom(tx.TransferToAddress);

                    CallValueInfo call_value_info = new CallValueInfo();
                    call_value_info.CallValue = tx.Value;
                    internal_transaction.CallValueInfo.Add(call_value_info);

                    foreach (var token_info in tx.TokenInfo)
                    {
                        call_value_info           = new CallValueInfo();
                        call_value_info.TokenId   = token_info.Key;
                        call_value_info.CallValue = token_info.Value;
                        internal_transaction.CallValueInfo.Add(call_value_info);
                    }

                    internal_transaction.Note     = ByteString.CopyFrom(Encoding.UTF8.GetBytes(tx.Note));
                    internal_transaction.Rejected = tx.IsReject;
                    result.InternalTransactions.Add(internal_transaction);
                }
            }

            return(new TransactionInfoCapsule(result));
        }