修改历史记录的存储结构

This commit is contained in:
zhl 2023-01-30 17:23:35 +08:00
parent 7490b8012b
commit a9c9012e32
2 changed files with 40 additions and 29 deletions

View File

@ -12,10 +12,6 @@ class RecordController extends BaseController {
data.account = user.id data.account = user.id
const info: any = { const info: any = {
transactionHash: params.transactionHash, transactionHash: params.transactionHash,
address: params.address,
tokenId: params.tokenId,
from: params.from,
to: params.to,
} }
let record = await TranRecord.insertOrUpdate(info, data) let record = await TranRecord.insertOrUpdate(info, data)
return record.toJson() return record.toJson()

View File

@ -2,9 +2,37 @@ import { getModelForClass, index, modelOptions, mongoose, prop, Severity } from
import { dbconn } from 'decorators/dbconn' import { dbconn } from 'decorators/dbconn'
import { BaseModule } from './Base' import { BaseModule } from './Base'
export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'
@modelOptions({ schemaOptions: { _id: false } })
export class TranDetail {
@prop()
public address: string
@prop({ default: ZERO_ADDRESS })
public from: string
@prop({ default: ZERO_ADDRESS })
public to: string
// 对于ERC20, 该值永远为'0'
@prop({ default: '0' })
public id: string
// 对于ERC721, 该值永远为'1'
// 如果address为eth, 那么该值为转账的金额
@prop({ default: '1' })
public value: string
public toJson() {
return {
address: this.address,
from: this.from,
to: this.to,
id: this.id,
value: this.value,
}
}
}
@dbconn() @dbconn()
@index({ transactionHash: 1, address: 1, tokenId: 1, from: 1, to: 1 }, { unique: true }) @index({ transactionHash: 1 }, { unique: true })
@index({ address: 1, account: 1, tokenId: 1 }) @index({ 'details.address': 1, account: 1, chain: 1 })
@index({ 'details.address': 1 })
@modelOptions({ @modelOptions({
schemaOptions: { collection: 'transaction_record', timestamps: true }, schemaOptions: { collection: 'transaction_record', timestamps: true },
}) })
@ -12,9 +40,7 @@ class TranRecordClass extends BaseModule {
@prop({ required: true }) @prop({ required: true })
public transactionHash!: string public transactionHash!: string
@prop() @prop()
public event: string public title: string
@prop({ required: true })
public address!: string
@prop() @prop()
public chain: string public chain: string
@prop({ required: true }) @prop({ required: true })
@ -23,30 +49,20 @@ class TranRecordClass extends BaseModule {
public blockNumber: number public blockNumber: number
@prop() @prop()
public blockHash: string public blockHash: string
@prop()
public from: string
@prop()
public to: string
// 对于ERC20, 该值永远为'0'
@prop({ default: '0' })
public tokenId: string
// 对于ERC721, 该值永远为'1'
@prop({ default: '1' })
public value: string
@prop() @prop()
public gas: string public gas: string
@prop() @prop()
public gasPrice: string public gasPrice: string
@prop() @prop({ type: () => [TranDetail], default: [] })
public data: string public details: TranDetail[]
/** /**
* *
* 0: 默认, * 0: 默认,
* 1: 已获取receipt, getTransactionReceipt获取状态 * 1: 已获取receipt, getTransactionReceipt获取状态
* 2: 已确认, 6 * 2: 已确认, 6
* 10: 错误 * 10: revert
* 11: other error
*/ */
@prop({ default: 0 }) @prop({ default: 0 })
public status: number public status: number
@ -60,17 +76,16 @@ class TranRecordClass extends BaseModule {
public toJson() { public toJson() {
return { return {
transactionHash: this.transactionHash, transactionHash: this.transactionHash,
address: this.address,
chain: this.chain, chain: this.chain,
event: this.event, title: this.title,
blockNumber: this.blockNumber, blockNumber: this.blockNumber,
blockHash: this.blockHash, blockHash: this.blockHash,
from: this.from,
to: this.to,
value: this.value,
tokenId: this.tokenId,
gas: this.gas, gas: this.gas,
gasPrice: this.gasPrice, gasPrice: this.gasPrice,
status: this.status,
startTime: this.startTime,
confirmTime: this.confirmTime,
details: this.details.forEach(o => o.toJson()),
} }
} }
} }