Browse Source

cmdInfo, cmdSetOption; append_tx can take hex

pull/1780/head
Ethan Buchman 9 years ago
parent
commit
86c2484c29
1 changed files with 53 additions and 3 deletions
  1. +53
    -3
      cmd/tmsp/cli.go

+ 53
- 3
cmd/tmsp/cli.go View File

@ -2,6 +2,7 @@ package main
import ( import (
"bufio" "bufio"
"encoding/hex"
"fmt" "fmt"
"net" "net"
"os" "os"
@ -36,6 +37,20 @@ func main() {
cmdConsole(app, c) cmdConsole(app, c)
}, },
}, },
{
Name: "info",
Usage: "Get some info about the application",
Action: func(c *cli.Context) {
cmdInfo(c)
},
},
{
Name: "set_option",
Usage: "Set an option on the application",
Action: func(c *cli.Context) {
cmdSetOption(c)
},
},
{ {
Name: "append_tx", Name: "append_tx",
Usage: "Append a new tx to application", Usage: "Append a new tx to application",
@ -100,14 +115,49 @@ func cmdConsole(app *cli.App, c *cli.Context) {
} }
} }
// Get some info from the application
func cmdInfo(c *cli.Context) {
res, err := makeRequest(conn, types.RequestInfo{})
if err != nil {
Exit(err.Error())
}
fmt.Println(res)
}
// Set an option on the application
func cmdSetOption(c *cli.Context) {
args := c.Args()
if len(args) != 2 {
Exit("set_option takes 2 arguments (key, value)")
}
_, err := makeRequest(conn, types.RequestSetOption{args[0], args[1]})
if err != nil {
Exit(err.Error())
}
fmt.Printf("Set option %s = %s\n", args[0], args[1])
}
// Append a new tx to application // Append a new tx to application
func cmdAppendTx(c *cli.Context) { func cmdAppendTx(c *cli.Context) {
args := c.Args() // Args to AppendTx
res, err := makeRequest(conn, types.RequestAppendTx{[]byte(args[0])})
args := c.Args()
if len(args) != 1 {
Exit("append_tx takes 1 argument")
}
txString := args[0]
tx := []byte(txString)
if len(txString) > 2 && strings.HasPrefix(txString, "0x") {
var err error
tx, err = hex.DecodeString(txString[2:])
if err != nil {
Exit(err.Error())
}
}
res, err := makeRequest(conn, types.RequestAppendTx{tx})
if err != nil { if err != nil {
Exit(err.Error()) Exit(err.Error())
} }
fmt.Println("Sent tx:", args[0], "response:", res)
fmt.Println("Sent tx:", txString, "response:", res)
} }
// Get application Merkle root hash // Get application Merkle root hash


Loading…
Cancel
Save