-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from firstbatchxyz/fix-micro
Fix micro test & code
- Loading branch information
Showing
6 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,37 @@ | ||
// load env variables (put this at top) | ||
import "dotenv/config"; | ||
|
||
import http from "http"; | ||
import { Redis } from "ioredis"; | ||
import { readFileSync } from "fs"; | ||
import { existsSync, readFileSync } from "fs"; | ||
import { SDK } from "hollowdb"; | ||
import { serve } from "micro"; | ||
import type { JWKInterface } from "warp-contracts"; | ||
|
||
import makeServer from "./server"; | ||
import config from "./config"; | ||
import { makeWarp } from "./util"; | ||
import { createCaches } from "./cache"; | ||
|
||
const contractTxId = process.env.CONTRACT_TXID; | ||
const contractTxId = process.env.CONTRACT; | ||
if (!contractTxId) { | ||
throw new Error("Please provide CONTRACT_TXID environment variable."); | ||
} | ||
if (Buffer.from(contractTxId, "base64").toString("hex").length !== 64) { | ||
throw new Error("Invalid CONTRACT_TXID."); | ||
} | ||
const redisClient = new Redis(config.REDIS_URL, { | ||
lazyConnect: false, // explicitly connect | ||
}); | ||
const caches = createCaches(contractTxId, redisClient); | ||
if (!existsSync(config.WALLET_PATH)) { | ||
throw new Error("No wallet found at: " + config.WALLET_PATH); | ||
} | ||
const wallet = JSON.parse(readFileSync(config.WALLET_PATH, "utf-8")) as JWKInterface; | ||
const warp = makeWarp(caches); | ||
|
||
const hollowdb = new SDK(wallet, contractTxId, warp); | ||
|
||
// module.exports needed by Micro | ||
module.exports = makeServer(hollowdb, contractTxId); | ||
const server = new http.Server(serve(makeServer(hollowdb, contractTxId))); | ||
|
||
server.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1933,7 +1933,36 @@ argparse@^2.0.1: | |
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" | ||
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== | ||
|
||
arlocal@^1.1.59, arlocal@^1.1.60: | ||
[email protected]: | ||
version "1.1.62" | ||
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.62.tgz#aecb7e8bc2e915a7e4be8c82b74a0a694c5a080a" | ||
integrity sha512-BnpolFe3obbQBGKvvkvrAZ4oleLHox7Xcly2l896cHzysPqvo8C9lYofUiQKYcprHIhHH1F7AFLrxAvZq5yQLQ== | ||
dependencies: | ||
"@koa/cors" "^3.1.0" | ||
apollo-server-koa "^3.6.2" | ||
arbundles "^0.6.19" | ||
arweave-bundles "^1.0.3" | ||
asn1.js "5.4.1" | ||
bignumber.js "^9.0.2" | ||
bytes "^3.1.2" | ||
graphql "^16.2.0" | ||
knex "^0.95.6" | ||
koa "^2.13.4" | ||
koa-body "^4.2.0" | ||
koa-bodyparser "^4.3.0" | ||
koa-json "^2.0.2" | ||
koa-logger "^3.2.1" | ||
koa-router "^10.1.1" | ||
lodash "^4.17.21" | ||
mime "^3.0.0" | ||
minimist "^1.2.5" | ||
moment "^2.29.1" | ||
rfc4648 "^1.5.1" | ||
smartweave "^0.4.46" | ||
sqlite3 "^5.0.3" | ||
tsc-watch "^4.6.0" | ||
|
||
arlocal@^1.1.59: | ||
version "1.1.64" | ||
resolved "https://registry.yarnpkg.com/arlocal/-/arlocal-1.1.64.tgz#153f6bdb8fdc8840813f4d147ac60d4c50d1b81a" | ||
integrity sha512-623LT99n+TVYYO7USXaETN+uTOcZOWxMbMtdnlQ6uGWiroGJzu13jSsB0w3Q0JHsaiOwIHG5tZFNVUpNCplrNQ== | ||
|