-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: cw721 * test: full test * feat: migration * fix: lint * fix: test * fix: test * refactor: test * refactor: code * refactor: test * fix: test * test: code * test: code * refactor: code * refactor: review * refactor: review * refactor: clean redundance get DB field
- Loading branch information
1 parent
62d6da3
commit 192caf3
Showing
9 changed files
with
1,657 additions
and
987 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
migrations/20230915032739_cw721_activity_update_owner_for_each.ts
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,46 @@ | ||
import { Knex } from 'knex'; | ||
import CW721Activity from '../src/models/cw721_tx'; | ||
import _, { Dictionary } from 'lodash'; | ||
import { CW721_ACTION } from '../src/services/cw721/cw721_handler'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex('cw721_activity').update({ | ||
sender: knex.ref('from'), | ||
}); | ||
await knex.transaction(async (trx) => { | ||
const activities = await CW721Activity.query() | ||
.joinRelated('event') | ||
.orderBy('event.id', 'asc') | ||
.transacting(trx); | ||
const latestOwners: Dictionary<string | null> = {}; | ||
activities.forEach((activity) => { | ||
const latestOwner = | ||
latestOwners[ | ||
activity.cw721_contract_id + '_' + activity.cw721_token_id | ||
]; | ||
if (latestOwner) { | ||
activity.from = latestOwner; | ||
} else { | ||
activity.from = null; | ||
} | ||
if ( | ||
activity.action === CW721_ACTION.MINT || | ||
activity.action === CW721_ACTION.TRANSFER || | ||
activity.action === CW721_ACTION.SEND_NFT | ||
) { | ||
latestOwners[ | ||
activity.cw721_contract_id + '_' + activity.cw721_token_id | ||
] = activity.to; | ||
} | ||
}); | ||
if (activities.length > 0) { | ||
await CW721Activity.query() | ||
.insert(activities) | ||
.onConflict(['id']) | ||
.merge() | ||
.transacting(trx); | ||
} | ||
}); | ||
} | ||
|
||
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
Oops, something went wrong.