Skip to content

Commit

Permalink
cmd: add skip and no-step options
Browse files Browse the repository at this point in the history
  • Loading branch information
halseth committed Dec 12, 2023
1 parent 5513285 commit 590dde1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 14 additions & 1 deletion cmd/tapsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func main() {
Aliases: []string{"ni"},
Usage: "disable interactive mode",
},
&cli.BoolFlag{
Name: "no-step",
Aliases: []string{"ns"},
Usage: "don't show step by step, just validate",
},

&cli.StringFlag{
Name: "privkeys",
Usage: "specify private keys as \"key1:<hex>,key2:<hex>\" to sign the transaction. Set <hex> empty to generate a random key with the given ID.",
Expand Down Expand Up @@ -96,6 +102,10 @@ func main() {
Name: "rows",
Usage: "max rows to print in execution table (default: 25)",
},
&cli.IntFlag{
Name: "skip",
Usage: "skip aheead",
},
},
},
}
Expand Down Expand Up @@ -134,6 +144,8 @@ func execute(cCtx *cli.Context) error {
output.MaxRows = maxRows
}

skipAhead := cCtx.Int("skip")

var scriptStr []string
scriptFile := cCtx.String("script")
scriptFiles := cCtx.String("scripts")
Expand Down Expand Up @@ -197,6 +209,7 @@ func execute(cCtx *cli.Context) error {
}

nonInteractive := cCtx.Bool("non-interactive")
noStep := cCtx.Bool("no-step")
privKeys := strings.Split(cCtx.String("privkeys"), ",")
keyMap := make(map[string][]byte)
for _, privKeyStr := range privKeys {
Expand Down Expand Up @@ -292,7 +305,7 @@ func execute(cCtx *cli.Context) error {

executeErr := script.Execute(
keyMap, inputKeyBytes, txOutKeys, parsedScripts, scriptIndex,
parsedWitness, !nonInteractive, tags,
parsedWitness, !nonInteractive, noStep, tags, skipAhead,
)
if executeErr != nil {
fmt.Printf("script exection failed: %s\r\n", executeErr)
Expand Down
10 changes: 7 additions & 3 deletions script/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const scriptFlags = txscript.StandardVerifyFlags
// If [input/output]KeyBytes is empty, a random key will be generated.
func Execute(privKeyBytes map[string][]byte, inputKeyBytes []byte,
outputs []TxOutput, pkScripts [][]byte, scriptIndex int,
witnessGen []WitnessGen, interactive bool, tags map[string]string) error {
witnessGen []WitnessGen, interactive, noStep bool, tags map[string]string,
skipAhead int) error {

// Parse the input private keys.
privKeys := make(map[string]*btcec.PrivateKey)
Expand Down Expand Up @@ -221,7 +222,9 @@ func Execute(privKeyBytes map[string][]byte, inputKeyBytes []byte,
clearLines = prevLines
}

output.DrawTable(table, clearLines)
if !noStep {
output.DrawTable(table, clearLines)
}
if interactive {
if currentStep > 1 {
fmt.Printf("Script execution: \u2190 back | next \u2192 ")
Expand Down Expand Up @@ -252,7 +255,8 @@ func Execute(privKeyBytes map[string][]byte, inputKeyBytes []byte,
// Otherwise script execution was aborted before it completed,
// so we continue with the next step of the execution.

if interactive {
if interactive && currentStep >= skipAhead {
skipAhead = 0
numRead, err := t.Read(bytes)
if err != nil {
return err
Expand Down

0 comments on commit 590dde1

Please sign in to comment.