common

package
v0.6.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// API Tracking id to follow status of account creation
	DATA_TRACKING_ID = iota
	// EVM address returned from API on account creation
	DATA_PUBLIC_KEY
	// Currently active PIN used to authenticate ussd state change requests
	DATA_ACCOUNT_PIN
	// The first name of the user
	DATA_FIRST_NAME
	// The last name of the user
	DATA_FAMILY_NAME
	// The year-of-birth of the user
	DATA_YOB
	// The location of the user
	DATA_LOCATION
	// The gender of the user
	DATA_GENDER
	// The offerings description of the user
	DATA_OFFERINGS
	// The ethereum address of the recipient of an ongoing send request
	DATA_RECIPIENT
	// The voucher value amount of an ongoing send request
	DATA_AMOUNT
	// A general swap field for temporary values
	DATA_TEMPORARY_VALUE
	// Currently active voucher symbol of user
	DATA_ACTIVE_SYM
	// Voucher balance of user's currently active voucher
	DATA_ACTIVE_BAL
	// String boolean indicating whether use of PIN is blocked
	DATA_BLOCKED_NUMBER
	// Reverse mapping of a user's evm address to a session id.
	DATA_PUBLIC_KEY_REVERSE
	// Decimal count of the currently active voucher
	DATA_ACTIVE_DECIMAL
	// EVM address of the currently active voucher
	DATA_ACTIVE_ADDRESS
)
View Source
const (
	DATA_TX_SENDERS = 512 + iota
	// List of recipients for valid transactions in the user context.
	DATA_TX_RECIPIENTS
	// List of voucher values for valid transactions in the user context.
	DATA_TX_VALUES
	// List of voucher EVM addresses for valid transactions in the user context.
	DATA_TX_ADDRESSES
	// List of valid transaction hashes in the user context.
	DATA_TX_HASHES
	// List of transaction dates for valid transactions in the user context.
	DATA_TX_DATES
	// List of voucher symbols for valid transactions in the user context.
	DATA_TX_SYMBOLS
	// List of voucher decimal counts for valid transactions in the user context.
	DATA_TX_DECIMALS
)

Variables

This section is empty.

Functions

func CheckRecipient

func CheckRecipient(recipient string) (string, error)

CheckRecipient validates the recipient format based on the criteria

func FormatPhoneNumber

func FormatPhoneNumber(phone string) (string, error)

FormatPhoneNumber formats a Kenyan phone number to "+254xxxxxxxx".

func GetTemporaryVoucherData

func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error)

GetTemporaryVoucherData retrieves temporary voucher metadata from the DataStore.

func GetTransferData

func GetTransferData(ctx context.Context, db storage.PrefixDb, publicKey string, index int) (string, error)

GetTransferData retrieves and matches transfer data returns a formatted string of the full transaction/statement

func GetVoucherData

func GetVoucherData(ctx context.Context, db storage.PrefixDb, input string) (*dataserviceapi.TokenHoldings, error)

GetVoucherData retrieves and matches voucher data

func IsSameHex

func IsSameHex(left string, right string) bool

func IsValidAddress

func IsValidAddress(address string) bool

IsValidAddress checks if the given address is a valid Ethereum address

func IsValidAlias

func IsValidAlias(alias string) bool

IsValidAlias checks if the alias is a valid alias format

func IsValidPhoneNumber

func IsValidPhoneNumber(phonenumber string) bool

IsValidPhoneNumber checks if the given number is a valid phone number

func MatchVoucher

func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol, balance, decimal, address string)

MatchVoucher finds the matching voucher symbol, balance, decimals and contract address based on the input.

func NormalizeHex

func NormalizeHex(s string) (string, error)

func PackKey

func PackKey(typ DataTyp, data []byte) []byte

func ParseAndScaleAmount

func ParseAndScaleAmount(storedAmount, activeDecimal string) (string, error)

func ScaleDownBalance

