-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/update owner for each cw721 activity ( develop ) #351
Closed
Closed
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
45fa9b4
docs: cw721
phamphong9981 b27aa4c
docs: cw20
phamphong9981 ccc8fbd
Merge branch 'main' into docs/cw721
fibonacci998 0fa8225
Merge branch 'main' into docs/cw20
fibonacci998 5e50079
fix: update validator as UNSPECIFIED when not found onchain
fibonacci998 147fb9b
fix: remove token and delegator_shares when validator is UNRECOGNIZED
fibonacci998 6fd8005
feat: add test for unrecognized validator
fibonacci998 d8eb803
feat: add migration to add index time to block, tx
fibonacci998 49ad0b2
Merge pull request #293 from aura-nw/feat/add-index-by-time-to-block-tx
peara a901780
Merge pull request #276 from aura-nw/fix/update-validator-not-found
peara 49bcd7c
Merge pull request #249 from aura-nw/docs/cw20
peara 6924407
Merge pull request #243 from aura-nw/docs/cw721
peara 32d103a
fix: allow whitelist query can have depth more than config (#312)
fibonacci998 685bb4b
feat: reindex cw20 service ( main ) (#277)
phamphong9981 92795eb
refactor: cw20/cw721 index and add relation ( main ) (#306)
phamphong9981 b6b007c
fix: duplicate latest migrate contract (#304)
phamphong9981 887ecfd
Feat/statistics (#272)
peara 8c01c5c
refactor: migrate cw721 activity missing smart contract event ( main …
phamphong9981 3c325dc
Fix/account stat with feegrant (#337)
fibonacci998 4adfdf0
Update api_gateway.service.ts (#336)
fibonacci998 5c86a9f
fix: cw721 activity missing from/to ( main ) (#294)
phamphong9981 dcec038
feat: crawl ibc tao ( main ) (#278)
phamphong9981 7e18483
fix: cw721 activity save owner at each time
phamphong9981 35d094d
fix: cw721 activity missing from/to ( main ) (#294)
phamphong9981 3c7c287
feat: crawl ibc tao ( main ) (#278)
phamphong9981 85c4dd9
fix: cw721 activity save owner at each time
phamphong9981 4873127
fix: resolve conflict
phamphong9981 8baa6b3
fix: resolve conflict
phamphong9981 ed03ca3
feat: config json
phamphong9981 b26cf9c
fix: update owner for each cw721 activity
phamphong9981 c93f995
fix: update owner for each cw721 activity
phamphong9981 cbd710f
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 0d2c5ef
test: test
phamphong9981 cbcab6b
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 ef4a4ba
Merge branch 'develop' of github.com:aura-nw/horoscope-v2 into fix/ap…
phamphong9981 b612310
Merge branch 'develop' of github.com:aura-nw/horoscope-v2 into fix/ap…
phamphong9981 cb66cf6
refactor: code
phamphong9981 8a07f98
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 e1d23ff
refactor: review code
phamphong9981 ced56b9
refactor: review code
phamphong9981 cc3467b
refactor: code
phamphong9981 01e0c70
refactor: migration
phamphong9981 37963fe
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 dcbd97d
refactor: sender
phamphong9981 4c5931d
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 f95072a
refactor: review
phamphong9981 7ff365a
Merge branch 'fix/approve-cw721-activity' of github.com:aura-nw/horos…
phamphong9981 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
migrations/20230830024631_cw721_activity_add_current_owner.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.service'; | ||
|
||
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> = {}; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { | |
Action, | ||
Service, | ||
} from '@ourparentcenter/moleculer-decorators-extended'; | ||
import _ from 'lodash'; | ||
import _, { Dictionary } from 'lodash'; | ||
import { Context, ServiceBroker } from 'moleculer'; | ||
import { Queue } from 'bullmq'; | ||
import config from '../../../config.json' assert { type: 'json' }; | ||
|
@@ -296,9 +296,12 @@ export default class Cw721HandlerService extends BullableService { | |
), | ||
'address' | ||
); | ||
const orderedEvents = _.orderBy(cw721Events, ['height'], ['asc']); | ||
const cw721Activities: CW721Activity[] = []; | ||
const latestOwners: Dictionary<string> = {}; | ||
await knex.transaction(async (trx) => { | ||
const queries: any[] = []; | ||
cw721Events.forEach((cw721Event) => { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const cw721Event of orderedEvents) { | ||
// find the cw721 Event's smart contract id | ||
const cw721Contract = | ||
cw721ContractDbRecords[cw721Event.contractAddress]; | ||
|
@@ -321,49 +324,85 @@ export default class Cw721HandlerService extends BullableService { | |
); | ||
} | ||
} | ||
queries.push( | ||
CW721Activity.query() | ||
.insert( | ||
CW721Activity.fromJson({ | ||
action: cw721Event.action, | ||
sender: cw721Event.sender, | ||
tx_hash: cw721Event.hash, | ||
cw721_contract_id: cw721Contract.id, | ||
cw721_token_id: cw721TokenId, | ||
height: cw721Event.height, | ||
smart_contract_event_id: cw721Event.smart_contract_event_id, | ||
from: getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.SENDER | ||
), | ||
to: | ||
getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.OWNER | ||
) || | ||
getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.RECIPIENT | ||
), | ||
}) | ||
) | ||
.onConflict(['smart_contract_event_id']) | ||
.merge() | ||
.transacting(trx) | ||
// eslint-disable-next-line no-await-in-loop | ||
const from = await this.getLatestOwnerForToken( | ||
cw721Contract.id, | ||
cw721TokenId, | ||
latestOwners | ||
); | ||
const to = | ||
getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.OWNER | ||
) || | ||
getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.RECIPIENT | ||
); | ||
const cw721Activity = CW721Activity.fromJson({ | ||
action: cw721Event.action, | ||
sender: getAttributeFrom( | ||
cw721Event.attributes, | ||
EventAttribute.ATTRIBUTE_KEY.SENDER | ||
), | ||
tx_hash: cw721Event.hash, | ||
cw721_contract_id: cw721Contract.id, | ||
cw721_token_id: cw721TokenId, | ||
height: cw721Event.height, | ||
smart_contract_event_id: cw721Event.smart_contract_event_id, | ||
to, | ||
from, | ||
}); | ||
// push to update records | ||
cw721Activities.push(cw721Activity); | ||
// update latestActivity for this token | ||
if ( | ||
cw721Activity.action === CW721_ACTION.MINT || | ||
cw721Activity.action === CW721_ACTION.TRANSFER || | ||
cw721Activity.action === CW721_ACTION.SEND_NFT | ||
) { | ||
latestOwners[ | ||
`${cw721Activity.cw721_contract_id}_${cw721Activity.cw721_token_id}` | ||
] = cw721Activity.to; | ||
} | ||
} | ||
}); | ||
if (queries.length > 0) { | ||
await Promise.all(queries) // Once every query is written | ||
.then(trx.commit) // Try to execute all of them | ||
.catch((e) => { | ||
this.logger.error(e); | ||
trx.rollback(); | ||
}); // And rollback in case any of them goes wrong | ||
} | ||
if (cw721Activities.length > 0) { | ||
await CW721Activity.query() | ||
.insert(cw721Activities) | ||
.onConflict(['smart_contract_event_id']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cái này mới tinh mà, làm gì có conflict |
||
.merge() | ||
.transacting(trx); | ||
} | ||
}); | ||
} | ||
|
||
async getLatestOwnerForToken( | ||
cw721ContractId: number, | ||
cw721TokenId: number | null, | ||
latestOwners: Dictionary<string> | ||
) { | ||
const latestOwner = latestOwners[`${cw721ContractId}_${cw721TokenId}`]; | ||
if (latestOwner) { | ||
return latestOwner; | ||
} | ||
const latestActivityDB = await CW721Activity.query() | ||
.joinRelated('event') | ||
.whereIn('cw721_activity.action', [ | ||
CW721_ACTION.MINT, | ||
CW721_ACTION.TRANSFER, | ||
CW721_ACTION.SEND_NFT, | ||
]) | ||
.andWhere('cw721_contract_id', cw721ContractId) | ||
.andWhere('cw721_token_id', cw721TokenId) | ||
.orderBy('event.block_height', 'desc') | ||
.first(); | ||
if (latestActivityDB) { | ||
return latestActivityDB.to; | ||
} | ||
return null; | ||
} | ||
|
||
// handle Instantiate Msgs | ||
async handleInstantiateMsgs(msgsInstantiate: SmartContractEvent[]) { | ||
const cw721Contracts: any[] = await SmartContract.query() | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
có cái
foundToken
ngay trên mà nhỉ?