Beispiel #1
0
        public static BlockCapsule GenerateGenesisBlock()
        {
            List <Transaction> transactions = Args.Instance.GenesisBlock.Assets.Select(asset =>
            {
                return(TransactionCapsule.GenerateGenesisTransaction(Wallet.Base58ToAddress(asset.Address), asset.Balance));
            }).ToList();

            BlockCapsule result = new BlockCapsule((int)Args.Instance.GenesisBlock.Timestamp,
                                                   ByteString.CopyFrom(Args.Instance.GenesisBlock.ParentHash),
                                                   Args.Instance.GenesisBlock.Number,
                                                   transactions);

            result.SetMerkleTree();
            result.SetWitness("A new system must allow existing systems to be linked together without "
                              + "requiring any central control or coordination");
            result.IsGenerateMyself = true;

            return(result);
        }
Beispiel #2
0
 public void AddTransaction(TransactionCapsule tx)
 {
     this.block.Transactions.Add(tx.Instance);
     this.transactions.Add(tx);
 }
        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));
        }