From 466b34b5bdc5a3e464d01b106aa9a2ee36469bb3 Mon Sep 17 00:00:00 2001 From: Darp Alakun Date: Sat, 4 Jan 2025 19:26:18 -0500 Subject: [PATCH] test: update tests to reflect hway changes --- .goreleaser.yaml | 94 +---- Makefile | 281 +------------ app/{routes.go => app.go} | 10 +- cmd/cmds.go | 2 +- cmd/main.go | 2 +- go.mod | 2 +- go.sum | 4 +- handlers/errors.go | 2 +- handlers/index.go | 2 +- handlers/register.go | 10 +- internal/config/Hway.pkl.go | 103 +++++ internal/config/init.pkl.go | 8 + internal/models/db.go | 31 ++ internal/models/models.go | 99 +++++ internal/models/querier.go | 34 ++ internal/models/query.sql.go | 581 +++++++++++++++++++++++++++ internal/sink/highway/query.sql | 151 ------- internal/sink/highway/schema.sql | 122 ------ internal/sink/{vault => }/query.sql | 0 internal/sink/{vault => }/schema.sql | 0 internal/sink/sink.go | 2 +- internal/sqlc.yaml | 23 +- pkg/common/chain_query.go | 6 +- pkg/common/ucan_store.go | 4 +- pkg/context/middleware.go | 8 +- pkg/context/profiles.go | 2 +- pkg/context/renderer.go | 2 +- pkg/context/resolver.go | 2 +- pkg/context/sessions.go | 2 +- pkg/context/types.go | 2 +- pkg/context/vaults.go | 4 +- pkg/views/base_hero.templ | 2 +- pkg/views/base_hero_templ.go | 2 +- pkg/views/view_register.templ | 2 +- pkg/views/view_register_templ.go | 2 +- pkl/App.pkl | 16 + 36 files changed, 928 insertions(+), 691 deletions(-) rename app/{routes.go => app.go} (76%) create mode 100644 internal/config/Hway.pkl.go create mode 100644 internal/config/init.pkl.go create mode 100644 internal/models/db.go create mode 100644 internal/models/models.go create mode 100644 internal/models/querier.go create mode 100644 internal/models/query.sql.go delete mode 100644 internal/sink/highway/query.sql delete mode 100644 internal/sink/highway/schema.sql rename internal/sink/{vault => }/query.sql (100%) rename internal/sink/{vault => }/schema.sql (100%) create mode 100644 pkl/App.pkl diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 1b59cd8..3a99e79 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -3,41 +3,8 @@ version: 2 project_name: sonr builds: - - id: motr - main: ./cmd/motr - binary: app - goos: - - js - goarch: - - wasm - - - id: sonr - main: ./cmd/sonrd - binary: sonrd - mod_timestamp: "{{ .CommitTimestamp }}" - goos: - - linux - - darwin - goarch: - - amd64 - - arm64 - goamd64: - - v1 - flags: - - -mod=readonly - - -trimpath - ldflags: - - -X github.com/cosmos/cosmos-sdk/version.Name=sonr - - -X github.com/cosmos/cosmos-sdk/version.AppName=sonrd - - -X github.com/cosmos/cosmos-sdk/version.Version={{.Version}} - - -X github.com/cosmos/cosmos-sdk/version.Commit={{.Commit}} - - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=netgo,ledger" - tags: - - netgo - - ledger - - id: hway - main: ./cmd/hway + main: ./cmd binary: hway goos: - linux @@ -51,24 +18,11 @@ builds: - -trimpath goamd64: - v1 - tags: - - netgo ldflags: - -X main.version={{.Version}} - -X main.commit={{.Commit}} - -X main.date={{.Date}} archives: - - id: sonr - builds: [sonr] - name_template: >- - sonr_{{ .Os }}_{{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - format: tar.gz - files: - - src: README* - wrap_in_directory: true - - id: hway builds: [hway] name_template: >- @@ -103,30 +57,6 @@ nfpms: section: net priority: optional # Add these lines to match build config - - - id: sonr - package_name: sonrd - file_name_template: "sonrd_{{ .Os }}_{{ .Arch }}{{ .ConventionalExtension }}" - builds: [sonr] - vendor: Sonr - homepage: "https://onsonr.dev" - maintainer: "Sonr " - description: "Sonr is a decentralized, permissionless, and censorship-resistant identity network." - license: "Apache 2.0" - formats: - - rpm - - deb - - apk - dependencies: - - ipfs - contents: - - src: README* - dst: /usr/share/doc/sonrd - bindir: /usr/bin - section: net - priority: optional - # Add these lines to match build config - brews: - name: hway ids: [hway] @@ -145,36 +75,16 @@ brews: branch: master token: "{{ .Env.GITHUB_PERSONAL_AUTH_TOKEN }}" - - name: sonr - ids: [sonr] - commit_author: - name: goreleaserbot - email: bot@goreleaser.com - directory: Formula - caveats: "Run a local sonr node and access it with the hway proxy" - homepage: "https://onsonr.dev" - description: "Sonr is a decentralized, permissionless, and censorship-resistant identity network." - dependencies: - - name: ipfs - repository: - owner: onsonr - name: homebrew-tap - branch: master - token: "{{ .Env.GITHUB_PERSONAL_AUTH_TOKEN }}" - release: github: owner: onsonr name: sonr - name_template: 'Release {{ .Env.RELEASE_DATE }}' + name_template: '{{ .Tag }} | {{ .Env.RELEASE_DATE }}' draft: false replace_existing_draft: true replace_existing_artifacts: true extra_files: - glob: ./README* - - glob: ./scripts/install.sh - - glob: ./scripts/test_node.sh - - glob: ./scripts/test_ics_node.sh announce: telegram: diff --git a/Makefile b/Makefile index fe82040..7358b0b 100644 --- a/Makefile +++ b/Makefile @@ -1,114 +1,32 @@ #!/usr/bin/make -f - -PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation') VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//') COMMIT := $(shell git log -1 --format='%H') -LEDGER_ENABLED ?= true -SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') BINDIR ?= $(GOPATH)/bin -SIMAPP = ./app - -PC_PORT_NUM=42069 -PC_LOG_FILE=./sonr.log -PC_SOCKET_PATH=/tmp/sonr-net.sock # for dockerized protobuf tools DOCKER := $(shell which docker) -HTTPS_GIT := github.com/onsonr/sonr.git -PROCESS_COMPOSE := $(shell which process-compose) +HTTPS_GIT := github.com/onsonr/hway.git -export GO111MODULE = on -# process build tags - -build_tags = netgo -ifeq ($(LEDGER_ENABLED),true) - ifeq ($(OS),Windows_NT) - GCCEXE = $(shell where gcc.exe 2> NUL) - ifeq ($(GCCEXE),) - $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - else - UNAME_S = $(shell uname -s) - ifeq ($(UNAME_S),OpenBSD) - $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) - else - GCC = $(shell command -v gcc 2> /dev/null) - ifeq ($(GCC),) - $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - endif - endif -endif - -ifeq ($(WITH_CLEVELDB),yes) - build_tags += gcc -endif -build_tags += $(BUILD_TAGS) -build_tags := $(strip $(build_tags)) - -whitespace := -empty = $(whitespace) $(whitespace) -comma := , -build_tags_comma_sep := $(subst $(empty),$(comma),$(build_tags)) - -# process linker flags -ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sonr \ - -X github.com/cosmos/cosmos-sdk/version.AppName=sonrd \ - -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ - -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" - -ifeq ($(WITH_CLEVELDB),yes) - ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb -endif -ifeq ($(LINK_STATICALLY),true) - ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static" -endif -ldflags += $(LDFLAGS) -ldflags := $(strip $(ldflags)) - -BUILD_FLAGS := -tags "$(build_tags_comma_sep)" -ldflags '$(ldflags)' -trimpath - -# The below include contains the tools and runsim targets. -all: install lint test +all: install test build: go.sum -ifeq ($(OS),Windows_NT) - $(error wasmd server not supported. Use "make build-windows-client" for client) - exit 1 -else - go build -mod=readonly $(BUILD_FLAGS) -o build/sonrd ./cmd/sonrd -endif - -build-motr: go.sum - GOOS=js GOARCH=wasm go build -o static/wasm/app.wasm ./cmd/motr/main.go - -build-hway: go.sum - go build -o build/hway ./cmd/hway - -build-windows-client: go.sum - GOOS=windows GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o build/sonrd.exe ./cmd/sonrd - -build-contract-tests-hooks: -ifeq ($(OS),Windows_NT) - go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests.exe ./cmd/contract_tests -else - go build -mod=readonly $(BUILD_FLAGS) -o build/contract_tests ./cmd/contract_tests -endif + go build -o build/hway ./cmd install: go.sum - go install -mod=readonly $(BUILD_FLAGS) ./cmd/sonrd - -install-hway: go.sum go install -mod=readonly ./cmd/hway ######################################## ### Tools & dependencies +######################################## +pkl-gen: + @go install github.com/apple/pkl-go/cmd/pkl-gen-go@latest + @pkl-gen-go ./pkl/App.pkl + +sqlc-gen: + @go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest + @go install github.com/apple/pkl-go/cmd/pkl-gen-go@latest + @cd internal && sqlc generate go-mod-cache: go.sum @echo "--> Download go modules to local cache" @@ -134,181 +52,6 @@ clean: distclean: clean rm -rf vendor/ -init-env: - @echo "Installing process-compose" - sh scripts/init_env.sh - -######################################## -### Testing - -test: test-unit -test-all: test-race test-cover test-system - -test-unit: - @VERSION=$(VERSION) go test -mod=readonly -tags='ledger test_ledger_mock' ./... - -test-race: - @VERSION=$(VERSION) go test -mod=readonly -race -tags='ledger test_ledger_mock' ./... - -test-cover: - @go test -mod=readonly -timeout 30m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' ./... - -benchmark: - @go test -mod=readonly -bench=. ./... - -test-sim-import-export: runsim - @echo "Running application import/export simulation. This may take several minutes..." - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestAppImportExport - -test-sim-multi-seed-short: runsim - @echo "Running short multi-seed application simulation. This may take awhile!" - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 5 TestFullAppSimulation - -test-sim-deterministic: runsim - @echo "Running application deterministic simulation. This may take awhile!" - @$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 1 1 TestAppStateDeterminism - -test-system: install - $(MAKE) -C tests/system/ test - -############################################################################### -### Linting ### -############################################################################### - -format-tools: - go install mvdan.cc/gofumpt@v0.4.0 - go install github.com/client9/misspell/cmd/misspell@v0.3.4 - go install github.com/daixiang0/gci@v0.11.2 - -lint: format-tools - golangci-lint run --tests=false - find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "*_test.go" | xargs gofumpt -d - -format: format-tools - find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gofumpt -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs misspell -w - find . -name '*.go' -type f -not -path "./vendor*" -not -path "./tests/system/vendor*" -not -path "*.git*" -not -path "./client/lcd/statik/statik.go" | xargs gci write --skip-generated -s standard -s default -s "prefix(cosmossdk.io)" -s "prefix(github.com/cosmos/cosmos-sdk)" -s "prefix(github.com/CosmWasm/wasmd)" --custom-order - -mod-tidy: - go mod tidy - -.PHONY: format-tools lint format mod-tidy - - -############################################################################### -### Protobuf ### -############################################################################### -protoVer=0.15.1 -protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) -protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) - -proto-gen: - @echo "Generating Protobuf files" - @go install cosmossdk.io/orm/cmd/protoc-gen-go-cosmos-orm@latest - @$(protoImage) sh ./scripts/protocgen.sh - spawn stub-gen - -proto-format: - @echo "Formatting Protobuf files" - @$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \; - -proto-lint: - @$(protoImage) buf lint --error-format=json - -proto-check-breaking: - @$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=master - -.PHONY: all install install-debug \ - go-mod-cache draw-deps clean build format \ - test test-all test-build test-cover test-unit test-race \ - test-sim-import-export build-windows-client \ - test-system - -## --- Testnet Utilities --- -get-localic: - @echo "Installing local-interchain" - git clone --branch v8.7.0 https://github.com/strangelove-ventures/interchaintest.git interchaintest-downloader - cd interchaintest-downloader/local-interchain && make install - @echo ✅ local-interchain installed $(shell which local-ic) - -is-localic-installed: -ifeq (,$(shell which local-ic)) - make get-localic -endif - -get-heighliner: - git clone https://github.com/strangelove-ventures/heighliner.git - cd heighliner && go install - -local-image: -ifeq (,$(shell which heighliner)) - echo 'heighliner' binary not found. Consider running `make get-heighliner` -else - heighliner build -c sonrd --local -f chains.yaml -endif - -.PHONY: get-heighliner local-image is-localic-installed - -############################################################################### -### e2e ### -############################################################################### - -ictest-basic: - @echo "Running basic interchain tests" - @cd interchaintest && go test -race -v -run TestBasicChain . - -ictest-ibc: - @echo "Running IBC interchain tests" - @cd interchaintest && go test -race -v -run TestIBC . - -ictest-wasm: - @echo "Running cosmwasm interchain tests" - @cd interchaintest && go test -race -v -run TestCosmWasmIntegration . - -ictest-packetforward: - @echo "Running packet forward middleware interchain tests" - @cd interchaintest && go test -race -v -run TestPacketForwardMiddleware . - -ictest-poa: - @echo "Running proof of authority interchain tests" - @cd interchaintest && go test -race -v -run TestPOA . - -ictest-tokenfactory: - @echo "Running token factory interchain tests" - @cd interchaintest && go test -race -v -run TestTokenFactory . - -############################################################################### -### testnet ### -############################################################################### - -setup-ipfs: - ./scripts/ipfs_config.sh - -setup-testnet: mod-tidy is-localic-installed install local-image set-testnet-configs setup-testnet-keys - -# Run this before testnet keys are added -# chainid-1 is used in the testnet.json -set-testnet-configs: - sonrd config set client chain-id sonr-testnet-1 - sonrd config set client keyring-backend test - sonrd config set client output text - -# import keys from testnet.json into test keyring -setup-testnet-keys: - -`echo "decorate bright ozone fork gallery riot bus exhaust worth way bone indoor calm squirrel merry zero scheme cotton until shop any excess stage laundry" | sonrd keys add acc0 --recover` - -`echo "wealth flavor believe regret funny network recall kiss grape useless pepper cram hint member few certain unveil rather brick bargain curious require crowd raise" | sonrd keys add acc1 --recover` - -# default testnet is with IBC -testnet: setup-testnet - spawn local-ic start ibc-testnet - -testnet-basic: setup-testnet - spawn local-ic start testnet - -sh-testnet: mod-tidy - CHAIN_ID="sonr-testnet-1" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh - -.PHONY: setup-testnet set-testnet-configs testnet testnet-basic sh-testnet dop-testnet ############################################################################### ### help ### diff --git a/app/routes.go b/app/app.go similarity index 76% rename from app/routes.go rename to app/app.go index ddd5ddc..a015865 100644 --- a/app/routes.go +++ b/app/app.go @@ -5,11 +5,11 @@ import ( "github.com/labstack/echo-contrib/echoprometheus" "github.com/labstack/echo/v4" echomiddleware "github.com/labstack/echo/v4/middleware" - "github.com/onsonr/sonr/gateway/context" - "github.com/onsonr/sonr/gateway/handlers" - "github.com/onsonr/sonr/internal/common" - config "github.com/onsonr/sonr/internal/config/hway" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + "github.com/onsonr/hway/gateway/handlers" + config "github.com/onsonr/hway/internal/config/hway" + hwayorm "github.com/onsonr/hway/internal/models" + "github.com/onsonr/hway/pkg/common" + "github.com/onsonr/hway/pkg/context" ) type Gateway = *echo.Echo diff --git a/cmd/cmds.go b/cmd/cmds.go index 1e6c92a..168aed3 100644 --- a/cmd/cmds.go +++ b/cmd/cmds.go @@ -7,7 +7,7 @@ import ( "os" "strings" - "github.com/onsonr/sonr/gateway" + "github.com/onsonr/hway/gateway" "github.com/spf13/cobra" ) diff --git a/cmd/main.go b/cmd/main.go index a35e33e..cdaca24 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -7,7 +7,7 @@ import ( "os" "github.com/jackc/pgx/v5" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + hwayorm "github.com/onsonr/hway/internal/models" ) // main is the entry point for the application diff --git a/go.mod b/go.mod index bdac8b8..dcf1d4a 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/labstack/echo-contrib v0.17.2 github.com/labstack/echo/v4 v4.13.3 github.com/medama-io/go-useragent v1.0.1 - github.com/onsonr/sonr v0.6.1 + github.com/onsonr/hway v0.6.1 github.com/segmentio/ksuid v1.0.4 github.com/spf13/cobra v1.8.1 lukechampine.com/blake3 v1.3.0 diff --git a/go.sum b/go.sum index 21c7f8b..89170fd 100644 --- a/go.sum +++ b/go.sum @@ -756,8 +756,8 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.34.2 h1:pNCwDkzrsv7MS9kpaQvVb1aVLahQXyJ/Tv5oAZMI3i8= github.com/onsi/gomega v1.34.2/go.mod h1:v1xfxRgk0KIsG+QOdm7p8UosrOzPYRo60fd3B/1Dukc= -github.com/onsonr/sonr v0.6.1 h1:pNP2BbOfe/3UN/bZSYNyf9F+nlIpZaqi2LJ6Ol0496w= -github.com/onsonr/sonr v0.6.1/go.mod h1:L4ywLeJemlGD2pmlIX/j3eEKEgu5o/yzgFjkHNr7dAk= +github.com/onsonr/hway v0.6.1 h1:pNP2BbOfe/3UN/bZSYNyf9F+nlIpZaqi2LJ6Ol0496w= +github.com/onsonr/hway v0.6.1/go.mod h1:L4ywLeJemlGD2pmlIX/j3eEKEgu5o/yzgFjkHNr7dAk= github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk= github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= diff --git a/handlers/errors.go b/handlers/errors.go index a90d812..55a3b39 100644 --- a/handlers/errors.go +++ b/handlers/errors.go @@ -2,7 +2,7 @@ package handlers import ( "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/gateway/context" + "github.com/onsonr/hway/pkg/context" ) func ErrorHandler(err error, c echo.Context) { diff --git a/handlers/index.go b/handlers/index.go index 6d1e208..0958e16 100644 --- a/handlers/index.go +++ b/handlers/index.go @@ -2,7 +2,7 @@ package handlers import ( "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/gateway/context" + "github.com/onsonr/hway/pkg/context" ) func IndexHandler(c echo.Context) error { diff --git a/handlers/register.go b/handlers/register.go index 637c65c..58e118a 100644 --- a/handlers/register.go +++ b/handlers/register.go @@ -4,11 +4,11 @@ import ( "encoding/json" "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/gateway/islands" - "github.com/onsonr/sonr/gateway/views" - "github.com/onsonr/sonr/gateway/context" - "github.com/onsonr/sonr/internal/common" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + "github.com/onsonr/hway/gateway/islands" + "github.com/onsonr/hway/gateway/views" + "github.com/onsonr/hway/internal/common" + hwayorm "github.com/onsonr/hway/internal/database/hwayorm" + "github.com/onsonr/hway/pkg/context" ) func RegisterHandler(g *echo.Group) { diff --git a/internal/config/Hway.pkl.go b/internal/config/Hway.pkl.go new file mode 100644 index 0000000..9c0660c --- /dev/null +++ b/internal/config/Hway.pkl.go @@ -0,0 +1,103 @@ +// Code generated from Pkl module `sonr.net.Hway`. DO NOT EDIT. +package config + +import ( + "context" + + "github.com/apple/pkl-go/pkl" +) + +type Hway interface { + GetServePort() int + + GetSqliteFile() string + + GetChainId() string + + GetIpfsGatewayUrl() string + + GetSonrApiUrl() string + + GetSonrGrpcUrl() string + + GetSonrRpcUrl() string + + GetPsqlDSN() string +} + +var _ Hway = (*HwayImpl)(nil) + +type HwayImpl struct { + ServePort int `pkl:"servePort"` + + SqliteFile string `pkl:"sqliteFile"` + + ChainId string `pkl:"chainId"` + + IpfsGatewayUrl string `pkl:"ipfsGatewayUrl"` + + SonrApiUrl string `pkl:"sonrApiUrl"` + + SonrGrpcUrl string `pkl:"sonrGrpcUrl"` + + SonrRpcUrl string `pkl:"sonrRpcUrl"` + + PsqlDSN string `pkl:"psqlDSN"` +} + +func (rcv *HwayImpl) GetServePort() int { + return rcv.ServePort +} + +func (rcv *HwayImpl) GetSqliteFile() string { + return rcv.SqliteFile +} + +func (rcv *HwayImpl) GetChainId() string { + return rcv.ChainId +} + +func (rcv *HwayImpl) GetIpfsGatewayUrl() string { + return rcv.IpfsGatewayUrl +} + +func (rcv *HwayImpl) GetSonrApiUrl() string { + return rcv.SonrApiUrl +} + +func (rcv *HwayImpl) GetSonrGrpcUrl() string { + return rcv.SonrGrpcUrl +} + +func (rcv *HwayImpl) GetSonrRpcUrl() string { + return rcv.SonrRpcUrl +} + +func (rcv *HwayImpl) GetPsqlDSN() string { + return rcv.PsqlDSN +} + +// LoadFromPath loads the pkl module at the given path and evaluates it into a Hway +func LoadFromPath(ctx context.Context, path string) (ret Hway, err error) { + evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) + if err != nil { + return nil, err + } + defer func() { + cerr := evaluator.Close() + if err == nil { + err = cerr + } + }() + ret, err = Load(ctx, evaluator, pkl.FileSource(path)) + return ret, err +} + +// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Hway +func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Hway, error) { + var ret HwayImpl + if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { + return nil, err + } + return &ret, nil +} diff --git a/internal/config/init.pkl.go b/internal/config/init.pkl.go new file mode 100644 index 0000000..9804ad5 --- /dev/null +++ b/internal/config/init.pkl.go @@ -0,0 +1,8 @@ +// Code generated from Pkl module `sonr.net.Hway`. DO NOT EDIT. +package config + +import "github.com/apple/pkl-go/pkl" + +func init() { + pkl.RegisterMapping("sonr.net.Hway", HwayImpl{}) +} diff --git a/internal/models/db.go b/internal/models/db.go new file mode 100644 index 0000000..e8b9935 --- /dev/null +++ b/internal/models/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package models + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/models/models.go b/internal/models/models.go new file mode 100644 index 0000000..418f717 --- /dev/null +++ b/internal/models/models.go @@ -0,0 +1,99 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package models + +import ( + "database/sql" + "time" +) + +type Account struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + Number int64 `json:"number"` + Sequence int64 `json:"sequence"` + Address string `json:"address"` + PublicKey string `json:"public_key"` + ChainID string `json:"chain_id"` + Controller string `json:"controller"` + IsSubsidiary bool `json:"is_subsidiary"` + IsValidator bool `json:"is_validator"` + IsDelegator bool `json:"is_delegator"` + IsAccountable bool `json:"is_accountable"` +} + +type Asset struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + Name string `json:"name"` + Symbol string `json:"symbol"` + Decimals int64 `json:"decimals"` + ChainID string `json:"chain_id"` + Channel string `json:"channel"` + AssetType string `json:"asset_type"` + CoingeckoID sql.NullString `json:"coingecko_id"` +} + +type Credential struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + Handle string `json:"handle"` + CredentialID string `json:"credential_id"` + AuthenticatorAttachment string `json:"authenticator_attachment"` + Origin string `json:"origin"` + Type string `json:"type"` + Transports string `json:"transports"` +} + +type Profile struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + Address string `json:"address"` + Handle string `json:"handle"` + Origin string `json:"origin"` + Name string `json:"name"` +} + +type Session struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + BrowserName string `json:"browser_name"` + BrowserVersion string `json:"browser_version"` + ClientIpaddr string `json:"client_ipaddr"` + Platform string `json:"platform"` + IsDesktop bool `json:"is_desktop"` + IsMobile bool `json:"is_mobile"` + IsTablet bool `json:"is_tablet"` + IsTv bool `json:"is_tv"` + IsBot bool `json:"is_bot"` + Challenge string `json:"challenge"` + IsHumanFirst bool `json:"is_human_first"` + IsHumanLast bool `json:"is_human_last"` + ProfileID int64 `json:"profile_id"` +} + +type Vault struct { + ID string `json:"id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt sql.NullTime `json:"deleted_at"` + Handle string `json:"handle"` + Origin string `json:"origin"` + Address string `json:"address"` + Cid string `json:"cid"` + Config string `json:"config"` + SessionID string `json:"session_id"` + RedirectUri string `json:"redirect_uri"` +} diff --git a/internal/models/querier.go b/internal/models/querier.go new file mode 100644 index 0000000..e774f75 --- /dev/null +++ b/internal/models/querier.go @@ -0,0 +1,34 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package models + +import ( + "context" +) + +type Querier interface { + CheckHandleExists(ctx context.Context, handle string) (bool, error) + CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) + GetChallengeBySessionID(ctx context.Context, id string) (string, error) + GetCredentialByID(ctx context.Context, credentialID string) (Credential, error) + GetCredentialsByHandle(ctx context.Context, handle string) ([]Credential, error) + GetHumanVerificationNumbers(ctx context.Context, id string) (GetHumanVerificationNumbersRow, error) + GetProfileByAddress(ctx context.Context, address string) (Profile, error) + GetProfileByHandle(ctx context.Context, handle string) (Profile, error) + GetProfileByID(ctx context.Context, id string) (Profile, error) + GetSessionByClientIP(ctx context.Context, clientIpaddr string) (Session, error) + GetSessionByID(ctx context.Context, id string) (Session, error) + GetVaultConfigByCID(ctx context.Context, cid string) (Vault, error) + GetVaultRedirectURIBySessionID(ctx context.Context, sessionID string) (string, error) + InsertCredential(ctx context.Context, arg InsertCredentialParams) (Credential, error) + InsertProfile(ctx context.Context, arg InsertProfileParams) (Profile, error) + SoftDeleteCredential(ctx context.Context, credentialID string) error + SoftDeleteProfile(ctx context.Context, address string) error + UpdateProfile(ctx context.Context, arg UpdateProfileParams) (Profile, error) + UpdateSessionHumanVerification(ctx context.Context, arg UpdateSessionHumanVerificationParams) (Session, error) + UpdateSessionWithProfileID(ctx context.Context, arg UpdateSessionWithProfileIDParams) (Session, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/models/query.sql.go b/internal/models/query.sql.go new file mode 100644 index 0000000..46436c4 --- /dev/null +++ b/internal/models/query.sql.go @@ -0,0 +1,581 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: query.sql + +package models + +import ( + "context" +) + +const checkHandleExists = `-- name: CheckHandleExists :one +SELECT COUNT(*) > 0 as handle_exists FROM profiles +WHERE handle = ? +AND deleted_at IS NULL +` + +func (q *Queries) CheckHandleExists(ctx context.Context, handle string) (bool, error) { + row := q.db.QueryRowContext(ctx, checkHandleExists, handle) + var handle_exists bool + err := row.Scan(&handle_exists) + return handle_exists, err +} + +const createSession = `-- name: CreateSession :one +INSERT INTO sessions ( + id, + browser_name, + browser_version, + client_ipaddr, + platform, + is_desktop, + is_mobile, + is_tablet, + is_tv, + is_bot, + challenge, + is_human_first, + is_human_last, + profile_id +) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) +RETURNING id, created_at, updated_at, deleted_at, browser_name, browser_version, client_ipaddr, platform, is_desktop, is_mobile, is_tablet, is_tv, is_bot, challenge, is_human_first, is_human_last, profile_id +` + +type CreateSessionParams struct { + ID string `json:"id"` + BrowserName string `json:"browser_name"` + BrowserVersion string `json:"browser_version"` + ClientIpaddr string `json:"client_ipaddr"` + Platform string `json:"platform"` + IsDesktop bool `json:"is_desktop"` + IsMobile bool `json:"is_mobile"` + IsTablet bool `json:"is_tablet"` + IsTv bool `json:"is_tv"` + IsBot bool `json:"is_bot"` + Challenge string `json:"challenge"` + IsHumanFirst bool `json:"is_human_first"` + IsHumanLast bool `json:"is_human_last"` + ProfileID int64 `json:"profile_id"` +} + +func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) { + row := q.db.QueryRowContext(ctx, createSession, + arg.ID, + arg.BrowserName, + arg.BrowserVersion, + arg.ClientIpaddr, + arg.Platform, + arg.IsDesktop, + arg.IsMobile, + arg.IsTablet, + arg.IsTv, + arg.IsBot, + arg.Challenge, + arg.IsHumanFirst, + arg.IsHumanLast, + arg.ProfileID, + ) + var i Session + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.BrowserName, + &i.BrowserVersion, + &i.ClientIpaddr, + &i.Platform, + &i.IsDesktop, + &i.IsMobile, + &i.IsTablet, + &i.IsTv, + &i.IsBot, + &i.Challenge, + &i.IsHumanFirst, + &i.IsHumanLast, + &i.ProfileID, + ) + return i, err +} + +const getChallengeBySessionID = `-- name: GetChallengeBySessionID :one +SELECT challenge FROM sessions +WHERE id = ? AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetChallengeBySessionID(ctx context.Context, id string) (string, error) { + row := q.db.QueryRowContext(ctx, getChallengeBySessionID, id) + var challenge string + err := row.Scan(&challenge) + return challenge, err +} + +const getCredentialByID = `-- name: GetCredentialByID :one +SELECT id, created_at, updated_at, deleted_at, handle, credential_id, authenticator_attachment, origin, type, transports FROM credentials +WHERE credential_id = ? +AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetCredentialByID(ctx context.Context, credentialID string) (Credential, error) { + row := q.db.QueryRowContext(ctx, getCredentialByID, credentialID) + var i Credential + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Handle, + &i.CredentialID, + &i.AuthenticatorAttachment, + &i.Origin, + &i.Type, + &i.Transports, + ) + return i, err +} + +const getCredentialsByHandle = `-- name: GetCredentialsByHandle :many +SELECT id, created_at, updated_at, deleted_at, handle, credential_id, authenticator_attachment, origin, type, transports FROM credentials +WHERE handle = ? +AND deleted_at IS NULL +` + +func (q *Queries) GetCredentialsByHandle(ctx context.Context, handle string) ([]Credential, error) { + rows, err := q.db.QueryContext(ctx, getCredentialsByHandle, handle) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Credential + for rows.Next() { + var i Credential + if err := rows.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Handle, + &i.CredentialID, + &i.AuthenticatorAttachment, + &i.Origin, + &i.Type, + &i.Transports, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getHumanVerificationNumbers = `-- name: GetHumanVerificationNumbers :one +SELECT is_human_first, is_human_last FROM sessions +WHERE id = ? AND deleted_at IS NULL +LIMIT 1 +` + +type GetHumanVerificationNumbersRow struct { + IsHumanFirst bool `json:"is_human_first"` + IsHumanLast bool `json:"is_human_last"` +} + +func (q *Queries) GetHumanVerificationNumbers(ctx context.Context, id string) (GetHumanVerificationNumbersRow, error) { + row := q.db.QueryRowContext(ctx, getHumanVerificationNumbers, id) + var i GetHumanVerificationNumbersRow + err := row.Scan(&i.IsHumanFirst, &i.IsHumanLast) + return i, err +} + +const getProfileByAddress = `-- name: GetProfileByAddress :one +SELECT id, created_at, updated_at, deleted_at, address, handle, origin, name FROM profiles +WHERE address = ? AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetProfileByAddress(ctx context.Context, address string) (Profile, error) { + row := q.db.QueryRowContext(ctx, getProfileByAddress, address) + var i Profile + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Address, + &i.Handle, + &i.Origin, + &i.Name, + ) + return i, err +} + +const getProfileByHandle = `-- name: GetProfileByHandle :one +SELECT id, created_at, updated_at, deleted_at, address, handle, origin, name FROM profiles +WHERE handle = ? +AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetProfileByHandle(ctx context.Context, handle string) (Profile, error) { + row := q.db.QueryRowContext(ctx, getProfileByHandle, handle) + var i Profile + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Address, + &i.Handle, + &i.Origin, + &i.Name, + ) + return i, err +} + +const getProfileByID = `-- name: GetProfileByID :one +SELECT id, created_at, updated_at, deleted_at, address, handle, origin, name FROM profiles +WHERE id = ? AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetProfileByID(ctx context.Context, id string) (Profile, error) { + row := q.db.QueryRowContext(ctx, getProfileByID, id) + var i Profile + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Address, + &i.Handle, + &i.Origin, + &i.Name, + ) + return i, err +} + +const getSessionByClientIP = `-- name: GetSessionByClientIP :one +SELECT id, created_at, updated_at, deleted_at, browser_name, browser_version, client_ipaddr, platform, is_desktop, is_mobile, is_tablet, is_tv, is_bot, challenge, is_human_first, is_human_last, profile_id FROM sessions +WHERE client_ipaddr = ? AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetSessionByClientIP(ctx context.Context, clientIpaddr string) (Session, error) { + row := q.db.QueryRowContext(ctx, getSessionByClientIP, clientIpaddr) + var i Session + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.BrowserName, + &i.BrowserVersion, + &i.ClientIpaddr, + &i.Platform, + &i.IsDesktop, + &i.IsMobile, + &i.IsTablet, + &i.IsTv, + &i.IsBot, + &i.Challenge, + &i.IsHumanFirst, + &i.IsHumanLast, + &i.ProfileID, + ) + return i, err +} + +const getSessionByID = `-- name: GetSessionByID :one +SELECT id, created_at, updated_at, deleted_at, browser_name, browser_version, client_ipaddr, platform, is_desktop, is_mobile, is_tablet, is_tv, is_bot, challenge, is_human_first, is_human_last, profile_id FROM sessions +WHERE id = ? AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetSessionByID(ctx context.Context, id string) (Session, error) { + row := q.db.QueryRowContext(ctx, getSessionByID, id) + var i Session + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.BrowserName, + &i.BrowserVersion, + &i.ClientIpaddr, + &i.Platform, + &i.IsDesktop, + &i.IsMobile, + &i.IsTablet, + &i.IsTv, + &i.IsBot, + &i.Challenge, + &i.IsHumanFirst, + &i.IsHumanLast, + &i.ProfileID, + ) + return i, err +} + +const getVaultConfigByCID = `-- name: GetVaultConfigByCID :one +SELECT id, created_at, updated_at, deleted_at, handle, origin, address, cid, config, session_id, redirect_uri FROM vaults +WHERE cid = ? +AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetVaultConfigByCID(ctx context.Context, cid string) (Vault, error) { + row := q.db.QueryRowContext(ctx, getVaultConfigByCID, cid) + var i Vault + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Handle, + &i.Origin, + &i.Address, + &i.Cid, + &i.Config, + &i.SessionID, + &i.RedirectUri, + ) + return i, err +} + +const getVaultRedirectURIBySessionID = `-- name: GetVaultRedirectURIBySessionID :one +SELECT redirect_uri FROM vaults +WHERE session_id = ? +AND deleted_at IS NULL +LIMIT 1 +` + +func (q *Queries) GetVaultRedirectURIBySessionID(ctx context.Context, sessionID string) (string, error) { + row := q.db.QueryRowContext(ctx, getVaultRedirectURIBySessionID, sessionID) + var redirect_uri string + err := row.Scan(&redirect_uri) + return redirect_uri, err +} + +const insertCredential = `-- name: InsertCredential :one +INSERT INTO credentials ( + handle, + credential_id, + origin, + type, + transports +) VALUES (?, ?, ?, ?, ?) +RETURNING id, created_at, updated_at, deleted_at, handle, credential_id, authenticator_attachment, origin, type, transports +` + +type InsertCredentialParams struct { + Handle string `json:"handle"` + CredentialID string `json:"credential_id"` + Origin string `json:"origin"` + Type string `json:"type"` + Transports string `json:"transports"` +} + +func (q *Queries) InsertCredential(ctx context.Context, arg InsertCredentialParams) (Credential, error) { + row := q.db.QueryRowContext(ctx, insertCredential, + arg.Handle, + arg.CredentialID, + arg.Origin, + arg.Type, + arg.Transports, + ) + var i Credential + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Handle, + &i.CredentialID, + &i.AuthenticatorAttachment, + &i.Origin, + &i.Type, + &i.Transports, + ) + return i, err +} + +const insertProfile = `-- name: InsertProfile :one +INSERT INTO profiles ( + address, + handle, + origin, + name +) VALUES (?, ?, ?, ?) +RETURNING id, created_at, updated_at, deleted_at, address, handle, origin, name +` + +type InsertProfileParams struct { + Address string `json:"address"` + Handle string `json:"handle"` + Origin string `json:"origin"` + Name string `json:"name"` +} + +func (q *Queries) InsertProfile(ctx context.Context, arg InsertProfileParams) (Profile, error) { + row := q.db.QueryRowContext(ctx, insertProfile, + arg.Address, + arg.Handle, + arg.Origin, + arg.Name, + ) + var i Profile + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Address, + &i.Handle, + &i.Origin, + &i.Name, + ) + return i, err +} + +const softDeleteCredential = `-- name: SoftDeleteCredential :exec +UPDATE credentials +SET deleted_at = CURRENT_TIMESTAMP +WHERE credential_id = ? +` + +func (q *Queries) SoftDeleteCredential(ctx context.Context, credentialID string) error { + _, err := q.db.ExecContext(ctx, softDeleteCredential, credentialID) + return err +} + +const softDeleteProfile = `-- name: SoftDeleteProfile :exec +UPDATE profiles +SET deleted_at = CURRENT_TIMESTAMP +WHERE address = ? +` + +func (q *Queries) SoftDeleteProfile(ctx context.Context, address string) error { + _, err := q.db.ExecContext(ctx, softDeleteProfile, address) + return err +} + +const updateProfile = `-- name: UpdateProfile :one +UPDATE profiles +SET + name = ?, + handle = ?, + updated_at = CURRENT_TIMESTAMP +WHERE address = ? +AND deleted_at IS NULL +RETURNING id, created_at, updated_at, deleted_at, address, handle, origin, name +` + +type UpdateProfileParams struct { + Name string `json:"name"` + Handle string `json:"handle"` + Address string `json:"address"` +} + +func (q *Queries) UpdateProfile(ctx context.Context, arg UpdateProfileParams) (Profile, error) { + row := q.db.QueryRowContext(ctx, updateProfile, arg.Name, arg.Handle, arg.Address) + var i Profile + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.Address, + &i.Handle, + &i.Origin, + &i.Name, + ) + return i, err +} + +const updateSessionHumanVerification = `-- name: UpdateSessionHumanVerification :one +UPDATE sessions +SET + is_human_first = ?, + is_human_last = ?, + updated_at = CURRENT_TIMESTAMP +WHERE id = ? +RETURNING id, created_at, updated_at, deleted_at, browser_name, browser_version, client_ipaddr, platform, is_desktop, is_mobile, is_tablet, is_tv, is_bot, challenge, is_human_first, is_human_last, profile_id +` + +type UpdateSessionHumanVerificationParams struct { + IsHumanFirst bool `json:"is_human_first"` + IsHumanLast bool `json:"is_human_last"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSessionHumanVerification(ctx context.Context, arg UpdateSessionHumanVerificationParams) (Session, error) { + row := q.db.QueryRowContext(ctx, updateSessionHumanVerification, arg.IsHumanFirst, arg.IsHumanLast, arg.ID) + var i Session + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.BrowserName, + &i.BrowserVersion, + &i.ClientIpaddr, + &i.Platform, + &i.IsDesktop, + &i.IsMobile, + &i.IsTablet, + &i.IsTv, + &i.IsBot, + &i.Challenge, + &i.IsHumanFirst, + &i.IsHumanLast, + &i.ProfileID, + ) + return i, err +} + +const updateSessionWithProfileID = `-- name: UpdateSessionWithProfileID :one +UPDATE sessions +SET + profile_id = ?, + updated_at = CURRENT_TIMESTAMP +WHERE id = ? +RETURNING id, created_at, updated_at, deleted_at, browser_name, browser_version, client_ipaddr, platform, is_desktop, is_mobile, is_tablet, is_tv, is_bot, challenge, is_human_first, is_human_last, profile_id +` + +type UpdateSessionWithProfileIDParams struct { + ProfileID int64 `json:"profile_id"` + ID string `json:"id"` +} + +func (q *Queries) UpdateSessionWithProfileID(ctx context.Context, arg UpdateSessionWithProfileIDParams) (Session, error) { + row := q.db.QueryRowContext(ctx, updateSessionWithProfileID, arg.ProfileID, arg.ID) + var i Session + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.UpdatedAt, + &i.DeletedAt, + &i.BrowserName, + &i.BrowserVersion, + &i.ClientIpaddr, + &i.Platform, + &i.IsDesktop, + &i.IsMobile, + &i.IsTablet, + &i.IsTv, + &i.IsBot, + &i.Challenge, + &i.IsHumanFirst, + &i.IsHumanLast, + &i.ProfileID, + ) + return i, err +} diff --git a/internal/sink/highway/query.sql b/internal/sink/highway/query.sql deleted file mode 100644 index 8130158..0000000 --- a/internal/sink/highway/query.sql +++ /dev/null @@ -1,151 +0,0 @@ --- name: InsertCredential :one -INSERT INTO credentials ( - id, - created_at, - updated_at, - deleted_at, - handle, - credential_id, - authenticator_attachment, - origin, - type, - transports -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) -RETURNING *; - --- name: InsertProfile :one -INSERT INTO profiles ( - id, - created_at, - updated_at, - deleted_at, - address, - handle, - origin, - name, - status -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) -RETURNING *; - --- name: GetProfileByID :one -SELECT * FROM profiles -WHERE id = ? AND deleted_at IS NULL -LIMIT 1; - --- name: GetProfileByAddress :one -SELECT * FROM profiles -WHERE address = ? AND deleted_at IS NULL -LIMIT 1; - --- name: GetChallengeBySessionID :one -SELECT challenge FROM sessions -WHERE id = ? AND deleted_at IS NULL -LIMIT 1; - --- name: GetHumanVerificationNumbers :one -SELECT is_human_first, is_human_last FROM sessions -WHERE id = ? AND deleted_at IS NULL -LIMIT 1; - --- name: GetSessionByID :one -SELECT * FROM sessions -WHERE id = ? AND deleted_at IS NULL -LIMIT 1; - --- name: GetSessionByClientIP :one -SELECT * FROM sessions -WHERE client_ipaddr = ? AND deleted_at IS NULL -LIMIT 1; - --- name: UpdateSessionHumanVerification :one -UPDATE sessions -SET - is_human_first = ?, - is_human_last = ?, - updated_at = CURRENT_TIMESTAMP -WHERE id = ? -RETURNING *; - --- name: UpdateSessionWithProfileID :one -UPDATE sessions -SET - profile_id = ?, - updated_at = CURRENT_TIMESTAMP -WHERE id = ? -RETURNING *; - --- name: CheckHandleExists :one -SELECT COUNT(*) > 0 as handle_exists FROM profiles -WHERE handle = ? -AND deleted_at IS NULL; - --- name: GetCredentialsByHandle :many -SELECT * FROM credentials -WHERE handle = ? -AND deleted_at IS NULL; - --- name: GetCredentialByID :one -SELECT * FROM credentials -WHERE credential_id = ? -AND deleted_at IS NULL -LIMIT 1; - --- name: SoftDeleteCredential :exec -UPDATE credentials -SET deleted_at = CURRENT_TIMESTAMP -WHERE credential_id = ?; - --- name: SoftDeleteProfile :exec -UPDATE profiles -SET deleted_at = CURRENT_TIMESTAMP -WHERE id = ?; - --- name: UpdateProfile :one -UPDATE profiles -SET - name = ?, - handle = ?, - updated_at = CURRENT_TIMESTAMP -WHERE id = ? -AND deleted_at IS NULL -RETURNING *; - --- name: GetProfileByHandle :one -SELECT * FROM profiles -WHERE handle = ? -AND deleted_at IS NULL -LIMIT 1; - --- name: GetVaultConfigByCID :one -SELECT * FROM vaults -WHERE cid = ? -AND deleted_at IS NULL -LIMIT 1; - --- name: GetVaultRedirectURIBySessionID :one -SELECT redirect_uri FROM vaults -WHERE session_id = ? -AND deleted_at IS NULL -LIMIT 1; - --- name: CreateSession :one -INSERT INTO sessions ( - id, - created_at, - updated_at, - deleted_at, - browser_name, - browser_version, - client_ipaddr, - platform, - is_desktop, - is_mobile, - is_tablet, - is_tv, - is_bot, - challenge, - is_human_first, - is_human_last, - profile_id -) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) -RETURNING *; diff --git a/internal/sink/highway/schema.sql b/internal/sink/highway/schema.sql deleted file mode 100644 index ecfc2b3..0000000 --- a/internal/sink/highway/schema.sql +++ /dev/null @@ -1,122 +0,0 @@ --- Profiles represent user identities -CREATE TABLE profiles ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - address TEXT NOT NULL, - handle TEXT NOT NULL UNIQUE, - origin TEXT NOT NULL, - name TEXT NOT NULL, - status TEXT NOT NULL, - UNIQUE(address, origin) -); - --- Accounts represent blockchain accounts -CREATE TABLE accounts ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - number INTEGER NOT NULL, - sequence INTEGER NOT NULL DEFAULT 0, - address TEXT NOT NULL UNIQUE, - public_key TEXT NOT NULL, - chain_id TEXT NOT NULL, - controller TEXT NOT NULL, - is_subsidiary INTEGER NOT NULL DEFAULT 0, - is_validator INTEGER NOT NULL DEFAULT 0, - is_delegator INTEGER NOT NULL DEFAULT 0, - is_accountable INTEGER NOT NULL DEFAULT 1 -); - --- Assets represent tokens and coins -CREATE TABLE assets ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - name TEXT NOT NULL, - symbol TEXT NOT NULL, - decimals INTEGER NOT NULL CHECK(decimals >= 0), - chain_id TEXT NOT NULL, - channel TEXT NOT NULL, - asset_type TEXT NOT NULL, - coingecko_id TEXT, - UNIQUE(chain_id, symbol) -); - --- Credentials store WebAuthn credentials -CREATE TABLE credentials ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - handle TEXT NOT NULL, - credential_id TEXT NOT NULL UNIQUE, - authenticator_attachment TEXT NOT NULL, - origin TEXT NOT NULL, - type TEXT NOT NULL, - transports TEXT NOT NULL -); - --- Sessions track user authentication state -CREATE TABLE sessions ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - browser_name TEXT NOT NULL, - browser_version TEXT NOT NULL, - client_ipaddr TEXT NOT NULL, - platform TEXT NOT NULL, - is_desktop INTEGER NOT NULL DEFAULT 0, - is_mobile INTEGER NOT NULL DEFAULT 0, - is_tablet INTEGER NOT NULL DEFAULT 0, - is_tv INTEGER NOT NULL DEFAULT 0, - is_bot INTEGER NOT NULL DEFAULT 0, - challenge TEXT NOT NULL, - is_human_first INTEGER NOT NULL DEFAULT 0, - is_human_last INTEGER NOT NULL DEFAULT 0, - profile_id TEXT NOT NULL, - FOREIGN KEY (profile_id) REFERENCES profiles(id) -); - --- Vaults store encrypted data -CREATE TABLE vaults ( - id TEXT PRIMARY KEY, - created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - deleted_at DATETIME, - handle TEXT NOT NULL, - origin TEXT NOT NULL, - address TEXT NOT NULL, - cid TEXT NOT NULL UNIQUE, - config TEXT NOT NULL, - session_id TEXT NOT NULL, - redirect_uri TEXT NOT NULL, - FOREIGN KEY (session_id) REFERENCES sessions(id) -); - --- Indexes for common queries -CREATE INDEX idx_profiles_handle ON profiles(handle); -CREATE INDEX idx_profiles_address ON profiles(address); -CREATE INDEX idx_profiles_origin ON profiles(origin); -CREATE INDEX idx_profiles_status ON profiles(status); -CREATE INDEX idx_profiles_deleted_at ON profiles(deleted_at); - -CREATE INDEX idx_accounts_address ON accounts(address); -CREATE INDEX idx_accounts_chain_id ON accounts(chain_id); -CREATE INDEX idx_accounts_deleted_at ON accounts(deleted_at); - -CREATE INDEX idx_assets_symbol ON assets(symbol); -CREATE INDEX idx_assets_chain_id ON assets(chain_id); -CREATE INDEX idx_assets_deleted_at ON assets(deleted_at); - -CREATE INDEX idx_credentials_handle ON credentials(handle); -CREATE INDEX idx_credentials_origin ON credentials(origin); -CREATE INDEX idx_credentials_deleted_at ON credentials(deleted_at); - -CREATE INDEX idx_sessions_profile_id ON sessions(profile_id); -CREATE INDEX idx_sessions_client_ipaddr ON sessions(client_ipaddr); -CREATE INDEX idx_sessions_deleted_at ON sessions(deleted_at); diff --git a/internal/sink/vault/query.sql b/internal/sink/query.sql similarity index 100% rename from internal/sink/vault/query.sql rename to internal/sink/query.sql diff --git a/internal/sink/vault/schema.sql b/internal/sink/schema.sql similarity index 100% rename from internal/sink/vault/schema.sql rename to internal/sink/schema.sql diff --git a/internal/sink/sink.go b/internal/sink/sink.go index 09c6622..f39cdf6 100644 --- a/internal/sink/sink.go +++ b/internal/sink/sink.go @@ -4,5 +4,5 @@ import ( _ "embed" ) -//go:embed vault/schema.sql +//go:embed schema.sql var SchemaVaultSQL string diff --git a/internal/sqlc.yaml b/internal/sqlc.yaml index e43516c..5697907 100644 --- a/internal/sqlc.yaml +++ b/internal/sqlc.yaml @@ -1,26 +1,11 @@ version: "2" sql: - engine: "sqlite" - queries: "./sink/vault/query.sql" - schema: "./sink/vault/schema.sql" + queries: "./sink/query.sql" + schema: "./sink/schema.sql" gen: go: emit_interface: true emit_json_tags: true - package: "motrorm" - out: "motrorm" - - - engine: "postgresql" - queries: "./sink/highway/query.sql" - schema: "./sink/highway/schema.sql" - gen: - go: - emit_all_enum_values: true - emit_enum_valid_method: true - emit_json_tags: true - emit_interface: true - emit_result_struct_pointers: true - omit_unused_structs: true - package: "hwayorm" - out: "hwayorm" - sql_package: "pgx/v5" + package: "models" + out: "models" diff --git a/pkg/common/chain_query.go b/pkg/common/chain_query.go index ae4409c..288f218 100644 --- a/pkg/common/chain_query.go +++ b/pkg/common/chain_query.go @@ -3,9 +3,9 @@ package common import ( bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1" nodev1beta1 "github.com/cosmos/cosmos-sdk/client/grpc/node" - didv1 "github.com/onsonr/sonr/api/did/v1" - dwnv1 "github.com/onsonr/sonr/api/dwn/v1" - svcv1 "github.com/onsonr/sonr/api/svc/v1" + didv1 "github.com/onsonr/hway/api/did/v1" + dwnv1 "github.com/onsonr/hway/api/dwn/v1" + svcv1 "github.com/onsonr/hway/api/svc/v1" "google.golang.org/grpc" ) diff --git a/pkg/common/ucan_store.go b/pkg/common/ucan_store.go index 5493792..9acd282 100644 --- a/pkg/common/ucan_store.go +++ b/pkg/common/ucan_store.go @@ -8,8 +8,8 @@ import ( "github.com/golang-jwt/jwt" "github.com/ipfs/go-cid" - "github.com/onsonr/sonr/internal/crypto/keys" - "github.com/onsonr/sonr/internal/crypto/ucan" + "github.com/onsonr/hway/internal/crypto/keys" + "github.com/onsonr/hway/internal/crypto/ucan" ) type IPFSTokenStore interface { diff --git a/pkg/context/middleware.go b/pkg/context/middleware.go index 40250cd..86a5691 100644 --- a/pkg/context/middleware.go +++ b/pkg/context/middleware.go @@ -6,10 +6,10 @@ import ( "github.com/labstack/echo/v4" "github.com/medama-io/go-useragent" - "github.com/onsonr/sonr/internal/crypto/mpc" - "github.com/onsonr/sonr/internal/common" - "github.com/onsonr/sonr/internal/config/hway" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + "github.com/onsonr/hway/internal/crypto/mpc" + "github.com/onsonr/hway/internal/common" + "github.com/onsonr/hway/internal/config/hway" + hwayorm "github.com/onsonr/hway/internal/database/hwayorm" ) type GatewayContext struct { diff --git a/pkg/context/profiles.go b/pkg/context/profiles.go index 971b9b7..920ba5f 100644 --- a/pkg/context/profiles.go +++ b/pkg/context/profiles.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/labstack/echo/v4" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + hwayorm "github.com/onsonr/hway/internal/database/hwayorm" ) func UpdateProfile(c echo.Context) (*hwayorm.Profile, error) { diff --git a/pkg/context/renderer.go b/pkg/context/renderer.go index 1280e85..02fd59f 100644 --- a/pkg/context/renderer.go +++ b/pkg/context/renderer.go @@ -5,7 +5,7 @@ import ( "github.com/a-h/templ" "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/gateway/views" + "github.com/onsonr/hway/gateway/views" ) func Render(c echo.Context, cmp templ.Component) error { diff --git a/pkg/context/resolver.go b/pkg/context/resolver.go index 348136a..9c86043 100644 --- a/pkg/context/resolver.go +++ b/pkg/context/resolver.go @@ -3,7 +3,7 @@ package context import ( "fmt" - "github.com/onsonr/sonr/internal/common" + "github.com/onsonr/hway/internal/common" ) // ParamsBank returns the bank params diff --git a/pkg/context/sessions.go b/pkg/context/sessions.go index d1ffe50..449a9d6 100644 --- a/pkg/context/sessions.go +++ b/pkg/context/sessions.go @@ -4,7 +4,7 @@ import ( gocontext "context" "github.com/labstack/echo/v4" - "github.com/onsonr/sonr/internal/common" + "github.com/onsonr/hway/internal/common" "github.com/segmentio/ksuid" "lukechampine.com/blake3" ) diff --git a/pkg/context/types.go b/pkg/context/types.go index 7072a7b..8c6a01a 100644 --- a/pkg/context/types.go +++ b/pkg/context/types.go @@ -4,7 +4,7 @@ import ( "github.com/go-webauthn/webauthn/protocol" "github.com/labstack/echo/v4" "github.com/medama-io/go-useragent" - hwayorm "github.com/onsonr/sonr/internal/database/hwayorm" + hwayorm "github.com/onsonr/hway/internal/database/hwayorm" ) // Define the credential structure matching our frontend data diff --git a/pkg/context/vaults.go b/pkg/context/vaults.go index 4be0d93..7c764be 100644 --- a/pkg/context/vaults.go +++ b/pkg/context/vaults.go @@ -1,8 +1,8 @@ package context import ( - "github.com/onsonr/sonr/internal/crypto/mpc" - "github.com/onsonr/sonr/internal/common" + "github.com/onsonr/hway/internal/crypto/mpc" + "github.com/onsonr/hway/internal/common" "lukechampine.com/blake3" ) diff --git a/pkg/views/base_hero.templ b/pkg/views/base_hero.templ index 596dc9e..aaa3315 100644 --- a/pkg/views/base_hero.templ +++ b/pkg/views/base_hero.templ @@ -29,7 +29,7 @@ templ HeroSocials() { - + diff --git a/pkg/views/base_hero_templ.go b/pkg/views/base_hero_templ.go index bc7ec5f..cf11e4c 100644 --- a/pkg/views/base_hero_templ.go +++ b/pkg/views/base_hero_templ.go @@ -113,7 +113,7 @@ func HeroSocials() templ.Component { templ_7745c5c3_Var5 = templ.NopComponent } ctx = templ.ClearChildren(ctx) - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/pkg/views/view_register.templ b/pkg/views/view_register.templ index b4a5af4..a44e372 100644 --- a/pkg/views/view_register.templ +++ b/pkg/views/view_register.templ @@ -1,6 +1,6 @@ package views -import "github.com/onsonr/sonr/gateway/islands" +import "github.com/onsonr/hway/gateway/islands" templ RegisterProfileView(firstNumber int, lastNumber int) { @LayoutView("New Profile | Sonr.ID") { diff --git a/pkg/views/view_register_templ.go b/pkg/views/view_register_templ.go index dfc546c..215e85b 100644 --- a/pkg/views/view_register_templ.go +++ b/pkg/views/view_register_templ.go @@ -8,7 +8,7 @@ package views import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "github.com/onsonr/sonr/gateway/islands" +import "github.com/onsonr/hway/gateway/islands" func RegisterProfileView(firstNumber int, lastNumber int) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { diff --git a/pkl/App.pkl b/pkl/App.pkl new file mode 100644 index 0000000..bd6fbf3 --- /dev/null +++ b/pkl/App.pkl @@ -0,0 +1,16 @@ +@go.Package { name = "github.com/onsonr/hway/internal/config" } + + +open module sonr.net.Hway + +import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl" + +servePort: Int = 3000 + +sqliteFile: String = "hway.db" +chainId: String = "sonr-testnet-1" +ipfsGatewayUrl: String = "http://localhost:8080" +sonrApiUrl: String = "http://localhost:1317" +sonrGrpcUrl: String = "http://localhost:9090" +sonrRpcUrl: String = "http://localhost:26657" +psqlDSN: String