Skip to content

Commit

Permalink
local fuzd service
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Nov 12, 2023
1 parent 10abe09 commit dc6b495
Show file tree
Hide file tree
Showing 10 changed files with 833 additions and 10 deletions.
4 changes: 4 additions & 0 deletions helper-services/fuzd/.dev.vars.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CHAIN_0x7a69="http://127.0.0.1:8545#finality=2&worstCaseBlockTime=5"
CHAIN_0xbb272="http://ethereum.local:8545#finality=2&worstCaseBlockTime=5"
HD_MNEMONIC="test test test test test test test test test test test junk"
TOKEN_ADMIN="random-token"
5 changes: 5 additions & 0 deletions helper-services/fuzd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.dev.vars
!.default
.wrangler
node_modules
contracts.json
20 changes: 20 additions & 0 deletions helper-services/fuzd/cron.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const toml = require('toml');
const cron = require('node-cron');
const fs = require('fs');
const path = require('path');

const wranglerConfigStr = fs.readFileSync(path.join(__dirname, 'wrangler.toml'), 'utf-8');
const config = toml.parse(wranglerConfigStr);

if (config.triggers?.crons) {
for (const trigger of config.triggers.crons) {
cron.schedule(trigger, async () => {
console.log(`triggering ${trigger} ... `)
try {
await fetch(`http://localhost:34002/cdn-cgi/mf/scheduled?cron=${trigger}`)
} catch(e) {
console.log(`failed to fetch...`, e)
}
})
}
}
19 changes: 19 additions & 0 deletions helper-services/fuzd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "fuzd-service",
"devDependencies": {
"fuzd-cf-worker": "^0.0.19",
"ldenv": "^0.3.7",
"node-cron": "^3.0.2",
"set-defaults": "^0.0.1",
"toml": "^3.0.0",
"wait-on": "^7.0.1",
"wrangler": "^3.9.0"
},
"scripts": {
"prepare": "set-defaults .",
"dev:cron": "node cron.js",
"dev:worker": "wrangler dev -c ./wrangler.toml --port 34002",
"dev": "pnpm run /^dev:.*/",
"wrangler": "wrangler"
}
}
24 changes: 24 additions & 0 deletions helper-services/fuzd/wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name = "fuzd-worker"
main = "node_modules/fuzd-cf-worker/src/index.ts"
compatibility_date = "2023-05-18"

[vars]

# The necessary secrets are:
# - HD_MNEMONIC
# - CHAIN_0x<CHAINID>
# see in .dev.vars.default
# Run `echo <VALUE> | wrangler secret put <NAME>` for each of these


[durable_objects]
bindings = [
{ name = "SCHEDULER", class_name = "SchedulerDO" }
]

[[migrations]]
tag = "v1"
new_classes = ["SchedulerDO"]

[triggers]
crons = ["* * * * *", "*/1 * * * *"]
4 changes: 4 additions & 0 deletions jolly-roger.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"name": "docs",
"path": "./docs"
},
{
"name": "helper-services",
"path": "./helper-services"
},
{
"name": "ROOT",
"path": "./"
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"common:dev": "pnpm --filter ./common dev",
"contracts:test": "pnpm --filter ./contracts test",
"contracts:docs": "ldenv -m localhost pnpm run --filter ./contracts docgen @@MODE -o ../docs/contracts",
"fuzd:dev": "pnpm --filter ./helper-services/fuzd dev",
"---------------------- DOCS ----------------------": "",
"docs:dev": "pnpm contracts:docs && vitepress dev docs",
"docs:build": "pnpm contracts:docs && vitepress build docs",
Expand Down
Loading

0 comments on commit dc6b495

Please sign in to comment.