Skip to content

Commit

Permalink
add minted by
Browse files Browse the repository at this point in the history
  • Loading branch information
ElessarST committed Feb 14, 2024
1 parent 0f8274b commit 0be1288
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 24 deletions.
11 changes: 11 additions & 0 deletions indexer/db/migrations/1707926335271-Data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = class Data1707926335271 {
name = 'Data1707926335271'

async up(db) {
await db.query(`ALTER TABLE "nft" ADD "minted_by" text NOT NULL`)
}

async down(db) {
await db.query(`ALTER TABLE "nft" DROP COLUMN "minted_by"`)
}
}
1 change: 1 addition & 0 deletions indexer/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type Nft @entity {
id: ID!
owner: String!
name: String!
mintedBy: String!
description: String!
idInCollection: Int!
collection: Collection!
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getLocalStorage } from './processing/storage/local.storage';
import { BatchService } from './processing/batch.service';

// @ts-ignore
BigInt.prototype["toJSON"] = function () {
BigInt.prototype['toJSON'] = function () {
return this.toString();
};

Expand Down
3 changes: 3 additions & 0 deletions indexer/src/model/generated/nft.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class Nft {
@Column_('text', { nullable: false })
name!: string;

@Column_('text', { nullable: false })
mintedBy!: string;

@Column_('text', { nullable: false })
description!: string;

Expand Down
24 changes: 20 additions & 4 deletions indexer/src/processing/events.processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,21 @@ export class EventsProcessing {
if (!parsed || !parsed.ok) {
return null;
}
console.log(`${blockNumber}-${messageId}: extracting marketplace event ${JSON.stringify(parsed.ok)}`);
console.log(
`${blockNumber}-${messageId}: extracting marketplace event ${JSON.stringify(
parsed.ok,
)}`,
);
const event = getMarketplaceEvent(parsed.ok);
if (!event) {
console.warn(`${blockNumber}-${messageId}: unknown event type`, parsed);
return null;
}
console.log(`${blockNumber}-${messageId}: detected event: ${event.type}\n${JSON.stringify(event)}`);
console.log(
`${blockNumber}-${messageId}: detected event: ${
event.type
}\n${JSON.stringify(event)}`,
);
await this.entitiesService
.addEvent({
blockNumber: eventInfo.blockNumber,
Expand Down Expand Up @@ -173,7 +181,11 @@ export class EventsProcessing {
);
return null;
}
console.log(`${blockNumber}-${messageId}: extracting nft event ${JSON.stringify(parsed.ok)}`);
console.log(
`${blockNumber}-${messageId}: extracting nft event ${JSON.stringify(
parsed.ok,
)}`,
);
const event = getNftEvent(parsed.ok);
if (!event) {
console.warn(
Expand All @@ -182,7 +194,11 @@ export class EventsProcessing {
);
return null;
}
console.log(`${blockNumber}-${messageId}: detected event: ${event.type}\n${JSON.stringify(event)}`);
console.log(
`${blockNumber}-${messageId}: detected event: ${
event.type
}\n${JSON.stringify(event)}`,
);
const eventHandler = nftEventsToHandler[event.type];
if (!eventHandler) {
console.warn(
Expand Down
10 changes: 6 additions & 4 deletions indexer/src/processing/marketplace/auction-closed.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export class AuctionClosedHandler implements INftMarketplaceEventHandler {
txHash: eventInfo.txHash,
}),
);
await storage.setNft(new Nft({
...nft,
owner: currentOwner,
}));
await storage.setNft(
new Nft({
...nft,
owner: currentOwner,
}),
);
}
}
}
10 changes: 6 additions & 4 deletions indexer/src/processing/marketplace/bid-added.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export class BidAddedHandler implements INftMarketplaceEventHandler {
);
return;
}
await storage.setAuction(new Auction({
...auction,
lastPrice: price,
}))
await storage.setAuction(
new Auction({
...auction,
lastPrice: price,
}),
);
storage.addBid(
new Bid({
id: uuidv4(),
Expand Down
10 changes: 6 additions & 4 deletions indexer/src/processing/marketplace/offer-accepted.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export class OfferAcceptedHandler implements INftMarketplaceEventHandler {
txHash: eventInfo.txHash,
}),
);
await storage.setNft(new Nft({
...nft,
owner: offer.creator,
}));
await storage.setNft(
new Nft({
...nft,
owner: offer.creator,
}),
);
}
}
1 change: 1 addition & 0 deletions indexer/src/processing/nft/nft-minted.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class NftMintedHandler implements INftEventHandler {
mediaUrl,
name,
owner,
mintedBy: owner,
metadata: JSON.stringify(metadata),
onSale: false,
createdAt: timestamp,
Expand Down
13 changes: 8 additions & 5 deletions indexer/src/processing/nft/transferred.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Nft, Transfer } from '../../model';
import { EventInfo } from '../event-info.type';
import { v4 as uuidv4 } from 'uuid';

const NullAddress = '0x0000000000000000000000000000000000000000000000000000000000000000'
const NullAddress =
'0x0000000000000000000000000000000000000000000000000000000000000000';

export class TransferredHandler implements INftEventHandler {
async handle(
Expand Down Expand Up @@ -33,10 +34,12 @@ export class TransferredHandler implements INftEventHandler {
txHash,
}),
);
await storage.setNft(new Nft({
...nft,
owner: recipient,
}));
await storage.setNft(
new Nft({
...nft,
owner: recipient,
}),
);
}
}
}
4 changes: 2 additions & 2 deletions indexer/src/processing/storage/local.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export class LocalStorage implements IStorage {
}
if (!this.marketplace!.nftMetadata) {
this.marketplace!.nftMetadata = nftMeta;
}} catch (e) {
}
}
} catch (e) {}
}

private async loadCollections() {
Expand Down

0 comments on commit 0be1288

Please sign in to comment.