data-items-cleanup #203
@ -32,10 +32,10 @@ const (
 | 
			
		||||
	DATA_PUBLIC_KEY_REVERSE
 | 
			
		||||
	DATA_ACTIVE_DECIMAL
 | 
			
		||||
	DATA_ACTIVE_ADDRESS
 | 
			
		||||
	DATA_PREFIX_SYMBOLS
 | 
			
		||||
	DATA_PREFIX_BALANCES
 | 
			
		||||
	DATA_PREFIX_DECIMALS
 | 
			
		||||
	DATA_PREFIX_ADDRESSES
 | 
			
		||||
	DATA_VOUCHER_SYMBOLS
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					Alfred-mk marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				 | 
			||||
	DATA_VOUCHER_BALANCES
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					Alfred-mk marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						lash
						commented  
			
		I would start at 256 (0x0100), and keep the DATATYPE_USERDATA prefix. I would start at 256 (0x0100), and keep the DATATYPE_USERDATA prefix. 
			
			
		 | 
			||||
	DATA_VOUCHER_DECIMALS
 | 
			
		||||
	DATA_VOUCHER_ADDRESSES
 | 
			
		||||
	DATA_PREFIX_TX_SENDERS
 | 
			
		||||
	DATA_PREFIX_TX_RECIPIENTS
 | 
			
		||||
| 
					
	
	
	
	
	
	
	
	 
					
					Alfred-mk marked this conversation as resolved
					
						
						
							Outdated
						
					
				 
				
				
					
						lash
						commented  
			
		Sorry perhaps it wasn't clear. The "PREFIX" part in general is implied and a thus redundant. TX should suffice. Sorry perhaps it wasn't clear. The "PREFIX" part in general is implied and a thus redundant. TX should suffice. 
			
			
		
				
					
						Alfred-mk
						commented  
			
		Apologies, I was to replace these as well. This has been done Apologies, I was to replace these as well. This has been done 
			
			
		 | 
			||||
	DATA_PREFIX_TX_VALUES
 | 
			
		||||
 | 
			
		||||
@ -64,22 +64,22 @@ func ScaleDownBalance(balance, decimals string) string {
 | 
			
		||||
 | 
			
		||||
// GetVoucherData retrieves and matches voucher data
 | 
			
		||||
func GetVoucherData(ctx context.Context, db storage.PrefixDb, input string) (*dataserviceapi.TokenHoldings, error) {
 | 
			
		||||
	keys := []DataTyp{DATA_PREFIX_SYMBOLS, DATA_PREFIX_BALANCES, DATA_PREFIX_DECIMALS, DATA_PREFIX_ADDRESSES}
 | 
			
		||||
	keys := []DataTyp{DATA_VOUCHER_SYMBOLS, DATA_VOUCHER_BALANCES, DATA_VOUCHER_DECIMALS, DATA_VOUCHER_ADDRESSES}
 | 
			
		||||
	data := make(map[DataTyp]string)
 | 
			
		||||
 | 
			
		||||
	for _, key := range keys {
 | 
			
		||||
		value, err := db.Get(ctx, key.ToBytes())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("failed to get %s: %v", key.ToBytes(), err)	
 | 
			
		||||
			return nil, fmt.Errorf("failed to get %s: %v", key.ToBytes(), err)
 | 
			
		||||
		}
 | 
			
		||||
		data[key] = string(value)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	symbol, balance, decimal, address := MatchVoucher(input,
 | 
			
		||||
		data[DATA_PREFIX_SYMBOLS],
 | 
			
		||||
		data[DATA_PREFIX_BALANCES],
 | 
			
		||||
		data[DATA_PREFIX_DECIMALS],
 | 
			
		||||
		data[DATA_PREFIX_ADDRESSES],
 | 
			
		||||
		data[DATA_VOUCHER_SYMBOLS],
 | 
			
		||||
		data[DATA_VOUCHER_BALANCES],
 | 
			
		||||
		data[DATA_VOUCHER_DECIMALS],
 | 
			
		||||
		data[DATA_VOUCHER_ADDRESSES],
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if symbol == "" {
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,8 @@ import (
 | 
			
		||||
	"github.com/alecthomas/assert/v2"
 | 
			
		||||
	"github.com/stretchr/testify/require"
 | 
			
		||||
 | 
			
		||||
	"git.grassecon.net/urdt/ussd/internal/storage"
 | 
			
		||||
	memdb "git.defalsify.org/vise.git/db/mem"
 | 
			
		||||
	"git.grassecon.net/urdt/ussd/internal/storage"
 | 
			
		||||
	dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -87,10 +87,10 @@ func TestGetVoucherData(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Test voucher data
 | 
			
		||||
	mockData := map[DataTyp][]byte{
 | 
			
		||||
		DATA_PREFIX_SYMBOLS:   []byte("1:SRF\n2:MILO"),
 | 
			
		||||
		DATA_PREFIX_BALANCES:  []byte("1:100\n2:200"),
 | 
			
		||||
		DATA_PREFIX_DECIMALS:  []byte("1:6\n2:4"),
 | 
			
		||||
		DATA_PREFIX_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),
 | 
			
		||||
		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"),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Put the data
 | 
			
		||||
 | 
			
		||||
@ -1577,10 +1577,10 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte)
 | 
			
		||||
 | 
			
		||||
	// Store all voucher data
 | 
			
		||||
	dataMap := map[common.DataTyp]string{
 | 
			
		||||
		common.DATA_PREFIX_SYMBOLS:   data.Symbols,
 | 
			
		||||
		common.DATA_PREFIX_BALANCES:  data.Balances,
 | 
			
		||||
		common.DATA_PREFIX_DECIMALS:  data.Decimals,
 | 
			
		||||
		common.DATA_PREFIX_ADDRESSES: data.Addresses,
 | 
			
		||||
		common.DATA_VOUCHER_SYMBOLS:   data.Symbols,
 | 
			
		||||
		common.DATA_VOUCHER_BALANCES:  data.Balances,
 | 
			
		||||
		common.DATA_VOUCHER_DECIMALS:  data.Decimals,
 | 
			
		||||
		common.DATA_VOUCHER_ADDRESSES: data.Addresses,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for key, value := range dataMap {
 | 
			
		||||
@ -1597,7 +1597,7 @@ func (h *Handlers) GetVoucherList(ctx context.Context, sym string, input []byte)
 | 
			
		||||
	var res resource.Result
 | 
			
		||||
 | 
			
		||||
	// Read vouchers from the store
 | 
			
		||||
	voucherData, err := h.prefixDb.Get(ctx, common.DATA_PREFIX_SYMBOLS.ToBytes())
 | 
			
		||||
	voucherData, err := h.prefixDb.Get(ctx, common.DATA_VOUCHER_SYMBOLS.ToBytes())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		logg.ErrorCtxf(ctx, "Failed to read the voucherData from prefixDb", "error", err)
 | 
			
		||||
		return res, err
 | 
			
		||||
 | 
			
		||||
@ -1937,7 +1937,7 @@ func TestCheckVouchers(t *testing.T) {
 | 
			
		||||
	assert.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
	// Read voucher sym data from the store
 | 
			
		||||
	voucherData, err := spdb.Get(ctx, common.DATA_PREFIX_SYMBOLS.ToBytes())
 | 
			
		||||
	voucherData, err := spdb.Get(ctx, common.DATA_VOUCHER_SYMBOLS.ToBytes())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
@ -1961,7 +1961,7 @@ func TestGetVoucherList(t *testing.T) {
 | 
			
		||||
	expectedSym := []byte("1:SRF\n2:MILO")
 | 
			
		||||
 | 
			
		||||
	// Put voucher sym data from the store
 | 
			
		||||
	err := spdb.Put(ctx, common.DATA_PREFIX_SYMBOLS.ToBytes(), expectedSym)
 | 
			
		||||
	err := spdb.Put(ctx, common.DATA_VOUCHER_SYMBOLS.ToBytes(), expectedSym)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
@ -1992,10 +1992,10 @@ func TestViewVoucher(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// Define mock voucher data
 | 
			
		||||
	mockData := map[common.DataTyp][]byte{
 | 
			
		||||
		common.DATA_PREFIX_SYMBOLS:   []byte("1:SRF\n2:MILO"),
 | 
			
		||||
		common.DATA_PREFIX_BALANCES:  []byte("1:100\n2:200"),
 | 
			
		||||
		common.DATA_PREFIX_DECIMALS:  []byte("1:6\n2:4"),
 | 
			
		||||
		common.DATA_PREFIX_ADDRESSES: []byte("1:0xd4c288865Ce\n2:0x41c188d63Qa"),
 | 
			
		||||
		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"),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Put the data
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
Perhaps better name
DATA_VOUCHER_*?