forked from urdt/ussd
Consolidate subtyp and typ debug
This commit is contained in:
parent
35cf3a1cd1
commit
6d4f3109f8
17
debug/db.go
17
debug/db.go
@ -8,6 +8,10 @@ import (
|
|||||||
"git.grassecon.net/urdt/ussd/common"
|
"git.grassecon.net/urdt/ussd/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
dbTypStr map[common.DataTyp]string = make(map[common.DataTyp]string)
|
||||||
|
)
|
||||||
|
|
||||||
type KeyInfo struct {
|
type KeyInfo struct {
|
||||||
SessionId string
|
SessionId string
|
||||||
Typ uint8
|
Typ uint8
|
||||||
@ -19,6 +23,7 @@ type KeyInfo struct {
|
|||||||
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
||||||
o := KeyInfo{}
|
o := KeyInfo{}
|
||||||
b := []byte(sessionId)
|
b := []byte(sessionId)
|
||||||
|
|
||||||
if len(k) <= len(b) {
|
if len(k) <= len(b) {
|
||||||
return o, fmt.Errorf("storage key missing")
|
return o, fmt.Errorf("storage key missing")
|
||||||
}
|
}
|
||||||
@ -35,8 +40,10 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
|||||||
}
|
}
|
||||||
v := binary.BigEndian.Uint16(k[:2])
|
v := binary.BigEndian.Uint16(k[:2])
|
||||||
o.SubTyp = common.DataTyp(v)
|
o.SubTyp = common.DataTyp(v)
|
||||||
o.Label = typToString(o.SubTyp)
|
o.Label = subTypToString(o.SubTyp)
|
||||||
k = k[2:]
|
k = k[2:]
|
||||||
|
} else {
|
||||||
|
o.Label = typToString(o.Typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(k) != 0 {
|
if len(k) != 0 {
|
||||||
@ -45,3 +52,11 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
|||||||
|
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subTypToString(v common.DataTyp) string {
|
||||||
|
return dbTypStr[v + storage.DATATYPE_USERSUB + 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func typToString(v uint8) string {
|
||||||
|
return dbTypStr[common.DataTyp(uint16(v))]
|
||||||
|
}
|
||||||
|
39
debug/db_debug.go
Normal file
39
debug/db_debug.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// +build debugdb
|
||||||
|
|
||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.defalsify.org/vise.git/db"
|
||||||
|
|
||||||
|
"git.grassecon.net/urdt/ussd/common"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
DebugCap |= 1
|
||||||
|
dbTypStr[db.DATATYPE_STATE] = "internal_state"
|
||||||
|
dbTypStr[db.DATATYPE_USERDATA] = "userdata"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACCOUNT] = "account"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACCOUNT_CREATED] = "account_created"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_TRACKING_ID] = "tracking id"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_PUBLIC_KEY] = "public key"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_CUSTODIAL_ID] = "custodial id"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACCOUNT_PIN] = "account pin"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACCOUNT_STATUS] = "account status"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_FIRST_NAME] = "first name"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_FAMILY_NAME] = "family name"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_YOB] = "year of birth"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_LOCATION] = "location"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_GENDER] = "gender"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_OFFERINGS] = "offerings"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_RECIPIENT] = "recipient"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_AMOUNT] = "amount"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_TEMPORARY_VALUE] = "temporary value"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACTIVE_SYM] = "active sym"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACTIVE_BAL] = "active bal"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_BLOCKED_NUMBER] = "blocked number"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACTIVE_DECIMAL] = "active decimal"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_ACTIVE_ADDRESS] = "active address"
|
||||||
|
dbTypStr[storage.DATATYPE_USERSUB + 1 + common.DATA_TRANSACTIONS] = "transactions"
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
// +build !debugdb
|
|
||||||
|
|
||||||
package debug
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
func typToString(v common.DataTyp) string {
|
|
||||||
return fmt.Sprintf("(%d)", v)
|
|
||||||
}
|
|
50
debug/db_test.go
Normal file
50
debug/db_test.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package debug
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDebugDbSubKeyInfo(t *testing.T) {
|
||||||
|
s := "foo"
|
||||||
|
b := []byte(s)
|
||||||
|
b = append(b, []byte{0x40, 0x00, 0x02}...)
|
||||||
|
r, err := ToKeyInfo(b, s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if r.SessionId != s {
|
||||||
|
t.Fatalf("expected %s, got %s", s, r.SessionId)
|
||||||
|
}
|
||||||
|
if r.Typ != 64 {
|
||||||
|
t.Fatalf("expected 64, got %d", r.Typ)
|
||||||
|
}
|
||||||
|
if r.SubTyp != 2 {
|
||||||
|
t.Fatalf("expected 2, got %d", r.SubTyp)
|
||||||
|
}
|
||||||
|
if DebugCap & 1 > 0 {
|
||||||
|
if r.Label != "tracking id" {
|
||||||
|
t.Fatalf("expected 'tracking id', got '%s'", r.Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDebugDbKeyInfo(t *testing.T) {
|
||||||
|
s := "bar"
|
||||||
|
b := []byte(s)
|
||||||
|
b = append(b, []byte{0x20}...)
|
||||||
|
r, err := ToKeyInfo(b, s)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if r.SessionId != s {
|
||||||
|
t.Fatalf("expected %s, got %s", s, r.SessionId)
|
||||||
|
}
|
||||||
|
if r.Typ != 32 {
|
||||||
|
t.Fatalf("expected 64, got %d", r.Typ)
|
||||||
|
}
|
||||||
|
if DebugCap & 1 > 0 {
|
||||||
|
if r.Label != "userdata" {
|
||||||
|
t.Fatalf("expected 'userdata', got '%s'", r.Label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,46 +0,0 @@
|
|||||||
// +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 init() {
|
|
||||||
DebugCap |= 1
|
|
||||||
}
|
|
||||||
|
|
||||||
func typToString(v common.DataTyp) string {
|
|
||||||
return dbTypStr[v]
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user