add decode tool
This commit is contained in:
parent
9a629bb545
commit
e02762ab6c
4 changed files with 46 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
.idea/
|
||||
lbryschema-cli
|
||||
|
|
1
build.sh
1
build.sh
|
@ -5,3 +5,4 @@ echo "Building protobuf files"
|
|||
rm -rf pb/*.pb.go
|
||||
protoc --go_out=. pb/*.proto
|
||||
go build ./...
|
||||
go build ./cli/lbryschema-cli.go
|
43
cli/lbryschema-cli.go
Normal file
43
cli/lbryschema-cli.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"../claim"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) == 1 {
|
||||
claim_bytes := []byte(args[0])
|
||||
decoded, err := claim.DecodeClaimBytes(claim_bytes)
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
text, err := decoded.RenderJSON()
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(text)
|
||||
return
|
||||
} else if (len(args) == 2) && (args[1] == "--decode_hex") {
|
||||
claim_hex := args[0]
|
||||
decoded, err := claim.DecodeClaimHex(claim_hex)
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
text, err := decoded.RenderJSON()
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error:", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(text)
|
||||
return
|
||||
} else {
|
||||
fmt.Println("encountered an error\nusage: \n\tlbryschema-cli <value to decode> [--decode_hex]")
|
||||
return
|
||||
}
|
||||
}
|
24
main.go
24
main.go
|
@ -1,24 +0,0 @@
|
|||
package lbryschema_go
|
||||
|
||||
import (
|
||||
"os"
|
||||
"./claim"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
claim_hex := args[0]
|
||||
decoded, err := claim.DecodeClaimHex(claim_hex)
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error: ", err)
|
||||
return
|
||||
}
|
||||
text, err := decoded.RenderJSON()
|
||||
if err != nil {
|
||||
fmt.Println("Decoding error: ", err)
|
||||
return
|
||||
}
|
||||
fmt.Println(text)
|
||||
return
|
||||
}
|
Loading…
Reference in a new issue