forked from TrueCloudLab/neoneo-go
rpc: update getrawtransaction
RPC call
Closes #1183. Added VMState to transaction output raw.
This commit is contained in:
parent
70ef733ce7
commit
0c424a0ed2
2 changed files with 12 additions and 4 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"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/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/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -22,10 +23,11 @@ type TransactionMetadata struct {
|
||||||
Blockhash util.Uint256 `json:"blockhash,omitempty"`
|
Blockhash util.Uint256 `json:"blockhash,omitempty"`
|
||||||
Confirmations int `json:"confirmations,omitempty"`
|
Confirmations int `json:"confirmations,omitempty"`
|
||||||
Timestamp uint64 `json:"blocktime,omitempty"`
|
Timestamp uint64 `json:"blocktime,omitempty"`
|
||||||
|
VMState string `json:"vmstate"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTransactionOutputRaw returns a new ransactionOutputRaw object.
|
// 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 formula
|
||||||
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
|
confirmations := int(chain.BlockHeight() - header.Base.Index + 1)
|
||||||
return TransactionOutputRaw{
|
return TransactionOutputRaw{
|
||||||
|
@ -34,6 +36,7 @@ func NewTransactionOutputRaw(tx *transaction.Transaction, header *block.Header,
|
||||||
Blockhash: header.Hash(),
|
Blockhash: header.Hash(),
|
||||||
Confirmations: confirmations,
|
Confirmations: confirmations,
|
||||||
Timestamp: header.Timestamp,
|
Timestamp: header.Timestamp,
|
||||||
|
VMState: appExecResult.VMState.String(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +47,7 @@ func (t TransactionOutputRaw) MarshalJSON() ([]byte, error) {
|
||||||
Blockhash: t.Blockhash,
|
Blockhash: t.Blockhash,
|
||||||
Confirmations: t.Confirmations,
|
Confirmations: t.Confirmations,
|
||||||
Timestamp: t.Timestamp,
|
Timestamp: t.Timestamp,
|
||||||
|
VMState: t.VMState,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -75,6 +79,7 @@ func (t *TransactionOutputRaw) UnmarshalJSON(data []byte) error {
|
||||||
t.Blockhash = output.Blockhash
|
t.Blockhash = output.Blockhash
|
||||||
t.Confirmations = output.Confirmations
|
t.Confirmations = output.Confirmations
|
||||||
t.Timestamp = output.Timestamp
|
t.Timestamp = output.Timestamp
|
||||||
|
t.VMState = output.VMState
|
||||||
|
|
||||||
return json.Unmarshal(data, &t.Transaction)
|
return json.Unmarshal(data, &t.Transaction)
|
||||||
}
|
}
|
||||||
|
|
|
@ -692,10 +692,13 @@ func (s *Server) getrawtransaction(reqParams request.Params) (interface{}, *resp
|
||||||
_header := s.chain.GetHeaderHash(int(height))
|
_header := s.chain.GetHeaderHash(int(height))
|
||||||
header, err := s.chain.GetHeader(_header)
|
header, err := s.chain.GetHeader(_header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resultsErr = response.NewInvalidParamsError(err.Error(), err)
|
return nil, response.NewInvalidParamsError(err.Error(), err)
|
||||||
} else {
|
|
||||||
results = result.NewTransactionOutputRaw(tx, header, s.chain)
|
|
||||||
}
|
}
|
||||||
|
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 {
|
} else {
|
||||||
results = hex.EncodeToString(tx.Bytes())
|
results = hex.EncodeToString(tx.Bytes())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue