Add debug package

This commit is contained in:
lash 2024-12-01 17:32:06 +00:00
parent 3d2ca606ca
commit 1a782c1db9
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 105 additions and 1 deletions

47
debug/db.go Normal file
View File

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

14
debug/db_no.go Normal file
View File

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

42
debug/db_yes.go Normal file
View File

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

View File

@ -22,6 +22,7 @@ func init() {
initializers.LoadEnvVariables() initializers.LoadEnvVariables()
} }
func main() { func main() {
config.LoadConfig() config.LoadConfig()
@ -59,6 +60,6 @@ func main() {
if k == nil { if k == nil {
break break
} }
fmt.Printf("%x %s\n", k, v) fmt.Printf("%x %s %x\n", k, v)
} }
} }