-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added demonstration for event based cl approach
Signed-off-by: artem.ivanov <[email protected]>
- Loading branch information
1 parent
dca3cdc
commit dbdcf18
Showing
9 changed files
with
105 additions
and
53 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Web3 from 'web3' | ||
import environment, { host } from '../environment' | ||
import { Actor } from './utils/actor' | ||
import { ROLES } from '../contracts-ts' | ||
import { createSchemaObject } from '../utils' | ||
|
||
async function demo() { | ||
const web3 = new Web3(new Web3.providers.HttpProvider(host)) | ||
|
||
let receipt: any | ||
|
||
const trustee = await new Actor(environment.accounts.account1).init() | ||
const faber = await new Actor().init() | ||
|
||
console.log('1. Trustee assign ENDORSER role to Faber') | ||
receipt = await trustee.roleControl.assignRole(ROLES.ENDORSER, faber.address) | ||
console.log(`Role ${ROLES.ENDORSER} assigned to account ${faber.address}. Receipt: ${JSON.stringify(receipt)}`) | ||
|
||
console.log('2. Faber creates DID Document') | ||
receipt = await trustee.didRegistry.createDid(faber.didDocument) | ||
console.log(`Did Document created for DID ${faber.did}. Receipt: ${JSON.stringify(receipt)}`) | ||
|
||
console.log('3. Faber creates Test Schema') | ||
const schema = createSchemaObject({ issuerId: faber.did }) | ||
receipt = await faber.schemaRegistry.createSchemaAsJson(schema) | ||
console.log(`Schema created for id ${schema.id}. Receipt: ${JSON.stringify(receipt)}`) | ||
|
||
const eventsByType = await faber.schemaRegistry.instance.queryFilter('SchemaStringCreated') | ||
console.log(`Events by type using Ethers ${JSON.stringify(eventsByType, null, 2)}`) | ||
console.log(JSON.stringify(eventsByType, null, 2)) | ||
|
||
const filter = await faber.schemaRegistry.instance.filters.SchemaStringCreated(web3.utils.keccak256(schema.id)) | ||
const eventsUsingEthers = await faber.schemaRegistry.instance.queryFilter(filter) | ||
console.log(`Events using Ethers ${JSON.stringify(eventsUsingEthers, null, 2)}`) | ||
|
||
let eventsUsingWeb3 = await web3.eth.getPastLogs({ | ||
address: '0x0000000000000000000000000000000000005555', | ||
topics: [ | ||
null, // same as: web3.utils.sha3("SchemaStringCreated(uint,uint)"), | ||
web3.utils.keccak256(schema.id), | ||
], | ||
}) | ||
console.log(`Events using Web3: ${JSON.stringify(eventsUsingWeb3, null, 2)}`) | ||
console.log(eventsUsingWeb3) | ||
} | ||
|
||
if (require.main === module) { | ||
demo() | ||
} | ||
|
||
module.exports = exports = demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters