logdb #56
| @ -77,12 +77,13 @@ type MenuHandlers struct { | ||||
| 	flagManager          *FlagManager | ||||
| 	accountService       remote.AccountService | ||||
| 	prefixDb             storedb.PrefixDb | ||||
| 	logDb                store.LogDb | ||||
| 	profile              *profile.Profile | ||||
| 	ReplaceSeparatorFunc func(string) string | ||||
| } | ||||
| 
 | ||||
| // NewHandlers creates a new instance of the Handlers struct with the provided dependencies.
 | ||||
| func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) { | ||||
| func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, logdb db.Db, accountService remote.AccountService, replaceSeparatorFunc func(string) string) (*MenuHandlers, error) { | ||||
| 	if userdataStore == nil { | ||||
| 		return nil, fmt.Errorf("cannot create handler with nil userdata store") | ||||
| 	} | ||||
| @ -90,6 +91,10 @@ func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, accountService | ||||
| 		Db: userdataStore, | ||||
| 	} | ||||
| 
 | ||||
| 	logDb := store.LogDb{ | ||||
| 		Db: logdb, | ||||
| 	} | ||||
| 
 | ||||
| 	// Instantiate the SubPrefixDb with "DATATYPE_USERDATA" prefix
 | ||||
| 	prefix := storedb.ToBytes(db.DATATYPE_USERDATA) | ||||
| 	prefixDb := storedb.NewSubPrefixDb(userdataStore, prefix) | ||||
| @ -99,6 +104,7 @@ func NewMenuHandlers(appFlags *FlagManager, userdataStore db.Db, accountService | ||||
| 		flagManager:          appFlags, | ||||
| 		accountService:       accountService, | ||||
| 		prefixDb:             prefixDb, | ||||
| 		logDb:                logDb, | ||||
| 		profile:              &profile.Profile{Max: 6}, | ||||
| 		ReplaceSeparatorFunc: replaceSeparatorFunc, | ||||
| 	} | ||||
| @ -199,11 +205,16 @@ func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId strin | ||||
| 		storedb.DATA_ACCOUNT_ALIAS: "", | ||||
| 	} | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 	for key, value := range data { | ||||
| 		err = store.WriteEntry(ctx, sessionId, key, []byte(value)) | ||||
| 		if err != nil { | ||||
| 			return err | ||||
| 		} | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, key, []byte(value)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write log entry", "key", string(key), "value", value) | ||||
| 		} | ||||
| 	} | ||||
| 	publicKeyNormalized, err := hex.NormalizeHex(publicKey) | ||||
| 	if err != nil { | ||||
| @ -213,6 +224,12 @@ func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId strin | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY_REVERSE, []byte(sessionId)) | ||||
| 	if err != nil { | ||||
| 		logg.DebugCtxf(ctx, "Failed to write log entry", "key", storedb.DATA_PUBLIC_KEY_REVERSE, "value", sessionId) | ||||
| 	} | ||||
| 
 | ||||
| 	res.FlagSet = append(res.FlagSet, flag_account_created) | ||||
| 	return nil | ||||
| } | ||||
| @ -509,6 +526,7 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [ | ||||
| 	} | ||||
| 
 | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 	hashedTemporaryPin, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) | ||||
| 	if err != nil { | ||||
| 		logg.ErrorCtxf(ctx, "failed to read hashedTemporaryPin entry with", "key", storedb.DATA_TEMPORARY_VALUE, "error", err) | ||||
| @ -532,6 +550,10 @@ func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input [ | ||||
| 		logg.ErrorCtxf(ctx, "failed to write DATA_ACCOUNT_PIN entry with", "key", storedb.DATA_ACCOUNT_PIN, "hashedPIN value", hashedTemporaryPin, "error", err) | ||||
| 		return res, err | ||||
| 	} | ||||
| 	err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_ACCOUNT_PIN, []byte(hashedTemporaryPin)) | ||||
| 	if err != nil { | ||||
| 		logg.DebugCtxf(ctx, "Failed to write hashed PIN db log entry", "key", storedb.DATA_ACCOUNT_PIN, "value", hashedTemporaryPin) | ||||
| 	} | ||||
| 
 | ||||
