From 183a25dbe3eb45f95c8e2bbde48757ee66d806e9 Mon Sep 17 00:00:00 2001 From: Iamnotagenius Date: Fri, 5 Jan 2024 17:41:00 +0300 Subject: [PATCH 1/2] 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") + } +} From b573544d94672615e749be486d9cf656b4744f6b Mon Sep 17 00:00:00 2001 From: Iamnotagenius Date: Fri, 5 Jan 2024 18:17:56 +0300 Subject: [PATCH 2/2] feat(contract): add README with config --- contract/README.md | 7 +++++++ contract/config.yml | 5 +++++ 2 files changed, 12 insertions(+) create mode 100644 contract/README.md create mode 100644 contract/config.yml diff --git a/contract/README.md b/contract/README.md new file mode 100644 index 0000000..b675468 --- /dev/null +++ b/contract/README.md @@ -0,0 +1,7 @@ +## Как скомпилить +`neo-go contract compile -i passtorage.go -c config.yml -m manifest.json` + +## Как сгенерить обёртку +`neo-go contract generate-rpcwrapper -m manifest.json -o wrapper.go` +Можно добавить хеш скрипта через `--hash HASH` +Потом можете поместить `wrapper.go` в свой проект и использовать его. diff --git a/contract/config.yml b/contract/config.yml new file mode 100644 index 0000000..f57464b --- /dev/null +++ b/contract/config.yml @@ -0,0 +1,5 @@ +name: "Password storage" +sourceurl: https://git.frostfs.info/Web3N3/neowolves +safemethods: ["checkUser"] +supportedstandards: [] +events: []