// Query a transaction with transaction id /// <summary>Query a transaction with transaction id</summary> /// <param name="bcname">the name of blockchain</param> /// <param name="txid">transaction id</param> /// <return>the request response, the <c>Data</c> field is a Transaction type</return> public Response QueryTx(string bcname, string txid) { var response = new Response() { Error = new XChainError() { ErrorCode = ErrorCode.Success, ErrorMessage = "Success", } }; if (string.IsNullOrEmpty(bcname) || string.IsNullOrEmpty(txid)) { return(MakeErrorResponse(ErrorCode.ParamError, null)); } var req = new Pb.TxStatus { Header = GetDefaultHeader(), Bcname = bcname, Txid = ByteString.CopyFrom(XConvert.HexStringToByteArray(txid)), }; var tx = client.QueryTx(req); if (tx.Header.Error != Pb.XChainErrorEnum.Success) { Console.WriteLine("query tx failed. errcode=" + (int)tx.Header.Error + ", logid=" + req.Header.Logid); return(MakeErrorResponse(ErrorCode.UnknownError, null)); } response.Data = XConvert.PbTxToLocalTx(tx.Tx); return(response); }
// Query a block with block id /// <summary>Query a block with block id</summary> /// <param name="bcname">the name of blockchain</param> /// <param name="blockid">block id</param> /// <return>the request response, the <c>Data</c> field is a Block type</return> public Response QueryBlock(string bcname, string blockid) { var req = new Pb.BlockID { Header = GetDefaultHeader(), Bcname = bcname, Blockid = ByteString.CopyFrom(XConvert.HexStringToByteArray(blockid)), NeedContent = true, }; var res = client.GetBlock(req); if (res.Header.Error != Pb.XChainErrorEnum.Success) { Console.WriteLine("query block failed. errcode=" + (int)res.Header.Error + ", logid=" + req.Header.Logid); return(MakeErrorResponse(ErrorCode.ConnectFailed, null)); } var block = XConvert.PbBlockToLocalBlock(res); return(MakeResponse("", block)); }