Skip to content

Commit 4c9ca1c

Browse files
committed
first pass at example oracle implementation based on one of our internal robust solutions
1 parent b5e3887 commit 4c9ca1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+9685
-11
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "daily"

.github/pull_request_template.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Proposed Changes
2+
3+
### Impacted Events
4+
<!-- Will this pull request change or implement any events? -->
5+
6+
### Caveats
7+
<!-- If there is anything hacky or unique being added in your code please define it.-->

.github/workflows/buildpushdev.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: buildpushdev
2+
on:
3+
push:
4+
branches:
5+
- main
6+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
7+
jobs:
8+
build_test:
9+
# The type of runner that the job will run on
10+
name: buildpushdev
11+
runs-on: [self-hosted, linux]
12+
steps:
13+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
14+
- uses: actions/checkout@v4
15+
16+
- name: Login to DockerHub
17+
uses: docker/login-action@v3
18+
with:
19+
username: ${{ secrets.DOCKERHUB_USERNAME }}
20+
password: ${{ secrets.DOCKERHUB_TOKEN }}
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
- name: Get short SHA
24+
id: slug
25+
run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)"
26+
27+
- name: Build and push
28+
uses: docker/build-push-action@v6
29+
with:
30+
context: .
31+
file: ./resources/docker/Dockerfile
32+
push: true
33+
tags: dimozone/oracle-example:${{ steps.slug.outputs.sha7 }}, dimozone/oracle-example:latest
34+
35+
- name: Update Image Version in the related HelmChart values.yaml
36+
uses: fjogeleit/yaml-update-action@master
37+
with:
38+
valueFile: 'charts/oracle-example/values.yaml'
39+
propertyPath: 'image.tag'
40+
value: ${{ steps.slug.outputs.sha7 }}
41+
branch: main
42+
message: 'Update Image Version to ${{ steps.slug.outputs.sha7 }}'

.github/workflows/buildpushtagged.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: buildpushprod
2+
on:
3+
push:
4+
tags:
5+
- v*
6+
7+
jobs:
8+
build_test:
9+
# The type of runner that the job will run on
10+
name: buildpush
11+
runs-on: [self-hosted, linux]
12+
steps:
13+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Docker Buildx
17+
uses: docker/setup-buildx-action@v3
18+
19+
- name: Login to DockerHub
20+
uses: docker/login-action@v3
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
25+
- name: Get tag
26+
id: tag
27+
uses: dawidd6/action-get-tag@v1
28+
with:
29+
strip_v: true
30+
31+
- name: Build and push
32+
uses: docker/build-push-action@v6
33+
with:
34+
context: .
35+
file: ./resources/docker/Dockerfile
36+
push: true
37+
platforms: linux/amd64
38+
tags: dimozone/oracle-example:${{steps.tag.outputs.tag}}
39+
40+
- name: Update Image Version in the related HelmChart values.yaml
41+
uses: fjogeleit/yaml-update-action@master
42+
with:
43+
valueFile: 'charts/oracle-example/values-prod.yaml'
44+
propertyPath: 'image.tag'
45+
value: ${{steps.tag.outputs.tag}}
46+
branch: main
47+
message: 'Update Image Version to ${{steps.tag.outputs.tag}}'

.github/workflows/lint.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: golangci-lint
2+
on:
3+
pull_request:
4+
branches: [ '**' ]
5+
env:
6+
GOPRIVATE: github.com/DIMO-Network
7+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8+
jobs:
9+
golangci:
10+
runs-on: [self-hosted, linux]
11+
12+
name: lint
13+
steps:
14+
- name: Install Go
15+
uses: actions/setup-go@v5
16+
with:
17+
go-version: 1.24.x
18+
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: golangci-lint
23+
uses: golangci/golangci-lint-action@v7
24+
with:
25+
version: latest
26+
only-new-issues: false

