Added connector contract data, and instaConnectors chief data

This commit is contained in:
Juan Manuel Rodriguez Defago 2020-05-22 17:24:12 -03:00
parent 64e8fc41d1
commit af73724a65
8 changed files with 220 additions and 9 deletions

33
abis/Connector.json Normal file
View File

@ -0,0 +1,33 @@
[
{
"inputs": [],
"name": "connectorID",
"outputs": [
{
"internalType": "uint256",
"name": "_type",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_id",
"type": "uint256"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]

80
abis/InstaEvent.json Normal file
View File

@ -0,0 +1,80 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "connectorType",
"type": "uint64"
},
{
"indexed": true,
"internalType": "uint64",
"name": "connectorID",
"type": "uint64"
},
{
"indexed": true,
"internalType": "uint64",
"name": "accountID",
"type": "uint64"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "eventCode",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes",
"name": "eventData",
"type": "bytes"
}
],
"name": "LogEvent",
"type": "event"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_connectorType",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_connectorID",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "_eventCode",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "_eventData",
"type": "bytes"
}
],
"name": "emitEvent",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "instaList",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
}
]

View File

@ -45,10 +45,13 @@ type InstaConnector @entity {
"Address of the InstaConnector contract. This contract has a list of connectors tracked."
id: ID!
chiefs: [Chief!]! @derivedFrom(field: "instaConnector")
connectors: [Connector!]! @derivedFrom(field: "instaConnector")
}
type Connector @entity {
"Connector ID includes the ID of the InstaConnector it belongs to and the internal ID of the connector"
id: ID!
isStatic: Boolean!
@ -56,4 +59,20 @@ type Connector @entity {
isEnabled: Boolean!
instaConnector: InstaConnector!
name: String!
connectorID: BigInt!
connectorType: BigInt!
address: String!
}
type Chief @entity {
id: ID!
isActive: Boolean!
instaConnector: InstaConnector!
}

View File

@ -11,5 +11,7 @@ export {
export {
handleLogEnableConnector,
handleLogDisableConnector,
handleLogEnableStaticConnector
handleLogEnableStaticConnector,
handleLogAddController,
handleLogRemoveController
} from "./mappings/instaConnectors";

View File

@ -1,18 +1,31 @@
import {
LogDisable,
LogEnable,
LogEnableStatic
LogEnableStatic,
LogAddController,
LogRemoveController
} from "../../generated/templates/InstaConnectors/InstaConnectors";
import { getOrCreateConnector } from "../utils/helpers";
import { Connector as ConnectorContract } from "../../generated/templates/InstaConnectors/Connector";
import { getOrCreateConnector, getOrCreateChief } from "../utils/helpers";
// - event: LogDisable(indexed address)
// handler: handleLogDisableConnector
export function handleLogDisableConnector(event: LogDisable): void {
let connector = getOrCreateConnector(event.params.connector.toHexString())
let contract = ConnectorContract.bind(event.params.connector);
let connectorIDResult = contract.connectorID();
let instaConnectorAddress = event.address.toHexString();
let entityId = instaConnectorAddress
.concat("-")
.concat(connectorIDResult.value1.toString());
let connector = getOrCreateConnector(entityId);
connector.isEnabled = false;
connector.instaConnector = event.address.toHexString();
connector.name = contract.name();
connector.address = event.params.connector.toHexString();
connector.connectorType = connectorIDResult.value0;
connector.connectorID = connectorIDResult.value1;
connector.save();
}
@ -21,11 +34,21 @@ export function handleLogDisableConnector(event: LogDisable): void {
// handler: handleLogEnableConnector
export function handleLogEnableConnector(event: LogEnable): void {
let connector = getOrCreateConnector(event.params.connector.toHexString())
let contract = ConnectorContract.bind(event.params.connector);
let connectorIDResult = contract.connectorID();
let instaConnectorAddress = event.address.toHexString();
let entityId = instaConnectorAddress
.concat("-")
.concat(connectorIDResult.value1.toString());
let connector = getOrCreateConnector(entityId);
connector.isEnabled = true;
connector.isStatic = false;
connector.instaConnector = event.address.toHexString();
connector.name = contract.name();
connector.address = event.params.connector.toHexString();
connector.connectorType = connectorIDResult.value0;
connector.connectorID = connectorIDResult.value1;
connector.save();
}
@ -34,11 +57,45 @@ export function handleLogEnableConnector(event: LogEnable): void {
// handler: handleLogEnableStaticConnector
export function handleLogEnableStaticConnector(event: LogEnableStatic): void {
let connector = getOrCreateConnector(event.params.connector.toHexString())
let contract = ConnectorContract.bind(event.params.connector);
let connectorIDResult = contract.connectorID();
let instaConnectorAddress = event.address.toHexString();
let entityId = instaConnectorAddress
.concat("-")
.concat(connectorIDResult.value1.toString());
let connector = getOrCreateConnector(entityId);
connector.isEnabled = true;
connector.isStatic = true;
connector.instaConnector = event.address.toHexString();
connector.instaConnector = instaConnectorAddress;
connector.name = contract.name();
connector.address = event.params.connector.toHexString();
connector.connectorType = connectorIDResult.value0;
connector.connectorID = connectorIDResult.value1;
connector.save();
}
// - event: LogAddController(indexed address)
// handler: handleLogAddController
export function handleLogAddController(event: LogAddController): void {
let chief = getOrCreateChief(event.params.addr.toHexString())
chief.isActive = true;
chief.instaConnector = event.address.toHexString();
chief.save()
}
// - event: LogRemoveController(indexed address)
// handler: handleLogRemoveController
export function handleLogRemoveController(event: LogRemoveController): void {
let chief = getOrCreateChief(event.params.addr.toHexString())
chief.isActive = false;
chief.instaConnector = event.address.toHexString();
chief.save()
}

View File

@ -7,5 +7,6 @@ export {
export {
getOrCreateConnector,
getOrCreateInstaConnector
getOrCreateInstaConnector,
getOrCreateChief
} from "./instaConnectors";

View File

@ -1,5 +1,5 @@
import { InstaConnectors as ConnectorsTemplate } from "../../../generated/templates";
import { InstaConnector, Connector } from "../../../generated/schema";
import { InstaConnector, Connector, Chief } from "../../../generated/schema";
import { Address } from "@graphprotocol/graph-ts";
export function getOrCreateInstaConnector(
@ -30,3 +30,16 @@ export function getOrCreateConnector(
return connector as Connector;
}
export function getOrCreateChief(
id: String,
createIfNotFound: boolean = true
): Chief {
let chief = Chief.load(id);
if (chief == null && createIfNotFound) {
chief = new Chief(id);
}
return chief as Chief;
}

View File

@ -55,6 +55,8 @@ templates:
abis:
- name: InstaConnectors
file: ./abis/InstaConnectors.json
- name: Connector
file: ./abis/Connector.json
eventHandlers:
- event: LogDisable(indexed address)
handler: handleLogDisableConnector
@ -62,6 +64,10 @@ templates:
handler: handleLogEnableConnector
- event: LogEnableStatic(indexed address)
handler: handleLogEnableStaticConnector
- event: LogAddController(indexed address)
handler: handleLogAddController
- event: LogRemoveController(indexed address)
handler: handleLogRemoveController
# - LogAddController(indexed address)
# - LogDisable(indexed address)
# - LogEnable(indexed address)