| 	return res, nil | ||||
| } | ||||
| @ -731,7 +753,10 @@ func (h *MenuHandlers) SaveFirstname(ctx context.Context, sym string, input []by | ||||
| 		return res, fmt.Errorf("missing session") | ||||
| 	} | ||||
| 	firstName := string(input) | ||||
| 
 | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| 	flag_firstname_set, _ := h.flagManager.GetFlag("flag_firstname_set") | ||||
| 
 | ||||
| @ -749,6 +774,11 @@ func (h *MenuHandlers) SaveFirstname(ctx context.Context, sym string, input []by | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_firstname_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_FIRST_NAME, []byte(temporaryFirstName)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write firtname db log entry", "key", storedb.DATA_FIRST_NAME, "value", temporaryFirstName) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if firstNameSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(firstName)) | ||||
| @ -774,6 +804,7 @@ func (h *MenuHandlers) SaveFamilyname(ctx context.Context, sym string, input []b | ||||
| 	} | ||||
| 
 | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 	familyName := string(input) | ||||
| 
 | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| @ -793,6 +824,11 @@ func (h *MenuHandlers) SaveFamilyname(ctx context.Context, sym string, input []b | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_familyname_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_FAMILY_NAME, []byte(temporaryFamilyName)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write firtname db log entry", "key", storedb.DATA_FAMILY_NAME, "value", temporaryFamilyName) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if familyNameSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(familyName)) | ||||
| @ -849,6 +885,8 @@ func (h *MenuHandlers) SaveYob(ctx context.Context, sym string, input []byte) (r | ||||
| 	} | ||||
| 	yob := string(input) | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| 	flag_yob_set, _ := h.flagManager.GetFlag("flag_yob_set") | ||||
| 
 | ||||
| @ -867,6 +905,11 @@ func (h *MenuHandlers) SaveYob(ctx context.Context, sym string, input []byte) (r | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_yob_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_YOB, []byte(temporaryYob)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write yob db log entry", "key", storedb.DATA_YOB, "value", temporaryYob) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if yobSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(yob)) | ||||
| @ -892,6 +935,7 @@ func (h *MenuHandlers) SaveLocation(ctx context.Context, sym string, input []byt | ||||
| 	} | ||||
| 	location := string(input) | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| 	flag_location_set, _ := h.flagManager.GetFlag("flag_location_set") | ||||
| @ -910,6 +954,11 @@ func (h *MenuHandlers) SaveLocation(ctx context.Context, sym string, input []byt | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_location_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_LOCATION, []byte(temporaryLocation)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write location db log entry", "key", storedb.DATA_LOCATION, "value", temporaryLocation) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if locationSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(location)) | ||||
| @ -937,6 +986,7 @@ func (h *MenuHandlers) SaveGender(ctx context.Context, sym string, input []byte) | ||||
| 	} | ||||
| 	gender := strings.Split(symbol, "_")[1] | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| 	flag_gender_set, _ := h.flagManager.GetFlag("flag_gender_set") | ||||
| 
 | ||||
| @ -955,6 +1005,12 @@ func (h *MenuHandlers) SaveGender(ctx context.Context, sym string, input []byte) | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_gender_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_GENDER, []byte(temporaryGender)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write gender db log entry", "key", storedb.DATA_TEMPORARY_VALUE, "value", temporaryGender) | ||||
| 		} | ||||
| 
 | ||||
| 	} else { | ||||
| 		if genderSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(gender)) | ||||
| @ -981,6 +1037,7 @@ func (h *MenuHandlers) SaveOfferings(ctx context.Context, sym string, input []by | ||||
| 
 | ||||
| 	offerings := string(input) | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	flag_allow_update, _ := h.flagManager.GetFlag("flag_allow_update") | ||||
| 	flag_offerings_set, _ := h.flagManager.GetFlag("flag_offerings_set") | ||||
| @ -1000,6 +1057,11 @@ func (h *MenuHandlers) SaveOfferings(ctx context.Context, sym string, input []by | ||||
| 			return res, err | ||||
| 		} | ||||
| 		res.FlagSet = append(res.FlagSet, flag_offerings_set) | ||||
| 
 | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_FIRST_NAME, []byte(temporaryOfferings)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write offerings db log entry", "key", storedb.DATA_OFFERINGS, "value", offerings) | ||||
| 		} | ||||
| 	} else { | ||||
| 		if offeringsSet { | ||||
| 			err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(offerings)) | ||||
| @ -1960,6 +2022,7 @@ func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, inpu | ||||
| func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) { | ||||
| 	var res resource.Result | ||||
| 	userStore := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	sessionId, ok := ctx.Value("SessionId").(string) | ||||
| 	if !ok { | ||||
| @ -2014,6 +2077,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b | ||||
| 					logg.ErrorCtxf(ctx, "Failed to write active voucher data", "key", key, "error", err) | ||||
| 					return res, err | ||||
| 				} | ||||
| 				err = logdb.WriteLogEntry(ctx, sessionId, key, []byte(value)) | ||||
| 				if err != nil { | ||||
| 					logg.DebugCtxf(ctx, "Failed to write voucher db log entry", "key", key, "value", value) | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			logg.InfoCtxf(ctx, "Default voucher set", "symbol", defaultSym, "balance", defaultBal, "decimals", defaultDec, "address", defaultAddr) | ||||
| @ -2210,6 +2277,7 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input | ||||
| 	flag_api_error, _ := h.flagManager.GetFlag("flag_api_error") | ||||
| 
 | ||||
| 	userStore := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 	publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) | ||||
| 	if err != nil { | ||||
| 		logg.ErrorCtxf(ctx, "failed to read publicKey entry with", "key", storedb.DATA_PUBLIC_KEY, "error", err) | ||||
| @ -2249,6 +2317,10 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input | ||||
| 			logg.ErrorCtxf(ctx, "failed to write to prefixDb", "error", err) | ||||
| 			return res, err | ||||
| 		} | ||||
| 		err = logdb.WriteLogEntry(ctx, sessionId, key, []byte(value)) | ||||
| 		if err != nil { | ||||
| 			logg.DebugCtxf(ctx, "Failed to write tx db log entry", "key", key, "value", value) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	res.FlagReset = append(res.FlagReset, flag_no_transfers) | ||||
| @ -2531,6 +2603,7 @@ func (h *MenuHandlers) GetSuggestedAlias(ctx context.Context, sym string, input | ||||
| func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input []byte) (resource.Result, error) { | ||||
| 	var res resource.Result | ||||
| 	store := h.userdataStore | ||||
| 	logdb := h.logDb | ||||
| 
 | ||||
| 	flag_alias_set, _ := h.flagManager.GetFlag("flag_alias_set") | ||||
| 
 | ||||
| @ -2549,6 +2622,11 @@ func (h *MenuHandlers) ConfirmNewAlias(ctx context.Context, sym string, input [] | ||||
| 		return res, err | ||||
| 	} | ||||
| 
 | ||||
| 	err = logdb.WriteLogEntry(ctx, sessionId, storedb.DATA_ACCOUNT_ALIAS, []byte(newAlias)) | ||||
| 	if err != nil { | ||||
| 		logg.DebugCtxf(ctx, "Failed to write account alias db log entry", "key", storedb.DATA_ACCOUNT_ALIAS, "value", newAlias) | ||||
| 	} | ||||
| 
 | ||||
| 	res.FlagSet = append(res.FlagSet, flag_alias_set) | ||||
| 	return res, nil | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user