Skip to content

Commit

Permalink
update chain height api (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
DLHTX authored Oct 17, 2023
1 parent 357d79c commit 8728ce8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 39 deletions.
66 changes: 45 additions & 21 deletions prisma/full.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ model t_applet {

model t_event_log {
f_id BigInt @id @default(autoincrement())
f_event_id BigInt @unique(map: "t_event_log_ui_event_id")
f_event_id String @db.VarChar(255)
f_project_id BigInt
f_applet_id BigInt
f_publisher_id BigInt
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_published_at BigInt
f_received_at BigInt
f_responded_at BigInt
@@index([f_project_id], map: "t_event_log_i_applet_id")
@@index([f_project_id], map: "t_event_log_i_project_id")
@@index([f_publisher_id], map: "t_event_log_i_publisher_id")
@@index([f_event_id], map: "t_event_log_i_event_id")
@@schema("applet_management")
}

Expand All @@ -75,6 +78,7 @@ model t_project {
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_public Int @default(2)
@@unique([f_project_id, f_deleted_at], map: "t_project_ui_project_id")
@@unique([f_name, f_deleted_at], map: "t_project_ui_name")
Expand Down Expand Up @@ -142,12 +146,12 @@ model t_wasm_log {
f_project_name String @db.VarChar(255)
f_applet_name String @default("") @db.VarChar(255)
f_instance_id BigInt @default(0)
f_src String @default("") @db.VarChar(255)
f_level String @default("") @db.VarChar(255)
f_log_time BigInt @default(0)
f_msg String @default("") @db.VarChar(1024)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_src String @default("") @db.VarChar(255)
@@schema("applet_management")
}
Expand Down Expand Up @@ -212,13 +216,14 @@ model t_chain_height {
f_finished Int @default(2)
f_uniq BigInt @default(0)
f_event_type String @db.VarChar(255)
f_chain_id BigInt
f_chain_id BigInt @default(0)
f_height BigInt
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_paused Int @default(2)
f_chain_name String @default("") @db.VarChar(255)
@@unique([f_project_name, f_event_type, f_chain_id, f_height, f_uniq], map: "t_chain_height_ui_chain_height_uniq")
@@unique([f_project_name, f_event_type, f_chain_id, f_chain_name, f_height, f_uniq], map: "t_chain_height_ui_chain_height_uniq")
@@schema("monitor")
}

Expand Down Expand Up @@ -275,10 +280,10 @@ model t_account_access_key {
f_name String @db.VarChar(255)
f_access_key String @db.VarChar(255)
f_expired_at BigInt @default(0)
f_desc String @default("") @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_desc String @default("") @db.VarChar(255)
@@unique([f_access_key, f_deleted_at], map: "t_account_access_key_ui_access_key")
@@unique([f_account_id, f_name, f_deleted_at], map: "t_account_access_key_ui_account_key_name")
Expand Down Expand Up @@ -319,15 +324,16 @@ model t_account_password {
}

model t_operator {
f_id BigInt @id @default(autoincrement())
f_account_id BigInt
f_operator_id BigInt
f_private_key String @db.VarChar(255)
f_name String @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_type Int @default(1)
f_id BigInt @id @default(autoincrement())
f_account_id BigInt
f_operator_id BigInt
f_private_key String @db.VarChar(255)
f_name String @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_type Int @default(1)
f_paymaster_key String @default("") @db.VarChar(255)
@@unique([f_account_id, f_name, f_deleted_at], map: "t_operator_ui_name")
@@unique([f_operator_id, f_deleted_at], map: "t_operator_ui_operator_id")
Expand Down Expand Up @@ -366,16 +372,39 @@ model t_traffic_limit {
f_threshold Int
f_duration BigInt
f_api_type Int
f_start_at BigInt @default(0)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_start_at BigInt @default(0)
@@unique([f_project_id, f_api_type, f_deleted_at], map: "t_traffic_limit_ui_prj_api_type")
@@unique([f_traffic_limit_id, f_deleted_at], map: "t_traffic_limit_ui_traffic_limit_id")
@@schema("applet_management")
}

model t_transaction {
f_id BigInt @id @default(autoincrement())
f_transaction_id BigInt
f_project_id BigInt
f_chain_name String @db.VarChar(255)
f_nonce BigInt @default(0)
f_hash String @default("") @db.VarChar(255)
f_sender String @default("") @db.VarChar(255)
f_receiver String @default("") @db.VarChar(255)
f_value String @default("") @db.VarChar(255)
f_data String @default("") @db.VarChar(255)
f_operator_name String @default("") @db.VarChar(255)
f_state Int @default(0)
f_event_type String @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
@@unique([f_transaction_id, f_deleted_at], map: "t_transaction_ui_transaction_id")
@@index([f_project_id], map: "t_transaction_i_project_id")
@@schema("applet_management")
}

model monitor_t_sql_meta_enum {
f_table_name String @db.VarChar(64)
f_column_name String @db.VarChar(64)
Expand All @@ -388,8 +417,3 @@ model monitor_t_sql_meta_enum {
@@map("t_sql_meta_enum")
@@schema("monitor")
}





22 changes: 12 additions & 10 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ model t_publisher {
}

model t_strategy {
f_id BigInt @id @default(autoincrement())
f_strategy_id BigInt
f_project_id BigInt
f_applet_id BigInt
f_event_type String @db.VarChar(255)
f_handler String @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_id BigInt @id @default(autoincrement())
f_strategy_id BigInt
f_project_id BigInt
f_applet_id BigInt
f_event_type String @db.VarChar(255)
f_handler String @db.VarChar(255)
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_deleted_at BigInt @default(0)
f_auto_collect_metric Int @default(2)
applet t_applet @relation(fields: [f_applet_id], references: [f_applet_id])
Expand Down Expand Up @@ -239,10 +239,12 @@ model t_chain_height {
f_height BigInt
f_created_at BigInt @default(0)
f_updated_at BigInt @default(0)
f_paused Int @default(2)
f_chain_name String @default("") @db.VarChar(255)
project t_project @relation(fields: [f_project_name], references: [f_name])
@@unique([f_project_name, f_event_type, f_chain_id, f_height, f_uniq], map: "t_chain_height_ui_chain_height_uniq")
@@unique([f_project_name, f_event_type, f_chain_id, f_chain_name, f_height, f_uniq], map: "t_chain_height_ui_chain_height_uniq")
@@schema("monitor")
}

Expand Down
8 changes: 6 additions & 2 deletions src/server/routers/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const envRouter = t.router({
async () => {
let w3bstreamVersion = '';
let blockChains: BlockchainType[] = [];
let allBlockChains: BlockchainType[] = [];


try {
const url = `${process.env.NEXT_PUBLIC_API_URL}/version`;
Expand All @@ -33,13 +35,15 @@ export const envRouter = t.router({
if (i.chainID) {
blockChains.push({ f_id: BigInt(i.chainID), f_chain_id: BigInt(i.chainID), f_chain_address: i.endpoint, f_chain_name: i.name })
}
allBlockChains.push({ f_chain_address: i.endpoint, f_chain_name: i.name })
})
} catch (error) {
console.error(error);
}

return {
blockChains,
allBlockChains,
w3bstreamVersion,
studioVersion: 'v' + pkg.version,
httpURL: process.env.NEXT_PUBLIC_GATEWAY_HTTP_URL || 'https://dev.w3bstream.com/api/w3bapp/event/:projectName',
Expand All @@ -55,8 +59,8 @@ export const envRouter = t.router({
export type EnvRouter = typeof envRouter;
export type EnvsType = inferProcedureOutput<EnvRouter['envs']>;
export type BlockchainType = {
f_id: bigint;
f_chain_id: bigint;
f_id?: bigint;
f_chain_id?: bigint;
f_chain_address: string;
f_chain_name: string;
};
3 changes: 2 additions & 1 deletion src/server/routers/w3bstream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export const w3bstreamRouter = t.router({
f_chain_id: true,
f_height: true,
f_created_at: true,
f_updated_at: true
f_updated_at: true,
f_chain_name: true
}
},
chainTxs: {
Expand Down
21 changes: 16 additions & 5 deletions src/store/lib/w3bstream/schema/chainHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ export const schema = {
properties: {
projectName: { $ref: '#/definitions/projects', title: 'Project Name' },
eventType: { type: 'string', title: 'Event Type', description: 'Please choose a unique name for the W3bstream event that should be triggered' },
chainID: { $ref: '#/definitions/blockChains', type: 'string', title: 'Chain ID', description: 'The blockchain network that should be monitored' },
chainName: { $ref: '#/definitions/blockChainNames', type: 'string', title: 'Chain Name', description: 'The blockchain network that should be monitored' },
height: { type: 'number', title: 'Height', description: 'The blockchain height at which the the W3bstream event should be triggered.' }
},
required: ['projectName', 'eventType', 'chainID', 'height']
required: ['projectName', 'eventType', 'chainName', 'height']
} as const;

type SchemaType = FromSchema<typeof schema>;

//@ts-ignore
schema.definitions = {
projects: definitions.projectName,
blockChains: definitions.blockChains
blockChainNames: definitions.blockChainNames
};

export default class ChainHeightModule {
Expand Down Expand Up @@ -87,7 +87,18 @@ export default class ChainHeightModule {
},
{
key: 'f_chain_id',
label: 'Chain ID'
label: 'Chain Name',
render: (item) => {
if (item.f_chain_name) {
return item.f_chain_name
} else {
try {
return globalThis.store.w3s.env.envs.value?.blockChains.find(i => i.f_chain_id == item.f_chain_id)?.f_chain_name || ''
} catch (e) {
return item.f_chain_id
}
}
}
},
{
key: 'f_height',
Expand Down Expand Up @@ -119,7 +130,7 @@ export default class ChainHeightModule {
default: {
projectName: '',
eventType: 'DEFAULT',
chainID: '4690',
chainName: '',
height: 0
}
})
Expand Down
11 changes: 11 additions & 0 deletions src/store/lib/w3bstream/schema/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export const definitions = {
return blockChains.map((i) => `${i.f_chain_name}`);
}
},
blockChainNames: {
type: 'string',
get enum() {
const blockChains = globalThis.store.w3s.env.envs.value?.allBlockChains || [];
return blockChains.map((i) => `${i.f_chain_name}`);
},
get enumNames() {
const blockChains = globalThis.store.w3s.env.envs.value?.allBlockChains || [];
return blockChains.map((i) => `${i.f_chain_name}`);
}
},
labContracts: {
type: 'string',
get enum() {
Expand Down

0 comments on commit 8728ce8

Please sign in to comment.