-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (56 loc) · 1.33 KB
/
main.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
62
package main
import (
"fmt"
"log"
"os"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btclog"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("txid is required as a command line argument.")
os.Exit(1)
}
txid := os.Args[1]
if txid == "" {
fmt.Println("txid is required as a command line argument.")
os.Exit(1)
}
l := btclog.LevelInfo
if len(os.Args) > 2 {
loglevelstr := os.Args[2]
l, _ = btclog.LevelFromString(loglevelstr)
}
// Set up a logger for the script package to use.
logger := btclog.NewBackend(os.Stdout).Logger("SCRIPT")
logger.SetLevel(l)
txscript.UseLogger(logger)
fetcher := NewFetcher()
defer fetcher.Close()
msgTx, err := fetcher.getTransaction(txid)
if err != nil {
log.Fatalf("Failed to fetch data: %v", err)
}
for i, txIn := range msgTx.TxIn {
fmt.Println("Input:", i)
prevout := fetcher.FetchPrevOutput(txIn.PreviousOutPoint)
vm, err := txscript.NewEngine(
prevout.PkScript,
msgTx,
i,
txscript.StandardVerifyFlags,
nil,
nil,
prevout.Value,
fetcher)
if err != nil {
log.Fatalf("failed to create script engine for input %d: %v", i, err)
}
// Execute the script.
// Debugging allows you to follow the details of the script's movement.
err = vm.Execute()
if err != nil {
log.Fatalf("failed to execute script for input %d: %v", i, err)
}
}
}