rpc: drop NewTransactionOutputRaw, move it server-side

This commit is contained in:
Roman Khimov 2022-07-08 14:32:29 +03:00
parent aa338b7960
commit 04fc737e2e
2 changed files with 12 additions and 24 deletions

View file

@ -4,8 +4,6 @@ import (
"encoding/json"
"errors"
"github.com/nspcc-dev/neo-go/pkg/core/block"
"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"
)
@ -25,25 +23,6 @@ type TransactionMetadata struct {
VMState string `json:"vmstate,omitempty"`
}
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header, appExecResult *state.AppExecResult, chain LedgerAux) TransactionOutputRaw {
result := TransactionOutputRaw{
Transaction: *tx,
}
if header == nil {
return result
}
// confirmations formula
confirmations := int(chain.BlockHeight() - header.Index + 1)
result.TransactionMetadata = TransactionMetadata{
Blockhash: header.Hash(),
Confirmations: confirmations,
Timestamp: header.Timestamp,
VMState: appExecResult.VMState.String(),
}
return result
}
// MarshalJSON implements the json.Marshaler interface.
func (t TransactionOutputRaw) MarshalJSON() ([]byte, error) {
output, err := json.Marshal(t.TransactionMetadata)

View file

@ -1542,8 +1542,11 @@ func (s *Server) getrawtransaction(reqParams params.Params) (interface{}, *respo
return nil, response.ErrUnknownTransaction
}
if v, _ := reqParams.Value(1).GetBoolean(); v {
if height == math.MaxUint32 {
return result.NewTransactionOutputRaw(tx, nil, nil, s.chain), nil
res := result.TransactionOutputRaw{
Transaction: *tx,
}
if height == math.MaxUint32 { // Mempooled transaction.
return res, nil
}
_header := s.chain.GetHeaderHash(int(height))
header, err := s.chain.GetHeader(_header)
@ -1557,7 +1560,13 @@ func (s *Server) getrawtransaction(reqParams params.Params) (interface{}, *respo
if len(aers) == 0 {
return nil, response.NewRPCError("Inconsistent application log", "application log for the transaction is empty")
}
return result.NewTransactionOutputRaw(tx, header, &aers[0], s.chain), nil
res.TransactionMetadata = result.TransactionMetadata{
Blockhash: header.Hash(),
Confirmations: int(s.chain.BlockHeight() - header.Index + 1),
Timestamp: header.Timestamp,
VMState: aers[0].VMState.String(),
}
return res, nil
}
return tx.Bytes(), nil
}