Token Ownership Workers
Two workers for managing NFT/token ownership: one for refreshing tokens and one for external ownership updates.
Included in Crypto Preset
Registered automatically by registerCryptoPlugins() / registerAllPlugins().
Registration
import { pluginRegistry } from '@unchainedshop/core';
import { UpdateTokenOwnershipPlugin } from '@unchainedshop/plugins/worker/update-token-ownership';
pluginRegistry.register(UpdateTokenOwnershipPlugin);
Workers Included
This plugin registers two worker adapters:
1. Refresh Tokens Worker
Automatically finds all tokens and accounts, then triggers ownership updates.
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.refresh-tokens |
| Type | REFRESH_TOKENS |
| Auto-Schedule | Every minute |
2. Update Token Ownership Worker (External)
External worker placeholder for the actual ownership verification process.
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.update-token-ownership |
| Type | UPDATE_TOKEN_OWNERSHIP |
| External | true |
How It Works
Refresh Tokens Flow
- Auto-scheduled every minute (configured on registration)
- Collects tokens: Finds all tokens with wallet addresses (no tokens = no-op)
- Collects accounts: Finds all verified Web3 addresses of users, plus the token wallet addresses
- Creates work: Triggers
UPDATE_TOKEN_OWNERSHIPwith the token and account data - External processing: An external system processes the ownership verification
External Update Flow
- External system receives
UPDATE_TOKEN_OWNERSHIPwork - Verifies token ownership on the blockchain
- Marks work as complete via GraphQL
Manual Trigger
Refresh All Tokens
// Trigger via API
await unchainedAPI.modules.worker.addWork({
type: 'REFRESH_TOKENS',
});
Update Specific Tokens (External)
// Trigger via API
await unchainedAPI.modules.worker.addWork({
type: 'UPDATE_TOKEN_OWNERSHIP',
input: {
filter: {
tokens: [{ _id: 'token-1' }, { _id: 'token-2' }],
accounts: ['0xAddress1', '0xAddress2'],
},
},
});
Result
Refresh Tokens
The result contains the created UPDATE_TOKEN_OWNERSHIP work item under forked (empty result if there are no tokens).
Input for UPDATE_TOKEN_OWNERSHIP
| Parameter | Type | Description |
|---|---|---|
filter.tokens | Array | Token objects to check ownership for |
filter.accounts | Array | Wallet addresses to verify |
Adapter Details
REFRESH_TOKENS
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.refresh-tokens |
| Type | REFRESH_TOKENS |
| Auto-Schedule | Every minute |
| Retries | 0 |
UPDATE_TOKEN_OWNERSHIP
| Property | Value |
|---|---|
| Key | shop.unchained.worker-plugin.update-token-ownership |
| Type | UPDATE_TOKEN_OWNERSHIP |
| External | true |