From 1a782c1db9b9d0339435f6e47d8c20e73ff23b7a Mon Sep 17 00:00:00 2001 From: lash Date: Sun, 1 Dec 2024 17:32:06 +0000 Subject: [PATCH] Add debug package --- debug/db.go | 47 ++++++++++++++++++++++++++++++++++++++++++ debug/db_no.go | 14 +++++++++++++ debug/db_yes.go | 42 +++++++++++++++++++++++++++++++++++++ devtools/store/main.go | 3 ++- 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 debug/db.go create mode 100644 debug/db_no.go create mode 100644 debug/db_yes.go diff --git a/debug/db.go b/debug/db.go new file mode 100644 index 0000000..9efad00 --- /dev/null +++ b/debug/db.go @@ -0,0 +1,47 @@ +package debug + +import ( + "fmt" + "encoding/binary" + + "git.grassecon.net/urdt/ussd/internal/storage" + "git.grassecon.net/urdt/ussd/common" +) + +type KeyInfo struct { + SessionId string + Typ uint8 + SubTyp common.DataTyp + Label string + Description string +} + +func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) { + o := KeyInfo{} + b := []byte(sessionId) + if len(k) <= len(b) { + return o, fmt.Errorf("storage key missing") + } + + o.SessionId = sessionId + + k = k[len(b):] + o.Typ = k[0] + k = k[1:] + + if o.Typ == storage.DATATYPE_USERSUB { + if len(k) == 0 { + return o, fmt.Errorf("missing subtype key") + } + v := binary.BigEndian.Uint16(k[:2]) + o.SubTyp = common.DataTyp(v) + o.Label = typToString(o.SubTyp) + k = k[2:] + } + + if len(k) != 0 { + return o, fmt.Errorf("excess key information") + } + + return o, nil +} diff --git a/debug/db_no.go b/debug/db_no.go new file mode 100644 index 0000000..a01c78f --- /dev/null +++ b/debug/db_no.go @@ -0,0 +1,14 @@ +// +build !debugdb + +package debug + +import ( + "fmt" + + "git.grassecon.net/urdt/ussd/common" +) + + +func typToString(v common.DataTyp) string { + return fmt.Sprintf("(%d)", v) +} diff --git a/debug/db_yes.go b/debug/db_yes.go new file mode 100644 index 0000000..fa8186e --- /dev/null +++ b/debug/db_yes.go @@ -0,0 +1,42 @@ +// +build debugdb + +package debug + +import ( + "git.defalsify.org/vise.git/db" + + "git.grassecon.net/urdt/ussd/common" +) + +var ( + dbTypStr map[common.DataTyp]string = map[common.DataTyp]string { + db.DATATYPE_USERDATA: "userdata", + common.DATA_ACCOUNT: "account", + common.DATA_ACCOUNT_CREATED: "account created", + common.DATA_TRACKING_ID: "tracking id", + common.DATA_PUBLIC_KEY: "public key", + common.DATA_CUSTODIAL_ID: "custodial id", + common.DATA_ACCOUNT_PIN: "account pin", + common.DATA_ACCOUNT_STATUS: "account status", + common.DATA_FIRST_NAME: "first name", + common.DATA_FAMILY_NAME: "family name", + common.DATA_YOB: "year of birth", + common.DATA_LOCATION: "location", + common.DATA_GENDER: "gender", + common.DATA_OFFERINGS: "offerings", + common.DATA_RECIPIENT: "recipient", + common.DATA_AMOUNT: "amount", + common.DATA_TEMPORARY_VALUE: "temporary value", + common.DATA_ACTIVE_SYM: "active sym", + common.DATA_ACTIVE_BAL: "active bal", + common.DATA_BLOCKED_NUMBER: "blocked number", + common.DATA_PUBLIC_KEY_REVERSE: "public key reverse", + common.DATA_ACTIVE_DECIMAL: "active decimal", + common.DATA_ACTIVE_ADDRESS: "active address", + common.DATA_TRANSACTIONS: "transactions", + } +) + +func typToString(v common.DataTyp) string { + return dbTypStr[v] +} diff --git a/devtools/store/main.go b/devtools/store/main.go index df27bb1..35587ea 100644 --- a/devtools/store/main.go +++ b/devtools/store/main.go @@ -22,6 +22,7 @@ func init() { initializers.LoadEnvVariables() } + func main() { config.LoadConfig() @@ -59,6 +60,6 @@ func main() { if k == nil { break } - fmt.Printf("%x %s\n", k, v) + fmt.Printf("%x %s %x\n", k, v) } }