Skip to content

Commit

Permalink
Merge pull request #27 from spinamp/nina_catalogfix
Browse files Browse the repository at this point in the history
fix catalog zora tracks
  • Loading branch information
musnit authored Aug 1, 2022
2 parents cfa7a8d + 5b3ed3b commit f92c797
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 2 additions & 4 deletions OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ yarn restore-db

```sql
-- Clear all erc721nfts where there was an error with their metadata or processing them into tracks so they can be tried again:
select * from "erc721nftProcessErrors";

delete from "erc721nftProcessErrors";
select * from "nftProcessErrors";
delete from "nftProcessErrors";
```

```sql
Expand All @@ -43,6 +42,5 @@ delete from erc721nfts where id like '%0xf5819e27b9bad9f97c177bf007c1f96f26d91ca
delete from "processedTracks";
delete from "artistProfiles";
delete from "artists";
delete from "erc721nfts";
delete from processors where id in ('stripIgnoredNFTs','createProcessedTracksFromAPI_noizd');
```
3 changes: 2 additions & 1 deletion src/db/migrations/01-bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const INITIAL_TABLES = [
}
},
{
name: Table.nfts_processedTracks, create: (table: Knex.CreateTableBuilder) => {
name: Table.nfts_processedTracks, create: (table: Knex.CreateTableBuilder) => {
table.string('nftId').references('id').inTable(Table.nfts).onDelete('cascade');
table.string('processedTrackId').references('id').inTable(Table.processedTracks).onDelete('cascade');
table.primary(['nftId','processedTrackId']);
Expand Down Expand Up @@ -146,6 +146,7 @@ const INITIAL_PLATFORM_ENUMS: MusicPlatform[] = [
{ id: 'noizd', type: MusicPlatformType.noizd, name: 'NOIZD' },
{ id: 'catalog', type: MusicPlatformType.catalog, name: 'Catalog' },
{ id: 'sound', type: MusicPlatformType.sound, name: 'Sound.xyz' },
{ id: 'zoraOriginals', type: MusicPlatformType.zora, name: 'Zora' },
{ id: 'zora', type: MusicPlatformType.zora, name: 'Zora' },
]

Expand Down
7 changes: 3 additions & 4 deletions src/db/migrations/02-insert-nft-factories.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Knex } from 'knex';

import { NftFactory, NFTContractTypeName, NFTStandard } from '../../types/nft';
import { MusicPlatformType } from '../../types/platform';
import { addNftFactory, removeNftFactory } from '../migration-helpers';

const INITIAL_CONTRACTS: NftFactory[] = [
Expand All @@ -10,18 +9,18 @@ const INITIAL_CONTRACTS: NftFactory[] = [
startingBlock: '11565020',
contractType: NFTContractTypeName.zora,
standard: NFTStandard.ERC721,
platformId: MusicPlatformType.zora
platformId: 'zoraOriginal'
},
{
address: '0xf5819e27b9bad9f97c177bf007c1f96f26d91ca6',
platformId: MusicPlatformType.noizd,
platformId: 'noizd',
startingBlock: '13470560',
contractType: NFTContractTypeName.default,
standard: NFTStandard.ERC721,
},
{
address: '0x0bc2a24ce568dad89691116d5b34deb6c203f342',
platformId: MusicPlatformType.catalog,
platformId: 'catalog',
startingBlock: '14566825',
contractType: NFTContractTypeName.default,
standard: NFTStandard.ERC721,
Expand Down
3 changes: 1 addition & 2 deletions src/db/migrations/03-insert-meta-factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import { Knex } from 'knex';

import { MetaFactory, MetaFactoryTypeName } from '../../types/metaFactory';
import { NFTStandard } from '../../types/nft';
import { MusicPlatformType } from '../../types/platform';
import { addMetaFactory, removeMetaFactory } from '../migration-helpers';

const INITIAL_CONTRACTS: MetaFactory[] = [
{
address: '0x78e3adc0e811e4f93bd9f1f9389b923c9a3355c2',
platformId: MusicPlatformType.sound,
platformId: 'sound',
startingBlock: '13725566',
contractType: MetaFactoryTypeName.soundArtistProfileCreator,
gap: '500000',
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const PROCESSORS = (nftFactories: NftFactory[], metaFactories: MetaFactory[], mu
addMetadataObjectProcessor(nftFactoriesByAddress),
stripNonAudio,
categorizeZora,
createNinaNfts,
addTimestampFromMetadata,
...platformTrackProcessors,
createProcessedTracksFromAPI('noizd'), //TODO: noizd here is being used both as platformId and MusicPlatformType. Need to bring in the full noizd platform object here and avoid mixing them
ipfsAudioPinner,
ipfsArtworkPinner,
errorProcessor,
createNinaNfts,
addTimestampFromMetadata,
]
};

Expand Down
11 changes: 5 additions & 6 deletions src/triggers/zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { Trigger } from '../types/trigger';
import { ZORA_CONTRACT_ADDRESS } from '../types/zora-contract';

export const zoraNFTs: Trigger<undefined> = async (clients) => {
const nftQuery = `select *
from "${Table.nfts}" en
left outer join "${Table.nftProcessErrors}" enpe
on en.id = enpe."nftId"
const nftQuery = `select *
from "${Table.nfts}" en
left outer join "${Table.nftProcessErrors}" enpe
on en.id = enpe."nftId"
where en."contractAddress" = '${ZORA_CONTRACT_ADDRESS}'
and en.metadata is not null
and enpe."metadataError" is null
and en."platformId" is null
and en."platformId"='zoraOriginal'
`
const nfts = (await clients.db.rawSQL(nftQuery))
.rows.slice(0, parseInt(process.env.QUERY_TRIGGER_BATCH_SIZE!));
return nfts;

};
8 changes: 6 additions & 2 deletions src/types/zora-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NFT } from './nft';
import { MusicPlatformType } from './platform';

export const ZORA_CONTRACT_ADDRESS = '0xabefbc9fd2f806065b4f3c237d4b59d9a97bcac7';
// const CATALOG_ETHEREUM_ADDRESS = '0xc236541380fc0C2C05c2F2c6c52a21ED57c37952'.toLowerCase();

const recoverCatalogAddress = (body: any, signature: string) => {
const bodyString = JSON.stringify(body);
Expand All @@ -13,7 +14,6 @@ const recoverCatalogAddress = (body: any, signature: string) => {
};

const verifyCatalogTrack = (nft: NFT) => {
const CATALOG_ETHEREUM_ADDRESS = '0xc236541380fc0C2C05c2F2c6c52a21ED57c37952'.toLowerCase();
if (!nft.metadata) {
throw new Error(`Full metadata missing for record ${nft.id}`)
}
Expand All @@ -22,7 +22,11 @@ const verifyCatalogTrack = (nft: NFT) => {
}
const signature = nft.metadata.origin.signature;
const body = nft.metadata.body;
return signature && body && recoverCatalogAddress(body, signature) === CATALOG_ETHEREUM_ADDRESS;
return signature && body && body.version === 'catalog-20210202';
// We should check the signature, but since we're storing the body as jsonb in the DB
// rather than json, the order of keys is not preserved and so the bytes are shuffled and
// won't match the signed bytes. So we just check the version above as a heuristic, even though this is insecure.
// return signature && body && recoverCatalogAddress(body, signature) === CATALOG_ETHEREUM_ADDRESS;
}

export const getZoraPlatform = (nft: NFT) => {
Expand Down

0 comments on commit f92c797

Please sign in to comment.