-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cw721 activity missing from/to ( main ) (#294)
* fix: cw721 activity missing from/to * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * fix: fill from/to cw721 activity * refactor: code * fix: code * refactor: code --------- Co-authored-by: Vu Ngoc Quang <quang.vn@outlook.com>
- Loading branch information
1 parent
4adfdf0
commit 5c86a9f
Showing
6 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Knex } from 'knex'; | ||
import config from '../config.json' assert { type: 'json' }; | ||
import CW721Activity from '../src/models/cw721_tx'; | ||
import { getAttributeFrom } from '../src/common/utils/smart_contract'; | ||
import { EventAttribute } from '../src/models'; | ||
const UPDATE_CW721_ACTIONS = ['mint', 'burn', 'transfer_nft', 'send_nft']; | ||
export async function up(knex: Knex): Promise<void> { | ||
await knex.transaction(async (trx) => { | ||
let prevId = 0; | ||
while (true) { | ||
const handleRecords = await CW721Activity.query() | ||
.withGraphFetched('smart_contract_event.attributes') | ||
.where('cw721_activity.from', null) | ||
.andWhere('cw721_activity.to', null) | ||
.andWhere('cw721_activity.id', '>', prevId) | ||
.whereIn('cw721_activity.action', UPDATE_CW721_ACTIONS) | ||
.whereNotNull('smart_contract_event_id') | ||
.orderBy('cw721_activity.id') | ||
.limit(100) | ||
.transacting(trx); | ||
|
||
if (handleRecords.length > 0) { | ||
const patchQueries: any[] = []; | ||
handleRecords.forEach((record) => { | ||
patchQueries.push( | ||
CW721Activity.query() | ||
.patch({ | ||
from: getAttributeFrom( | ||
record.smart_contract_event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.SENDER | ||
), | ||
to: | ||
getAttributeFrom( | ||
record.smart_contract_event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.OWNER | ||
) || | ||
getAttributeFrom( | ||
record.smart_contract_event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.RECIPIENT | ||
), | ||
}) | ||
.where('id', record.id) | ||
.transacting(trx) | ||
); | ||
}); | ||
await Promise.all(patchQueries); | ||
prevId = handleRecords[handleRecords.length - 1].id; | ||
} else { | ||
break; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters