add decode tool

This commit is contained in:
Jack Robison 2017-11-07 21:41:07 -05:00
parent 9a629bb545
commit e02762ab6c
No known key found for this signature in database
GPG key ID: 284699E7404E3CFF
4 changed files with 46 additions and 25 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
.idea/
lbryschema-cli

View file

@ -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
View 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
View file

@ -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
}