/// <summary>
        /// GetTransactionLog
        /// </summary>
        /// <returns></returns>
        public async Task <object> GetApplicationLog(UInt256 txId)
        {
            var db     = new TrackDB();
            var result = db.GetExecuteLog(txId);

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// query transaction info
        /// </summary>
        /// <param name="txId"></param>
        /// <param name="showJson"></param>
        /// <returns></returns>
        public async Task <object> GetRawTransaction(UInt256 txId, bool showJson = false)
        {
            var snapshot    = Helpers.GetDefaultSnapshot();
            var transaction = snapshot.GetTransaction(txId);

            if (transaction == null)
            {
                return(Error(ErrorCode.TxIdNotFound));
            }
            if (showJson)
            {
                JObject          json    = transaction.ToJson(CliSettings.Default.Protocol);
                TransactionState txState = snapshot.GetTransactionState(txId);
                if (txState != null)
                {
                    Header header = snapshot.GetHeader(txState.BlockIndex);
                    json["blockhash"]     = header.Hash.ToString();
                    json["confirmations"] = snapshot.GetHeight() - header.Index + 1;
                    json["blocktime"]     = header.Timestamp;
                    using var db          = new TrackDB();
                    var executelog = db.GetExecuteLog(txId);
                    json["vm_state"] = executelog?.VMState;
                }
                return(json.ToString());
            }
            return(transaction.ToArray().ToHexString());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// analysis block transaction execute result logs
        /// </summary>
        /// <param name="blockHeight"></param>
        /// <returns></returns>
        public async Task <bool> Sync(uint blockHeight)
        {
            if (blockHeight > Blockchain.Singleton.Height)
            {
                return(false);
            }

            if (_db.HasSyncIndex(blockHeight))
            {
                return(true);
            }

            var block = Blockchain.Singleton.GetBlock(blockHeight);

            if (block.Transactions.IsEmpty())
            {
                return(true);
            }
            using var snapshot = Blockchain.Singleton.GetSnapshot();
            foreach (var transaction in block.Transactions)
            {
                _db.AddTransaction(new TransactionInfo()
                {
                    TxId        = transaction.Hash,
                    BlockHeight = blockHeight,
                    Sender      = transaction.Sender,
                    Time        = block.Timestamp.FromTimestampMS(),
                });
                var executeResult = _db.GetExecuteLog(transaction.Hash);
                if (executeResult == null || executeResult.VMState.HasFlag(VMState.FAULT) || executeResult.Notifications.IsEmpty())
                {
                    continue;
                }

                foreach (var notification in executeResult.Notifications)
                {
                    HasTransfer(notification, transaction, block, snapshot);
                }

                //shouldCommit = executeResult.Notifications.Aggregate(shouldCommit, (current, notification) => current | HasTransfer(notification, transaction, block, snapshot));
            }

            _db.AddSyncIndex(blockHeight);
            _db.Commit();
            Console.WriteLine($"Syncing:{_scanHeight}");
            if (_db.LiveTime.TotalSeconds > 15)
            {
                //release memory
                _db.Dispose();
                _db = new TrackDB();
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// query transaction info
        /// </summary>
        /// <param name="txId"></param>
        /// <returns></returns>
        public async Task <object> GetTransaction(UInt256 txId)
        {
            var snapshot    = Helpers.GetDefaultSnapshot();
            var transaction = snapshot.GetTransaction(txId);

            if (transaction == null)
            {
                return(Error(ErrorCode.TxIdNotFound));
            }

            var model = new TransactionModel(transaction);

            var txState = snapshot.GetTransactionState(txId);

            if (txState != null)
            {
                Header header = snapshot.GetHeader(txState.BlockIndex);
                model.BlockHash     = header.Hash;
                model.BlockHeight   = txState.BlockIndex;
                model.Timestamp     = header.Timestamp;
                model.Confirmations = snapshot.GetHeight() - header.Index + 1;
            }
            using var db = new TrackDB();
            var trans = db.QueryTransfers(new TransferFilter()
            {
                TxIds = new List <UInt256>()
                {
                    txId
                }, PageSize = int.MaxValue
            }).List;

            model.Transfers = trans.Select(tx => tx.ToTransferModel()).ToList();

            var executeResult = db.GetExecuteLog(txId);

            if (executeResult?.Notifications.NotEmpty() == true)
            {
                model.Notifies.AddRange(
                    executeResult.Notifications.Select(n => new NotifyModel()
                {
                    Contract  = n.Contract,
                    EventName = n.EventName,
                    State     = JStackItem.FromJson(n.State),
                }));
            }
            return(model);
        }
        /// <summary>
        /// query transaction info
        /// </summary>
        /// <param name="txId"></param>
        /// <returns></returns>
        public async Task <object> GetTransaction(UInt256 txId)
        {
            var transaction = Blockchain.Singleton.GetTransaction(txId);

            if (transaction == null)
            {
                return(Error(ErrorCode.TxIdNotFound));
            }

            var model = new TransactionModel(transaction);

            TransactionState txState = Blockchain.Singleton.View.Transactions.TryGet(txId);

            if (txState != null)
            {
                Header header = Blockchain.Singleton.GetHeader(txState.BlockIndex);
                model.BlockHash     = header.Hash;
                model.BlockHeight   = txState.BlockIndex;
                model.Timestamp     = header.Timestamp;
                model.Confirmations = Blockchain.Singleton.Height - header.Index + 1;
            }
            using var db = new TrackDB();
            var trans = db.FindTransfer(new TransferFilter()
            {
                TxIds = new List <UInt256>()
                {
                    txId
                }, PageSize = int.MaxValue
            }).List;

            model.Transfers = trans.Select(tx => tx.ToTransferModel()).ToList();

            var executeResult = db.GetExecuteLog(txId);

            if (executeResult?.Notifications.NotEmpty() == true)
            {
                model.Notifies.AddRange(
                    executeResult.Notifications.Select(n => new NotifyModel()
                {
                    Contract = UInt160.Parse(n.Contract),
                    State    = JStackItem.FromJson(n.State),
                }));
            }
            return(model);
        }