Exemplo n.º 1
0
        public IAPIResult CancelTransaction([APIParameter("Hash of transaction", "EE2CC7BA3FFC4EE7B4030DDFE9CB7B643A0199A1873956759533BB3D25D95322")] string hashText)
        {
            if (Mempool == null)
            {
                return(new ErrorResult {
                    error = "mempool not available"
                });
            }

            Hash hash;

            if (!Hash.TryParse(hashText, out hash))
            {
                return(new ErrorResult {
                    error = "Invalid hash"
                });
            }

            var tx = Nexus.FindTransactionByHash(hash);

            if (tx != null)
            {
                return(new ErrorResult {
                    error = "already in chain"
                });
            }

            var status = Mempool.GetTransactionStatus(hash, out string reason);

            if (status == MempoolTransactionStatus.Pending)
            {
                if (Mempool.RejectTransaction(hash))
                {
                    return(new SingleResult()
                    {
                        value = hash
                    });
                }
            }

            return(new ErrorResult {
                error = "Transaction not found"
            });
        }