-
Notifications
You must be signed in to change notification settings - Fork 178
/
transaction.go
60 lines (50 loc) · 1.51 KB
/
transaction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package fvm
import (
"github.com/opentracing/opentracing-go"
"github.com/onflow/flow-go/fvm/errors"
"github.com/onflow/flow-go/fvm/programs"
"github.com/onflow/flow-go/fvm/state"
"github.com/onflow/flow-go/model/flow"
)
func Transaction(tx *flow.TransactionBody, txIndex uint32) *TransactionProcedure {
return &TransactionProcedure{
ID: tx.ID(),
Transaction: tx,
TxIndex: txIndex,
}
}
type TransactionProcessor interface {
Process(*VirtualMachine, *Context, *TransactionProcedure, *state.StateHolder, *programs.Programs) error
}
type TransactionProcedure struct {
ID flow.Identifier
Transaction *flow.TransactionBody
TxIndex uint32
Logs []string
Events []flow.Event
ServiceEvents []flow.Event
GasUsed uint64
Err errors.Error
Retried int
TraceSpan opentracing.Span
}
func (proc *TransactionProcedure) SetTraceSpan(traceSpan opentracing.Span) {
proc.TraceSpan = traceSpan
}
func (proc *TransactionProcedure) Run(vm *VirtualMachine, ctx Context, st *state.StateHolder, programs *programs.Programs) error {
for _, p := range ctx.TransactionProcessors {
err := p.Process(vm, &ctx, proc, st, programs)
txErr, failure := errors.SplitErrorTypes(err)
if failure != nil {
// log the full error path
ctx.Logger.Err(err).Msg("fatal error when execution a transaction")
return failure
}
if txErr != nil {
proc.Err = txErr
// TODO we should not break here we should continue for fee deductions
break
}
}
return nil
}