fix(prisma): header schema

This commit is contained in:
Wanseob Lim
2020-06-05 15:32:54 +09:00
parent 7aa2f5fcde
commit 20dcc88b41
9 changed files with 492 additions and 14 deletions

View File

@@ -13,6 +13,7 @@
"scripts": {
"build:prisma": "prisma generate",
"migrate-save": "prisma migrate save --experimental",
"migrate-up": "prisma migrate up --experimental",
"prebuild": "shx mkdir -p dist",
"build": "tsc --build tsconfig.build.json",
"clean": "tsc --build tsconfig.build.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache",

Binary file not shown.

View File

@@ -0,0 +1,136 @@
# Migration `20200605153155-change-header`
This migration has been generated by Wanseob Lim at 6/5/2020, 3:31:55 PM.
You can check out the [state of the schema](./schema.prisma) after the migration.
## Database Steps
```sql
PRAGMA foreign_keys=OFF;
CREATE TABLE "quaint"."EncryptedWallet" (
"N" INTEGER NOT NULL ,"algorithm" TEXT NOT NULL ,"ciphertext" TEXT NOT NULL ,"id" TEXT NOT NULL ,"iv" TEXT NOT NULL ,"kdf" TEXT NOT NULL ,"keylen" INTEGER NOT NULL ,"p" INTEGER NOT NULL ,"r" INTEGER NOT NULL ,"salt" TEXT NOT NULL ,
PRIMARY KEY ("id"))
CREATE TABLE "quaint"."Keystore" (
"address" TEXT NOT NULL ,"encrypted" TEXT NOT NULL ,"pubKey" TEXT NOT NULL ,
PRIMARY KEY ("address"))
CREATE TABLE "quaint"."Config" (
"address" TEXT NOT NULL ,"chainId" INTEGER NOT NULL ,"challengePeriod" INTEGER NOT NULL ,"id" TEXT NOT NULL ,"maxUtxoPerTree" TEXT NOT NULL ,"maxWithdrawalPerTree" TEXT NOT NULL ,"minimumStake" TEXT NOT NULL ,"networkId" INTEGER NOT NULL ,"nullifierTreeDepth" INTEGER NOT NULL ,"referenceDepth" INTEGER NOT NULL ,"txoTreeDepth" INTEGER NOT NULL ,"utxoSubTreeDepth" INTEGER NOT NULL ,"utxoSubTreeSize" INTEGER NOT NULL ,"withdrawalSubTreeDepth" INTEGER NOT NULL ,"withdrawalSubTreeSize" INTEGER NOT NULL ,"withdrawalTreeDepth" INTEGER NOT NULL ,
PRIMARY KEY ("id"),FOREIGN KEY ("id") REFERENCES "ZkOPRUChain"("id") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE TABLE "quaint"."ZkOPRUChain" (
"id" TEXT NOT NULL ,
PRIMARY KEY ("id"))
CREATE TABLE "quaint"."Block" (
"chainId" TEXT ,"hash" TEXT NOT NULL ,"proposalData" TEXT NOT NULL ,"proposalNum" INTEGER NOT NULL ,"proposalTx" TEXT NOT NULL ,"proposedAt" INTEGER NOT NULL ,"status" INTEGER NOT NULL ,
PRIMARY KEY ("hash"),FOREIGN KEY ("hash") REFERENCES "Header"("hash") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ("hash") REFERENCES "Bootstrap"("hash") ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY ("chainId") REFERENCES "ZkOPRUChain"("id") ON DELETE SET NULL ON UPDATE CASCADE)
CREATE TABLE "quaint"."Header" (
"depositRoot" TEXT NOT NULL ,"fee" TEXT NOT NULL ,"hash" TEXT NOT NULL ,"metadata" TEXT NOT NULL ,"migrationRoot" TEXT NOT NULL ,"nullifierRoot" TEXT NOT NULL ,"parentBlock" TEXT NOT NULL ,"proposer" TEXT NOT NULL ,"txRoot" TEXT NOT NULL ,"utxoIndex" TEXT NOT NULL ,"utxoRoot" TEXT NOT NULL ,"withdrawalIndex" TEXT NOT NULL ,"withdrawalRoot" TEXT NOT NULL ,
PRIMARY KEY ("hash"))
CREATE TABLE "quaint"."Bootstrap" (
"hash" TEXT NOT NULL ,"utxoBootstrap" TEXT NOT NULL ,"utxoTreeIndex" INTEGER NOT NULL ,"withdrawalBootstrap" TEXT NOT NULL ,"withdrawalTreeIndex" INTEGER NOT NULL ,
PRIMARY KEY ("hash"))
CREATE TABLE "quaint"."MassDeposit" (
"blockNumber" INTEGER NOT NULL ,"fee" TEXT NOT NULL ,"includedIn" TEXT ,"index" TEXT NOT NULL ,"merged" TEXT NOT NULL ,
PRIMARY KEY ("index"),FOREIGN KEY ("includedIn") REFERENCES "Block"("hash") ON DELETE SET NULL ON UPDATE CASCADE)
CREATE TABLE "quaint"."Deposit" (
"blockNumber" INTEGER NOT NULL ,"fee" TEXT NOT NULL ,"includedIn" TEXT ,"logIndex" INTEGER NOT NULL ,"note" TEXT NOT NULL ,"queuedAt" TEXT ,"transactionIndex" INTEGER NOT NULL ,
PRIMARY KEY ("note"),FOREIGN KEY ("queuedAt") REFERENCES "MassDeposit"("index") ON DELETE SET NULL ON UPDATE CASCADE)
CREATE TABLE "quaint"."Nullifier" (
"blockHash" TEXT NOT NULL ,"index" TEXT NOT NULL ,"nullified" BOOLEAN NOT NULL ,
PRIMARY KEY ("index"))
CREATE TABLE "quaint"."Note" (
"erc20Amount" TEXT ,"eth" TEXT ,"fee" TEXT ,"hash" TEXT NOT NULL ,"index" TEXT ,"nft" TEXT ,"pubKey" TEXT ,"salt" TEXT ,"status" INTEGER ,"tokenAddr" TEXT ,"treeId" TEXT ,"type" INTEGER ,"withdrawOutTo" TEXT ,
PRIMARY KEY ("hash"),FOREIGN KEY ("treeId") REFERENCES "LightTree"("id") ON DELETE SET NULL ON UPDATE CASCADE)
CREATE TABLE "quaint"."TreeNode" (
"nodeIndex" TEXT NOT NULL ,"treeId" TEXT NOT NULL ,"value" TEXT NOT NULL ,
PRIMARY KEY ("treeId","nodeIndex"))
CREATE TABLE "quaint"."LightTree" (
"block" TEXT ,"end" TEXT NOT NULL ,"id" TEXT NOT NULL ,"index" TEXT NOT NULL ,"root" TEXT NOT NULL ,"siblings" TEXT NOT NULL ,"species" INTEGER NOT NULL ,"start" TEXT NOT NULL ,"treeIndex" INTEGER NOT NULL ,"zkopru" TEXT NOT NULL ,
PRIMARY KEY ("id"),FOREIGN KEY ("zkopru") REFERENCES "ZkOPRUChain"("id") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE TABLE "quaint"."NullifierTree" (
"block" TEXT ,"id" TEXT NOT NULL ,"root" TEXT NOT NULL ,"siblings" TEXT NOT NULL ,"treeIndex" INTEGER NOT NULL ,"zkopru" TEXT NOT NULL ,
PRIMARY KEY ("id"),FOREIGN KEY ("zkopru") REFERENCES "ZkOPRUChain"("id") ON DELETE CASCADE ON UPDATE CASCADE)
CREATE UNIQUE INDEX "quaint"."Config_id" ON "Config"("id")
CREATE INDEX "quaint"."LightTree.species_treeIndex" ON "LightTree"("species","treeIndex")
CREATE UNIQUE INDEX "quaint"."NullifierTree.treeIndex" ON "NullifierTree"("treeIndex")
CREATE UNIQUE INDEX "quaint"."NullifierTree_zkopru" ON "NullifierTree"("zkopru")
PRAGMA "quaint".foreign_key_check;
PRAGMA foreign_keys=ON;
```
## Changes
```diff
diff --git schema.prisma schema.prisma
migration 20200605150020-initial..20200605153155-change-header
--- datamodel.dml
+++ datamodel.dml
@@ -3,14 +3,14 @@
}
datasource sqlite {
provider = "sqlite"
- url = "***"
+ url = env("DATABASE_URL")
}
// datasource posgres {
// provider = "postgres"
-// url = "***"
+// url = env("POSTGRES_URL")
// }
model EncryptedWallet {
id String @id @default(uuid())
@@ -74,20 +74,20 @@
}
model Header {
hash String @id
- txoTreeDepth Int
- withdrawalTreeDepth Int
- nullifierTreeDepth Int
- challengePeriod Int
- minimumStake String
- referenceDepth Int
- maxUtxoPerTree String
- maxWithdrawalPerTree String
- utxoSubTreeDepth Int
- utxoSubTreeSize Int
- withdrawalSubTreeDepth Int
- withdrawalSubTreeSize Int
+ proposer String
+ parentBlock String
+ metadata String
+ fee String
+ utxoRoot String
+ utxoIndex String
+ nullifierRoot String
+ withdrawalRoot String
+ withdrawalIndex String
+ txRoot String
+ depositRoot String
+ migrationRoot String
}
model Bootstrap {
hash String @id
```

View File

@@ -0,0 +1,179 @@
generator client {
provider = "prisma-client-js"
}
datasource sqlite {
provider = "sqlite"
url = "***"
}
// datasource posgres {
// provider = "postgres"
// url = "***"
// }
model EncryptedWallet {
id String @id @default(uuid())
ciphertext String
iv String
algorithm String
keylen Int
kdf String
N Int
r Int
p Int
salt String
}
model Keystore {
address String @id
pubKey String
encrypted String // stringified json
}
model Config {
id String @id @default(uuid())
networkId Int
chainId Int
address String
txoTreeDepth Int
withdrawalTreeDepth Int
nullifierTreeDepth Int
challengePeriod Int
minimumStake String
referenceDepth Int
maxUtxoPerTree String
maxWithdrawalPerTree String
utxoSubTreeDepth Int
utxoSubTreeSize Int
withdrawalSubTreeDepth Int
withdrawalSubTreeSize Int
chain ZkOPRUChain @relation(fields: [id], references: [id])
}
model ZkOPRUChain {
id String @id @default(uuid())
config Config?
nullifierTree NullifierTree
// utxoTrees UtxoTree[]
// withdrawalTrees WithdrawalTree[]
blocks Block[]
}
model Block {
hash String @id
header Header @relation(fields: [hash], references: [hash])
status Int // NOT_FETCHED = 0 / FETCHED = 1 / PARTIALLY_VERIFEID = 2 / FULLY_VERIFIED = 3 / FINALIZED = 4 / INVALIDATED = 5 / REVERTED = 6
proposalNum Int
proposedAt Int
proposalTx String // tx hash
proposalData String // stringified json
bootstrap Bootstrap @relation(fields: [hash], references: [hash])
chainId String?
chain ZkOPRUChain? @relation(fields: [chainId], references: [id])
}
model Header {
hash String @id
proposer String
parentBlock String
metadata String
fee String
utxoRoot String
utxoIndex String
nullifierRoot String
withdrawalRoot String
withdrawalIndex String
txRoot String
depositRoot String
migrationRoot String
}
model Bootstrap {
hash String @id
utxoTreeIndex Int
// utxoBootstrap String[]
utxoBootstrap String // jsonified arr : sqlite does not support arr
withdrawalTreeIndex Int
// withdrawalBootstrap String[]
withdrawalBootstrap String //jsonified arr : sqlite does not support arr
}
model MassDeposit {
index String @id
merged String
fee String
blockNumber Int
includedIn String?
block Block? @relation(fields: [includedIn], references: [hash])
deposits Deposit[]
}
model Deposit {
note String @id
fee String
transactionIndex Int
logIndex Int
blockNumber Int
queuedAt String?
includedIn String?
massDeposit MassDeposit? @relation(fields: [queuedAt], references: [index])
}
model Nullifier {
index String @id
nullified Boolean
blockHash String
}
model Note {
hash String @id
index String?
eth String?
pubKey String?
salt String?
tokenAddr String?
erc20Amount String?
nft String?
type Int?
withdrawOutTo String?
fee String?
status Int?
treeId String?
tree LightTree? @relation(fields: [treeId], references: [id])
}
model TreeNode {
treeId String
nodeIndex String
value String
// tree UtxoTree @relation(fields: [treeId], references: [id])
@@id([treeId, nodeIndex])
}
model LightTree {
id String @id @default(uuid())
species Int // 0: utxo 1: withdrawal
treeIndex Int
zkopru String
block String?
// rollup sync data
start String
end String
// rollup snapshot data
root String
index String
siblings String // stringified str[]
chain ZkOPRUChain @relation(fields: [zkopru], references: [id])
@@index([species, treeIndex])
}
model NullifierTree {
id String @id @default(uuid())
zkopru String
treeIndex Int @unique
block String?
root String
siblings String // stringified str[]
chain ZkOPRUChain @relation(fields: [zkopru], references: [id])
}

View File

@@ -0,0 +1,149 @@
{
"version": "0.3.14-fixed",
"steps": [
{
"tag": "CreateField",
"model": "Header",
"field": "proposer",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "parentBlock",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "metadata",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "fee",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "utxoRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "utxoIndex",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "nullifierRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "withdrawalRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "withdrawalIndex",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "txRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "depositRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "CreateField",
"model": "Header",
"field": "migrationRoot",
"type": "String",
"arity": "Required"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "txoTreeDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "withdrawalTreeDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "nullifierTreeDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "challengePeriod"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "minimumStake"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "referenceDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "maxUtxoPerTree"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "maxWithdrawalPerTree"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "utxoSubTreeDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "utxoSubTreeSize"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "withdrawalSubTreeDepth"
},
{
"tag": "DeleteField",
"model": "Header",
"field": "withdrawalSubTreeSize"
}
]
}

View File

@@ -1,3 +1,4 @@
# Prisma Migrate lockfile v1
20200605150020-initial
20200605150020-initial
20200605153155-change-header

View File

@@ -75,18 +75,18 @@ model Block {
model Header {
hash String @id
txoTreeDepth Int
withdrawalTreeDepth Int
nullifierTreeDepth Int
challengePeriod Int
minimumStake String
referenceDepth Int
maxUtxoPerTree String
maxWithdrawalPerTree String
utxoSubTreeDepth Int
utxoSubTreeSize Int
withdrawalSubTreeDepth Int
withdrawalSubTreeSize Int
proposer String
parentBlock String
metadata String
fee String
utxoRoot String
utxoIndex String
nullifierRoot String
withdrawalRoot String
withdrawalIndex String
txRoot String
depositRoot String
migrationRoot String
}
model Bootstrap {

BIN
packages/prisma/schema.db Normal file

Binary file not shown.

View File

@@ -10,12 +10,24 @@ export enum TreeSpecies {
WITHDRAWAL = 1,
}
export enum BlockStatus {
NOT_FETCHED = 0,
FETCHED = 1,
PARTIALLY_VERIFIED = 2,
FULLY_VERIFIED = 3,
FINALIZED = 4,
INVALIDATED = 5,
REVERTED = 6,
}
export {
LightTree,
TreeNode,
Nullifier,
Keystore,
EncryptedWallet,
Block,
Header,
} from '@prisma/client'
export class DB {
@@ -58,7 +70,7 @@ export class DB {
const dbPath = `${path.join(path.resolve('.'), dbName)}`
const predefined = `${path.join(
path.resolve(__dirname),
'../prisma/schema1.db',
'../prisma/schema.db',
)}`
console.log('predefiend, ', predefined)
fs.promises.copyFile(predefined, dbPath)