func ScaleDownBalance(balance, decimals string) string

func StoreTemporaryVoucher

func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error

StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore.

func StoreToDb

func StoreToDb(store *UserDataStore) db.Db

func StoreToPrefixDb

func StoreToPrefixDb(store *UserDataStore, pfx []byte) storage.PrefixDb

func ToBytes

func ToBytes[T ~uint16 | int](value T) []byte

ToBytes converts DataTyp or int to a byte slice

func UpdateVoucherData

func UpdateVoucherData(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error

UpdateVoucherData updates the active voucher data in the DataStore.

Types

type DataStore

type DataStore interface {
	db.Db
	ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error)
	WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error
}

type DataTyp

type DataTyp uint16

DataType is a subprefix value used in association with vise/db.DATATYPE_USERDATA.

All keys are used only within the context of a single account. Unless otherwise specified, the user context is the session id.

* The first byte is vise/db.DATATYPE_USERDATA * The last 2 bytes are the DataTyp value, big-endian. * The intermediate bytes are the id of the user context.

All values are strings

const (
	// List of valid voucher symbols in the user context.
	DATA_VOUCHER_SYMBOLS DataTyp = 256 + iota
	// List of voucher balances for vouchers valid in the user context.
	DATA_VOUCHER_BALANCES
	// List of voucher decimal counts for vouchers valid in the user context.
	DATA_VOUCHER_DECIMALS
	// List of voucher EVM addresses for vouchers valid in the user context.
	DATA_VOUCHER_ADDRESSES
)

func StringToDataTyp

func StringToDataTyp(str string) (DataTyp, error)

type StorageService

type StorageService struct {
	// contains filtered or unexported fields
}

func NewStorageService

func NewStorageService(dbDir string) *StorageService

func (*StorageService) EnsureDbDir

func (ss *StorageService) EnsureDbDir() error

func (*StorageService) GetPersister

func (ss *StorageService) GetPersister(ctx context.Context) (*persist.Persister, error)

func (*StorageService) GetResource

func (ss *StorageService) GetResource(ctx context.Context) (resource.Resource, error)

func (*StorageService) GetUserdataDb

func (ss *StorageService) GetUserdataDb(ctx context.Context) (db.Db, error)

type StorageServices

type StorageServices interface {
	GetPersister(ctx context.Context) (*persist.Persister, error)
	GetUserdataDb(ctx context.Context) (db.Db, error)
	GetResource(ctx context.Context) (resource.Resource, error)
	EnsureDbDir() error
}

type TransactionData

type TransactionData struct {
	TemporaryValue string
	ActiveSym      string
	Amount         string
	PublicKey      string
	Recipient      string
	ActiveDecimal  string
	ActiveAddress  string
}

func ReadTransactionData

func ReadTransactionData(ctx context.Context, store DataStore, sessionId string) (TransactionData, error)

type TransferMetadata

type TransferMetadata struct {
	Senders        string
	Recipients     string
	TransferValues string
	Addresses      string
	TxHashes       string
	Dates          string
	Symbols        string
	Decimals       string
}

TransferMetadata helps organize data fields

func ProcessTransfers

func ProcessTransfers(transfers []dataserviceapi.Last10TxResponse) TransferMetadata

ProcessTransfers converts transfers into formatted strings

type UserDataStore

type UserDataStore struct {
	db.Db
}

func (*UserDataStore) ReadEntry

func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ DataTyp) ([]byte, error)

ReadEntry retrieves an entry to the userdata store.

func (*UserDataStore) WriteEntry

func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ DataTyp, value []byte) error

WriteEntry adds an entry to the userdata store. BUG: this uses sessionId twice

type VoucherMetadata

type VoucherMetadata struct {
	Symbols   string
	Balances  string
	Decimals  string
	Addresses string
}

VoucherMetadata helps organize data fields

func ProcessVouchers

func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata

ProcessVouchers converts holdings into formatted strings

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL