style: fix eslint errors for subgraph (#218)

* style: fix eslint errors.

* fix: remove yarn-error.log from serverless dir.
This commit is contained in:
Shredder 2023-04-12 19:37:25 +03:30 committed by GitHub
parent c4ced2ff93
commit aa98d91c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 184 additions and 219 deletions

View File

@ -1,110 +1,100 @@
import {
Address,
Bytes,
log,
store,
ethereum,
BigInt,
} from '@graphprotocol/graph-ts';
import { Bytes, log } from '@graphprotocol/graph-ts';
// Event Imports [based on the yaml config]
import {
TokenRoleChanged as TokenRoleChangedEvent,
CollectionRoleChanged as CollectionRoleChangedEvent,
TokenRoleChanged as TokenRoleChangedEvent,
CollectionRoleChanged as CollectionRoleChangedEvent,
} from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
import {
Owner,
Token,
} from '../generated/schema';
import { Owner, Token } from '../generated/schema';
enum CollectionRoles {
Owner,
Owner,
}
enum TokenRoles {
Controller,
Controller,
}
export function handleCollectionRoleChanged(
event: CollectionRoleChangedEvent
event: CollectionRoleChangedEvent
): void {
let toAddress = event.params.toAddress;
let byAddress = event.params.byAddress;
let role = event.params.role;
let status = event.params.status;
const toAddress = event.params.toAddress;
const byAddress = event.params.byAddress;
const role = event.params.role;
const status = event.params.status;
if (role === CollectionRoles.Owner) {
// Owner role
if (status) {
// granted
let owner = Owner.load(toAddress);
if (!owner) {
owner = new Owner(toAddress);
}
owner.collection = true;
owner.save();
} else {
// revoked
let owner = Owner.load(toAddress);
if (!owner) {
log.error(
'Owner entity not found. Role: {}, byAddress: {}, toAddress: {}',
[role.toString(), byAddress.toHexString(), toAddress.toHexString()]
);
return;
}
owner.collection = false;
owner.save();
}
if (role === CollectionRoles.Owner) {
// Owner role
if (status) {
// granted
let owner = Owner.load(toAddress);
if (!owner) {
owner = new Owner(toAddress);
}
owner.collection = true;
owner.save();
} else {
log.error('Role not supported. Role: {}, byAddress: {}, toAddress: {}', [
role.toString(),
byAddress.toHexString(),
toAddress.toHexString(),
]);
// revoked
const owner = Owner.load(toAddress);
if (!owner) {
log.error(
'Owner entity not found. Role: {}, byAddress: {}, toAddress: {}',
[role.toString(), byAddress.toHexString(), toAddress.toHexString()]
);
return;
}
owner.collection = false;
owner.save();
}
} else {
log.error('Role not supported. Role: {}, byAddress: {}, toAddress: {}', [
role.toString(),
byAddress.toHexString(),
toAddress.toHexString(),
]);
}
}
export function handleTokenRoleChanged(event: TokenRoleChangedEvent): void {
let tokenId = event.params.tokenId;
let toAddress = event.params.toAddress;
let byAddress = event.params.byAddress;
let role = event.params.role;
let status = event.params.status;
const tokenId = event.params.tokenId;
const toAddress = event.params.toAddress;
const byAddress = event.params.byAddress;
const role = event.params.role;
const status = event.params.status;
// load token
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(tokenId)));
if (!token) {
log.error('Token not found. TokenId: {}', [tokenId.toString()]);
return;
// load token
const token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(tokenId)));
if (!token) {
log.error('Token not found. TokenId: {}', [tokenId.toString()]);
return;
}
if (role === TokenRoles.Controller) {
// Controller role
// get the list of controllers.
let token_controllers = token.controllers;
if (!token_controllers) {
token_controllers = [];
}
if (role === TokenRoles.Controller) {
// Controller role
// get the list of controllers.
let token_controllers = token.controllers;
if (!token_controllers) {
token_controllers = [];
}
if (status) {
// granted
token_controllers.push(toAddress);
} else {
// revoked
// remove address from the controllers list
const index = token_controllers.indexOf(event.params.toAddress, 0);
if (index > -1) {
token_controllers.splice(index, 1);
}
}
token.controllers = token_controllers;
if (status) {
// granted
token_controllers.push(toAddress);
} else {
log.error('Role not supported. Role: {}, byAddress: {}, toAddress: {}', [
role.toString(),
byAddress.toHexString(),
toAddress.toHexString(),
]);
// revoked
// remove address from the controllers list
const index = token_controllers.indexOf(event.params.toAddress, 0);
if (index > -1) {
token_controllers.splice(index, 1);
}
}
}
token.controllers = token_controllers;
} else {
log.error('Role not supported. Role: {}, byAddress: {}, toAddress: {}', [
role.toString(),
byAddress.toHexString(),
toAddress.toHexString(),
]);
}
}

