Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
feat: elastic beanstalk server (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanleecode authored Apr 27, 2023
1 parent 632d5b0 commit 0007d3e
Show file tree
Hide file tree
Showing 25 changed files with 2,020 additions and 2,564 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Elastic Beanstalk Files
.elasticbeanstalk/*
.git
.gitignore
node_modules
www/node_modules
server/node_modules
common/node_modules
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ dist-ssr

.env
tsconfig.tsbuildinfo

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
strict-peer-dependencies=false
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node:18

RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm

WORKDIR /capi-multisig-app

COPY package.json pnpm-lock.yaml pnpm-workspace.yaml /capi-multisig-app/
COPY www/package.json /capi-multisig-app/www/package.json
COPY server/package.json /capi-multisig-app/server/package.json
COPY common/package.json /capi-multisig-app/common/package.json

RUN pnpm install

COPY . /capi-multisig-app/

RUN pnpm run build:server

EXPOSE 5000
CMD [ "node", "server/dist/main.js" ]
17 changes: 17 additions & 0 deletions capi.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { binary, Config } from "capi"

const polkadot = binary("polkadot", "v0.9.38")

export const config: Config = {
server: "https://capi.dev/@v0.1.0-beta.36/",
chains: {
westend: {
url: "wss://westend-rpc.polkadot.io/",
version: "v0.9.40",
},
westendDev: {
binary: polkadot,
chain: "westend-dev",
},
},
}
108 changes: 108 additions & 0 deletions common/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* TODO: import { $runtimeCall, RuntimeCall } from "@capi/westend" */
import * as $ from "scale-codec"

export interface Submit {
type: "submit"
// TODO: call: RuntimeCall
channel: string
signedExtrinsic: string
}

export interface Subscribe {
type: "subscribe"
channel: string
}

export interface Unsubscribe {
type: "unsubscribe"
channel: string
}

export type Input = Submit | Subscribe | Unsubscribe

export const $input: $.Codec<Input> = $.taggedUnion("type", [
$.variant(
"submit",
$.object(
// $.field("call", $runtimeCall),
$.field("channel", $.str),
$.field("signedExtrinsic", $.str),
),
),
$.variant("subscribe", $.object($.field("channel", $.str))),
$.variant("unsubscribe", $.object($.field("channel", $.str))),
])

export interface SubscribeResult {
type: "subscribe"
channel: string
result: "ok" | "error"
}

export interface UnsubscribeResult {
type: "unsubscribe"
channel: string
result: "ok" | "error"
}

export interface SubmitResult {
type: "submit"
channel: string
// TODO: callHash: string
result:
| { status: "future" }
| { status: "ready" }
| { status: "broadcast" }
| { status: "inBlock" }
| { status: "retracted" }
| { status: "finalityTimeout" }
| { status: "finalized"; hash: string }
| { status: "usurped" }
| { status: "dropped" }
| { status: "invalid" }
| { status: "failed" }
}

export type Result = SubmitResult | SubscribeResult | UnsubscribeResult

export const $result: $.Codec<Result> = $.taggedUnion("type", [
$.variant(
"subscribe",
$.object(
$.field("channel", $.str),
$.field("result", $.literalUnion(["ok", "error"] as const)),
),
),
$.variant(
"unsubscribe",
$.object(
$.field("channel", $.str),
$.field("result", $.literalUnion(["ok", "error"] as const)),
),
),
$.variant(
"submit",
$.object(
$.field("channel", $.str),
$.field(
"result",
$.taggedUnion(
"status",
[
$.variant("future"),
$.variant("ready"),
$.variant("broadcast"),
$.variant("inBlock"),
$.variant("retracted"),
$.variant("finalityTimeout"),
$.variant("finalized", $.object($.field("hash", $.str))),
$.variant("usurped"),
$.variant("dropped"),
$.variant("invalid"),
$.variant("failed"),
],
),
),
),
),
])
3 changes: 2 additions & 1 deletion common/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const HI = "World"
export * from "./action.js"
export * from "./models.js"
64 changes: 45 additions & 19 deletions server/models.ts → common/models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
export type Model = Setup | Account
import * as $ from "scale-codec"

export interface Approvals {
/** The block at which the approval was finalized */
blockHash: string
/** The accountId of the voting user */
member: string
}

export const $approvals: $.Codec<Approvals> = $.object(
$.field("blockHash", $.str),
$.field("member", $.str),
)

export interface HistoryItem {
/** The scale-encoded call data */
callData: string
/** Time point of the first approval */
timePoint: [blockNumber: number, txIndex: number]
/** All votes, the first of which is the initiator */
approvals: Approvals[]
/** Whether the proposal was cancelled */
cancelled?: string
}

export const $historyItem: $.Codec<HistoryItem> = $.object(
$.field("callData", $.str),
$.field("timePoint", $.tuple($.u32, $.u32)),
$.field("approvals", $.array($approvals)),
$.optionalField("cancelled", $.str),
)

export interface Setup {
type: "setup"
Expand All @@ -9,7 +39,7 @@ export interface Setup {
/** A human-readable name for the setup */
name: string
/** member accountIds */
members: [user: string, proxy?: string][]
members: [user: string, proxy: string][]
/** The number of signatories a proposal need in order to be executed */
threshold: number
/** The underlying multisig accountId */
Expand All @@ -20,23 +50,17 @@ export interface Setup {
history: HistoryItem[]
}

export interface HistoryItem {
/** The scale-encoded call data */
callData: string
/** Time point of the first approval */
timePoint: [blockNumber: number, txIndex: number]
/** All votes, the first of which is the initiator */
approvals: Approvals[]
/** Whether the proposal was cancelled */
cancelled?: string
}

export interface Approvals {
/** The block at which the approval was finalized */
blockHash: string
/** The accountId of the voting user */
member: string
}
export const $setup: $.Codec<Setup> = $.object(
$.field("type", $.constant<"setup">("setup", $.str)),
$.field("id", $.str),
$.field("genesisHash", $.str),
$.field("name", $.str),
$.field("members", $.array($.tuple($.str, $.str))),
$.field("threshold", $.u32),
$.field("multisig", $.str),
$.field("stash", $.str),
$.field("history", $.array($historyItem)),
)

export interface Account {
type: "account"
Expand All @@ -45,3 +69,5 @@ export interface Account {
/** The setups of which the account is member */
setups: string[]
}

export type Model = Setup | Account
4 changes: 3 additions & 1 deletion common/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"name": "common",
"private": true,
"type": "module"
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts"
}
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.8'
services:
web:
build:
context: ./
ports:
- "80:5000"
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
"www"
],
"dependencies": {
"@capi/westend": "https://capi.dev/frame/wss/westend-rpc.polkadot.io/@latest/pkg.tar",
"@capi/westend": "https://capi.dev/@v0.1.0-beta.36/2c655e26fc9ba86a/westend.tar",
"@capi/westend-dev": "https://capi.dev/@v0.1.0-beta.36/2c655e26fc9ba86a/westend-dev.tar",
"@headlessui/react": "^1.7.11",
"@preact/signals": "^1.1.3",
"@talisman-connect/wallets": "^1.1.3",
"capi": "0.1.0-beta.31",
"capi": "0.1.0-beta.36",
"dotenv": "^16.0.3",
"preact": "^10.12.1",
"react-hook-form": "^7.43.3",
"react-router-dom": "^6.8.1",
"scale-codec": "0.11.0-beta.1",
"scale-codec": "0.11.2",
"tailwind-merge": "^1.10.0",
"vite-tsconfig-paths": "^4.0.5",
"zod": "^3.21.4"
Expand All @@ -25,13 +27,16 @@
"react-dom": "preact/compat"
},
"devDependencies": {
"@types/node": "^18.16.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
"scripts": {
"compile": "tsc -b",
"watch:compile": "npm run compile -- -w",
"watch:server": "npm run watch -w server",
"watch:www": "npm run watch -w www",
"build": "npm run compile && npm run build -w www"
"build": "npm run compile && npm run build -w www",
"build:server": "npm run compile -w server"
}
}
Loading

0 comments on commit 0007d3e

Please sign in to comment.