Compare commits
4 Commits
f38ea59569
...
7aea2af9a1
| Author | SHA1 | Date | |
|---|---|---|---|
| 7aea2af9a1 | |||
| 5cd791aae7 | |||
| df5e5f1a4b | |||
| 64c1fe5276 |
@ -30,10 +30,10 @@ 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,13 +128,14 @@ 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 {
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
|
menuSeparator = ": "
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -67,13 +68,14 @@ 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 {
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
|
menuSeparator = ": "
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -55,13 +56,14 @@ 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 {
|
||||||
|
|||||||
@ -18,8 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
|
menuSeparator = ": "
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -46,6 +47,7 @@ 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{
|
||||||
@ -53,7 +55,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
|
||||||
|
|||||||
@ -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]
|
||||||
|
|||||||
@ -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"),
|
||||||
|
|||||||
@ -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) {
|
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 {
|
||||||
@ -1683,7 +1688,9 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte)
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Content = string(voucherData)
|
formattedData := strings.ReplaceAll(string(voucherData), ":", menuSeparator)
|
||||||
|
|
||||||
|
res.Content = string(formattedData)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -1853,6 +1860,12 @@ 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 {
|
||||||
@ -1900,7 +1913,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", 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")
|
res.Content = strings.Join(formattedTransactions, "\n")
|
||||||
|
|||||||
@ -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,7 +1982,11 @@ 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)
|
||||||
|
|
||||||
@ -2024,7 +2028,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"),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user