From 183a25dbe3eb45f95c8e2bbde48757ee66d806e9 Mon Sep 17 00:00:00 2001 From: Iamnotagenius Date: Fri, 5 Jan 2024 17:41:00 +0300 Subject: [PATCH] feat(contract): init and implement create with get --- contract/go.mod | 5 +++++ contract/go.sum | 2 ++ contract/passtorage.go | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 contract/go.mod create mode 100644 contract/go.sum create mode 100644 contract/passtorage.go diff --git a/contract/go.mod b/contract/go.mod new file mode 100644 index 0000000..99e976e --- /dev/null +++ b/contract/go.mod @@ -0,0 +1,5 @@ +module git.frostfs.info/Web3N3/neowolves/contract + +go 1.21.5 + +require github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595 diff --git a/contract/go.sum b/contract/go.sum new file mode 100644 index 0000000..e153659 --- /dev/null +++ b/contract/go.sum @@ -0,0 +1,2 @@ +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595 h1:vWtkeZPpwlHV55W/PSTbRP8aH37UrbdTAOyB5J1xgDM= +github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20231229133344-d90169761595/go.mod h1:J/Mk6+nKeKSW4wygkZQFLQ6SkLOSGX5Ga0RuuuktEag= diff --git a/contract/passtorage.go b/contract/passtorage.go new file mode 100644 index 0000000..99f1816 --- /dev/null +++ b/contract/passtorage.go @@ -0,0 +1,23 @@ +package main + +import ( + "github.com/nspcc-dev/neo-go/pkg/interop" + "github.com/nspcc-dev/neo-go/pkg/interop/storage" +) + +func CreateUser(login string, password interop.Hash256) { + ctx := storage.GetContext() + // NOTE: maybe we should handle case where user already exists + storage.Put(ctx, login, password) +} + +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") + } + if !password.Equals(givenPassword) { + panic("Password hashes does not match") + } +}