Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matt #4

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion coffee-subgraph/networks.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"goerli": {
"coffee": {
"address": "0xD260302a241A2CFBc1493676b4fA3f365870De59"
"address": "0x9E2eF6C92dC1D724c1E4dFdB22AcAcd3B80cC26B"
}
}
}
13 changes: 12 additions & 1 deletion coffee-subgraph/package-lock.json

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

3 changes: 2 additions & 1 deletion coffee-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"@graphprotocol/graph-cli": "0.33.1",
"@graphprotocol/graph-ts": "0.27.0",
"dotenv": "^16.0.3"
"dotenv": "^16.0.3",
"matchstick": "^1.2.1"
},
"devDependencies": {
"matchstick-as": "0.5.0"
Expand Down
91 changes: 73 additions & 18 deletions coffee-subgraph/src/coffee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,62 @@ export function handleworkerCheckedIn(event: workerCheckedIn): void {
[]
);
}
/*
// ╔═════════════════════════════╗
// ║ HANDLE FOREMAN CHECKIN ║
// ╚═════════════════════════════╝

// Ideas:
// - create a new event for foreman checkin
// - add a new field to checkin for foreman
// - treat foreman as worker
// - link foreman to a worker address

// create a new worker entity that links to the foreman address if it doesn't exist
let foremanWorker = Worker.load(event.params.foreman.toHex());
if(!foremanWorker){
foremanWorker = new Worker(event.params.foreman.toHex());
// foremanWorker.daysWorked = 1;
// foremanWorker.daysUnpaid = 1;
// foremanWorker.payments = [];
// foremanWorker.hasForeman = [event.params.foreman.toHex()];
// foremanWorker.checkIns = [];
}
// foremanWorker.daysWorked = foremanWorker.daysWorked + 1;
// foremanWorker.daysUnpaid = foremanWorker.daysUnpaid + 1;

// add checkin to foreman's checkIns array
// if(foreman.madeCheckIns != null){
// foreman.madeCheckIns!.push(event.params.checkInId.toHex());
// } else{
// foreman.madeCheckIns = [event.params.checkInId.toHex()];
// }

// add foreman to worker's hasForeman array
// if(foremanWorker.hasForeman != null){
// if(!foremanWorker.hasForeman!.includes(event.params.foreman.toHex())){
// foremanWorker.hasForeman!.push(event.params.foreman.toHex());
// }
// } else{
// foremanWorker.hasForeman = [event.params.foreman.toHex()];
// }

// add worker to foreman's hasWorkers array
// if(foreman.hasWorkers != null){
// if(!foreman.hasWorkers!.includes(foremanWorker.id)){
// foreman.hasWorkers!.push(foremanWorker.id);
// }
// } else{
// foreman.hasWorkers = [foremanWorker.id];

// }
*/







// update worker and checkin table for each worker in event
for (var i = 0; i< event.params.worker.length; i++) {
Expand Down Expand Up @@ -186,7 +242,15 @@ export function handleworkerCheckedIn(event: workerCheckedIn): void {
}

export function handleworkerPaid(event: workerPaid): void {
for (var i = 0; i< event.params.worker.length; i++) {

//if the farm doesn't exist, revert the transaction
let farm = event.transaction.from.toHex();
if(!farm){
log.critical("workerPaid event emitted but no farm with this address exists in table",[]);
return;
}

for (let i = 0; i< event.params.worker.length; i++) {
let thisWorker = event.params.worker[i];
let thisPayment = event.params.amount[i];

Expand All @@ -201,13 +265,14 @@ export function handleworkerPaid(event: workerPaid): void {
// We are assuming that a worker will never be paid before being
// checked in, so the worker should already exist.
if(!worker){
worker = new Worker(thisWorker.toHex());
worker.daysWorked = 1;
worker.daysUnpaid = 1;
// worker.payments = [];
worker.hasForeman = [];
// worker.checkIns = [];
log.critical("Worker was paid before being checked in", []);
continue;
// worker = new Worker(thisWorker.toHex());
// worker.daysWorked = 1;
// worker.daysUnpaid = 1;
// // worker.payments = [];
// worker.hasForeman = [];
// // worker.checkIns = [];
// log.critical("Worker was paid before being checked in", []);
}
// Worker is now paid for all their previous days unpaid
let oldDaysUnpaid = worker.daysUnpaid;
Expand Down Expand Up @@ -250,16 +315,6 @@ export function handleworkerPaid(event: workerPaid): void {













/*╔══════════════════════════════════════════════════════════╗
║ BELOW ARE JUST NOTES GENERATED BY THEGRAPH ║
╚══════════════════════════════════════════════════════════╝*/
Expand Down
2 changes: 1 addition & 1 deletion coffee-subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dataSources:
name: coffee
network: goerli
source:
address: "0xD260302a241A2CFBc1493676b4fA3f365870De59"
address: "0x9E2eF6C92dC1D724c1E4dFdB22AcAcd3B80cC26B"
abi: coffee
mapping:
kind: ethereum/events
Expand Down
Binary file added coffee-subgraph/tests/.bin/coffee.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions coffee-subgraph/tests/.latest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "0.5.4",
"timestamp": 1678215640216
}
13 changes: 7 additions & 6 deletions coffee-subgraph/tests/coffee-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function createnewForemanEvent(

export function createworkerCheckedInEvent(
foreman: Address,
worker: Address,
worker: Array<Address>,
date: string
): workerCheckedIn {
let workerCheckedInEvent = changetype<workerCheckedIn>(newMockEvent())
Expand All @@ -80,7 +80,7 @@ export function createworkerCheckedInEvent(
new ethereum.EventParam("foreman", ethereum.Value.fromAddress(foreman))
)
workerCheckedInEvent.parameters.push(
new ethereum.EventParam("worker", ethereum.Value.fromAddress(worker))
new ethereum.EventParam("worker", ethereum.Value.fromAddressArray(worker))
)
workerCheckedInEvent.parameters.push(
new ethereum.EventParam("date", ethereum.Value.fromString(date))
Expand All @@ -91,8 +91,8 @@ export function createworkerCheckedInEvent(

export function createworkerPaidEvent(
farm: Address,
worker: Address,
amount: BigInt,
worker: Array<Address>,
amount: Array<BigInt>,
date: string
): workerPaid {
let workerPaidEvent = changetype<workerPaid>(newMockEvent())
Expand All @@ -103,10 +103,11 @@ export function createworkerPaidEvent(
new ethereum.EventParam("farm", ethereum.Value.fromAddress(farm))
)
workerPaidEvent.parameters.push(
new ethereum.EventParam("worker", ethereum.Value.fromAddress(worker))
new ethereum.EventParam("worker", ethereum.Value.fromAddressArray(worker))

)
workerPaidEvent.parameters.push(
new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigInt(amount))
new ethereum.EventParam("amount", ethereum.Value.fromUnsignedBigIntArray(amount))
)
workerPaidEvent.parameters.push(
new ethereum.EventParam("date", ethereum.Value.fromString(date))
Expand Down
Loading