feat: metadata update and token changes on subgraph (#135)
* feat: add entity and handler. * merge: reverse lookup and ap auto approval. * feat: update the token entity on metadata changes. * merge: develop. fix conflicts. * fix: tests.
This commit is contained in:
parent
2ae7666648
commit
d7841717ff
|
|
@ -31,11 +31,10 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
|||
string gitRepository,
|
||||
string logo,
|
||||
uint24 color,
|
||||
bool accessPointAutoApprovalSettings,
|
||||
bool accessPointAutoApproval,
|
||||
address indexed minter,
|
||||
address indexed owner
|
||||
);
|
||||
|
||||
event MetadataUpdate(uint256 indexed _tokenId, string key, string value, address indexed triggeredBy);
|
||||
event MetadataUpdate(uint256 indexed _tokenId, string key, uint24 value, address indexed triggeredBy);
|
||||
event MetadataUpdate(uint256 indexed _tokenId, string key, string[2] value, address indexed triggeredBy);
|
||||
|
|
@ -43,7 +42,11 @@ contract FleekERC721 is Initializable, ERC721Upgradeable, FleekAccessControl, Fl
|
|||
event NewAccessPoint(string apName, uint256 indexed tokenId, address indexed owner);
|
||||
event RemoveAccessPoint(string apName, uint256 indexed tokenId, address indexed owner);
|
||||
|
||||
event ChangeAccessPointAutoApproval(uint256 indexed token, bool indexed settings, address indexed triggeredBy);
|
||||
event ChangeAccessPointAutoApproval(
|
||||
uint256 indexed token,
|
||||
bool indexed settings,
|
||||
address indexed triggeredBy
|
||||
);
|
||||
|
||||
event ChangeAccessPointScore(string apName, uint256 indexed tokenId, uint256 score, address indexed triggeredBy);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import "../TestBase.sol";
|
|||
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
|
||||
import {FleekAccessControl} from "contracts/FleekAccessControl.sol";
|
||||
import "../../../../contracts/FleekERC721.sol";
|
||||
import "./ApBase.sol";
|
||||
import './ApBase.sol';
|
||||
|
||||
contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
|
||||
using Strings for address;
|
||||
|
|
@ -37,7 +37,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
|
|||
string memory accessPointName = "accesspoint.com";
|
||||
CuT.addAccessPoint(tokenId, accessPointName);
|
||||
CuT.removeAccessPoint(accessPointName);
|
||||
|
||||
|
||||
APConstants.assertAccessPointJSON(
|
||||
accessPointName,
|
||||
"0",
|
||||
|
|
@ -65,6 +65,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
|
|||
function test_increaseAccessPointScore() public {
|
||||
string memory accessPointName = "accesspoint.com";
|
||||
CuT.addAccessPoint(tokenId, accessPointName);
|
||||
|
||||
APConstants.assertAccessPointJSON(
|
||||
accessPointName,
|
||||
"0",
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ contract Test_FleekERC721_AccessPoint is Test_FleekERC721_Base, APConstants {
|
|||
function test_increaseAccessPointScore() public {
|
||||
string memory accessPointName = "accesspoint.com";
|
||||
CuT.addAccessPoint(tokenId, accessPointName);
|
||||
|
||||
APConstants.assertAccessPointJSON(
|
||||
accessPointName,
|
||||
"0",
|
||||
|
|
|
|||
|
|
@ -204,7 +204,10 @@ describe('FleekERC721.AccessPoints.AutoApprovalOff', () => {
|
|||
it('should token owner be able to change the auto approval settings to on', async () => {
|
||||
const { contract, tokenId, owner } = fixture;
|
||||
|
||||
await contract.connect(owner).setAccessPointAutoApproval(tokenId, true);
|
||||
|
||||
await contract
|
||||
.connect(owner)
|
||||
.setAccessPointAutoApproval(tokenId, true);
|
||||
|
||||
await contract.addAccessPoint(tokenId, 'accesspoint.com');
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,6 @@ export const TestConstants = Object.freeze({
|
|||
REJECTED: 2,
|
||||
REMOVED: 3,
|
||||
},
|
||||
AccessPointStatus: {
|
||||
DRAFT: 0,
|
||||
APPROVED: 1,
|
||||
REJECTED: 2,
|
||||
REMOVED: 3,
|
||||
},
|
||||
MintParams: {
|
||||
name: 'Fleek Test App',
|
||||
description: 'Fleek Test App Description',
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ type NewMint @entity(immutable: true) {
|
|||
gitRepository: String! # string
|
||||
logo: String!
|
||||
color: Int!
|
||||
accessPointAutoApprovalSettings: Boolean!
|
||||
accessPointAutoApproval: Boolean!
|
||||
triggeredBy: Bytes! # address
|
||||
tokenOwner: Owner! # address
|
||||
blockNumber: BigInt!
|
||||
|
|
@ -57,61 +57,14 @@ type NewMint @entity(immutable: true) {
|
|||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewBuild @entity(immutable: true) {
|
||||
type MetadataUpdate @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
commitHash: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewTokenDescription @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
description: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewTokenENS @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
ENS: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewTokenExternalURL @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
externalURL: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewTokenLogo @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
logo: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
}
|
||||
|
||||
type NewTokenName @entity(immutable: true) {
|
||||
id: Bytes!
|
||||
token: BigInt! # uint256
|
||||
name: String! # string
|
||||
triggeredBy: Bytes! # address
|
||||
tokenId: BigInt!
|
||||
key: String!
|
||||
stringValue: String
|
||||
uint24Value: Int
|
||||
doubleStringValue: [String!]!
|
||||
byAddress: Bytes!
|
||||
blockNumber: BigInt!
|
||||
blockTimestamp: BigInt!
|
||||
transactionHash: Bytes!
|
||||
|
|
@ -159,7 +112,7 @@ type Token @entity {
|
|||
ENS: String!
|
||||
logo: String!
|
||||
color: Int!
|
||||
accessPointAutoApprovalSettings: Boolean!
|
||||
accessPointAutoApproval: Boolean!
|
||||
owner: Owner!
|
||||
mintedBy: Bytes!
|
||||
controllers: [Controller!]
|
||||
|
|
|
|||
|
|
@ -4,13 +4,9 @@ import {
|
|||
ApprovalForAll as ApprovalForAllEvent,
|
||||
CollectionRoleGranted as CollectionRoleGrantedEvent,
|
||||
CollectionRoleRevoked as CollectionRoleRevokedEvent,
|
||||
FleekNFA,
|
||||
NewBuild as NewBuildEvent,
|
||||
NewTokenDescription as NewTokenDescriptionEvent,
|
||||
NewTokenENS as NewTokenENSEvent,
|
||||
NewTokenExternalURL as NewTokenExternalURLEvent,
|
||||
NewTokenLogo as NewTokenLogoEvent,
|
||||
NewTokenName as NewTokenNameEvent,
|
||||
MetadataUpdate as MetadataUpdateEvent,
|
||||
MetadataUpdate1 as MetadataUpdateEvent1,
|
||||
MetadataUpdate2 as MetadataUpdateEvent2,
|
||||
TokenRoleGranted as TokenRoleGrantedEvent,
|
||||
TokenRoleRevoked as TokenRoleRevokedEvent,
|
||||
Transfer as TransferEvent,
|
||||
|
|
@ -25,13 +21,8 @@ import {
|
|||
CollectionRoleRevoked,
|
||||
Controller,
|
||||
GitRepository as GitRepositoryEntity,
|
||||
NewBuild,
|
||||
MetadataUpdate,
|
||||
NewMint,
|
||||
NewTokenDescription,
|
||||
NewTokenENS,
|
||||
NewTokenExternalURL,
|
||||
NewTokenLogo,
|
||||
NewTokenName,
|
||||
Owner,
|
||||
Token,
|
||||
TokenRoleGranted,
|
||||
|
|
@ -155,7 +146,6 @@ export function handleCollectionRoleRevoked(
|
|||
store.remove('CollectionOwner', event.params.toAddress.toHexString());
|
||||
}
|
||||
}
|
||||
|
||||
export function handleNewMint(event: NewMintEvent): void {
|
||||
let newMintEntity = new NewMint(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
|
|
@ -169,8 +159,8 @@ export function handleNewMint(event: NewMintEvent): void {
|
|||
let commitHash = event.params.commitHash;
|
||||
let logo = event.params.logo;
|
||||
let color = event.params.color;
|
||||
let accessPointAutoApprovalSettings =
|
||||
event.params.accessPointAutoApprovalSettings;
|
||||
let accessPointAutoApproval =
|
||||
event.params.accessPointAutoApproval;
|
||||
let tokenId = event.params.tokenId;
|
||||
let ownerAddress = event.params.owner;
|
||||
|
||||
|
|
@ -183,8 +173,8 @@ export function handleNewMint(event: NewMintEvent): void {
|
|||
newMintEntity.gitRepository = gitRepository;
|
||||
newMintEntity.logo = logo;
|
||||
newMintEntity.color = color;
|
||||
newMintEntity.accessPointAutoApprovalSettings =
|
||||
accessPointAutoApprovalSettings;
|
||||
newMintEntity.accessPointAutoApproval =
|
||||
accessPointAutoApproval;
|
||||
newMintEntity.triggeredBy = event.params.minter;
|
||||
newMintEntity.tokenOwner = ownerAddress;
|
||||
newMintEntity.blockNumber = event.block.number;
|
||||
|
|
@ -224,7 +214,7 @@ export function handleNewMint(event: NewMintEvent): void {
|
|||
token.commitHash = commitHash;
|
||||
token.logo = logo;
|
||||
token.color = color;
|
||||
token.accessPointAutoApprovalSettings = accessPointAutoApprovalSettings;
|
||||
token.accessPointAutoApproval = accessPointAutoApproval;
|
||||
token.owner = ownerAddress;
|
||||
token.mintTransaction = event.transaction.hash.concatI32(
|
||||
event.logIndex.toI32()
|
||||
|
|
@ -239,98 +229,108 @@ export function handleNewMint(event: NewMintEvent): void {
|
|||
token.save();
|
||||
}
|
||||
|
||||
export function handleNewBuild(event: NewBuildEvent): void {
|
||||
let entity = new NewBuild(
|
||||
export function handleMetadataUpdateWithStringValue(event: MetadataUpdateEvent): void {
|
||||
/**
|
||||
* Metadata handled here:
|
||||
* setTokenExternalURL
|
||||
* setTokenENS
|
||||
* setTokenName
|
||||
* setTokenDescription
|
||||
* setTokenLogo
|
||||
* */
|
||||
let entity = new MetadataUpdate(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.commitHash = event.params.commitHash.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
|
||||
entity.tokenId = event.params._tokenId;
|
||||
entity.key = event.params.key;
|
||||
entity.stringValue = event.params.value;
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
// UPDATE TOKEN
|
||||
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
|
||||
|
||||
if (token) {
|
||||
if (event.params.key == 'externalURL') {
|
||||
token.externalURL = event.params.value;
|
||||
} else if (event.params.key == 'ENS') {
|
||||
token.ENS = event.params.value;
|
||||
} else if (event.params.key == 'name') {
|
||||
token.name = event.params.value;
|
||||
} else if (event.params.key == 'description') {
|
||||
token.description = event.params.value;
|
||||
} else {
|
||||
// logo
|
||||
token.logo = event.params.value;
|
||||
}
|
||||
token.save();
|
||||
}
|
||||
}
|
||||
|
||||
export function handleNewTokenDescription(
|
||||
event: NewTokenDescriptionEvent
|
||||
): void {
|
||||
let entity = new NewTokenDescription(
|
||||
export function handleMetadataUpdateWithDoubleStringValue(event: MetadataUpdateEvent2): void {
|
||||
/**
|
||||
* setTokenBuild
|
||||
*/
|
||||
let entity = new MetadataUpdate(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.description = event.params.description.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
|
||||
entity.key = event.params.key;
|
||||
entity.tokenId = event.params._tokenId;
|
||||
entity.doubleStringValue = event.params.value;
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
|
||||
// UPDATE TOKEN
|
||||
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
|
||||
|
||||
if (token) {
|
||||
if (event.params.key == 'build') {
|
||||
let gitRepositoryEntity = GitRepositoryEntity.load(event.params.value[1]);
|
||||
if (!gitRepositoryEntity) {
|
||||
// Create a new gitRepository entity
|
||||
gitRepositoryEntity = new GitRepositoryEntity(event.params.value[1]);
|
||||
}
|
||||
token.commitHash = event.params.value[0];
|
||||
token.gitRepository = event.params.value[1];
|
||||
token.save();
|
||||
gitRepositoryEntity.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function handleNewTokenENS(event: NewTokenENSEvent): void {
|
||||
let entity = new NewTokenENS(
|
||||
export function handleMetadataUpdateWithIntValue(event: MetadataUpdateEvent1): void {
|
||||
/**
|
||||
* setTokenColor
|
||||
*/
|
||||
let entity = new MetadataUpdate(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.ENS = event.params.ENS.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
|
||||
entity.key = event.params.key;
|
||||
entity.tokenId = event.params._tokenId;
|
||||
entity.uint24Value = event.params.value;
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
}
|
||||
|
||||
export function handleNewTokenExternalURL(
|
||||
event: NewTokenExternalURLEvent
|
||||
): void {
|
||||
let entity = new NewTokenExternalURL(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.externalURL = event.params.externalURL.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
let token = Token.load(Bytes.fromByteArray(Bytes.fromBigInt(event.params._tokenId)));
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
}
|
||||
|
||||
export function handleNewTokenLogo(event: NewTokenLogoEvent): void {
|
||||
let entity = new NewTokenLogo(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.logo = event.params.logo.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
}
|
||||
|
||||
export function handleNewTokenName(event: NewTokenNameEvent): void {
|
||||
let entity = new NewTokenName(
|
||||
event.transaction.hash.concatI32(event.logIndex.toI32())
|
||||
);
|
||||
entity.token = event.params.tokenId;
|
||||
entity.name = event.params.name.toString();
|
||||
entity.triggeredBy = event.params.triggeredBy;
|
||||
|
||||
entity.blockNumber = event.block.number;
|
||||
entity.blockTimestamp = event.block.timestamp;
|
||||
entity.transactionHash = event.transaction.hash;
|
||||
|
||||
entity.save();
|
||||
if (token) {
|
||||
if (event.params.key == 'color') {
|
||||
token.color = event.params.value;
|
||||
}
|
||||
token.save();
|
||||
}
|
||||
}
|
||||
|
||||
export function handleTokenRoleGranted(event: TokenRoleGrantedEvent): void {
|
||||
|
|
|
|||
|
|
@ -18,12 +18,8 @@ dataSources:
|
|||
- ApprovalForAll
|
||||
- CollectionRoleGranted
|
||||
- CollectionRoleRevoked
|
||||
- NewBuild
|
||||
- NewTokenDescription
|
||||
- NewTokenENS
|
||||
- NewTokenExternalURL
|
||||
- NewTokenImage
|
||||
- NewTokenName
|
||||
- MetadataUpdate
|
||||
- NewMint
|
||||
- TokenRoleGranted
|
||||
- TokenRoleRevoked
|
||||
- Transfer
|
||||
|
|
@ -40,24 +36,18 @@ dataSources:
|
|||
handler: handleApproval
|
||||
- event: ApprovalForAll(indexed address,indexed address,bool)
|
||||
handler: handleApprovalForAll
|
||||
- event: MetadataUpdate(indexed uint256,string,string,indexed address)
|
||||
handler: handleMetadataUpdateWithStringValue
|
||||
- event: MetadataUpdate(indexed uint256,string,string[2],indexed address)
|
||||
handler: handleMetadataUpdateWithDoubleStringValue
|
||||
- event: MetadataUpdate(indexed uint256,string,uint24,indexed address)
|
||||
handler: handleMetadataUpdateWithIntValue
|
||||
- event: CollectionRoleGranted(indexed uint8,indexed address,address)
|
||||
handler: handleCollectionRoleGranted
|
||||
- event: CollectionRoleRevoked(indexed uint8,indexed address,address)
|
||||
handler: handleCollectionRoleRevoked
|
||||
- event: NewMint(indexed uint256,string,string,string,string,string,string,string,uint24,bool,indexed address,indexed address)
|
||||
handler: handleNewMint
|
||||
- event: NewBuild(indexed uint256,string,indexed address)
|
||||
handler: handleNewBuild
|
||||
- event: NewTokenDescription(indexed uint256,string,indexed address)
|
||||
handler: handleNewTokenDescription
|
||||
- event: NewTokenENS(indexed uint256,string,indexed address)
|
||||
handler: handleNewTokenENS
|
||||
- event: NewTokenExternalURL(indexed uint256,string,indexed address)
|
||||
handler: handleNewTokenExternalURL
|
||||
- event: NewTokenLogo(indexed uint256,string,indexed address)
|
||||
handler: handleNewTokenLogo
|
||||
- event: NewTokenName(indexed uint256,string,indexed address)
|
||||
handler: handleNewTokenName
|
||||
- event: TokenRoleGranted(indexed uint256,indexed uint8,indexed address,address)
|
||||
handler: handleTokenRoleGranted
|
||||
- event: TokenRoleRevoked(indexed uint256,indexed uint8,indexed address,address)
|
||||
|
|
|
|||
Loading…
Reference in New Issue