Skip to content

Commit

Permalink
Allow read tx hex from stdin or file
Browse files Browse the repository at this point in the history
  • Loading branch information
devfans committed Apr 20, 2022
1 parent 3b2b1d4 commit cac8dfa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tx",
Usage: "raw tx hex",
Required: true,
Usage: "raw tx hex or path to hex file",
},
},
},
Expand All @@ -349,8 +348,7 @@ func main() {
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tx",
Usage: "raw tx hex",
Required: true,
Usage: "raw tx hex for path to hex file",
},
},
},
Expand Down
29 changes: 25 additions & 4 deletions relayer/sidechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"os"
"path/filepath"
Expand Down Expand Up @@ -204,9 +205,19 @@ func SyncHeader(ctx *cli.Context) (err error) {
func SendPolyTx(ctx *cli.Context) (err error) {
raw := ctx.String("tx")
tx := &types.Transaction{}
data, err := hex.DecodeString(raw)
if raw == "" {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil { return err }
raw = string(data)
}
data, err := hex.DecodeString(util.LowerHex(raw))
if err != nil {
return err
log.Info("Failed to decode hex, will treat as file")
body, err := ioutil.ReadFile(raw)
if err != nil { return err }
raw = string(body)
data, err = hex.DecodeString(util.LowerHex(raw))
if err != nil { return err }
}
if err := tx.Deserialization(common.NewZeroCopySource(data)); err != nil {
return err
Expand Down Expand Up @@ -235,9 +246,19 @@ func SendPolyTx(ctx *cli.Context) (err error) {
func SignPolyTx(ctx *cli.Context) (err error) {
raw := ctx.String("tx")
tx := &types.Transaction{}
data, err := hex.DecodeString(raw)
if raw == "" {
data, err := ioutil.ReadAll(os.Stdin)
if err != nil { return err }
raw = string(data)
}
data, err := hex.DecodeString(util.LowerHex(raw))
if err != nil {
return err
log.Info("Failed to decode hex, will treat as file")
body, err := ioutil.ReadFile(raw)
if err != nil { return err }
raw = string(body)
data, err = hex.DecodeString(util.LowerHex(raw))
if err != nil { return err }
}
if err := tx.Deserialization(common.NewZeroCopySource(data)); err != nil {
return err
Expand Down

0 comments on commit cac8dfa

Please sign in to comment.