示例#1
0
 public static ReceiptModel FromSmartContractReceipt(SmartContractReceipt receipt, Network network)
 {
     return(new ReceiptModel
     {
         TxHash = new uint256(receipt.TxHash).ToString(),
         BlockHeight = receipt.BlockHeight,
         ContractAddress = receipt.NewContractAddress != null ? new uint160(receipt.NewContractAddress).ToAddress(network).ToString() : null,
         Successful = receipt.Successful,
         Exception = receipt.Exception,
         Returned = receipt.Returned
     });
 }
        public void ReceiptStorage_General_Use()
        {
            // Test that we can save and retrieve a receipt, even if everything but the transaction hash is null.
            var txContextMock = new Mock <ISmartContractTransactionContext>();

            txContextMock.Setup(x => x.TransactionHash).Returns(() => new uint256(0));
            ISmartContractTransactionContext txContext = txContextMock.Object;
            ISmartContractExecutionResult    result    = new Mock <ISmartContractExecutionResult>().Object;

            this.receiptStorage.SaveReceipt(txContext, result);
            SmartContractReceipt receipt = this.receiptStorage.GetReceipt(txContext.TransactionHash);

            Assert.NotNull(receipt);
        }
        public IActionResult GetReceipt([FromQuery] string txHash)
        {
            this.logger.LogTrace("(){0}:{1}", nameof(txHash), txHash);
            if (!this.ModelState.IsValid)
            {
                this.logger.LogTrace("(-)[MODELSTATE_INVALID]");
                return(BuildErrorResponse(this.ModelState));
            }

            uint256 txHashNum            = new uint256(txHash);
            SmartContractReceipt receipt = this.receiptStorage.GetReceipt(txHashNum);

            if (receipt == null)
            {
                this.logger.LogTrace("(-)[RECEIPT_NOT_FOUND]");
                return(ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest,
                                                       "Receipt not found.",
                                                       "Could not find a stored transaction for this hash."));
            }

            return(Json(ReceiptModel.FromSmartContractReceipt(receipt, this.network)));
        }