View File

@ -1,11 +1,4 @@
import {
Address,
Bytes,
log,
store,
ethereum,
BigInt,
} from '@graphprotocol/graph-ts';
import { Bytes, log, BigInt } from '@graphprotocol/graph-ts';
// Event Imports [based on the yaml config]
import {
@ -27,7 +20,7 @@ import { AccessPoint, Owner } from '../generated/schema';
*/
export function handleNewAccessPoint(event: NewAccessPointEvent): void {
// Create an AccessPoint entity
let accessPointEntity = new AccessPoint(event.params.apName);
const accessPointEntity = new AccessPoint(event.params.apName);
accessPointEntity.score = BigInt.fromU32(0);
accessPointEntity.contentVerified = false;
accessPointEntity.nameVerified = false;
@ -59,8 +52,8 @@ export function handleChangeAccessPointCreationStatus(
event: ChangeAccessPointCreationStatusEvent
): void {
// Load the AccessPoint entity
let accessPointEntity = AccessPoint.load(event.params.apName);
let status = event.params.status;
const accessPointEntity = AccessPoint.load(event.params.apName);
const status = event.params.status;
if (accessPointEntity) {
switch (status) {
@ -101,7 +94,7 @@ export function handleChangeAccessPointScore(
event: ChangeAccessPointCreationScoreEvent
): void {
// Load the AccessPoint entity
let accessPointEntity = AccessPoint.load(event.params.apName);
const accessPointEntity = AccessPoint.load(event.params.apName);
if (accessPointEntity) {
accessPointEntity.score = event.params.score;
@ -122,7 +115,7 @@ export function handleChangeAccessPointNameVerify(
event: ChangeAccessPointNameVerifyEvent
): void {
// Load the AccessPoint entity
let accessPointEntity = AccessPoint.load(event.params.apName);
const accessPointEntity = AccessPoint.load(event.params.apName);
if (accessPointEntity) {
accessPointEntity.nameVerified = event.params.verified;
@ -143,7 +136,7 @@ export function handleChangeAccessPointContentVerify(
event: ChangeAccessPointContentVerifyEvent
): void {
// Load the AccessPoint entity
let accessPointEntity = AccessPoint.load(event.params.apName);
const accessPointEntity = AccessPoint.load(event.params.apName);
if (accessPointEntity) {
accessPointEntity.contentVerified = event.params.verified;

View File

@ -1,41 +1,38 @@
// Event Imports [based on the yaml config]
import {
Approval as ApprovalEvent,
ApprovalForAll as ApprovalForAllEvent,
Approval as ApprovalEvent,
ApprovalForAll as ApprovalForAllEvent,
} from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
import {
Approval,
ApprovalForAll,
} from '../generated/schema';
import { Approval, ApprovalForAll } from '../generated/schema';
export function handleApproval(event: ApprovalEvent): void {
let entity = new Approval(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.owner = event.params.owner;
entity.approved = event.params.approved;
entity.tokenId = event.params.tokenId;
const entity = new Approval(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.owner = event.params.owner;
entity.approved = event.params.approved;
entity.tokenId = event.params.tokenId;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.save();
entity.save();
}
export function handleApprovalForAll(event: ApprovalForAllEvent): void {
let entity = new ApprovalForAll(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.owner = event.params.owner;
entity.operator = event.params.operator;
entity.approved = event.params.approved;
const entity = new ApprovalForAll(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
entity.owner = event.params.owner;
entity.operator = event.params.operator;
entity.approved = event.params.approved;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.blockNumber = event.block.number;
entity.blockTimestamp = event.block.timestamp;
entity.transactionHash = event.transaction.hash;
entity.save();
}
entity.save();
}

View File

@ -1,29 +1,22 @@
import {
log,
ethereum,
} from '@graphprotocol/graph-ts';
import { log, ethereum } from '@graphprotocol/graph-ts';
// Event Imports [based on the yaml config]
import {
Initialized as InitializedEvent,
} from '../generated/FleekNFA/FleekNFA';
import { Initialized as InitializedEvent } from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
import {
Owner,
} from '../generated/schema';
import { Owner } from '../generated/schema';
export function handleInitialized(event: InitializedEvent): void {
// This is the contract creation transaction.
log.warning('This is the contract creation transaction.', []);
if (event.receipt) {
let receipt = event.receipt as ethereum.TransactionReceipt;
log.warning('Contract address is: {}', [
receipt.contractAddress.toHexString(),
]);
// This is the contract creation transaction.
log.warning('This is the contract creation transaction.', []);
if (event.receipt) {
const receipt = event.receipt as ethereum.TransactionReceipt;
log.warning('Contract address is: {}', [
receipt.contractAddress.toHexString(),
]);
// add owner
let owner = new Owner(event.transaction.from);
owner.collection = true;
owner.save();
}
}
// add owner
const owner = new Owner(event.transaction.from);
owner.collection = true;
owner.save();
}
}

View File

@ -1,5 +1,5 @@
export * from './access-control';
export * from './access-point';
export * from './access-point';
export * from './approval';
export * from './contract';
export * from './metadata-update';

View File

@ -27,7 +27,7 @@ export function handleMetadataUpdateWithStringValue(
* setTokenDescription
* setTokenLogo
* */
let entity = new MetadataUpdate(
const entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
@ -41,7 +41,7 @@ export function handleMetadataUpdateWithStringValue(
entity.save();
// UPDATE TOKEN
let token = Token.load(
const token = Token.load(
Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId))
);
@ -68,7 +68,7 @@ export function handleMetadataUpdateWithDoubleStringValue(
/**
* setTokenBuild
*/
let entity = new MetadataUpdate(
const entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
@ -82,7 +82,7 @@ export function handleMetadataUpdateWithDoubleStringValue(
entity.save();
// UPDATE TOKEN
let token = Token.load(
const token = Token.load(
Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId))
);
@ -107,7 +107,7 @@ export function handleMetadataUpdateWithIntValue(
/**
* setTokenColor
*/
let entity = new MetadataUpdate(
const entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
@ -120,7 +120,7 @@ export function handleMetadataUpdateWithIntValue(
entity.save();
let token = Token.load(
const token = Token.load(
Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId))
);
@ -138,7 +138,7 @@ export function handleMetadataUpdateWithBooleanValue(
/**
* accessPointAutoApproval
*/
let entity = new MetadataUpdate(
const entity = new MetadataUpdate(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
@ -151,7 +151,7 @@ export function handleMetadataUpdateWithBooleanValue(
entity.save();
let token = Token.load(
const token = Token.load(
Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId))
);

View File

@ -4,30 +4,25 @@ import { Bytes, log } from '@graphprotocol/graph-ts';
import { NewMint as NewMintEvent } from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
import {
Owner,
GitRepository as GitRepositoryEntity,
NewMint,
Token,
} from '../generated/schema';
import { Owner, NewMint, Token } from '../generated/schema';
export function handleNewMint(event: NewMintEvent): void {
let newMintEntity = new NewMint(
const newMintEntity = new NewMint(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
let name = event.params.name;
let description = event.params.description;
let externalURL = event.params.externalURL;
let ENS = event.params.ENS;
let gitRepository = event.params.gitRepository;
let commitHash = event.params.commitHash;
let logo = event.params.logo;
let color = event.params.color;
let accessPointAutoApproval = event.params.accessPointAutoApproval;
let tokenId = event.params.tokenId;
let ownerAddress = event.params.owner;
let verifierAddress = event.params.verifier;
const name = event.params.name;
const description = event.params.description;
const externalURL = event.params.externalURL;
const ENS = event.params.ENS;
const gitRepository = event.params.gitRepository;
const commitHash = event.params.commitHash;
const logo = event.params.logo;
const color = event.params.color;
const accessPointAutoApproval = event.params.accessPointAutoApproval;
const tokenId = event.params.tokenId;
const ownerAddress = event.params.owner;
const verifierAddress = event.params.verifier;
newMintEntity.tokenId = tokenId;
newMintEntity.name = name;
@ -51,7 +46,7 @@ export function handleNewMint(event: NewMintEvent): void {
// Create Token, Owner, and Controller entities
let owner = Owner.load(ownerAddress);
let token = new Token(Bytes.fromByteArray(Bytes.fromBigInt(tokenId)));
const token = new Token(Bytes.fromByteArray(Bytes.fromBigInt(tokenId)));
if (!owner) {
// Create a new owner entity

View File

@ -7,7 +7,7 @@ import { Transfer as TransferEvent } from '../generated/FleekNFA/FleekNFA';
import { Owner, Token, Transfer } from '../generated/schema';
export function handleTransfer(event: TransferEvent): void {
let transfer = new Transfer(
const transfer = new Transfer(
event.transaction.hash.concatI32(event.logIndex.toI32())
);
@ -25,7 +25,7 @@ export function handleTransfer(event: TransferEvent): void {
let token: Token | null;
let owner_address = event.params.to;
const owner_address = event.params.to;
let owner = Owner.load(owner_address);
if (!owner) {

View File

@ -6,13 +6,12 @@ import {
beforeAll,
afterAll,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { BigInt } from '@graphprotocol/graph-ts';
import {
createNewAccessPointEvent,
createNewChangeAccessPointCreationStatus,
handleChangeAccessPointCreationStatusList,
handleNewAccessPoints,
makeEventId,
USER_ONE,
USER_TWO,
} from '../helpers/utils';
@ -24,7 +23,7 @@ import {
describe('Change Access Point Creation Status tests', () => {
beforeAll(() => {
// New Access Points
let newAccessPoints: NewAccessPoint[] = [];
const newAccessPoints: NewAccessPoint[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
newAccessPoints.push(
@ -54,7 +53,7 @@ describe('Change Access Point Creation Status tests', () => {
test('Check the `creationStatus` field of each access point entity after changing it', () => {
// New Access Points
let changeAccessPointCreationStatusList: ChangeAccessPointCreationStatus[] =
const changeAccessPointCreationStatusList: ChangeAccessPointCreationStatus[] =
[];
// User One has two access points: one for tokenId 0 and one for tokenId 1

View File

@ -23,7 +23,7 @@ import {
describe('Change Access Point Name Verify tests', () => {
beforeAll(() => {
// New Access Points
let newAccessPoints: NewAccessPoint[] = [];
const newAccessPoints: NewAccessPoint[] = [];
// User One has two access points: one for tokenId 0 and one for tokenId 1
newAccessPoints.push(
@ -53,7 +53,7 @@ describe('Change Access Point Name Verify tests', () => {
test('Check the `nameVerified` field of each access point entity after changing it', () => {
// New Access Point Name Verified fields
let changeAccessPointNameVerifies: ChangeAccessPointNameVerify[] = [];
const changeAccessPointNameVerifies: ChangeAccessPointNameVerify[] = [];
changeAccessPointNameVerifies.push(
createNewChangeAccessPointNameVerify(

View File

@ -27,11 +27,11 @@ export function createApprovalEvent(
event_count: i32,
owner: Address,
approved: Address,
tokenId: BigInt
tokenId: bigint
): ApprovalEvent {
let approvalEvent = changetype<ApprovalEvent>(newMockEvent());
const approvalEvent = changetype<ApprovalEvent>(newMockEvent());
approvalEvent.parameters = new Array();
approvalEvent.parameters = [];
approvalEvent.parameters.push(
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
@ -58,9 +58,9 @@ export function createApprovalForAllEvent(
operator: Address,
approved: boolean
): ApprovalForAllEvent {
let approvalForAllEvent = changetype<ApprovalForAllEvent>(newMockEvent());
const approvalForAllEvent = changetype<ApprovalForAllEvent>(newMockEvent());
approvalForAllEvent.parameters = new Array();
approvalForAllEvent.parameters = [];
approvalForAllEvent.parameters.push(
new ethereum.EventParam('owner', ethereum.Value.fromAddress(owner))
@ -82,11 +82,11 @@ export function createTransferEvent(
event_count: i32,
from: Address,
to: Address,
tokenId: BigInt
tokenId: bigint
): TransferEvent {
let transferEvent = changetype<TransferEvent>(newMockEvent());
const transferEvent = changetype<TransferEvent>(newMockEvent());
transferEvent.parameters = new Array();
transferEvent.parameters = [];
transferEvent.parameters.push(
new ethereum.EventParam('from', ethereum.Value.fromAddress(from))
@ -110,11 +110,11 @@ export function createTransferEvent(
export function createNewMintEvent(
event_count: i32,
to: Address,
tokenId: BigInt
tokenId: bigint
): NewMintEvent {
let newMintEvent = changetype<NewMintEvent>(newMockEvent());
const newMintEvent = changetype<NewMintEvent>(newMockEvent());
newMintEvent.parameters = new Array();
newMintEvent.parameters = [];
newMintEvent.parameters.push(
new ethereum.EventParam(
@ -177,12 +177,12 @@ export function createNewMintEvent(
export function createNewAccessPointEvent(
event_count: i32,
apName: string,
tokenId: BigInt,
tokenId: bigint,
owner: Address
): NewAccessPoint {
let newAccessPoint = changetype<NewAccessPoint>(newMockEvent());
const newAccessPoint = changetype<NewAccessPoint>(newMockEvent());
newAccessPoint.parameters = new Array();
newAccessPoint.parameters = [];
newAccessPoint.parameters.push(
new ethereum.EventParam(
@ -211,14 +211,14 @@ export function createNewAccessPointEvent(
export function createNewChangeAccessPointCreationStatus(
event_count: i32,
apName: string,
tokenId: BigInt,
tokenId: bigint,
status: i32,
triggeredBy: Address
): ChangeAccessPointCreationStatus {
let changeAccessPointCreationStatus =
const changeAccessPointCreationStatus =
changetype<ChangeAccessPointCreationStatus>(newMockEvent());
changeAccessPointCreationStatus.parameters = new Array();
changeAccessPointCreationStatus.parameters = [];
changeAccessPointCreationStatus.parameters.push(
new ethereum.EventParam(
@ -254,15 +254,15 @@ export function createNewChangeAccessPointCreationStatus(
export function createNewChangeAccessPointNameVerify(
event_count: i32,
apName: string,
tokenId: BigInt,
tokenId: bigint,
verified: boolean,
triggeredBy: Address
): ChangeAccessPointNameVerify {
let changeAccessPointNameVerify = changetype<ChangeAccessPointNameVerify>(
const changeAccessPointNameVerify = changetype<ChangeAccessPointNameVerify>(
newMockEvent()
);
changeAccessPointNameVerify.parameters = new Array();
changeAccessPointNameVerify.parameters = [];
changeAccessPointNameVerify.parameters.push(
new ethereum.EventParam(
@ -297,15 +297,15 @@ export function createNewChangeAccessPointNameVerify(
export function createNewTokenRoleChanged(
event_count: i32,
tokenId: BigInt,
tokenId: bigint,
role: i32,
toAddress: Address,
status: boolean,
byAddress: Address
): TokenRoleChanged {
let tokenRoleChanged = changetype<TokenRoleChanged>(newMockEvent());
const tokenRoleChanged = changetype<TokenRoleChanged>(newMockEvent());
tokenRoleChanged.parameters = new Array();
tokenRoleChanged.parameters = [];
tokenRoleChanged.parameters.push(
new ethereum.EventParam(
@ -343,9 +343,11 @@ export function createNewCollectionRoleChanged(
status: boolean,
byAddress: Address
): CollectionRoleChanged {
let collectionRoleChanged = changetype<CollectionRoleChanged>(newMockEvent());
const collectionRoleChanged = changetype<CollectionRoleChanged>(
newMockEvent()
);
collectionRoleChanged.parameters = new Array();
collectionRoleChanged.parameters = [];
collectionRoleChanged.parameters.push(
new ethereum.EventParam('role', ethereum.Value.fromI32(role))

View File

@ -5,8 +5,6 @@ import {
clearStore,
beforeAll,
afterAll,
logStore,
log,
} from 'matchstick-as/assembly/index';
import { BigInt } from '@graphprotocol/graph-ts';
import {
@ -24,7 +22,7 @@ import { NewMint, Transfer } from '../../generated/FleekNFA/FleekNFA';
describe('Owner tests', () => {
beforeAll(() => {
// NEW MINTS
let newMints: NewMint[] = [];
const newMints: NewMint[] = [];
newMints.push(createNewMintEvent(0, USER_ONE, BigInt.fromI32(0)));
newMints.push(createNewMintEvent(1, USER_TWO, BigInt.fromI32(1)));
newMints.push(createNewMintEvent(2, USER_ONE, BigInt.fromI32(2)));
@ -32,7 +30,7 @@ describe('Owner tests', () => {
newMints.push(createNewMintEvent(4, USER_TWO, BigInt.fromI32(4)));
handleNewMints(newMints);
// TRANSFERS
let transfers: Transfer[] = [];
const transfers: Transfer[] = [];
transfers.push(
createTransferEvent(0, CONTRACT, USER_ONE, BigInt.fromI32(0))
);

View File

@ -5,10 +5,8 @@ import {
clearStore,
beforeAll,
afterAll,
logStore,
log,
} from 'matchstick-as/assembly/index';
import { BigInt, Bytes } from '@graphprotocol/graph-ts';
import { BigInt } from '@graphprotocol/graph-ts';
import {
CONTRACT,
createTransferEvent,
@ -22,7 +20,7 @@ import { Transfer } from '../../generated/FleekNFA/FleekNFA';
describe('Transfer tests', () => {
beforeAll(() => {
// TRANSFERS
let transfers: Transfer[] = [];
const transfers: Transfer[] = [];
transfers.push(
createTransferEvent(0, CONTRACT, USER_ONE, BigInt.fromI32(0))
);