-
Notifications
You must be signed in to change notification settings - Fork 3
DLT Adapter updated to IED #68
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
Open
DavSanOl
wants to merge
8
commits into
dev
Choose a base branch
from
dlt-ied-dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f9267cb
Merge pull request #4 from alastria/release/v1.0.0
alejandro-nieto-git a3c6824
Merge pull request #39 from alastria/release/v1.2.1
alejandro-nieto-git 460263d
Merge pull request #60 from alastria/dev
alejandro-nieto-git 4b20408
Merge pull request #61 from alastria/pre
alejandro-nieto-git bbd3837
Merge pull request #63 from alastria/dev
alejandro-nieto-git c691edc
Merge pull request #64 from alastria/pre
alejandro-nieto-git e4875bc
Swagger UI added
42c31d4
- New route for subscribing to all events added (/api/v2/subscribeTo…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -11,9 +11,10 @@ import { DOMEEvent } from "../utils/types"; | |
const debugLog = debug("DLT Interface Service: "); | ||
const errorLog = debug("DLT Interface Service:error "); | ||
|
||
|
||
/** | ||
* Publish DOME event as a blockchain event. | ||
* | ||
* Publishes DOME event as a blockchain event | ||
* | ||
* @param eventType the name of the dome event | ||
* @param dataLocation the storage or location of the data associated with the event. | ||
* @param relevantMetadata additional information or metadata relevant to the event. | ||
|
@@ -77,6 +78,9 @@ export async function publishDOMEEvent( | |
relevantMetadata, | ||
}); | ||
|
||
debugLog(" > Adding netwotk:",process.env.NETWORK); | ||
const metadata = [...relevantMetadata, process.env.NETWORK]; | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(rpcAddress); | ||
|
||
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY!, provider); | ||
|
@@ -98,7 +102,8 @@ export async function publishDOMEEvent( | |
previousEntityHash, | ||
eventType, | ||
dataLocation, | ||
relevantMetadata | ||
// relevantMetadata | ||
metadata | ||
); | ||
debugLog(" > Transaction waiting to be mined..."); | ||
await tx.wait(); | ||
|
@@ -372,7 +377,6 @@ export async function getActiveDOMEEventsByDate( | |
return allActiveDOMEEvents; | ||
} | ||
|
||
|
||
/** | ||
* Returns all the DOME active blockchain events from the blockchain between given dates | ||
* @param DOMEEvents some DOME blockchain events | ||
|
@@ -452,4 +456,103 @@ async function getAllActiveDOMEBlockchainEventsBetweenDates(DOMEEvents: ethers.E | |
} | ||
|
||
return activeEvents; | ||
} | ||
|
||
/** | ||
* Returns all the DOME active events from the blockchain | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realmente lo que hace esto es devolver todos los eventos de la cadena recorriendo previamente: es muy costoso y hay una forma más sencilla que complicarse así. |
||
* | ||
* @param rpcAddress the blockchain node RPC address | ||
* @returns a JSON with all the DOME active events from the blockchain | ||
*/ | ||
export async function getAllDOMEEvents( | ||
rpcAddress: string | ||
): Promise<DOMEEvent[]>{ | ||
if(rpcAddress === ""){ | ||
throw new IllegalArgumentError("The RPC address is blank"); | ||
} | ||
|
||
debugLog(">>>> Getting active events"); | ||
|
||
const provider = new ethers.providers.JsonRpcProvider(rpcAddress); | ||
const DOMEEventsContract = new ethers.Contract( | ||
process.env.DOME_EVENT_CONTRACT_ADDRESS!, | ||
process.env.DOME_EVENTS_CONTRACT_ABI!, | ||
provider | ||
); | ||
debugLog(">>>> Connecting to blockchain node..."); | ||
debugLog(" >> rpcAddress: " + rpcAddress); | ||
let blockNumber = await provider.getBlockNumber(); | ||
debugLog(" >> Blockchain block number is " + blockNumber); | ||
let allDOMEEvents = await DOMEEventsContract.queryFilter( | ||
"*", | ||
parseInt(process.env.DOME_PRODUCTION_BLOCK_NUMBER!), | ||
blockNumber | ||
); | ||
allDOMEEvents = allDOMEEvents.slice(1); | ||
let DOMEEvents: DOMEEvent[] = []; | ||
allDOMEEvents.forEach((event) => { | ||
if(event.args == undefined || event.args!.length == 0){ | ||
debugLog("Event with no args, passing to next...") | ||
return; | ||
} | ||
|
||
let eventJson: DOMEEvent = { | ||
id: event.args![0], | ||
timestamp: event.args![1], | ||
eventType: event.args![5], | ||
dataLocation: event.args![6], | ||
relevantMetadata: event.args![7], | ||
entityId: event.args![3], | ||
previousEntityHash: event.args![4] | ||
}; | ||
|
||
debugLog(eventJson); | ||
DOMEEvents.push(eventJson); | ||
}); | ||
debugLog(">>>> Events found: " + DOMEEvents.length); | ||
return DOMEEvents; | ||
} | ||
|
||
|
||
/** | ||
* Subscribes to all DOME Events | ||
* | ||
* @param rpcAddress the blockchain node address to be used for event subscription | ||
* @param ownIss the organization identifier hash | ||
* @param notificationEndpoint the user's endpoint to be notified to of the events of interest. | ||
* The notification is sent as a POST | ||
* @param handler an optional function to handle the events | ||
*/ | ||
export async function subscribeToAllEvents( | ||
rpcAddress: string, | ||
ownIss: string, | ||
notificationEndpoint?: string, | ||
handler?: (event: object) => void | ||
){ | ||
if (rpcAddress === null || rpcAddress === undefined) { | ||
throw new IllegalArgumentError("The rpc address is null."); | ||
} | ||
if (ownIss === "") { | ||
throw new IllegalArgumentError("The ownIss is blank."); | ||
} | ||
if (ownIss === null || ownIss === undefined) { | ||
throw new IllegalArgumentError("The ownIss is null."); | ||
} | ||
try{ | ||
debugLog(">>>> Retrieving all DOME Events..."); | ||
const allEvents = await getAllDOMEEvents(rpcAddress); | ||
debugLog(">>>> Subscribing to " + allEvents.length + " events"); | ||
allEvents.forEach(async (event) => { | ||
await subscribeToDOMEEvents( | ||
[event.eventType], | ||
rpcAddress, | ||
ownIss, | ||
notificationEndpoint, | ||
handler | ||
); | ||
}); | ||
} catch (error) { | ||
errorLog(" > !! Error subscribing to DOME Events"); | ||
throw error; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esto lo dejamos como estaba porque no recuerdo exactamente si esto implica modificarlo en el smart contract también