Skip to content

Commit

Permalink
Added support for symbol and symbol_code to eosc tools names
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed Mar 30, 2019
1 parent 9d4bcaf commit 1d3fa3c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions eosc/cmd/toolsNames.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"os"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -37,7 +38,20 @@ This command auto-detects encoding and converts it to different encodings.
}
}

fromName, err := eos.ExtendedStringToName(input)
fromSymbol, err := eos.StringToSymbol(input)
if err == nil {
symbolUint, err := fromSymbol.ToName()
if err == nil {
showFrom["symbol"] = symbolUint
}
}

fromSymbolCode, err := eos.StringToSymbolCode(input)
if err == nil {
showFrom["symbol_code"] = uint64(fromSymbolCode)
}

fromName, err := eos.StringToName(input)
if err == nil {
showFrom["name"] = fromName
}
Expand All @@ -48,16 +62,16 @@ This command auto-detects encoding and converts it to different encodings.
}

someFound := false
rows := []string{"| from \\ to | hex | hex_be | name | uint64", "| --------- | --- | ------ | ---- | ------ |"}
for _, from := range []string{"hex", "hex_be", "name", "uint64"} {
rows := []string{"| from \\ to | hex | hex_be | name | uint64 | symbol | symbol_code", "| --------- | --- | ------ | ---- | ------ | ------ | ----------- |"}
for _, from := range []string{"hex", "hex_be", "name", "uint64", "symbol", "symbol_code"} {
val, found := showFrom[from]
if !found {
continue
}
someFound = true

row := []string{from}
for _, to := range []string{"hex", "hex_be", "name", "uint64"} {
for _, to := range []string{"hex", "hex_be", "name", "uint64", "symbol", "symbol_code"} {

cnt := make([]byte, 8)
switch to {
Expand All @@ -73,6 +87,12 @@ This command auto-detects encoding and converts it to different encodings.

case "uint64":
row = append(row, strconv.FormatUint(val, 10))

case "symbol":
row = append(row, symbOrDash(fmt.Sprintf("%d,%s", uint8(val&0xFF), eos.SymbolCode(val>>8).String())))

case "symbol_code":
row = append(row, symbOrDash(eos.SymbolCode(val).String()))
}
}
rows = append(rows, "| "+strings.Join(row, " | ")+" |")
Expand All @@ -89,6 +109,15 @@ This command auto-detects encoding and converts it to different encodings.
},
}

var symbOrDashRE = regexp.MustCompile(`^[0-9A-Z,]+$`)

func symbOrDash(input string) string {
if !symbOrDashRE.MatchString(input) {
return "-"
}
return input
}

func init() {
toolsCmd.AddCommand(toolsNamesCmd)
}

0 comments on commit 1d3fa3c

Please sign in to comment.