Compare commits

..

No commits in common. "7aea2af9a1baca5ca5b9ef3ac38ef74f6b1b08d3" and "f38ea59569404c8fa967f6d78279a2227f421a16" have entirely different histories.

8 changed files with 19 additions and 43 deletions

View File

@ -32,8 +32,8 @@ import (
var ( var (
logg = logging.NewVanilla() logg = logging.NewVanilla()
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
build = "dev" build = "dev"
menuSeparator = ": "
) )
func init() { func init() {
@ -128,14 +128,13 @@ func main() {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "Database", database) ctx = context.WithValue(ctx, "Database", database)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
pfp := path.Join(scriptDir, "pp.csv") pfp := path.Join(scriptDir, "pp.csv")
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
OutputSize: uint32(size), OutputSize: uint32(size),
FlagCount: uint32(128), FlagCount: uint32(128),
MenuSeparator: menuSeparator, MenuSeparator: ": ",
} }
if engineDebug { if engineDebug {

View File

@ -23,7 +23,6 @@ import (
var ( var (
logg = logging.NewVanilla() logg = logging.NewVanilla()
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
menuSeparator = ": "
) )
func init() { func init() {
@ -68,14 +67,13 @@ func main() {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "Database", database) ctx = context.WithValue(ctx, "Database", database)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
pfp := path.Join(scriptDir, "pp.csv") pfp := path.Join(scriptDir, "pp.csv")
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
OutputSize: uint32(size), OutputSize: uint32(size),
FlagCount: uint32(128), FlagCount: uint32(128),
MenuSeparator: menuSeparator, MenuSeparator: ": ",
} }
if engineDebug { if engineDebug {

View File

@ -26,7 +26,6 @@ import (
var ( var (
logg = logging.NewVanilla() logg = logging.NewVanilla()
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
menuSeparator = ": "
) )
func init() { func init() {
@ -56,14 +55,13 @@ func main() {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "Database", database) ctx = context.WithValue(ctx, "Database", database)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
pfp := path.Join(scriptDir, "pp.csv") pfp := path.Join(scriptDir, "pp.csv")
cfg := engine.Config{ cfg := engine.Config{
Root: "root", Root: "root",
OutputSize: uint32(size), OutputSize: uint32(size),
FlagCount: uint32(128), FlagCount: uint32(128),
MenuSeparator: menuSeparator, MenuSeparator: ": ",
} }
if engineDebug { if engineDebug {

View File

@ -20,7 +20,6 @@ import (
var ( var (
logg = logging.NewVanilla() logg = logging.NewVanilla()
scriptDir = path.Join("services", "registration") scriptDir = path.Join("services", "registration")
menuSeparator = ": "
) )
func init() { func init() {
@ -47,7 +46,6 @@ func main() {
ctx := context.Background() ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId) ctx = context.WithValue(ctx, "SessionId", sessionId)
ctx = context.WithValue(ctx, "Database", database) ctx = context.WithValue(ctx, "Database", database)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
pfp := path.Join(scriptDir, "pp.csv") pfp := path.Join(scriptDir, "pp.csv")
cfg := engine.Config{ cfg := engine.Config{
@ -55,7 +53,7 @@ func main() {
SessionId: sessionId, SessionId: sessionId,
OutputSize: uint32(size), OutputSize: uint32(size),
FlagCount: uint32(128), FlagCount: uint32(128),
MenuSeparator: menuSeparator, MenuSeparator: ": ",
} }
resourceDir := scriptDir resourceDir := scriptDir

View File

@ -24,7 +24,7 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
var symbols, balances, decimals, addresses []string var symbols, balances, decimals, addresses []string
for i, h := range holdings { 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 // Scale down the balance
scaledBalance := ScaleDownBalance(h.Balance, h.TokenDecimals) 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) logg.Tracef("found", "symlist", symList, "syms", symbols, "input", input)
for i, sym := range symList { for i, sym := range symList {
parts := strings.SplitN(sym, ":", 2) parts := strings.SplitN(sym, ": ", 2)
if input == parts[0] || strings.EqualFold(input, parts[1]) { if input == parts[0] || strings.EqualFold(input, parts[1]) {
symbol = parts[1] symbol = parts[1]

View File

@ -34,7 +34,7 @@ func InitializeTestDb(t *testing.T) (context.Context, *UserDataStore) {
} }
func TestMatchVoucher(t *testing.T) { func TestMatchVoucher(t *testing.T) {
symbols := "1:SRF\n2:MILO" symbols := "1: SRF\n2: MILO"
balances := "1:100\n2:200" balances := "1:100\n2:200"
decimals := "1:6\n2:4" decimals := "1:6\n2:4"
addresses := "1:0xd4c288865Ce\n2:0x41c188d63Qa" addresses := "1:0xd4c288865Ce\n2:0x41c188d63Qa"
@ -65,7 +65,7 @@ func TestProcessVouchers(t *testing.T) {
} }
expectedResult := VoucherMetadata{ expectedResult := VoucherMetadata{
Symbols: "1:SRF\n2:MILO", Symbols: "1: SRF\n2: MILO",
Balances: "1:100\n2:20000", Balances: "1:100\n2:20000",
Decimals: "1:6\n2:4", Decimals: "1:6\n2:4",
Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa", Addresses: "1:0xd4c288865Ce\n2:0x41c188d63Qa",
@ -90,7 +90,7 @@ func TestGetVoucherData(t *testing.T) {
// Test voucher data // Test voucher data
mockData := map[DataTyp][]byte{ 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_BALANCES: []byte("1:100\n2:200"),
DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"), DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"),
DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"), DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),

View File

@ -1676,11 +1676,6 @@ 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) { func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result var res resource.Result
menuSeparator, ok := ctx.Value("MenuSeparator").(string)
if !ok {
return res, fmt.Errorf("missing menu Separator")
}
// Read vouchers from the store // Read vouchers from the store
voucherData, err := h.prefixDb.Get(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS)) voucherData, err := h.prefixDb.Get(ctx, common.ToBytes(common.DATA_VOUCHER_SYMBOLS))
if err != nil { if err != nil {
@ -1688,9 +1683,7 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte)
return res, err return res, err
} }
formattedData := strings.ReplaceAll(string(voucherData), ":", menuSeparator) res.Content = string(voucherData)
res.Content = string(formattedData)
return res, nil return res, nil
} }
@ -1860,12 +1853,6 @@ func (h *Handlers) GetTransactionsList(ctx context.Context, sym string, input []
if !ok { if !ok {
return res, fmt.Errorf("missing session") return res, fmt.Errorf("missing session")
} }
menuSeparator, ok := ctx.Value("MenuSeparator").(string)
if !ok {
return res, fmt.Errorf("missing menu Separator")
}
store := h.userdataStore store := h.userdataStore
publicKey, err := store.ReadEntry(ctx, sessionId, common.DATA_PUBLIC_KEY) publicKey, err := store.ReadEntry(ctx, sessionId, common.DATA_PUBLIC_KEY)
if err != nil { if err != nil {
@ -1913,7 +1900,7 @@ func (h *Handlers) GetTransactionsList(ctx context.Context, sym string, input []
status = "Sent" status = "Sent"
} }
formattedTransactions = append(formattedTransactions, fmt.Sprintf("%d%s%s %s %s %s", i+1, menuSeparator, status, value, sym, date)) formattedTransactions = append(formattedTransactions, fmt.Sprintf("%d: %s %s %s %s", i+1, status, value, sym, date))
} }
res.Content = strings.Join(formattedTransactions, "\n") res.Content = strings.Join(formattedTransactions, "\n")

View File

@ -1961,7 +1961,7 @@ func TestCheckVouchers(t *testing.T) {
{ContractAddress: "0x41c188d63Qa", TokenSymbol: "MILO", TokenDecimals: "4", Balance: "200"}, {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) mockAccountService.On("FetchVouchers", string(publicKey)).Return(mockVouchersResponse, nil)
@ -1982,11 +1982,7 @@ func TestCheckVouchers(t *testing.T) {
func TestGetVoucherList(t *testing.T) { func TestGetVoucherList(t *testing.T) {
sessionId := "session123" sessionId := "session123"
menuSeparator := ":"
ctx := context.WithValue(context.Background(), "SessionId", sessionId) ctx := context.WithValue(context.Background(), "SessionId", sessionId)
ctx = context.WithValue(ctx, "MenuSeparator", menuSeparator)
spdb := InitializeTestSubPrefixDb(t, ctx) spdb := InitializeTestSubPrefixDb(t, ctx)
@ -2028,7 +2024,7 @@ func TestViewVoucher(t *testing.T) {
// Define mock voucher data // Define mock voucher data
mockData := map[common.DataTyp][]byte{ 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_BALANCES: []byte("1:100\n2:200"),
common.DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"), common.DATA_VOUCHER_DECIMALS: []byte("1:6\n2:4"),
common.DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"), common.DATA_VOUCHER_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),