From 39bc5251a9b37250ab0f99014976fd5640300d15 Mon Sep 17 00:00:00 2001 From: Iamnotagenius Date: Sat, 13 Jan 2024 21:44:49 +0300 Subject: [PATCH] feat: getUser method --- contract/config.yml | 2 +- contract/passtorage.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/contract/config.yml b/contract/config.yml index f57464b..7fb61da 100644 --- a/contract/config.yml +++ b/contract/config.yml @@ -1,5 +1,5 @@ name: "Password storage" sourceurl: https://git.frostfs.info/Web3N3/neowolves -safemethods: ["checkUser"] +safemethods: ["checkUser", "getUser"] supportedstandards: [] events: [] diff --git a/contract/passtorage.go b/contract/passtorage.go index e17c295..4b4f6ba 100644 --- a/contract/passtorage.go +++ b/contract/passtorage.go @@ -16,16 +16,21 @@ func CreateUser(login string, password interop.Hash256) { } func CheckUser(login string, givenPassword interop.Hash256) { - ctx := storage.GetReadOnlyContext() - password := storage.Get(ctx, login).(interop.Hash256) - if password == nil { - panic("This user does not exist") - } + password := GetUser(login) if !password.Equals(givenPassword) { panic("Password hashes does not match") } } +func GetUser(login string) interop.Hash256 { + ctx := storage.GetReadOnlyContext() + password := storage.Get(ctx, login).(interop.Hash256) + if password == nil { + panic("The user does not exist") + } + return password +} + func DeleteUser(login string) { ctx := storage.GetContext() storage.Delete(ctx, login)