From 0c424a0ed29743fe7312800475960842d375ba40 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Mon, 27 Jul 2020 18:07:05 +0300 Subject: [PATCH] rpc: update `getrawtransaction` RPC call Closes #1183. Added VMState to transaction output raw. --- pkg/rpc/response/result/tx_raw_output.go | 7 ++++++- pkg/rpc/server/server.go | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/rpc/response/result/tx_raw_output.go b/pkg/rpc/response/result/tx_raw_output.go index 484158f74..518e8ef9b 100644 --- a/pkg/rpc/response/result/tx_raw_output.go +++ b/pkg/rpc/response/result/tx_raw_output.go @@ -6,6 +6,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/blockchainer" + "github.com/nspcc-dev/neo-go/pkg/core/state" "github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/util" ) @@ -22,10 +23,11 @@ type TransactionMetadata struct { Blockhash util.Uint256 `json:"blockhash,omitempty"` Confirmations int `json:"confirmations,omitempty"` Timestamp uint64 `json:"blocktime,omitempty"` + VMState string `json:"vmstate"` } // NewTransactionOutputRaw returns a new ransactionOutputRaw object. -func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, chain blockchainer.Blockchainer) TransactionOutputRaw { +func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, appExecResult *state.AppExecResult, chain blockchainer.Blockchainer) TransactionOutputRaw { // confirmations formula confirmations := int(chain.BlockHeight() - header.Base.Index + 1) return TransactionOutputRaw{ @@ -34,6 +36,7 @@ func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, Blockhash: header.Hash(), Confirmations: confirmations, Timestamp: header.Timestamp, + VMState: appExecResult.VMState.String(), }, } } @@ -44,6 +47,7 @@ func (t TransactionOutputRaw) MarshalJSON() ([]byte, error) { Blockhash: t.Blockhash, Confirmations: t.Confirmations, Timestamp: t.Timestamp, + VMState: t.VMState, }) if err != nil { return nil, err @@ -75,6 +79,7 @@ func (t *TransactionOutputRaw) UnmarshalJSON(data []byte) error { t.Blockhash = output.Blockhash t.Confirmations = output.Confirmations t.Timestamp = output.Timestamp + t.VMState = output.VMState return json.Unmarshal(data, &t.Transaction) } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index 03f6c5191..9d17c71c5 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -692,10 +692,13 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp _header := s.chain.GetHeaderHash(int(height)) header, err := s.chain.GetHeader(_header) if err != nil { - resultsErr = response.NewInvalidParamsError(err.Error(), err) - } else { - results = result.NewTransactionOutputRaw(tx, header, s.chain) + return nil, response.NewInvalidParamsError(err.Error(), err) } + st, err := s.chain.GetAppExecResult(txHash) + if err != nil { + return nil, response.NewRPCError("Unknown transaction", err.Error(), err) + } + results = result.NewTransactionOutputRaw(tx, header, st, s.chain) } else { results = hex.EncodeToString(tx.Bytes()) }