Skip to content

Commit

Permalink
Merge pull request #921 from multiversx/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
danielailie authored Mar 6, 2023
2 parents df84811 + ca68f27 commit 13e2bfc
Show file tree
Hide file tree
Showing 37 changed files with 350 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ PINATA_API_URL="https://api.pinata.cloud"

# Auth config
JWT_SECRET_KEY=some_secret
NATIVE_AUTH_MAX_EXPIRY_SECONDS=86400
NATIVE_AUTH_ACCEPTED_ORIGINS=

# Admins
ADMINS=erd...000,erd...001
Expand Down
65 changes: 64 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@elrondnetwork/erdnest": "0.1.84",
"@golevelup/nestjs-rabbitmq": "3.4.0",
"@multiversx/sdk-core": "^11.1.3",
"@multiversx/sdk-native-auth-server": "1.0.5",
"@multiversx/sdk-network-providers": "^1.2.1",
"@nestjs-query/query-graphql": "0.30.0",
"@nestjs/common": "8.4.7",
Expand Down
9 changes: 8 additions & 1 deletion schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ type Collection {
artistFollowersCount: Int!

"""This will return only the first 10 assets"""
assets(filters: AssetsCollectionFilter, pagination: ConnectionArgs): AssetsResponse
assets(
filters: AssetsCollectionFilter

"""
This filter will be removed in the next version, we return the latest 10 assets for this collection
"""
pagination: ConnectionArgs
): AssetsResponse
canAddQuantity: Boolean
canBurn: Boolean
canCreate: Boolean
Expand Down
7 changes: 7 additions & 0 deletions src/db/auctions/auctions.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ export class AuctionsRepository {
await this.triggerCacheInvalidation(
auction.identifier,
auction.ownerAddress,
auction.marketplaceKey,
);
return await this.auctionsRepository.save(auction);
}
Expand Down Expand Up @@ -601,6 +602,7 @@ export class AuctionsRepository {
await this.triggerCacheInvalidation(
auction.identifier,
auction.ownerAddress,
auction.marketplaceKey,
);

auction.modifiedDate = new Date(new Date().toUTCString());
Expand All @@ -617,6 +619,7 @@ export class AuctionsRepository {
await this.triggerCacheInvalidation(
auction.identifier,
auction.ownerAddress,
auction.marketplaceKey,
);
if (auction) {
auction.status = status;
Expand All @@ -638,6 +641,7 @@ export class AuctionsRepository {
await this.triggerCacheInvalidation(
auction.identifier,
auction.ownerAddress,
auction.marketplaceKey,
);
if (auction) {
auction.status = status;
Expand All @@ -653,6 +657,7 @@ export class AuctionsRepository {
await this.triggerCacheInvalidation(
auction.identifier,
auction.ownerAddress,
auction.marketplaceKey,
);
}
return await this.auctionsRepository.save(auctions);
Expand All @@ -661,12 +666,14 @@ export class AuctionsRepository {
private async triggerCacheInvalidation(
identifier: string,
ownerAddress: string,
marketplaceKey: string,
) {
await this.cacheEventsPublisherService.publish(
new ChangedEvent({
id: identifier,
type: CacheEventTypeEnum.UpdateAuction,
address: ownerAddress,
extraInfo: { marketplaceKey: marketplaceKey },
}),
);
}
Expand Down
16 changes: 0 additions & 16 deletions src/modules/account-stats/accounts-stats.caching.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,6 @@ export class AccountsStatsCachingService {
this.redisClient,
this.getStatsCacheKey(`owner_${address}`),
);
await this.redisCacheService.delByPattern(
this.redisClient,
this.getStatsCacheKey(address),
);
await this.redisCacheService.delByPattern(
this.redisClient,
this.getClaimableCacheKey(address),
);
await this.redisCacheService.delByPattern(
this.redisClient,
this.getBiddingBalanceCacheKey(address),
);
return await this.redisCacheService.delByPattern(
this.redisClient,
this.getStatsCacheKey(`owner_${address}`),
);
}

private getStatsCacheKey(address: string) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/account-stats/accounts-stats.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export class AccountsStatsResolver {
@ResolveField(() => [Price])
async biddings(@Parent() stats: AccountStats) {
const { address, marketplaceKey } = stats;
const claimableCount = await this.accountsStatsService.getBiddingBalance(
const biddings = await this.accountsStatsService.getBiddingBalance(
address,
marketplaceKey,
);
return claimableCount || 0;
return biddings;
}

@ResolveField(() => Int)
Expand Down
20 changes: 14 additions & 6 deletions src/modules/admins/flag-nft.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ export class FlagNftService {
return false;
}

const value = await this.getNsfwValue(nftMedia, identifier);
if (value) {
await this.addNsfwFlag(identifier, value);
this.triggerCacheInvalidation(identifier);
let value = 0;
if (nftMedia.fileType.includes('image')) {
value = await this.getNsfwValue(nftMedia, identifier);
}

await this.addNsfwFlag(identifier, value);
this.triggerCacheInvalidation(identifier, nft?.ownerAddress);

return true;
} catch (error) {
this.logger.error('An error occurred while updating NSFW for nft', {
Expand Down Expand Up @@ -186,6 +189,7 @@ export class FlagNftService {
public async updateNftNSFWByAdmin(identifier: string, value) {
try {
this.logger.log(`Setting nsfw for '${identifier}' with value ${value}`);
const nft = await this.assetByIdentifierService.getAsset(identifier);
await this.persistenceService.updateFlag(
new NftFlagsEntity({
identifier: identifier,
Expand All @@ -202,7 +206,7 @@ export class FlagNftService {
'?retry_on_conflict=2',
);

await this.triggerCacheInvalidation(identifier);
await this.triggerCacheInvalidation(identifier, nft?.ownerAddress);
return true;
} catch (error) {
this.logger.error('An error occurred while updating NSFW', {
Expand All @@ -216,11 +220,15 @@ export class FlagNftService {
}
}

private async triggerCacheInvalidation(identifier: string) {
private async triggerCacheInvalidation(
identifier: string,
ownerAddress: string,
) {
await this.cacheEventPublisherService.publish(
new ChangedEvent({
id: identifier,
type: CacheEventTypeEnum.AssetRefresh,
address: ownerAddress,
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/assets/asset-by-identifier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class AssetByIdentifierService {
identifier: string,
): Promise<{ key: string; value: Asset; ttl: number }> {
const nft = await this.apiService.getNftByIdentifierForQuery(identifier);
if (!NftTypeEnum[nft?.type])
return {
key: identifier,
value: undefined,
ttl: TimeConstants.oneDay,
};
let ttl = TimeConstants.oneDay;
if (!nft) {
ttl = 3 * TimeConstants.oneSecond;
Expand Down
10 changes: 9 additions & 1 deletion src/modules/assets/assets-likes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import { AssetByIdentifierService } from './asset-by-identifier.service';
import { PersistenceService } from 'src/common/persistence/persistence.service';
import { Asset } from './models';
import { AssetsLikesCachingService } from './assets-likes.caching.service';
import { CacheEventsPublisherService } from '../rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service';
import {
CacheEventsPublisherService,
NftLikePublisherService,
} from '../rabbitmq/cache-invalidation/cache-invalidation-publisher/change-events-publisher.service';
import {
CacheEventTypeEnum,
ChangedEvent,
} from '../rabbitmq/cache-invalidation/events/changed.event';
import { UserNftLikeEvent } from '../rabbitmq/cache-invalidation/events/userNftLike.event';

@Injectable()
export class AssetsLikesService {
Expand All @@ -24,6 +28,7 @@ export class AssetsLikesService {
private accountFeedService: MxFeedService,
private assetsLikesCachingService: AssetsLikesCachingService,
private cacheEventsPublisherService: CacheEventsPublisherService,
private nftLikePublisherService: NftLikePublisherService,
private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -68,6 +73,9 @@ export class AssetsLikesService {
const nftData = await this.assetByIdentifierService.getAsset(
identifier,
);
await this.nftLikePublisherService.publish(
new UserNftLikeEvent({ address, nftIdentifier: identifier }),
);
await this.accountFeedService.addFeed(
new Feed({
actor: address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ export class AssetsCollectionsForOwnerProvider extends BaseProvider<string> {
}

async getData(identifiers: string[]) {
const page = parseInt(identifiers[0].split('_')[1]);
const size = parseInt(identifiers[0].split('_')[2]);
const ownerAddress = identifiers[0].split('_')[3];
const ownerAddress = identifiers[0].split('_')[1];
const nftsPromises = identifiers.map((identifier) =>
this.apiService.getNftsAndCountForAccount(
ownerAddress,
new AssetsQuery()
.addCollection(identifier.split('_')[0])
.addPageSize(page, size)
.addPageSize(0, 10)
.build(),
new AssetsQuery().addCollection(identifier.split('_')[0]).build(),
),
Expand All @@ -37,7 +35,7 @@ export class AssetsCollectionsForOwnerProvider extends BaseProvider<string> {
const nftsPromisesResponse = await Promise.all(nftsPromises);
let response: any = {};
for (const [nfts, count] of nftsPromisesResponse) {
const key = `${nfts[0].collection}_${page}_${size}_${ownerAddress}`;
const key = `${nfts[0]?.collection}_${ownerAddress}`;
response[key] = { nfts: nfts, count: count };
}
return response;
Expand Down
11 changes: 3 additions & 8 deletions src/modules/assets/loaders/assets-collection.loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,17 @@ export class AssetsCollectionsProvider extends BaseProvider<string> {
}

async getData(identifiers: string[]) {
const page = parseInt(identifiers[0].split('_')[1]);
const size = parseInt(identifiers[0].split('_')[2]);
const nftsPromises = identifiers.map((identifier) =>
this.apiService.getNftsAndCount(
new AssetsQuery()
.addCollection(identifier.split('_')[0])
.addPageSize(page, size)
.build(),
new AssetsQuery().addCollection(identifier.split('_')[0]).build(),
new AssetsQuery().addCollection(identifier).addPageSize(0, 10).build(),
new AssetsQuery().addCollection(identifier).build(),
),
);

const nftsPromisesResponse = await Promise.all(nftsPromises);
let response: any = {};
for (const [nfts, count] of nftsPromisesResponse) {
const key = `${nfts[0].collection}_${page}_${size}`;
const key = nfts[0]?.collection;
response[key] = { nfts: nfts, count: count };
}
return response;
Expand Down
1 change: 1 addition & 0 deletions src/modules/assets/models/AuctionEvent.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum ExternalAuctionEventEnum {
ChangePrice = 'changePrice',
UpdatePrice = 'updatePrice',
UpdateListing = 'changeListing',
ReturnListing = 'returnListing',
AcceptOffer = 'acceptOffer',
UpdateOffer = 'update_offer_event',
AcceptGlobalOffer = 'acceptGlobalOffer',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/assets/models/Price.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Price {
@Field(() => String, { nullable: true })
usdAmount: string;
@Field(() => Int)
nonce: number;
nonce: number = 0;

@Field(() => Token)
tokenData: Token;
Expand Down
Loading

0 comments on commit 13e2bfc

Please sign in to comment.