wip-flag-migration #28

Merged
Alfred-mk merged 44 commits from wip-flag-migration into master 2024-09-04 11:25:34 +02:00
2 changed files with 12 additions and 8 deletions
Showing only changes of commit fee51edade - Show all commits

View File

@ -107,7 +107,7 @@ func main() {
fp := path.Join(dp, sessionId)
ussdHandlers, err := ussd.NewHandlers(fp, &st)
ussdHandlers, err := ussd.NewHandlers(fp, &st,sessionId)
if err != nil {
fmt.Fprintf(os.Stderr, "handler setup failed with error: %v\n", err)
Review

Exit in main if any setup fails.

Exit in main if any setup fails.

View File

@ -24,7 +24,7 @@ import (
var (
scriptDir = path.Join("services", "registration")
translationDir = path.Join(scriptDir, "locale")
dbFile = path.Join(scriptDir, "vise.gdbm")
//dbFile = path.Join(scriptDir, "userdata.gdbm")
)
const (
@ -65,8 +65,9 @@ type Handlers struct {
accountService server.AccountServiceInterface
}
func NewHandlers(dir string, st *state.State) (*Handlers, error) {
db, err := gdbm.Open(dbFile, gdbm.ModeWrcreat)
func NewHandlers(dir string, st *state.State, sessionId string) (*Handlers, error) {
Outdated
Review

FYI this will truncate the file on every open.

... but lets not spend time on that, as it needs to be changed to the new gdbm implementation anyway.

FYI this will truncate the file on every open. ... but lets not spend time on that, as it needs to be changed to the new gdbm implementation anyway.

So a question on this,we want to be able to keep a reference to the file created for each session and be able to initialize a database instance depending on its existence.So we have this code and it still seems to be removing the previously stored information when it is opened with mode ModeWriter .A fix for the time being for this will be appreciated because the refactoring depends on storing the user information to gdbm.

filename := path.Join(scriptDir, sessionId+"_userdata.gdbm")
_, err := os.Open(filename)
if err != nil {
	// Check if the error is due to the file not existing
	if os.IsNotExist(err) {
		fmt.Printf("File open error: the file '%s' does not exist\n", filename)
		db, err = gdbm.Open(filename, gdbm.ModeWrcreat)
		if err != nil {
			panic(err)
		}
	} else {
		panic(err)
	}
} else {
	db, err = gdbm.Open(filename, gdbm.ModeWriter)
	if err != nil {
		panic(err)
	}
}`                                                                                                                                                                                                                                                               
So a question on this,we want to be able to keep a reference to the file created for each session and be able to initialize a database instance depending on its existence.So we have this code and it still seems to be removing the previously stored information when it is opened with mode **ModeWriter** .A fix for the time being for this will be appreciated because the refactoring depends on storing the user information to gdbm. filename := path.Join(scriptDir, sessionId+"_userdata.gdbm") _, err := os.Open(filename) if err != nil { // Check if the error is due to the file not existing if os.IsNotExist(err) { fmt.Printf("File open error: the file '%s' does not exist\n", filename) db, err = gdbm.Open(filename, gdbm.ModeWrcreat) if err != nil { panic(err) } } else { panic(err) } } else { db, err = gdbm.Open(filename, gdbm.ModeWriter) if err != nil { panic(err) } }`
Outdated
Review

First, as I said, let's not spend time on this, since this code will be gone when you implement db.gdbmDb in dev-0.1.0.

That said, choosing flag on os.Stat would be the way to go, I guess.

As a reference example on how to do it directly, see go-vise branch dev-0.1.0 method db/gdbm/gdbmDb.Connect(...)

But I repeat, please don't spend time on this.

First, as I said, let's not spend time on this, since this code will be gone when you implement db.gdbmDb in dev-0.1.0. That said, choosing flag on os.Stat would be the way to go, I guess. As a reference example on how to do it directly, see `go-vise` branch `dev-0.1.0` method `db/gdbm/gdbmDb.Connect(...)` But I repeat, please don't spend time on this.
filename := path.Join(scriptDir, sessionId+"_userdata.gdbm")
db, err := gdbm.Open(filename, gdbm.ModeWrcreat)
if err != nil {
panic(err)
}
@ -425,9 +426,12 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
res.FlagReset = append(res.FlagReset, flags["flag_account_authorized"])
return res, nil
}
} else {
res.FlagSet = append(res.FlagSet, flags["flag_incorrect_pin"])
res.FlagReset = append(res.FlagReset, flags["flag_account_authorized"])
}
} else if errors.Is(err, gdbm.ErrItemNotFound) {
//PIN not set yet
return res, err
} else {
return res, err
}
@ -620,11 +624,11 @@ func (h *Handlers) TransactionReset(ctx context.Context, sym string, input []byt
err = h.db.Delete([]byte(Amount))
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
return res,err
return res, err
}
err = h.db.Delete([]byte(Recipient))
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
return res,err
return res, err
carlos marked this conversation as resolved Outdated
Outdated
Review

we cannot have panics anywhere in the vm execution! Just return error.

we cannot have panics anywhere in the vm execution! Just return error.
}
res.FlagReset = append(res.FlagReset, flags["flag_invalid_recipient"], flags["flag_invalid_recipient_with_invite"])
@ -645,7 +649,7 @@ func (h *Handlers) ResetTransactionAmount(ctx context.Context, sym string, input
err = h.db.Delete([]byte(Amount))
if err != nil && !errors.Is(err, gdbm.ErrItemNotFound) {
return res,err
return res, err
}
res.FlagReset = append(res.FlagReset, flags["flag_invalid_amount"])