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
Release 2.2.0 #65
Merged
Merged
Release 2.2.0 #65
Conversation
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
Add `WebSocket` object and support native events for function arguments (needed to get `data`). Websockets are automatically closed when a VM instance is stopped. Example using WebSocket for the FT transfer events. It handles reconnects. ```jsx if (state.ws === undefined) { const eventsFilter = { status: "SUCCESS", event: { event: "ft_transfer", }, }; function startWebSocket(processEvents) { let ws = State.get().ws; if (ws) { ws.close(); return; } ws = new WebSocket("wss://events.near.stream/ws"); ws.onopen = () => { console.log(`Connection to WS has been established`); ws.send( JSON.stringify({ secret: "near-social-events", filter: eventsFilter, fetch_past_events: 10, }) ); }; ws.onclose = () => { State.update({ ws: null }); console.log(`WS Connection has been closed`); State.get().startWebSocket(processEvents); }; ws.onmessage = (e) => { const data = JSON.parse(e.data); processEvents(data.events); }; ws.onerror = (err) => { State.update({ ws: null }); console.log("WebSocket error", err); }; State.update({ ws }); } function processEvent(event) { return { time: new Date(parseFloat(event.block_timestamp) / 1e6), event: event.event, accountId: event.account_id, predecessorId: event.predecessor_id, }; } function processEvents(events) { events = events.flatMap(processEvent); events.reverse(); State.update((state) => { const prevActions = state.actions || []; state.actions = [ ...events.filter( (event) => prevActions.length === 0 || event.time.getTime() > prevActions[0].time.getTime() ), ...prevActions, ].slice(0, 10); return state; }); } State.init({ startWebSocket, }); state.startWebSocket(processEvents); } return state.actions; ``` **Note, this PR is based on top of a fix for the legacy function call creation.** https://github.com/NearSocial/VM/tree/fix/legacy-function-call-creator Fixes #35
chore: switch to pagoda's higher capcity public archival node
_BETA_: Introduce `VM.require`. This is a new API that allows to retrieve a module source from the Social DB, execute it and return the results. Note, this should be considered a beta feature and the API and the functionality might change. `VM.require(src)` takes a `src` the path for the source code of the module. The `src` argument may contain the source version by including the `blockHeight`. E.g. `VM.require("mob.near/widget/Module.Abc@91698491")` to get the source code at block height `91698491`. Module example: ```jsx function Magic(props) { return <div>Magic: {props.children}</div>; } return { Magic }; ``` Widget example: ```jsx const { Magic } = VM.require("mob.near/widget/Module.Magic"); return <Magic>Hello World</Magic>; ```
…performance degraded significantly
Revert archival node
calebjacob
approved these changes
May 18, 2023
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.
The require
feature looks great! Excited to use it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
2.2.0
VM.require
. This is a new API that allows to retrieve a module source from the Social DB, execute it and return the results.Note, this should be considered a beta feature and the API and the functionality might change.
VM.require(src)
takes asrc
the path for the source code of the module.The
src
argument may contain the source version by including theblockHeight
. E.g.VM.require("mob.near/widget/Module.Abc@91698491")
to get the source code at block height91698491
.Module example:
Widget example:
WebSocket
object and support native events for function arguments (needed to getdata
). Websockets are automatically closed when a VM instance is stopped.