-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update to ORM * fix: remove test from GitHub action * chore: remove year
- Loading branch information
1 parent
671fba7
commit 067135d
Showing
17 changed files
with
470 additions
and
3,276 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
DATABASE_URL=mysql://root:default_password@localhost:3306/checkpoint | ||
|
||
DATABASE_URL=mysql://user:password@host:port/database |
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,7 +1,7 @@ | ||
name: Build and Run Tests | ||
name: Lint and build | ||
on: [push] | ||
jobs: | ||
build-test: | ||
lint-build: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
@@ -16,6 +16,5 @@ jobs: | |
- run: yarn install | ||
- run: yarn lint | ||
- run: yarn build | ||
- run: yarn test | ||
env: | ||
DATABASE_URL: 'mysql://root:[email protected]:3306/checkpoint' |
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 |
---|---|---|
|
@@ -9,3 +9,6 @@ coverage | |
.idea | ||
.vscode | ||
*.log | ||
|
||
# Checkpoint | ||
.checkpoint |
This file was deleted.
Oops, something went wrong.
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,44 +1,35 @@ | ||
{ | ||
"name": "@snapshot-labs/checkpoint-template", | ||
"version": "1.0.0", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"description": "Checkpoint starter template", | ||
"main": "dist/src/index.js", | ||
"repository": "[email protected]:snapshot-labs/checkpoint-template.git", | ||
"scripts": { | ||
"lint": "eslint src/ test/ --ext .ts --fix", | ||
"build": "tsc -p tsconfig.build.json", | ||
"codegen": "checkpoint generate", | ||
"lint": "eslint src/ --ext .ts --fix", | ||
"prebuild": "yarn codegen", | ||
"build": "tsc", | ||
"dev": "nodemon src/index.ts", | ||
"start": "node dist/src/index.js", | ||
"test": "jest" | ||
"start": "node dist/src/index.js" | ||
}, | ||
"author": "Snapshot Labs", | ||
"license": "MIT", | ||
"eslintConfig": { | ||
"extends": "@snapshot-labs" | ||
}, | ||
"prettier": "@snapshot-labs/prettier-config", | ||
"dependencies": { | ||
"@ethersproject/address": "^5.6.0", | ||
"@ethersproject/bignumber": "^5.6.1", | ||
"@snapshot-labs/checkpoint": "^0.1.0-beta.25", | ||
"@snapshot-labs/sx": "^0.1.0-beta.44", | ||
"@snapshot-labs/checkpoint": "^0.1.0-beta.26", | ||
"@types/node": "^18.11.6", | ||
"cors": "^2.8.5", | ||
"dotenv": "^16.0.1", | ||
"express": "^4.18.1", | ||
"starknet": "^5.19.3" | ||
"nodemon": "^2.0.19", | ||
"starknet": "^5.19.3", | ||
"ts-node": "^10.8.1", | ||
"typescript": "^4.9.3" | ||
}, | ||
"devDependencies": { | ||
"@types/bn.js": "^5.1.0", | ||
"@types/express": "^4.17.13", | ||
"@types/jest": "^27.5.1", | ||
"@types/mysql": "^2.15.21", | ||
"@types/node": "^20.8.10", | ||
"@typescript-eslint/eslint-plugin": "^5.25.0", | ||
"@typescript-eslint/parser": "^5.25.0", | ||
"eslint": "^8.15.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"jest": "^28.1.0", | ||
"jest-mock-extended": "^2.0.6", | ||
"nodemon": "^2.0.16", | ||
"prettier": "^2.6.2", | ||
"ts-jest": "^28.0.2", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.9.3" | ||
"@snapshot-labs/eslint-config": "^0.1.0-beta.7", | ||
"@snapshot-labs/prettier-config": "^0.1.0-beta.7", | ||
"eslint": "^8.28.0", | ||
"prettier": "^2.8.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
[ | ||
{ | ||
"data": [ | ||
{ | ||
"name": "address", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "content_len", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "content", | ||
"type": "felt*" | ||
}, | ||
{ | ||
"name": "tag_len", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "tag", | ||
"type": "felt*" | ||
} | ||
], | ||
"keys": [], | ||
"name": "new_post", | ||
"type": "event" | ||
}, | ||
{ | ||
"name": "post", | ||
"type": "function", | ||
"inputs": [ | ||
{ | ||
"name": "content_len", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "content", | ||
"type": "felt*" | ||
}, | ||
{ | ||
"name": "tag_len", | ||
"type": "felt" | ||
}, | ||
{ | ||
"name": "tag", | ||
"type": "felt*" | ||
} | ||
], | ||
"outputs": [] | ||
} | ||
] |
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,16 +1,5 @@ | ||
import { getAddress } from '@ethersproject/address'; | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { shortStringArrToStr } from '@snapshot-labs/sx/dist/utils/strings'; | ||
import { shortString } from 'starknet'; | ||
|
||
export const toAddress = bn => { | ||
try { | ||
return getAddress(BigNumber.from(bn).toHexString()); | ||
} catch (e) { | ||
return bn; | ||
} | ||
}; | ||
|
||
export const hexStrArrToStr = (data, start: number, length: number | bigint): string => { | ||
const dataSlice = data.slice(start, start + Number(length)); | ||
return shortStringArrToStr(dataSlice.map(m => BigInt(m))); | ||
}; | ||
export function longStringToText(array: string[]): string { | ||
return array.reduce((acc, slice) => acc + shortString.decodeShortString(slice), ''); | ||
} |
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,53 +1,22 @@ | ||
import { hexStrArrToStr, toAddress } from './utils'; | ||
import type { CheckpointWriter } from '@snapshot-labs/checkpoint'; | ||
import { validateAndParseAddress } from 'starknet'; | ||
import { CheckpointWriter } from '@snapshot-labs/checkpoint'; | ||
import { Post } from '../.checkpoint/models'; | ||
import { longStringToText } from './utils'; | ||
|
||
export async function handleDeploy() { | ||
// Run logic as at the time Contract was deployed. | ||
} | ||
export const handleNewPost: CheckpointWriter = async ({ block, tx, rawEvent, event }) => { | ||
if (!block || !event || !rawEvent) return; | ||
|
||
// This decodes the new_post events data and stores successfully | ||
// decoded information in the `posts` table. | ||
// | ||
// See here for the original logic used to create post transactions: | ||
// https://gist.github.com/perfectmak/417a4dab69243c517654195edf100ef9#file-index-ts | ||
export async function handleNewPost({ block, tx, event, mysql }: Parameters<CheckpointWriter>[0]) { | ||
if (!block || !event) return; | ||
const author = validateAndParseAddress(rawEvent.from_address); | ||
const content = longStringToText(event.content); | ||
const tag = longStringToText(event.tag); | ||
|
||
const author = toAddress(event.data[0]); | ||
let content = ''; | ||
let tag = ''; | ||
const contentLength = BigInt(event.data[1]); | ||
const tagLength = BigInt(event.data[2 + Number(contentLength)]); | ||
const timestamp = block.timestamp; | ||
const blockNumber = block.block_number; | ||
const post = new Post(`${author}/${tx.transaction_hash}`); | ||
post.author = author; | ||
post.content = content; | ||
post.tag = tag; | ||
post.tx_hash = tx.transaction_hash; | ||
post.created_at = block.timestamp; | ||
post.created_at_block = block.block_number; | ||
|
||
// parse content bytes | ||
try { | ||
content = hexStrArrToStr(event.data, 2, contentLength); | ||
} catch (e) { | ||
console.error(`failed to decode content on block [${blockNumber}]: ${e}`); | ||
return; | ||
} | ||
|
||
// parse tag bytes | ||
try { | ||
tag = hexStrArrToStr(event.data, 3 + Number(contentLength), tagLength); | ||
} catch (e) { | ||
console.error(`failed to decode tag on block [${blockNumber}]: ${e}`); | ||
return; | ||
} | ||
|
||
// post object matches fields of Post type in schema.gql | ||
const post = { | ||
id: `${author}/${tx.transaction_hash}`, | ||
author, | ||
content, | ||
tag, | ||
tx_hash: tx.transaction_hash, | ||
created_at: timestamp, | ||
created_at_block: blockNumber | ||
}; | ||
|
||
// table names are `lowercase(TypeName)s` and can be interacted with sql | ||
await mysql.queryAsync('INSERT IGNORE INTO posts SET ?', [post]); | ||
} | ||
await post.save(); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.