修改历史记录的存储结构
This commit is contained in:
parent
7490b8012b
commit
a9c9012e32
@ -12,10 +12,6 @@ class RecordController extends BaseController {
|
||||
data.account = user.id
|
||||
const info: any = {
|
||||
transactionHash: params.transactionHash,
|
||||
address: params.address,
|
||||
tokenId: params.tokenId,
|
||||
from: params.from,
|
||||
to: params.to,
|
||||
}
|
||||
let record = await TranRecord.insertOrUpdate(info, data)
|
||||
return record.toJson()
|
||||
|
@ -2,9 +2,37 @@ import { getModelForClass, index, modelOptions, mongoose, prop, Severity } from
|
||||
import { dbconn } from 'decorators/dbconn'
|
||||
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()
|
||||
@index({ transactionHash: 1, address: 1, tokenId: 1, from: 1, to: 1 }, { unique: true })
|
||||
@index({ address: 1, account: 1, tokenId: 1 })
|
||||
@index({ transactionHash: 1 }, { unique: true })
|
||||
@index({ 'details.address': 1, account: 1, chain: 1 })
|
||||
@index({ 'details.address': 1 })
|
||||
@modelOptions({
|
||||
schemaOptions: { collection: 'transaction_record', timestamps: true },
|
||||
})
|
||||
@ -12,9 +40,7 @@ class TranRecordClass extends BaseModule {
|
||||
@prop({ required: true })
|
||||
public transactionHash!: string
|
||||
@prop()
|
||||
public event: string
|
||||
@prop({ required: true })
|
||||
public address!: string
|
||||
public title: string
|
||||
@prop()
|
||||
public chain: string
|
||||
@prop({ required: true })
|
||||
@ -23,30 +49,20 @@ class TranRecordClass extends BaseModule {
|
||||
public blockNumber: number
|
||||
@prop()
|
||||
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()
|
||||
public gas: string
|
||||
@prop()
|
||||
public gasPrice: string
|
||||
|
||||
@prop()
|
||||
public data: string
|
||||
@prop({ type: () => [TranDetail], default: [] })
|
||||
public details: TranDetail[]
|
||||
/**
|
||||
* 交易状态
|
||||
* 0: 默认, 未确认
|
||||
* 1: 已获取receipt, 能通过getTransactionReceipt获取状态
|
||||
* 2: 已确认, 交易已经经过6个块确认
|
||||
* 10: 错误
|
||||
* 10: revert
|
||||
* 11: other error
|
||||
*/
|
||||
@prop({ default: 0 })
|
||||
public status: number
|
||||
@ -60,17 +76,16 @@ class TranRecordClass extends BaseModule {
|
||||
public toJson() {
|
||||
return {
|
||||
transactionHash: this.transactionHash,
|
||||
address: this.address,
|
||||
chain: this.chain,
|
||||
event: this.event,
|
||||
title: this.title,
|
||||
blockNumber: this.blockNumber,
|
||||
blockHash: this.blockHash,
|
||||
from: this.from,
|
||||
to: this.to,
|
||||
value: this.value,
|
||||
tokenId: this.tokenId,
|
||||
gas: this.gas,
|
||||
gasPrice: this.gasPrice,
|
||||
status: this.status,
|
||||
startTime: this.startTime,
|
||||
confirmTime: this.confirmTime,
|
||||
details: this.details.forEach(o => o.toJson()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user