/// <summary> /// query all transactions(on chain) /// </summary> /// <returns></returns> public async Task <object> QueryTransactions(int pageIndex = 1, int limit = 100, uint?blockHeight = null) { using var db = new TrackDB(); var trans = db.FindTransactions(new TransactionFilter() { BlockHeight = blockHeight, PageIndex = pageIndex, PageSize = limit }); var transfers = new List <TransferInfo>(); if (trans.List.NotEmpty()) { transfers = db.FindTransfer(new TransferFilter() { TxIds = trans.List.Select(tx => tx.TxId).ToList(), PageSize = int.MaxValue }).List; } var result = new PageList <TransactionPreviewModel> { TotalCount = trans.TotalCount, PageSize = trans.PageSize, PageIndex = pageIndex, List = ConvertToTransactionPreviewModel(trans.List, transfers), }; return(result); }
/// <summary> /// query transaction info /// </summary> /// <returns></returns> public async Task <PageList <TransferInfo> > QueryTransfers(TransferFilter filter) { using var db = new TrackDB(); var result = db.FindTransfer(filter) as PageList <TransferInfo>; return(result); }
/// <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); }