.github/workflows/rules.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: rulestest
2+
3+
on:
4+
pull_request:
5+
branches: [ '**' ]
6+
7+
jobs:
8+
rules-test:
9+
runs-on: [self-hosted, linux]
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
# we need to install promtool to run the tests
16+
- name: Install promtool
17+
run: sudo wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz && sudo tar -xvf prometheus-2.47.0.linux-amd64.tar.gz && sudo cp prometheus-2.47.0.linux-amd64/promtool /usr/local/bin/
18+
19+
- name: Sed helm chart placeholders
20+
run: sed "s/{{ .Release.Namespace }}/dev/g" ./charts/oracle-example/templates/alerts.yaml | sed 's/{{.*}}//g' > ./charts/oracle-example/alert_tests/alerts-modified.yaml
21+
22+
# this action only can execute check and config promtool commands
23+
- name: Check Prometheus alert rules
24+
uses: peimanja/promtool-github-actions@master
25+
with:
26+
promtool_actions_subcommand: 'rules'
27+
promtool_actions_files: './charts/oracle-example/alert_tests/alerts-modified.yaml'
28+
promtool_actions_version: '2.14.0'
29+
promtool_actions_comment: true
30+
31+
- name: Exec promtool tests on alerts
32+
run: promtool test rules ./charts/oracle-example/alert_tests/rules-tests.yaml

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: gotest
2+
3+
on:
4+
pull_request:
5+
branches: [ '**' ]
6+
7+
jobs:
8+
tests:
9+
runs-on: [self-hosted, linux]
10+
11+
steps:
12+
- name: Install Go
13+
uses: actions/setup-go@v5
14+
with:
15+
go-version: 1.21.x
16+
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Get dependencies
21+
run: |
22+
go get -v -t ./...
23+
go install gotest.tools/gotestsum@latest
24+
25+
- name: modVerify
26+
run: go mod verify
27+
28+
- name: modTidy
29+
run: go mod tidy
30+
31+
- name: Run Tests with go testsum
32+
run: gotestsum --format pkgname --jsonfile test.json
33+
34+
- name: Annotate tests
35+
if: always()
36+
uses: guyarb/golang-test-annotations@v0.8.0
37+
with:
38+
test-results: test.json

.gitignore

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
# If you prefer the allow list template instead of the deny list, see community template:
2-
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3-
#
41
# Binaries for programs and plugins
52
*.exe
63
*.exe~
74
*.dll
85
*.so
96
*.dylib
7+
.DS_Store
108

119
# Test binary, built with `go test -c`
1210
*.test
1311

1412
# Output of the go coverage tool, specifically when used with LiteIDE
1513
*.out
16-
14+
target/
15+
bin/
1716
# Dependency directories (remove the comment below to include it)
18-
# vendor/
17+
vendor/
18+
.vscode/
19+
.vscode
20+
21+
dist/
22+
.idea/
23+
# ignore settings file as it could contain secrets
24+
settings.yaml
1925

20-
# Go workspace file
21-
go.work
22-
go.work.sum
26+
test.json
2327

24-
# env file
25-
.env
28+
_playground

