Compare commits
4 Commits
f38ea59569
...
7aea2af9a1
Author | SHA1 | Date | |
---|---|---|---|
7aea2af9a1 | |||
5cd791aae7 | |||
df5e5f1a4b | |||
64c1fe5276 |
@ -30,10 +30,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
|
||||
build = "dev"
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
build = "dev"
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -128,13 +128,14 @@ func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
MenuSeparator: ": ",
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
if engineDebug {
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -67,13 +68,14 @@ func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
MenuSeparator: ": ",
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
if engineDebug {
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -55,13 +56,14 @@ func main() {
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
MenuSeparator: ": ",
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
if engineDebug {
|
||||
|
@ -18,8 +18,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
logg = logging.NewVanilla()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -46,6 +47,7 @@ func main() {
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
@ -53,7 +55,7 @@ func main() {
|
||||
SessionId: sessionId,
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
MenuSeparator: ": ",
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
resourceDir := scriptDir
|
||||
|
@ -24,7 +24,7 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
|
||||
var symbols, balances, decimals, addresses []string
|
||||
|
||||
for i, h := range holdings {
|
||||
symbols = append(symbols, fmt.Sprintf("%d: %s", i+1, h.TokenSymbol))
|
||||
symbols = append(symbols, fmt.Sprintf("%d:%s", i+1, h.TokenSymbol))
|
||||
|
||||
// Scale down the balance
|
||||
scaledBalance := ScaleDownBalance(h.Balance, h.TokenDecimals)
|
||||
@ -103,7 +103,7 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
|
||||
|
||||
logg.Tracef("found", "symlist", symList, "syms", symbols, "input", input)
|
||||
for i, sym := range symList {
|
||||
parts := strings.SplitN(sym, ": ", 2)
|
||||
parts := strings.SplitN(sym, ":", 2)
|
||||
|
||||
if input == parts[0] || strings.EqualFold(input, parts[1]) {
|
||||
symbol = parts[1]
|
||||
|
@ -34,7 +34,7 @@ func InitializeTestDb(t *testing.T) (context.Context, *UserDataStore) {
|
||||
}
|
||||
|
||||
func TestMatchVoucher(t *testing.T) {
|
||||
symbols := "1: SRF\n2: MILO"
|
||||
symbols := "1:SRF\n2:MILO"
|
||||
balances := "1:100\n2:200"
|
||||
decimals := "1:6\n2:4"
|
||||
addresses := "1:0xd4c288865Ce\n2:0x41c188d63Qa"
|
||||
@ -65,7 +65,7 @@ func TestProcessVouchers(t *testing.T) {
|
||||
}
|
||||
|
||||
expectedResult := VoucherMetadata{
|
||||
Symbols: "1: SRF\n2: MILO",
|
||||
Symbols: "1:SRF\n2:MILO",
|
||||
Balances: "1:100\n2:20000",
|
||||
Decimals: "1:6\n2:4",
|
||||
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
|
||||
@ -90,7 +90,7 @@ func TestGetVoucherData(t *testing.T) {
|
||||
|
||||
// Test voucher data
|
||||
mockData := map[DataTyp][]byte{
|
||||
DATA_VOUCHER_SYMBOLS: []byte("1: SRF\n2: MILO"),
|
||||
DATA_VOUCHER_SYMBOLS: []byte("1:SRF\n2:MILO"),
|
||||
DATA_VOUCHER_BALANCES: []byte("1:100\n2:200"),
|
||||
DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"),
|
||||
DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),
|
||||
|
@ -1676,6 +1676,11 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
|
||||
func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
|
||||
menuSeparator, ok := ctx.Value("MenuSeparator").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing menu Separator")
|
||||
}
|
||||
|
||||
// Read vouchers from the store
|
||||
voucherData, err := h.prefixDb.Get(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS))
|
||||
if err != nil {
|
||||
@ -1683,7 +1688,9 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte)
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = string(voucherData)
|
||||
formattedData := strings.ReplaceAll(string(voucherData), ":", menuSeparator)
|
||||
|
||||
res.Content = string(formattedData)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@ -1853,6 +1860,12 @@ func (h *Handlers) GetTransactionsList(ctx context.Context, sym string, input []
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
menuSeparator, ok := ctx.Value("MenuSeparator").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing menu Separator")
|
||||
}
|
||||
|
||||
store := h.userdataStore
|
||||
publicKey, err := store.ReadEntry(ctx, sessionId, common.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
@ -1900,7 +1913,7 @@ func (h *Handlers) GetTransactionsList(ctx context.Context, sym string, input []
|
||||
status = "Sent"
|
||||
}
|
||||
|
||||
formattedTransactions = append(formattedTransactions, fmt.Sprintf("%d: %s %s %s %s", i+1, status, value, sym, date))
|
||||
formattedTransactions = append(formattedTransactions, fmt.Sprintf("%d%s%s %s %s %s", i+1, menuSeparator, status, value, sym, date))
|
||||
}
|
||||
|
||||
res.Content = strings.Join(formattedTransactions, "\n")
|
||||
|
@ -1961,7 +1961,7 @@ func TestCheckVouchers(t *testing.T) {
|
||||
{ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"},
|
||||
}
|
||||
|
||||
expectedSym := []byte("1: SRF\n2: MILO")
|
||||
expectedSym := []byte("1:SRF\n2:MILO")
|
||||
|
||||
mockAccountService.On("FetchVouchers", string(publicKey)).Return(mockVouchersResponse, nil)
|
||||
|
||||
@ -1982,7 +1982,11 @@ func TestCheckVouchers(t *testing.T) {
|
||||
|
||||
func TestGetVoucherList(t *testing.T) {
|
||||
sessionId := "session123"
|
||||
menuSeparator := ":"
|
||||
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
|
||||
|
||||
|
||||
spdb := InitializeTestSubPrefixDb(t, ctx)
|
||||
|
||||
@ -2024,7 +2028,7 @@ func TestViewVoucher(t *testing.T) {
|
||||
|
||||
// Define mock voucher data
|
||||
mockData := map[common.DataTyp][]byte{
|
||||
common.DATA_VOUCHER_SYMBOLS: []byte("1: SRF\n2: MILO"),
|
||||
common.DATA_VOUCHER_SYMBOLS: []byte("1:SRF\n2:MILO"),
|
||||
common.DATA_VOUCHER_BALANCES: []byte("1:100\n2:200"),
|
||||
common.DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"),
|
||||
common.DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),
|
||||
|
Loading…
Reference in New Issue
Block a user