Compare commits
45 commits
new_backen
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
51a2940e53 | ||
06e281c1a8 | |||
90aa236efb | |||
867e7fdc9e | |||
78d398b0be | |||
ecc94cace6 | |||
d5126a94e4 | |||
956395df8a | |||
d09455e06f | |||
d89fc3b31f | |||
720eb16d72 | |||
ef2b1ec82c | |||
9968be4cd9 | |||
674c1bf358 | |||
efc1d5eafe | |||
|
11cfa20533 | ||
|
5abd38c4e6 | ||
46c6e5c2ae | |||
9aa04d2d19 | |||
|
5a6cd4bbb8 | ||
|
0b7874e00e | ||
9f016ed9ab | |||
3b3191bfb9 | |||
259f1aa1e5 | |||
|
accc23b6b3 | ||
6f0d12dec1 | |||
|
4858338a04 | ||
a08d9ebc61 | |||
0e16887aab | |||
|
792708dd07 | ||
e97733fa6f | |||
8d90e22772 | |||
892f607cd0 | |||
125cb1ad63 | |||
547efeb914 | |||
80f57e3327 | |||
cb81ed0aea | |||
d62a6daa4f | |||
|
1b152f2b77 | ||
e334c3fb9d | |||
d1d6b51c80 | |||
974a9c9be6 | |||
1c7d169c21 | |||
8224f25c18 | |||
22b871e07e |
10 changed files with 878 additions and 169 deletions
489
.gitignore
vendored
489
.gitignore
vendored
|
@ -21,3 +21,492 @@
|
||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/rider
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=rider
|
||||||
|
|
||||||
|
### Rider ###
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# AWS User-specific
|
||||||
|
.idea/**/aws.xml
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/artifacts
|
||||||
|
# .idea/compiler.xml
|
||||||
|
# .idea/jarRepositories.xml
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
# *.iml
|
||||||
|
# *.ipr
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# SonarLint plugin
|
||||||
|
.idea/sonarlint/
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/rider
|
||||||
|
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/visualstudio
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio
|
||||||
|
|
||||||
|
### VisualStudio ###
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.tlog
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
|
||||||
|
*.vbp
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
|
||||||
|
*.dsw
|
||||||
|
*.dsp
|
||||||
|
|
||||||
|
# Visual Studio 6 technical files
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# Visual Studio History (VSHistory) files
|
||||||
|
.vshistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
# VS Code files for those working on multiple tools
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
*.code-workspace
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Windows Installer files from build outputs
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
### VisualStudio Patch ###
|
||||||
|
# Additional files built by Visual Studio
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/visualstudio
|
||||||
|
|
|
@ -1,69 +1,85 @@
|
||||||
package Comment
|
package Comment
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/oracle"
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Comment struct {
|
type Comment struct {
|
||||||
id string
|
id string
|
||||||
authorId string
|
userLogin string
|
||||||
postId string
|
postId string
|
||||||
text string
|
text string
|
||||||
likes int
|
likes int
|
||||||
dislikes int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateNewComment(authorId string, postId string, text string) {
|
const (
|
||||||
|
comment_prefix = "comment_"
|
||||||
|
user_comment_count_prefix = "comment_count_"
|
||||||
|
gas_decimals = 1_0000_0000
|
||||||
|
comment_hash = "comment_hash"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _deploy(data interface{}, isUpdate bool) {
|
||||||
|
if isUpdate {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
storage.Put(ctx, "index_comment", "0")
|
||||||
|
}
|
||||||
|
|
||||||
|
func CreateNewComment(userLogin string, postId string, text string) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
|
id := std.Atoi10(storage.Get(ctx, "index_comment").(string))
|
||||||
|
id++
|
||||||
|
storage.Put(ctx, "index_comment", std.Itoa10(id))
|
||||||
|
|
||||||
|
if storage.Get(ctx, user_comment_count_prefix+userLogin) == nil {
|
||||||
|
storage.Put(ctx, user_comment_count_prefix+userLogin, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
commentId := comment_prefix + std.Itoa10(id)
|
||||||
newComment := Comment{
|
newComment := Comment{
|
||||||
id: "none",
|
id: commentId,
|
||||||
authorId: authorId,
|
userLogin: userLogin,
|
||||||
postId: postId,
|
postId: postId,
|
||||||
text: text,
|
text: text,
|
||||||
likes: 0,
|
likes: 0,
|
||||||
dislikes: 0,
|
|
||||||
}
|
}
|
||||||
|
var comments = make([]Comment, 0)
|
||||||
storeURL := "https://www.uuidgenerator.net/api/version7"
|
comments = GetByPostId(postId)
|
||||||
oracle.Request(storeURL, nil, "cbGetUUID", nil, oracle.MinimumResponseGas)
|
|
||||||
|
|
||||||
newComment.id = storage.Get(ctx, "lastCommentId").(string)
|
|
||||||
|
|
||||||
comments := GetByPostId(postId)
|
|
||||||
comments = append(comments, newComment)
|
comments = append(comments, newComment)
|
||||||
storage.Put(ctx, postId+"_comment", std.Serialize(comments))
|
storage.Put(ctx, comment_prefix+postId, std.Serialize(comments)) // { "comment_post_{i} : comments.json"}
|
||||||
}
|
storage.Put(ctx, commentId, std.Serialize(newComment)) // { "comment_{i}" : comment.json}
|
||||||
|
|
||||||
func cbGetUUID(url string, commentData any, code int, result []byte) {
|
commentCount := storage.Get(ctx, user_comment_count_prefix+userLogin).(int)
|
||||||
callingHash := runtime.GetCallingScriptHash()
|
commentCount++
|
||||||
if !callingHash.Equals(oracle.Hash) {
|
storage.Put(ctx, user_comment_count_prefix+userLogin, commentCount) // { "comment_count_{login}" : {i} }
|
||||||
panic("not called from the oracle contract")
|
storage.Put(ctx, userLogin+"_c_"+std.Itoa10(commentCount), commentId) // { "{login}_c_{i} : comment_{i} }
|
||||||
}
|
|
||||||
if code != oracle.Success {
|
|
||||||
panic("request failed for " + url + " with code " + std.Itoa(code, 10))
|
|
||||||
}
|
|
||||||
runtime.Log("result for " + url + " is: " + string(result))
|
|
||||||
|
|
||||||
runtime.Log("Last Comment id is: " + string(result))
|
runtime.Log("Comment created: " + commentId + " ----- " + user_comment_count_prefix + userLogin + " ------ " + userLogin + "_c_" + std.Itoa10(commentCount))
|
||||||
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
storage.Put(ctx, "lastCommentId", string(result))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetByPostId(postId string) []Comment {
|
func GetByPostId(postId string) []Comment {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
return std.Deserialize(storage.Get(ctx, postId+"_comment").([]byte)).([]Comment)
|
comments := storage.Get(ctx, comment_prefix+postId)
|
||||||
|
if comments == nil {
|
||||||
|
storage.Put(ctx, comment_prefix+postId, std.Serialize(make([]Comment, 0)))
|
||||||
|
}
|
||||||
|
return std.Deserialize(storage.Get(ctx, comment_prefix+postId).([]byte)).([]Comment)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetByAuthorId(postId string, authorId string) []Comment {
|
func GetByLoginInPost(postId string, login string) []Comment {
|
||||||
comments := GetByPostId(postId)
|
comments := GetByPostId(postId)
|
||||||
var commentsByAuthor []Comment
|
var commentsByAuthor []Comment
|
||||||
for _, comment := range comments {
|
for _, comment := range comments {
|
||||||
if comment.authorId == authorId {
|
if comment.userLogin == login {
|
||||||
commentsByAuthor = append(commentsByAuthor, comment)
|
commentsByAuthor = append(commentsByAuthor, comment)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,36 +87,53 @@ func GetByAuthorId(postId string, authorId string) []Comment {
|
||||||
return commentsByAuthor
|
return commentsByAuthor
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetComment(commentId string, postId string) Comment {
|
func GetByLogin(login string) []Comment {
|
||||||
comments := GetByPostId(postId)
|
var comments []Comment = make([]Comment, 0)
|
||||||
for _, comment := range comments {
|
|
||||||
if comment.id == commentId {
|
|
||||||
return comment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
panic("Коммента с таким айдишником нету")
|
|
||||||
}
|
|
||||||
|
|
||||||
func RateComment(isLike bool, postId string, commentId string) {
|
|
||||||
comment := GetComment(commentId, postId)
|
|
||||||
if isLike {
|
|
||||||
comment.likes++
|
|
||||||
} else {
|
|
||||||
comment.dislikes++
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateComment(comment, postId)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateComment(comment Comment, postId string) {
|
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
comments := GetByPostId(postId)
|
it := storage.Find(ctx, login+"_c_", storage.ValuesOnly|storage.DeserializeValues)
|
||||||
|
for iterator.Next(it) {
|
||||||
|
commentId := iterator.Value(it).(string)
|
||||||
|
comments = append(comments, GetComment(commentId))
|
||||||
|
}
|
||||||
|
|
||||||
|
return comments
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetComment(commentId string) Comment {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
comment := storage.Get(ctx, commentId)
|
||||||
|
if comment == nil {
|
||||||
|
panic("comment not found")
|
||||||
|
}
|
||||||
|
return std.Deserialize(comment.([]byte)).(Comment)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Rate(commentId string, walletHashFrom interop.Hash160) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
comment := GetComment(commentId)
|
||||||
|
success := gas.Transfer(walletHashFrom, storage.Get(ctx, comment.userLogin+"_hash").(interop.Hash160), gas_decimals, nil)
|
||||||
|
if !success {
|
||||||
|
panic("gas transfer failed")
|
||||||
|
} else {
|
||||||
|
comment.likes += 1
|
||||||
|
updateComment(comment)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateComment(comment Comment) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
comments := GetByPostId(comment.postId)
|
||||||
for i := 0; i < len(comments); i++ {
|
for i := 0; i < len(comments); i++ {
|
||||||
if comments[i].id == comment.id {
|
if comments[i].id == comment.id {
|
||||||
comments[i] = comment
|
comments[i] = comment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
storage.Put(ctx, postId+"_comment", std.Serialize(comments))
|
storage.Put(ctx, comment_prefix+comment.postId, std.Serialize(comments))
|
||||||
|
storage.Put(ctx, comment.id, std.Serialize(comment))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetContractHash() interop.Hash160 {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
return storage.Get(ctx, comment_hash).(interop.Hash160)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package Forums
|
|
||||||
|
|
||||||
type Forum struct {
|
|
||||||
threads []string
|
|
||||||
}
|
|
|
@ -1,7 +1,9 @@
|
||||||
package Post
|
package Post
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/oracle"
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/iterator"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/gas"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
|
@ -9,69 +11,51 @@ import (
|
||||||
|
|
||||||
type Post struct {
|
type Post struct {
|
||||||
postName string
|
postName string
|
||||||
header string
|
|
||||||
text string
|
text string
|
||||||
authorId string
|
login string
|
||||||
category string
|
|
||||||
likes int
|
likes int
|
||||||
dislikes int
|
|
||||||
id string
|
id string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
lastIndex = "_lastIndex"
|
lastIndex = "user_post_index"
|
||||||
all_posts_key = "all_posts"
|
id = "current_post_id"
|
||||||
|
comment_prefix = "comment_"
|
||||||
|
gas_decimals = 1_0000_0000
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewPost(authorId string, text string, postName string) {
|
func NewPost(login string, text string, postName string) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
updatePostId()
|
||||||
|
id := storage.Get(ctx, id).(int)
|
||||||
|
post_id := "post_" + std.Itoa10(id)
|
||||||
|
|
||||||
post := Post{
|
post := Post{
|
||||||
text: text,
|
text: text,
|
||||||
authorId: authorId,
|
login: login,
|
||||||
dislikes: 0,
|
|
||||||
likes: 0,
|
likes: 0,
|
||||||
category: "none",
|
|
||||||
postName: postName,
|
postName: postName,
|
||||||
id: "none",
|
id: post_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
storeURL := "https://www.uuidgenerator.net/api/version7"
|
|
||||||
oracle.Request(storeURL, nil, "cbGetUUID", nil, oracle.MinimumResponseGas)
|
|
||||||
post.id = storage.Get(ctx, "lastPostId").(string)
|
|
||||||
|
|
||||||
storage.Put(ctx, post.id, std.Serialize(post))
|
storage.Put(ctx, post.id, std.Serialize(post))
|
||||||
|
|
||||||
updatePostIndex(authorId)
|
updatePostIndex(login)
|
||||||
lastPostIndex := storage.Get(ctx, authorId+lastIndex).(string)
|
lastPostIndex := storage.Get(ctx, login+lastIndex).(int)
|
||||||
|
storage.Put(ctx, login+"_p_"+std.Itoa10(lastPostIndex), post.id)
|
||||||
storage.Put(ctx, authorId+lastPostIndex, post.id)
|
runtime.Log("Post created. Post id: " + post.id + "; User post id" + login + "_p_" + std.Itoa10(lastPostIndex))
|
||||||
}
|
|
||||||
|
|
||||||
func CbGetUUID(url string, postData any, code int, result []byte) {
|
|
||||||
callingHash := runtime.GetCallingScriptHash()
|
|
||||||
if !callingHash.Equals(oracle.Hash) {
|
|
||||||
panic("not called from the oracle contract")
|
|
||||||
}
|
|
||||||
if code != oracle.Success {
|
|
||||||
panic("request failed for " + url + " with code " + std.Itoa10(code))
|
|
||||||
}
|
|
||||||
runtime.Log("result for " + url + " is: " + string(result))
|
|
||||||
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
storage.Put(ctx, "lastPostId", string(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
func appendPostToAllPosts(post Post) {
|
|
||||||
ctx := storage.GetContext()
|
|
||||||
all_posts := GetAllPosts()
|
|
||||||
posts := append(all_posts, post)
|
|
||||||
storage.Put(ctx, all_posts_key, posts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllPosts() []Post {
|
func GetAllPosts() []Post {
|
||||||
ctx := storage.GetContext()
|
posts := make([]Post, 0)
|
||||||
posts := std.Deserialize(storage.Get(ctx, all_posts_key).([]byte)).([]Post)
|
ctx := storage.GetReadOnlyContext()
|
||||||
|
it := storage.Find(ctx, "post", storage.ValuesOnly|storage.DeserializeValues)
|
||||||
|
for iterator.Next(it) {
|
||||||
|
post := iterator.Value(it).(Post)
|
||||||
|
runtime.Log(string(std.Serialize(post)))
|
||||||
|
posts = append(posts, post)
|
||||||
|
}
|
||||||
|
|
||||||
return posts
|
return posts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,33 +70,48 @@ func GetPost(postId string) Post {
|
||||||
return std.Deserialize(data.([]byte)).(Post)
|
return std.Deserialize(data.([]byte)).(Post)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllPostsByUser(userId string) []Post {
|
func GetAllPostsByUser(login string) []Post {
|
||||||
ctx := storage.GetReadOnlyContext()
|
ctx := storage.GetReadOnlyContext()
|
||||||
var postsByUser []Post
|
var postsByUser []Post = make([]Post, 0)
|
||||||
i := 0
|
i := 1
|
||||||
n := getPostIndex(userId)
|
n := getPostIndex(login)
|
||||||
for i < n {
|
for i < n+1 {
|
||||||
post := storage.Get(ctx, userId+std.Itoa10(i))
|
post_key := storage.Get(ctx, login+"_p_"+std.Itoa10(i))
|
||||||
|
if post_key == nil {
|
||||||
|
panic("post key not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
post_key = post_key.(string)
|
||||||
|
|
||||||
|
post := storage.Get(ctx, post_key)
|
||||||
|
if post == nil {
|
||||||
|
panic("post not found")
|
||||||
|
}
|
||||||
|
|
||||||
i++
|
i++
|
||||||
postsByUser = append(postsByUser, std.Deserialize(post.([]byte)).(Post))
|
postsByUser = append(postsByUser, std.Deserialize(post.([]byte)).(Post))
|
||||||
}
|
}
|
||||||
return postsByUser
|
return postsByUser
|
||||||
}
|
}
|
||||||
|
|
||||||
func RatePost(isLike bool, postId string) {
|
func Rate(postId string, walletHashFrom interop.Hash160) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
post := GetPost(postId)
|
post := GetPost(postId)
|
||||||
if isLike {
|
success := gas.Transfer(walletHashFrom, storage.Get(ctx, post.login+"_hash").(interop.Hash160), gas_decimals, nil)
|
||||||
post.likes++
|
if !success {
|
||||||
|
panic("gas transfer failed")
|
||||||
} else {
|
} else {
|
||||||
post.dislikes++
|
post.likes += 1
|
||||||
|
storage.Put(ctx, post.id, std.Serialize(post))
|
||||||
}
|
}
|
||||||
storage.Put(ctx, post.id, std.Serialize(post))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPostIndex(userId string) int {
|
func getPostIndex(userId string) int {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
index := storage.Get(ctx, userId+lastIndex)
|
index := storage.Get(ctx, userId+lastIndex)
|
||||||
|
if index == nil {
|
||||||
|
index = 0
|
||||||
|
}
|
||||||
return index.(int)
|
return index.(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,3 +120,18 @@ func updatePostIndex(userId string) {
|
||||||
index := getPostIndex(userId)
|
index := getPostIndex(userId)
|
||||||
storage.Put(ctx, userId+lastIndex, index+1)
|
storage.Put(ctx, userId+lastIndex, index+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPostId() int {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
current_id := storage.Get(ctx, id)
|
||||||
|
if current_id == nil {
|
||||||
|
current_id = 0
|
||||||
|
}
|
||||||
|
return current_id.(int)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updatePostId() {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
cur_id := getPostId()
|
||||||
|
storage.Put(ctx, id, cur_id+1)
|
||||||
|
}
|
||||||
|
|
16
User/user.go
Executable file → Normal file
16
User/user.go
Executable file → Normal file
|
@ -2,6 +2,7 @@ package Users
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop"
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/interop/contract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
"github.com/nspcc-dev/neo-go/pkg/interop/native/std"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/interop/runtime"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
"github.com/nspcc-dev/neo-go/pkg/interop/storage"
|
||||||
|
@ -21,7 +22,6 @@ const (
|
||||||
|
|
||||||
func NewUser(name string, surname string, login string, password string, owner interop.Hash160) {
|
func NewUser(name string, surname string, login string, password string, owner interop.Hash160) {
|
||||||
ctx := storage.GetContext()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
existing_login := storage.Get(ctx, login)
|
existing_login := storage.Get(ctx, login)
|
||||||
if existing_login != nil {
|
if existing_login != nil {
|
||||||
panic("this login is taken by someone else")
|
panic("this login is taken by someone else")
|
||||||
|
@ -36,9 +36,19 @@ func NewUser(name string, surname string, login string, password string, owner i
|
||||||
}
|
}
|
||||||
|
|
||||||
saveUser(ctx, login, user)
|
saveUser(ctx, login, user)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUser(ctx storage.Context, login string) User {
|
func GetUser(login string) User {
|
||||||
|
return getUserTst(storage.GetReadOnlyContext(), login)
|
||||||
|
}
|
||||||
|
|
||||||
|
func RateForGas(commentId string, contractHash interop.Hash160, login string) {
|
||||||
|
ctx := storage.GetContext()
|
||||||
|
contract.Call(contractHash, "rate", contract.ReadOnly, commentId, storage.Get(ctx, login+"_hash"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUserTst(ctx storage.Context, login string) User {
|
||||||
data := storage.Get(ctx, login)
|
data := storage.Get(ctx, login)
|
||||||
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
|
@ -51,6 +61,6 @@ func GetUser(ctx storage.Context, login string) User {
|
||||||
func saveUser(ctx storage.Context, userLogin string, user User) {
|
func saveUser(ctx storage.Context, userLogin string, user User) {
|
||||||
runtime.Log("User " + userLogin + " was created")
|
runtime.Log("User " + userLogin + " was created")
|
||||||
|
|
||||||
storage.Put(ctx, userLogin+lastIndex, -1)
|
storage.Put(ctx, userLogin+"_hash", user.ownerHash)
|
||||||
storage.Put(ctx, userLogin, std.Serialize(user))
|
storage.Put(ctx, userLogin, std.Serialize(user))
|
||||||
}
|
}
|
||||||
|
|
0
User/user.yml
Executable file → Normal file
0
User/user.yml
Executable file → Normal file
|
@ -2,60 +2,213 @@ import http.server
|
||||||
import socketserver
|
import socketserver
|
||||||
import subprocess
|
import subprocess
|
||||||
from urllib.parse import urlparse, parse_qs
|
from urllib.parse import urlparse, parse_qs
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def compile_and_deploy_contract(
|
||||||
|
user_path: str,
|
||||||
|
post_path: str,
|
||||||
|
comment_path: str,
|
||||||
|
password: str,
|
||||||
|
node_wallet: str,
|
||||||
|
run_start_funcs: bool=False
|
||||||
|
) -> dict[str, str]:
|
||||||
|
|
||||||
|
user_compile_command = f"sshpass -p {password} neo-go contract compile -i {user_path}/user.go -c {user_path}/user.yml -m {user_path}/user.json"
|
||||||
|
subprocess.run(user_compile_command, shell=True, check=False)
|
||||||
|
user_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {user_path}/user.nef -w {node_wallet} -r http://localhost:30333 -m {user_path}/user.json --force"
|
||||||
|
proc = subprocess.Popen(user_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
user_out_list = []
|
||||||
|
while True:
|
||||||
|
line = proc.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
user_out_list.append(line.rstrip())
|
||||||
|
|
||||||
|
user_hash = str(user_out_list[-1], encoding='utf-8').replace("Contract: ", "")
|
||||||
|
|
||||||
|
post_compile_command = f"sshpass -p {password} neo-go contract compile -i {post_path}/post_contract.go -c {post_path}/post_contract.yml -m {post_path}/post_contract.json"
|
||||||
|
subprocess.run(post_compile_command, shell=True, check=False)
|
||||||
|
post_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {post_path}/post_contract.nef -w {node_wallet} -r http://localhost:30333 -m {post_path}/post_contract.json --force"
|
||||||
|
proc = subprocess.Popen(post_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
post_out_list = []
|
||||||
|
while True:
|
||||||
|
line = proc.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
post_out_list.append(line.rstrip())
|
||||||
|
|
||||||
|
post_hash = str(post_out_list[-1], encoding='utf-8').replace("Contract: ", "")
|
||||||
|
|
||||||
|
comment_compile_command = f"sshpass -p {password} neo-go contract compile -i {comment_path}/comment.go -c {comment_path}/comment.yml -m {comment_path}/comment.json"
|
||||||
|
subprocess.run(comment_compile_command, shell=True, check=False)
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract deploy -i {comment_path}/comment.nef -w {node_wallet} -r http://localhost:30333 -m {comment_path}/comment.json --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_out_list = []
|
||||||
|
while True:
|
||||||
|
line = proc.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
comment_out_list.append(line.rstrip())
|
||||||
|
|
||||||
|
comment_hash = str(comment_out_list[-1], encoding='utf-8').replace("Contract: ", "")
|
||||||
|
|
||||||
|
print(user_hash, post_hash, comment_hash)
|
||||||
|
|
||||||
|
if run_start_funcs:
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {user_hash} newUser user_test1 user_test1 user_test1 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {user_hash} newUser user_test2 user_test2 user_test2 1 Nhfg3TbpwogLvDGVvAvqyThbsHgoSUKwtn --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {post_hash} newPost user_test1 test test --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {post_hash} newPost user_test2 test test --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test1 post_1 some_text --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test1 post_1 some_text --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
comment_deploy_command = f"sshpass -p {password} neo-go contract invokefunction -w {node_wallet} -r http://localhost:30333 {comment_hash} createNewComment user_test2 post_1 some_text --force"
|
||||||
|
proc = subprocess.Popen(comment_deploy_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
return user_hash, post_hash, comment_hash
|
||||||
|
|
||||||
|
|
||||||
|
user_hash, post_hash, comment_hash = compile_and_deploy_contract(
|
||||||
|
"../User",
|
||||||
|
"../Post",
|
||||||
|
"../Comment",
|
||||||
|
"one",
|
||||||
|
"/home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json",
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
|
|
||||||
|
with open("./route.json", "r") as f:
|
||||||
|
route_dict = json.load(f)
|
||||||
|
|
||||||
|
with open("logs.log", "w") as f:
|
||||||
|
f.write("starting...")
|
||||||
|
|
||||||
|
with open("logs.log", "a") as f:
|
||||||
|
f.write(f"user_hash: {user_hash}\npost_hash: {post_hash}\ncomment_hash: {comment_hash}")
|
||||||
|
|
||||||
parsed_path = urlparse(self.path)
|
parsed_path = urlparse(self.path)
|
||||||
query = parse_qs(parsed_path.query)
|
query = parse_qs(parsed_path.query)
|
||||||
print(query)
|
|
||||||
|
|
||||||
if 'command' in query and 'args' in query:
|
if "command_type" in query and "command_id" in query:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-type', 'text/html')
|
self.send_header("Content-type", "text/html")
|
||||||
|
self.send_header("Access-Control-Allow-Origin", "*")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(bytes(f"command: {query['command']}, args: {query['args']}", "utf-8"))
|
|
||||||
|
params = query.get("args", None)
|
||||||
|
parsed_params = " " + ' '.join(params) if params else ""
|
||||||
|
|
||||||
|
command_type = query["command_type"][0]
|
||||||
|
contract_name = query["contract"][0]
|
||||||
|
method = query["method"][0]
|
||||||
|
|
||||||
|
with open("logs.log", "a") as f:
|
||||||
|
f.write("reading params...\n")
|
||||||
|
|
||||||
|
if command_type == "get":
|
||||||
|
hash_for_req = None
|
||||||
|
if contract_name == "post":
|
||||||
|
hash_for_req = post_hash
|
||||||
|
elif contract_name == "user":
|
||||||
|
hash_for_req = user_hash
|
||||||
|
elif contract_name == "comment":
|
||||||
|
hash_for_req = comment_hash
|
||||||
|
|
||||||
|
with open("logs.log", "a") as f:
|
||||||
|
f.write(f"params: {[command_type, contract_name, method, parsed_params]}\n")
|
||||||
|
|
||||||
|
command = f"neo-go contract testinvokefunction -r http://localhost:30333 {hash_for_req} {method}{parsed_params}"
|
||||||
|
|
||||||
|
print(command)
|
||||||
|
|
||||||
|
proc = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
out_list = []
|
||||||
|
while True:
|
||||||
|
if proc.stdout is None:
|
||||||
|
break
|
||||||
|
|
||||||
|
line = proc.stdout.readline()
|
||||||
|
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
out_list.append(line.rstrip())
|
||||||
|
|
||||||
|
answer = " ".join(map(lambda x: x.decode("utf-8"), out_list))
|
||||||
|
answer = re.sub(r"[\n\t\s]*", "", answer)
|
||||||
|
|
||||||
|
print(json.loads(answer)["stack"][0])
|
||||||
|
|
||||||
|
if json.loads(answer)["stack"][0]["type"] == "Struct":
|
||||||
|
answer_dict = json.loads(answer)["stack"][0]["value"]
|
||||||
|
obj_fiedls = []
|
||||||
|
for field in answer_dict:
|
||||||
|
if field["type"] in ["ByteString", "Buffer"]:
|
||||||
|
encoded_string = field["value"]
|
||||||
|
result_string = base64.b64decode(encoded_string)
|
||||||
|
try:
|
||||||
|
result_string = result_string.decode('utf-8')
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
obj_fiedls.append(result_string)
|
||||||
|
elif field["type"] == "Integer":
|
||||||
|
encoded_string = field["value"]
|
||||||
|
obj_fiedls.append(encoded_string)
|
||||||
|
|
||||||
|
self.wfile.write(bytes(f"{obj_fiedls}", "utf-8"))
|
||||||
|
else:
|
||||||
|
answer_dict = json.loads(answer)["stack"][0]["value"]
|
||||||
|
answer_list = []
|
||||||
|
for obj_i in answer_dict:
|
||||||
|
obj = obj_i["value"]
|
||||||
|
obj_fiedls = []
|
||||||
|
for field in obj:
|
||||||
|
if field["type"] in ["ByteString", "Buffer"]:
|
||||||
|
encoded_string = field["value"]
|
||||||
|
result_string = base64.b64decode(encoded_string)
|
||||||
|
result_string = result_string.decode('utf-8')
|
||||||
|
obj_fiedls.append(result_string)
|
||||||
|
elif field["type"] == "Integer":
|
||||||
|
encoded_string = field["value"]
|
||||||
|
obj_fiedls.append(encoded_string)
|
||||||
|
|
||||||
|
answer_list.append(obj_fiedls)
|
||||||
|
|
||||||
|
self.wfile.write(bytes(f"{answer_list}", "utf-8"))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.send_response(400)
|
self.send_response(400)
|
||||||
self.send_header('Content-type', 'text/html')
|
self.send_header("Content-type", "text/html")
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
self.wfile.write(bytes("Bad request", "utf-8"))
|
self.wfile.write(bytes("Bad request", "utf-8"))
|
||||||
|
|
||||||
PORT = 2281
|
|
||||||
Handler = MyHttpRequestHandler
|
|
||||||
|
|
||||||
def compile_and_deploy_contract():
|
|
||||||
password = 'one'
|
|
||||||
# User
|
|
||||||
user_compile_command = "neo-go contract compile -i User/user.go -c User/user.yml -m User/user.json"
|
|
||||||
subprocess.run(user_compile_command, shell=True, check=True)
|
|
||||||
|
|
||||||
user_deploy_command = "neo-go contract deploy -i User/user.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m User/user.json"
|
|
||||||
subprocess.run(user_deploy_command, shell=True, check=True)
|
|
||||||
result_user = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
|
|
||||||
print(result_user)
|
|
||||||
|
|
||||||
# Post
|
|
||||||
post_compile_command = "neo-go contract compile -i Post/post_contract.go -c Post/post_contract.yml -m Post/post_contract.json"
|
|
||||||
subprocess.run(post_compile_command, shell=True, check=True)
|
|
||||||
|
|
||||||
post_deploy_command = "neo-go contract deploy -i Post/post_contract.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Post/post_contract.json"
|
|
||||||
subprocess.run(post_deploy_command, shell=True, check=True)
|
|
||||||
result_post = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
|
|
||||||
print(result_post)
|
|
||||||
|
|
||||||
# Comment
|
|
||||||
comment_compile_command = "neo-go contract compile -i Comment/comment.go -c Comment/comment.yml -m Comment/comment.json"
|
|
||||||
subprocess.run(comment_compile_command, shell=True, check=True)
|
|
||||||
|
|
||||||
comment_deploy_command = "neo-go contract deploy -i Comment/comment.nef -w /home/ftmi-krasotka/Desktop/frostfs_test/frostfs-aio/morph/node-wallet.json -r http://localhost:30333 -m Comment/comment.json"
|
|
||||||
subprocess.run(comment_deploy_command, shell=True, check=True)
|
|
||||||
result_comment = subprocess.check_output(password, shell=True, text=True).stdout[-40:]
|
|
||||||
print(result_comment)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
compile_and_deploy_contract()
|
PORT = 2281
|
||||||
|
Handler = MyHttpRequestHandler
|
||||||
|
|
||||||
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
||||||
print("Сервер запущен на порту", PORT)
|
print("Сервер запущен на порту", PORT)
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
httpd.server_close()
|
httpd.server_close()
|
||||||
|
|
|
@ -55,6 +55,14 @@ route = {
|
||||||
"func_name": "name of invoked func",
|
"func_name": "name of invoked func",
|
||||||
"parameters": "list([]) of func parameters"
|
"parameters": "list([]) of func parameters"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"8": {
|
||||||
|
"command": "neo-go contract testinvokefunction",
|
||||||
|
"flags": {
|
||||||
|
"contract_hash": "hash of contract",
|
||||||
|
"func_name": "name of invoked func",
|
||||||
|
"parameters": "list([]) of func parameters"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
# Отправляем GET запрос на сервер
|
# Отправляем GET запрос на сервер
|
||||||
response = requests.get('http://localhost:2281', params={"command": 0, "args": {"amount_1": 1, "amount": 1}})
|
response = requests.get(
|
||||||
|
'http://localhost:2281',
|
||||||
|
params={
|
||||||
|
"command_type": "get",
|
||||||
|
"method": "getPost",
|
||||||
|
"command_id": "8",
|
||||||
|
"contract": "post",
|
||||||
|
"args": ["post_1"]})
|
||||||
|
|
||||||
# Выводим ответ от сервера
|
# Выводим ответ от сервера
|
||||||
print('Ответ от сервера:', response.text)
|
print('Ответ от сервера:', response.text)
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"1": {"command": "neo-go wallet init", "flags": {"wallet": "wallet file name", "account": "create new account"}}, "2": {"command": "neo-go wallet dump-keys", "flags": {"wallet": "wallet file name"}}, "3": {"command": "neo-go wallet nep17 balance", "flags": {"wallet": "wallet file name"}}, "4": {"command": "neo-go wallet nep17 transfer", "flags": {"wallet": "wallet file name(wallet from which transfer is made)", "from": "hash of wallet from which transfer is made", "to": "hash of wallet to which transfer is made", "amount": "gas transfer amount", "token": "token for transfer NEO/GAS"}}, "5": {"command": "neo-go contract compile", "flags": {"in": "smart contract file name(*.go)", "manifest": "contract manifest file name(*.json)", "contract_config": "contract config file name(*.yml)"}}, "6": {"command": "neo-go contract deploy", "flags": {"wallet": "wallet file name", "in": "compiled smart contract file name(*.nef)", "manifest": "manifest file name(*.json)"}}, "7": {"command": "neo-go contract invokefunction", "flags": {"wallet": "wallet file name", "contract_hash": "hash of contract", "func_name": "name of invoked func", "parameters": "list([]) of func parameters"}}}
|
{"1": {"command": "neo-go wallet init", "flags": {"wallet": "wallet file name", "account": "create new account"}}, "2": {"command": "neo-go wallet dump-keys", "flags": {"wallet": "wallet file name"}}, "3": {"command": "neo-go wallet nep17 balance", "flags": {"wallet": "wallet file name"}}, "4": {"command": "neo-go wallet nep17 transfer", "flags": {"wallet": "wallet file name(wallet from which transfer is made)", "from": "hash of wallet from which transfer is made", "to": "hash of wallet to which transfer is made", "amount": "gas transfer amount", "token": "token for transfer NEO/GAS"}}, "5": {"command": "neo-go contract compile", "flags": {"in": "smart contract file name(*.go)", "manifest": "contract manifest file name(*.json)", "contract_config": "contract config file name(*.yml)"}}, "6": {"command": "neo-go contract deploy", "flags": {"wallet": "wallet file name", "in": "compiled smart contract file name(*.nef)", "manifest": "manifest file name(*.json)"}}, "7": {"command": "neo-go contract invokefunction", "flags": {"wallet": "wallet file name", "contract_hash": "hash of contract", "func_name": "name of invoked func", "parameters": "list([]) of func parameters"}}, "8": {"command": "neo-go contract testinvokefunction", "flags": {"contract_hash": "hash of contract", "func_name": "name of invoked func", "parameters": "list([]) of func parameters"}}}
|
Loading…
Add table
Reference in a new issue