-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathengine.go
61 lines (53 loc) · 1.54 KB
/
engine.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
61
// Copyright (c) 2013-2018 The btcsuite developers
// Copyright (c) 2015-2018 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package interpreter
// Engine is the virtual machine that executes scripts.
type Engine interface {
Execute(opts ...ExecutionOptionFunc) error
}
type engine struct{}
// NewEngine returns a new script engine for the provided locking script
// (of a previous transaction out), transaction, and input index. The
// flags modify the behaviour of the script engine according to the
// description provided by each flag.
func NewEngine() Engine {
return &engine{}
}
// Execute will execute all scripts in the script engine and return either nil
// for successful validation or an error if one occurred.
//
// Execute with tx example:
// if err := engine.Execute(
// interpreter.WithTx(tx, inputIdx, previousOutput),
// interpreter.WithAfterGenesis(),
// interpreter.WithForkID(),
// ); err != nil {
// // handle err
// }
//
// Execute with scripts example:
// if err := engine.Execute(
// interpreter.WithScripts(lockingScript, unlockingScript),
// interpreter.WithAfterGenesis(),
// interpreter.WithForkID(),
// }); err != nil {
// // handle err
// }
//
func (e *engine) Execute(oo ...ExecutionOptionFunc) error {
opts := &execOpts{}
for _, o := range oo {
o(opts)
}
t, err := createThread(opts)
if err != nil {
return err
}
if err := t.execute(); err != nil {
t.afterError(err)
return err
}
return nil
}