dao: add GetTxExecResult method
This commit is contained in:
parent
18c5f638b9
commit
4254407a9b
1 changed files with 68 additions and 25 deletions
|
@ -254,41 +254,84 @@ func (dao *Simple) GetAppExecResults(hash util.Uint256, trig trigger.Type) ([]st
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r := io.NewBinReaderFromBuf(bs)
|
if len(bs) == 0 {
|
||||||
switch pref := r.ReadB(); pref {
|
return nil, fmt.Errorf("%w: empty execution log", ErrInternalDBInconsistency)
|
||||||
|
}
|
||||||
|
switch bs[0] {
|
||||||
case storage.ExecBlock:
|
case storage.ExecBlock:
|
||||||
|
r := io.NewBinReaderFromBuf(bs)
|
||||||
|
_ = r.ReadB()
|
||||||
_, err = block.NewTrimmedFromReader(dao.Version.StateRootInHeader, r)
|
_, err = block.NewTrimmedFromReader(dao.Version.StateRootInHeader, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case storage.ExecTransaction:
|
result := make([]state.AppExecResult, 0, 2)
|
||||||
if len(bs) >= 6 && bs[5] == transaction.DummyVersion {
|
for {
|
||||||
return nil, storage.ErrKeyNotFound
|
aer := new(state.AppExecResult)
|
||||||
}
|
aer.DecodeBinary(r)
|
||||||
_ = r.ReadU32LE()
|
if r.Err != nil {
|
||||||
tx := &transaction.Transaction{}
|
if r.Err == iocore.EOF {
|
||||||
tx.DecodeBinary(r)
|
break
|
||||||
default:
|
}
|
||||||
return nil, fmt.Errorf("%w: unexpected executable prefix %d", ErrInternalDBInconsistency, pref)
|
return nil, r.Err
|
||||||
}
|
|
||||||
if r.Err != nil {
|
|
||||||
return nil, r.Err
|
|
||||||
}
|
|
||||||
result := make([]state.AppExecResult, 0, 2)
|
|
||||||
for {
|
|
||||||
aer := new(state.AppExecResult)
|
|
||||||
aer.DecodeBinary(r)
|
|
||||||
if r.Err != nil {
|
|
||||||
if r.Err == iocore.EOF {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
return nil, r.Err
|
if aer.Trigger&trig != 0 {
|
||||||
|
result = append(result, *aer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
case storage.ExecTransaction:
|
||||||
|
_, _, aer, err := decodeTxAndExecResult(bs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
if aer.Trigger&trig != 0 {
|
if aer.Trigger&trig != 0 {
|
||||||
result = append(result, *aer)
|
return []state.AppExecResult{*aer}, nil
|
||||||
}
|
}
|
||||||
|
return nil, nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("%w: unexpected executable prefix %d", ErrInternalDBInconsistency, bs[0])
|
||||||
}
|
}
|
||||||
return result, nil
|
}
|
||||||
|
|
||||||
|
// GetTxExecResult gets application execution result of the specified transaction
|
||||||
|
// and returns the transaction itself, its height and its AppExecResult.
|
||||||
|
func (dao *Simple) GetTxExecResult(hash util.Uint256) (uint32, *transaction.Transaction, *state.AppExecResult, error) {
|
||||||
|
key := dao.makeExecutableKey(hash)
|
||||||
|
bs, err := dao.Store.Get(key)
|
||||||
|
if err != nil {
|
||||||
|
return 0, nil, nil, err
|
||||||
|
}
|
||||||
|
if len(bs) == 0 {
|
||||||
|
return 0, nil, nil, fmt.Errorf("%w: empty execution log", ErrInternalDBInconsistency)
|
||||||
|
}
|
||||||
|
if bs[0] != storage.ExecTransaction {
|
||||||
|
return 0, nil, nil, storage.ErrKeyNotFound
|
||||||
|
}
|
||||||
|
return decodeTxAndExecResult(bs)
|
||||||
|
}
|
||||||
|
|
||||||
|
// decodeTxAndExecResult decodes transaction, its height and execution result from
|
||||||
|
// the given executable bytes. It performs no executable prefix check.
|
||||||
|
func decodeTxAndExecResult(buf []byte) (uint32, *transaction.Transaction, *state.AppExecResult, error) {
|
||||||
|
if len(buf) >= 6 && buf[5] == transaction.DummyVersion {
|
||||||
|
return 0, nil, nil, storage.ErrKeyNotFound
|
||||||
|
}
|
||||||
|
r := io.NewBinReaderFromBuf(buf)
|
||||||
|
_ = r.ReadB()
|
||||||
|
h := r.ReadU32LE()
|
||||||
|
tx := &transaction.Transaction{}
|
||||||
|
tx.DecodeBinary(r)
|
||||||
|
if r.Err != nil {
|
||||||
|
return 0, nil, nil, r.Err
|
||||||
|
}
|
||||||
|
aer := new(state.AppExecResult)
|
||||||
|
aer.DecodeBinary(r)
|
||||||
|
if r.Err != nil {
|
||||||
|
return 0, nil, nil, r.Err
|
||||||
|
}
|
||||||
|
|
||||||
|
return h, tx, aer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// -- end notification event.
|
// -- end notification event.
|
||||||
|
|
Loading…
Reference in a new issue