Skip to content

Commit

Permalink
Properly filter events
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Aug 13, 2023
1 parent e81336f commit cb09d2c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
7 changes: 6 additions & 1 deletion dist/utils.js

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

2 changes: 1 addition & 1 deletion dist/utils.js.map

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ethereum-attestation-service/eas-sdk",
"version": "1.1.0-beta.1",
"version": "1.1.0-beta.2",
"description": "Ethereum Attestation Service - TypeScript/JavaScript SDK",
"repository": "git@github.com:ethereum-attestation-service/eas-sdk.git",
"author": "Leonid Beder <leonid@lbeder.com>",
Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EAS__factory } from '@ethereum-attestation-service/eas-contracts';
import {
hexlify,
Interface,
keccak256,
solidityPackedKeccak256,
toUtf8Bytes,
TransactionReceipt,
Expand All @@ -19,6 +20,12 @@ enum Event {
RevokedOffchain = 'RevokedOffchain'
}

const TOPICS = {
[Event.Attested]: keccak256(toUtf8Bytes('Attested(address,address,bytes32,bytes32)')),
[Event.Timestamped]: keccak256(toUtf8Bytes('Timestamped(bytes32,uint64)')),
[Event.RevokedOffchain]: keccak256(toUtf8Bytes('RevokedOffchain(address,bytes32,uint64)'))
};

export const getSchemaUID = (schema: string, resolverAddress: string, revocable: boolean) =>
solidityPackedKeccak256(['string', 'address', 'bool'], [schema, resolverAddress, revocable]);

Expand Down Expand Up @@ -81,7 +88,7 @@ const getDataFromReceipt = (receipt: TransactionReceipt, event: Event, attribute
const eas = new Interface(EAS__factory.abi);
const logs = [];

for (const log of receipt.logs || []) {
for (const log of receipt.logs.filter((l) => l.topics[0] === TOPICS[event]) || []) {
logs.push({
...log,
log: event,
Expand Down
7 changes: 7 additions & 0 deletions test/contracts/ETHResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ contract ETHResolver is SchemaResolver {

error InvalidValue();

event Paid(address indexed attester, uint256 value);
event Refunded(address indexed revoker, uint256 value);

uint256 private immutable _incentive;

constructor(IEAS eas, uint256 incentive) SchemaResolver(eas) {
Expand All @@ -27,6 +30,8 @@ contract ETHResolver is SchemaResolver {
function onAttest(Attestation calldata attestation, uint256 /*value*/) internal virtual override returns (bool) {
payable(attestation.attester).transfer(_incentive);

emit Paid({ attester: attestation.attester, value: _incentive });

return true;
}

Expand All @@ -39,6 +44,8 @@ contract ETHResolver is SchemaResolver {
payable(address(attestation.attester)).sendValue(value - _incentive);
}

emit Refunded({ revoker: attestation.attester, value: _incentive });

return true;
}
}

0 comments on commit cb09d2c

Please sign in to comment.