Makefile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.PHONY: all deps clean docker test fmt lint install
2+
3+
TAGS =
4+
5+
INSTALL_DIR = $(GOPATH)/bin
6+
DEST_DIR = ./target
7+
PATHINSTBIN = $(DEST_DIR)/bin
8+
PATHINSTDOCKER = $(DEST_DIR)/docker
9+
10+
VERSION := $(shell git describe --tags || echo "v0.0.0")
11+
VER_CUT := $(shell echo $(VERSION) | cut -c2-)
12+
VER_MAJOR := $(shell echo $(VER_CUT) | cut -f1 -d.)
13+
VER_MINOR := $(shell echo $(VER_CUT) | cut -f2 -d.)
14+
VER_PATCH := $(shell echo $(VER_CUT) | cut -f3 -d.)
15+
VER_RC := $(shell echo $(VER_PATCH) | cut -f2 -d-)
16+
DATE := $(shell date +"%Y-%m-%dT%H:%M:%SZ")
17+
18+
LD_FLAGS = -w -s
19+
GO_FLAGS =
20+
DOCS_FLAGS =
21+
22+
APPS = oracle-example
23+
all: $(APPS)
24+
25+
oracle-example:
26+
@go build -o $(PATHINSTBIN)/oracle-example ./cmd/oracle-example
27+
28+
install: $(APPS)
29+
@mkdir -p bin
30+
@cp $(PATHINSTBIN)/oracle-example ./bin/
31+
32+
deps:
33+
@go mod tidy
34+
@go mod vendor
35+
36+
docker: deps
37+
@docker build -f ./resources/docker/Dockerfile . -t dimozone/oracle-example:$(VER_CUT)
38+
@docker tag dimozone/oracle-example:$(VER_CUT) dimozone/oracle-example:latest
39+
40+
fmt:
41+
@go list -f {{.Dir}} ./... | xargs -I{} gofmt -w -s {}
42+
@go mod tidy
43+
44+
lint:
45+
@golangci-lint run ./...
46+
47+
test: $(APPS)
48+
@go test $(GO_FLAGS) -timeout 3m -race ./...
49+
50+
migrate:
51+
@go run ./cmd/oracle-example migrate
52+
53+
sqlboiler:
54+
@sqlboiler psql --no-tests --wipe
55+
56+
addmigration:
57+
@goose -dir internal/db/migrations create rename_me sql
58+
59+
clean:
60+
rm -rf $(PATHINSTBIN)
61+
rm -rf $(DEST_DIR)/dist
62+
rm -rf $(PATHINSTDOCKER)
63+
rm -rf ./vendor

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,28 @@ or require the user to input something specific to that vehicle or PIN code etc.
4545
2. Generate an API key and add your preferred redirect URI
4646
3. Create your Connection License. In the future this will be in the dev console but for now provide your ClientID to your developer relations person at DIMO.
4747
4. Obtain the required Synthetic Device Minting roles - engineers at DIMO will do this for you.
48-
5.
48+
5. Create an Account Abstracted wallet with zerodev, we'll call this the Developer AA Wallet - engineers at DIMO can do this for you.
49+
6. Fund your Developer AA Wallet with some DCX. You can do this from the DIMO Dev Console. Required for the minting operations.
50+
51+
## Onboarding
52+
53+
If you look at the go package `internal/onboarding` you'll see an example we've built for this.
54+
In general, onboarding in this example codebase happens through a couple API endpoints, and then all the operations are handled
55+
by a backend job (we use river for the jobs). Jobs are stored in the database.
56+
57+
THe REST endpoints that handle onboarding are in `internal/app/app.go`. The process of onboarding boils down to:
58+
- Decoding the vehicle's VIN or whatever identifier is used. The example code uses DIMO Protocol decoder. If your VINs are uncommon to decode, please reach out.
59+
- Enrolling the vehicle with your backend, whatever way makes sense to you. Basically it tells your external system it's ok for this Oracle app to connect to it.
60+
- Minting the Vehicle NFT. This creates the on-chain representation of the vehicle, with the owner set to your logged in wallet 0x.
61+
- Minting the Synthetic Device NFT. This represents the connection of the Vehicle NFT to your software connection. Contains your oracle's connection license 0x.
62+
- Optionally Sharing & setting Permissions via DIMO SACD. If you know you'll be sharing vehicles you onboard immediately with a customer for example, you can include SACD permissions.
63+
64+
Minting operations above require your Developer AA Wallet address to have DCX balance to pay for the operations.
65+
66+
### vendor.go file
67+
68+
This implements the onboarding process with your external system. It has a common interface with 2 functions:
69+
- Validate: used to check if the VIN (or identifier) is compatible with your system. You could imagine this calling out to some endpoint in your system that checks.
70+
- Connect: actually onboards the VIN (or identifier) into your system so that it knows to allow connections however you with to implement it - Streaming, grpc, kafka, REST etc.
71+
72+
There is an example struct implementation `ExternalOnboardingService` in this file, but feel free to change it up as needed.

0 commit comments

Comments
 (0)