2024-10-30 02:28:55 +01:00
|
|
|
package common
|
2024-09-05 16:12:38 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
2024-11-07 07:18:11 +01:00
|
|
|
"errors"
|
2024-11-03 15:34:26 +01:00
|
|
|
|
|
|
|
"git.defalsify.org/vise.git/logging"
|
2024-09-05 16:12:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type DataTyp uint16
|
|
|
|
|
|
|
|
const (
|
|
|
|
DATA_ACCOUNT DataTyp = iota
|
|
|
|
DATA_ACCOUNT_CREATED
|
|
|
|
DATA_TRACKING_ID
|
|
|
|
DATA_PUBLIC_KEY
|
|
|
|
DATA_CUSTODIAL_ID
|
2024-09-05 18:50:02 +02:00
|
|
|
DATA_ACCOUNT_PIN
|
2024-09-06 07:35:01 +02:00
|
|
|
DATA_ACCOUNT_STATUS
|
|
|
|
DATA_FIRST_NAME
|
|
|
|
DATA_FAMILY_NAME
|
|
|
|
DATA_YOB
|
|
|
|
DATA_LOCATION
|
|
|
|
DATA_GENDER
|
|
|
|
DATA_OFFERINGS
|
|
|
|
DATA_RECIPIENT
|
|
|
|
DATA_AMOUNT
|
2024-10-31 22:42:23 +01:00
|
|
|
DATA_TEMPORARY_VALUE
|
2024-10-09 14:38:19 +02:00
|
|
|
DATA_ACTIVE_SYM
|
2024-10-10 13:48:23 +02:00
|
|
|
DATA_ACTIVE_BAL
|
2024-10-28 13:47:56 +01:00
|
|
|
DATA_BLOCKED_NUMBER
|
2024-10-30 01:59:59 +01:00
|
|
|
DATA_PUBLIC_KEY_REVERSE
|
2024-10-25 16:24:09 +02:00
|
|
|
DATA_ACTIVE_DECIMAL
|
|
|
|
DATA_ACTIVE_ADDRESS
|
2024-11-02 17:38:29 +01:00
|
|
|
DATA_TRANSACTIONS
|
2024-09-05 16:12:38 +02:00
|
|
|
)
|
|
|
|
|
2024-11-03 15:34:26 +01:00
|
|
|
var (
|
|
|
|
logg = logging.NewVanilla().WithDomain("urdt-common")
|
|
|
|
)
|
|
|
|
|
2024-09-05 16:12:38 +02:00
|
|
|
func typToBytes(typ DataTyp) []byte {
|
2024-09-05 16:41:27 +02:00
|
|
|
var b [2]byte
|
|
|
|
binary.BigEndian.PutUint16(b[:], uint16(typ))
|
|
|
|
return b[:]
|
2024-09-05 16:12:38 +02:00
|
|
|
}
|
|
|
|
|
2024-09-07 15:25:29 +02:00
|
|
|
func PackKey(typ DataTyp, data []byte) []byte {
|
2024-09-05 16:12:38 +02:00
|
|
|
v := typToBytes(typ)
|
|
|
|
return append(v, data...)
|
|
|
|
}
|
2024-11-07 07:18:11 +01:00
|
|
|
|
|
|
|
func StringToDataTyp(str string) (DataTyp, error) {
|
|
|
|
switch str {
|
|
|
|
case "DATA_FIRST_NAME":
|
|
|
|
return DATA_FIRST_NAME, nil
|
|
|
|
case "DATA_FAMILY_NAME":
|
|
|
|
return DATA_FAMILY_NAME, nil
|
|
|
|
case "DATA_YOB":
|
|
|
|
return DATA_YOB, nil
|
|
|
|
case "DATA_LOCATION":
|
|
|
|
return DATA_LOCATION, nil
|
|
|
|
case "DATA_GENDER":
|
|
|
|
return DATA_GENDER, nil
|
|
|
|
case "DATA_OFFERINGS":
|
|
|
|
return DATA_OFFERINGS, nil
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0, errors.New("invalid DataTyp string")
|
|
|
|
}
|
|
|
|
}
|