每日签到增加连签标志
This commit is contained in:
parent
ad86cb3eb8
commit
0bb8709fcd
@ -1,4 +1,5 @@
|
|||||||
import { CheckIn } from "models/CheckIn"
|
import { CheckIn } from "models/CheckIn"
|
||||||
|
import { utf8ToHex } from "utils/string.util"
|
||||||
|
|
||||||
export interface IScriptionCfg {
|
export interface IScriptionCfg {
|
||||||
chain: number,
|
chain: number,
|
||||||
@ -8,15 +9,19 @@ export interface IScriptionCfg {
|
|||||||
process: (event: any) => Promise<void>,
|
process: (event: any) => Promise<void>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CHECKIN_DATA_STR = 'data:,{"p":"cf-20","op":"check"}'
|
||||||
|
const CHECKIN_DATA_HEX = '0x'+utf8ToHex(CHECKIN_DATA_STR)
|
||||||
|
const CHECKIN_ADDRESS = '0x50a8e60041a206acaa5f844a1104896224be6f39'
|
||||||
|
|
||||||
export const SCRIPTIONS_CFG: IScriptionCfg[] = [
|
export const SCRIPTIONS_CFG: IScriptionCfg[] = [
|
||||||
{
|
{
|
||||||
chain: 421614,
|
chain: 421614,
|
||||||
// rpc: 'https://arbitrum-sepolia.infura.io/v3/25559ac58e714177b31ff48d507e7ac9',
|
// rpc: 'https://arbitrum-sepolia.infura.io/v3/25559ac58e714177b31ff48d507e7ac9',
|
||||||
rpc: 'https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3',
|
rpc: 'https://arb-sepolia.g.alchemy.com/v2/EKR1je8ZGia332kkemNc4mtXQuFskIq3',
|
||||||
fromBlock: 5063559,
|
fromBlock: 5624211,
|
||||||
filter: (event: any) => {
|
filter: (event: any) => {
|
||||||
return ( event.input === '0x646174613a2c7b2270223a2263662d3230222c226f70223a22636869636b227d'
|
return ( event.input === CHECKIN_DATA_HEX
|
||||||
&& event.to.toLowerCase() === '0x50a8e60041a206acaa5f844a1104896224be6f39')
|
&& event.to.toLowerCase() === CHECKIN_ADDRESS)
|
||||||
},
|
},
|
||||||
process: async (tx: any) => {
|
process: async (tx: any) => {
|
||||||
return CheckIn.saveEvent(tx)
|
return CheckIn.saveEvent(tx)
|
||||||
|
@ -13,7 +13,7 @@ class TaskController extends BaseController {
|
|||||||
if (!address || (!days && !limit)) {
|
if (!address || (!days && !limit)) {
|
||||||
throw new ZError(10, 'params mismatch')
|
throw new ZError(10, 'params mismatch')
|
||||||
}
|
}
|
||||||
let query: any = { from: address }
|
let query: any = { from: address.toLowerCase() }
|
||||||
if (!limit) {
|
if (!limit) {
|
||||||
if (typeof days === 'number') {
|
if (typeof days === 'number') {
|
||||||
let begin = getNDayAgo(days, true)
|
let begin = getNDayAgo(days, true)
|
||||||
@ -31,9 +31,9 @@ class TaskController extends BaseController {
|
|||||||
}
|
}
|
||||||
let records
|
let records
|
||||||
if (limit) {
|
if (limit) {
|
||||||
records = await CheckIn.find(query).limit(limit)
|
records = await CheckIn.find(query).sort({_id: -1}).limit(limit)
|
||||||
} else {
|
} else {
|
||||||
records = await CheckIn.find(query)
|
records = await CheckIn.find(query).sort({_id: -1})
|
||||||
}
|
}
|
||||||
let result = []
|
let result = []
|
||||||
for (let record of records) {
|
for (let record of records) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
|
import { getModelForClass, index, modelOptions, prop } from '@typegoose/typegoose'
|
||||||
import { dbconn } from 'decorators/dbconn'
|
import { dbconn } from 'decorators/dbconn'
|
||||||
import { BaseModule } from './Base'
|
import { BaseModule } from './Base'
|
||||||
|
import { formatDate, yesterday } from 'utils/date.util'
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@index({ from: 1 }, { unique: false })
|
@index({ from: 1 }, { unique: false })
|
||||||
@ -24,12 +25,20 @@ export class CheckInClass extends BaseModule {
|
|||||||
public blockTime: number
|
public blockTime: number
|
||||||
@prop()
|
@prop()
|
||||||
public dateTag: string
|
public dateTag: string
|
||||||
|
// 连签天数
|
||||||
|
@prop({default: 0})
|
||||||
|
public count: number
|
||||||
@prop()
|
@prop()
|
||||||
public value: string
|
public value: string
|
||||||
@prop()
|
@prop()
|
||||||
public input: string
|
public input: string
|
||||||
|
|
||||||
public static async saveEvent(event: any) {
|
public static async saveEvent(event: any) {
|
||||||
|
const preDay = formatDate(yesterday());
|
||||||
|
const preDayEvent = await CheckIn.findOne({ from: event.from, dateTag: preDay })
|
||||||
|
if (preDayEvent) {
|
||||||
|
event.count = preDayEvent.count + 1
|
||||||
|
}
|
||||||
return CheckIn.insertOrUpdate({ hash: event.hash }, event)
|
return CheckIn.insertOrUpdate({ hash: event.hash }, event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +47,7 @@ export class CheckInClass extends BaseModule {
|
|||||||
address: this.from,
|
address: this.from,
|
||||||
day: this.dateTag,
|
day: this.dateTag,
|
||||||
time: this.blockTime,
|
time: this.blockTime,
|
||||||
|
count: this.count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,3 +104,21 @@ export function string62to10(numberCode: string) {
|
|||||||
}
|
}
|
||||||
return originNumber
|
return originNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hexToUtf8(hexString) {
|
||||||
|
// Remove any leading "0x" prefix and split into pairs of characters
|
||||||
|
let _hexString = hexString.replace(/^0x/, "");
|
||||||
|
let buffer = Buffer.from(_hexString, 'hex')
|
||||||
|
return buffer.toString('utf8')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function utf8ToHex(utf8String) {
|
||||||
|
// Create a Buffer object from the UTF-8 string
|
||||||
|
const buffer = Buffer.from(utf8String, "utf8");
|
||||||
|
|
||||||
|
// Convert the Buffer object to a hex string
|
||||||
|
const hexString = buffer.toString("hex");
|
||||||
|
|
||||||
|
return hexString;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user