增加开箱信息的抓取
This commit is contained in:
parent
f542d62057
commit
66e336c2fa
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@ -17,5 +17,18 @@
|
|||||||
],
|
],
|
||||||
"type": "pwa-node"
|
"type": "pwa-node"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug Scription",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeArgs": [
|
||||||
|
"run-script",
|
||||||
|
"dev:scription"
|
||||||
|
],
|
||||||
|
"runtimeExecutable": "npm",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"type": "pwa-node"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"chain": 421614,
|
"chain": 421614,
|
||||||
"rpc": "https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3",
|
"rpc": "https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3",
|
||||||
"fromBlock": 5624211,
|
"fromBlock": 26760154,
|
||||||
"filters": [{
|
"filters": [{
|
||||||
"key": "input",
|
"key": "input",
|
||||||
"op": "eq",
|
"op": "eq",
|
||||||
@ -15,5 +15,22 @@
|
|||||||
"value": "0x50a8e60041a206acaa5f844a1104896224be6f39"
|
"value": "0x50a8e60041a206acaa5f844a1104896224be6f39"
|
||||||
}],
|
}],
|
||||||
"dataModel": "CheckIn"
|
"dataModel": "CheckIn"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"chain": 421614,
|
||||||
|
"rpc": "https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3",
|
||||||
|
"fromBlock": 26760154,
|
||||||
|
"filters": [{
|
||||||
|
"key": "input",
|
||||||
|
"op": "like",
|
||||||
|
"type": "regex",
|
||||||
|
"value": "data:,{\"p\":\"cf-20\",\"op\":\"chest_open\",\"id\":\"(.+?)\"}"
|
||||||
|
},{
|
||||||
|
"key": "to",
|
||||||
|
"op": "eq",
|
||||||
|
"type": "address",
|
||||||
|
"value": "0x50a8e60041a206acaa5f844a1104896224be6f39"
|
||||||
|
}],
|
||||||
|
"dataModel": "ChestRecord"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -28,8 +28,10 @@ export class CheckInClass extends BaseModule {
|
|||||||
@prop()
|
@prop()
|
||||||
public dateTag: string
|
public dateTag: string
|
||||||
// 连签天数
|
// 连签天数
|
||||||
@prop({ default: 0 })
|
@prop({ default: 1 })
|
||||||
public count: number
|
public count: number
|
||||||
|
@prop({ default: 1 })
|
||||||
|
public total: number
|
||||||
@prop()
|
@prop()
|
||||||
public value: string
|
public value: string
|
||||||
@prop()
|
@prop()
|
||||||
@ -41,6 +43,8 @@ export class CheckInClass extends BaseModule {
|
|||||||
if (preDayEvent) {
|
if (preDayEvent) {
|
||||||
event.count = preDayEvent.count + 1
|
event.count = preDayEvent.count + 1
|
||||||
}
|
}
|
||||||
|
const total = await CheckIn.countDocuments({ from: event.from })
|
||||||
|
event.total = total + 1
|
||||||
try {
|
try {
|
||||||
await CheckIn.insertOrUpdate({ from: event.from, dateTag: event.dateTag }, event)
|
await CheckIn.insertOrUpdate({ from: event.from, dateTag: event.dateTag }, event)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
60
src/models/ChestRecord.ts
Normal file
60
src/models/ChestRecord.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
|
||||||
|
import { dbconn } from 'decorators/dbconn'
|
||||||
|
import { BaseModule } from './Base'
|
||||||
|
import { hexToUtf8 } from 'zutils/utils/string.util'
|
||||||
|
import logger from 'logger/logger'
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@index({ from: 1 }, { unique: false })
|
||||||
|
@index({ from: 1, chestId: 1 }, { unique: true })
|
||||||
|
@index({ from: 1, blockTime: 1 }, { unique: false })
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions: { collection: 'chest_open_record', timestamps: true },
|
||||||
|
})
|
||||||
|
export class ChestRecordClass extends BaseModule {
|
||||||
|
@prop({ required: true })
|
||||||
|
public from!: string
|
||||||
|
@prop()
|
||||||
|
public to: string
|
||||||
|
@prop({ required: true })
|
||||||
|
public hash: string
|
||||||
|
@prop()
|
||||||
|
public blockNumber: string
|
||||||
|
@prop()
|
||||||
|
public blockHash: string
|
||||||
|
@prop()
|
||||||
|
public blockTime: number
|
||||||
|
@prop()
|
||||||
|
public dateTag: string
|
||||||
|
@prop()
|
||||||
|
public chestId: string
|
||||||
|
@prop()
|
||||||
|
public value: string
|
||||||
|
@prop()
|
||||||
|
public input: string
|
||||||
|
|
||||||
|
public static async saveEvent(event: any) {
|
||||||
|
const dataStr = hexToUtf8(event.input)
|
||||||
|
const regexp = /data:,{\"p\":\"cf-20\",\"op\":\"chest_open\",\"id\":\"(.+?)\"}/
|
||||||
|
const match = dataStr.match(regexp)
|
||||||
|
if (!match) {
|
||||||
|
logger.log('not a chest open event:', event.hash)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
event.chestId = match[1]
|
||||||
|
logger.log('open chest with id:', event.chestId)
|
||||||
|
return ChestRecord.insertOrUpdate({ hash: event.hash }, event)
|
||||||
|
}
|
||||||
|
|
||||||
|
public toJson() {
|
||||||
|
return {
|
||||||
|
address: this.from,
|
||||||
|
day: this.dateTag,
|
||||||
|
time: this.blockTime,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ChestRecord = getModelForClass(ChestRecordClass, {
|
||||||
|
existingConnection: ChestRecordClass['db'],
|
||||||
|
})
|
@ -5,6 +5,7 @@ import { NftHolder } from './NftHolder'
|
|||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@index({ chain: 1, hash: 1, logIndex: 1 }, { unique: true })
|
@index({ chain: 1, hash: 1, logIndex: 1 }, { unique: true })
|
||||||
|
@index({ chain: 1, address: 1, blockNumber: 1 }, { unique: false })
|
||||||
@modelOptions({
|
@modelOptions({
|
||||||
schemaOptions: { collection: 'general_event', timestamps: true },
|
schemaOptions: { collection: 'general_event', timestamps: true },
|
||||||
options: { allowMixed: Severity.ALLOW },
|
options: { allowMixed: Severity.ALLOW },
|
||||||
|
@ -11,14 +11,19 @@ import { IScriptionCfg } from 'interface/IScriptionCfg'
|
|||||||
import { buildScriptionFilters } from 'utils/block.util'
|
import { buildScriptionFilters } from 'utils/block.util'
|
||||||
import { CheckIn } from 'models/CheckIn'
|
import { CheckIn } from 'models/CheckIn'
|
||||||
import { ZRedisClient } from 'zutils'
|
import { ZRedisClient } from 'zutils'
|
||||||
|
import { hexToUtf8 } from 'zutils/utils/string.util'
|
||||||
|
import { ChestRecord } from 'models/ChestRecord'
|
||||||
|
|
||||||
let svrs: any[] = []
|
let svrs: any[] = []
|
||||||
let lock = false
|
let lock = false
|
||||||
|
|
||||||
let eventProcessers = {
|
let eventProcessers = {
|
||||||
CheckIn: CheckIn,
|
CheckIn: CheckIn,
|
||||||
|
ChestRecord: ChestRecord,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.hexToUtf8 = hexToUtf8
|
||||||
|
|
||||||
async function initEventSvrs() {
|
async function initEventSvrs() {
|
||||||
const cfgMap: Map<IChain, IScriptionCfg[]> = new Map()
|
const cfgMap: Map<IChain, IScriptionCfg[]> = new Map()
|
||||||
for (let cfg of scriptions) {
|
for (let cfg of scriptions) {
|
||||||
|
@ -180,7 +180,7 @@ export const buildScriptionFilters = (cfg: IScriptionCfg) => {
|
|||||||
} else if (filter.type === 'boolean') {
|
} else if (filter.type === 'boolean') {
|
||||||
value = !!value
|
value = !!value
|
||||||
} else {
|
} else {
|
||||||
value = `'${value}'`
|
value = `${value}`
|
||||||
}
|
}
|
||||||
if (op) {
|
if (op) {
|
||||||
if (op === 'in') {
|
if (op === 'in') {
|
||||||
@ -188,9 +188,9 @@ export const buildScriptionFilters = (cfg: IScriptionCfg) => {
|
|||||||
} else if (op === 'nin') {
|
} else if (op === 'nin') {
|
||||||
body += `!(event.${filter.key}.indexOf(${value}) >= 0)`
|
body += `!(event.${filter.key}.indexOf(${value}) >= 0)`
|
||||||
} else if (op === 'nlike') {
|
} else if (op === 'nlike') {
|
||||||
body += `!new RegExp(${value}).test(event.${filter.key})`
|
body += `!new RegExp(/${value}/).test(hexToUtf8(event.${filter.key}))`
|
||||||
} else if (op === 'like') {
|
} else if (op === 'like') {
|
||||||
body += new RegExp(value).test(`event.${filter.key}`)
|
body += `new RegExp(/${value}/).test(hexToUtf8(event.${filter.key}))`
|
||||||
} else {
|
} else {
|
||||||
body += `event.${filter.key}${op}${value}`
|
body += `event.${filter.key}${op}${value}`
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
"name": "chain-client",
|
"name": "chain-client",
|
||||||
"script": "npm",
|
"script": "npm",
|
||||||
"args": "run prod:api",
|
"args": "run prod:api",
|
||||||
"cwd": "/data/apps/web_chain_client",
|
"cwd": "/home/kingsome/code/web_chain_client",
|
||||||
"max_memory_restart": "1024M",
|
"max_memory_restart": "1024M",
|
||||||
"log_date_format": "YYYY-MM-DD HH:mm Z",
|
"log_date_format": "YYYY-MM-DD HH:mm Z",
|
||||||
"watch": false,
|
"watch": false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user