-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add support to retrieve the observable events from the contracts in a given Clarinet project #1034
Comments
We probably want to see a bunch of our libraries being exported to wasm. |
Totally makes sense.
With this approach, the clarinet-sdk would be the only one requiring wasm-bindgen Although I'm not sure of the need to publish anything on crates.io? What's the use case?
Yes |
clarity-events
as a js-wasm
libraryclarity-events
as a WASM library
This work will be a dependency for https://github.com/hirosystems/platform/issues/546 |
Sounds like we can tackle this in Q3 (September) with the progress made on the JS clarinet-sdk 🙌 |
Hey @sabbyanandan @lgalabru also mentioned to possibility to get the events from the devnet package (I think it already returns the ABI, it could also have the events) |
The ABI is unfortunately not part of the packaged plans, but this is something we can address, and would make sense to me, so I'm going re-purpose this issue. |
clarity-events
as a WASM library
Also, I'm still interesting in adding it in the JS SDK, but just wanted to warn that it won't be available in the browser (at least not out of the box) |
Sure thing! 👍 |
After working on an initial implementation we have the following proposal to the specification: Leveraging the use of the Clarinet Any feedback on that? @sabbyanandan @beguene @hugocaillard @lgalabru @MicaiahReid
$ clarinet contracts abi contract-file.clar [
{
"trigger": "say-hello",
"name": "print",
"data_type": {
"value": "hello!",
"type": "string"
},
"type": "event"
},
{
"trigger": "transfer-to-recipient!",
"name": "transfer_stx_event",
"type": "event"
},
{
"name": "transfer-to-recipient!",
"access": "private",
"args": [
{
"type": "principal",
"name": "recipient"
},
{
"type": "uint",
"name": "amount"
}
],
"outputs": [
{
"type": "response",
"value": {
"ok": "bool",
"err": "string"
}
}
],
"type": "function"
},
{
"name": "say-hello",
"access": "public",
"args": [],
"outputs": [
{
"type": "string"
}
],
"type": "function"
}
] |
Some thoughts about the data structure. What about splitting the ABI and events like so: { events: [], functions: [] } Or even having two commands clarinet contract interfaces <contract-name>
clarinet contract events <contract-name> ( I think it also depends on the platform needs, @sabbyanandan
|
@beguene @sabbyanandan would you mind reviewing the json output and adding feedback on this issue, please? |
@hugocaillard: My apologies for the delayed response. The DevEx and the use-case requirements for why |
@csgui: If I understand the data structure correctly, it appears we have a few different ways to get the "possible" event-streams for a given contract. Did I get this right? Regardless of these options (it looks like we can get the data multiple ways, anyway), the goal for the Platform is to discover the possible event streams automatically and offer an improved DevEx for developers to select and create Chainhooks rapidly instead of manually drafting each Chainhook. I hope this clarifies the ask. For further context into Chainhook improvements in the Platform, see here. |
@csgui I think the output format you described makes sense, it's perfectly fine to have everything in a plain array. We can filter in our app if required. |
So it looks like the first idea of having it on the clarinet-sdk still make sense. Would something like that work for you: import { initVM } from "@hirosystems/clarinet-sdk";
const vm = await initVM();
const contractInterfaces = vm.getContractsInterfaces()
// contractInterfaces interfaces is a map of all contract interfaces
const counterInterface = contractInterfaces.get(`${deployerAddr}.counter`);
console.log(counterInterface?.functions) // array of the functions
// not implemented yet / tbc
const events = vm.getContractEvent(`${deployerAddr}.counter`); The clarinet-sdk is basically Clarinet wrapped in WASM. Also right now the package only work in Node.js (not in the browser), but that's something we could work on |
@hugocaillard Yes this should work. |
Would be better to follow a pattern, like contract files under a |
@hugocaillard Thinking about the platform requirements seems that makes more sense to implement this on the |
Long story short, the manifest file (Clarinet.toml) allows to get the exact path of each contracts along with the setting (clarity_version, epoch) that could change the result of the ABI. So the Clarinet.toml is a source of truth and a good way to make that our tools behave the same way.
It is slightly, it also depends on the size of the project. But it basically what happens every time the Clarity VSCode extension starts.
Yes
Not necessarily, because the contracts path are specified in the manifest (Clarinet.toml), allowing for flexibility. (sbtc is using multiple directories) [contracts.hello-world-v1]
path = "contract-v1-directory/hello-world.clar" # dir 1
clarity_version = 1
epoch = 2.0
[contracts.hello-world-v2]
path = "contract-v2-directory/hello-world.clar" # dir 2
clarity_version = 2
epoch = 2.4
[contracts.hello-world-tests]
path = "some-other-directory/hello-world.clar" # dir 3
clarity_version = 2
epoch = 2.4
I'm not sure if we want to add this constraint to Clarity developers on the platform, having the Clarinet.toml as a source of truth to list contract and get their paths and settings (epoch / clarity_version / maybe more in the future) is quite useful. Ideas for the future
|
Yes it does 👍 So the ABI is already available if you want to start implementing that @beguene const contractInterfaces = vm.getContractsInterfaces() I can also prioritize implement contract events, it shouldn't be too long. What's your timeline @beguene @sabbyanandan? (I could implement it this week it could make it the v1 or v1.1) |
Got it @hugocaillard ! Sounds good to me. We anyway rely a lot on the Clarinet.toml for deployment plan and devnet so we can continue like this. |
@beguene Ok I see. In the vscode pod, do you have access to the actual FS (ie: |
@hugocaillard We do have the actual filesystem so everything should work fine. We access it via a custom nodejs server and indeed we use |
@beguene ok perfect, thanks.
Thx |
@hugocaillard: Nakamoto/sBTC is the immediate priority, and access to events via the SDK can take a back seat until you free up. There is no rush; the Platform can pick it up whenever it is ready (even in a milestone capacity versus a full-blown release). |
@beguene this makes me think that the Platform team could be missing a feature that we shipped in |
Nice! This is good to know. Yes, we missed it because we started working on deployment plan before this was available, but we use the |
Will try to do it in October in sdk v1.1. |
@smcclellan: Once 2.2 ships, could we timebox to review the scope and estimate this effort? There are additional signals from devs using Chainhooks, but they also create things manually, which we can entirely automate once we automatically provide visibility into observable events. |
@sabbyanandan Yes, this is on my radar. Thanks for flagging. |
@hugocaillard to clarify the approach, possibly opening a new ticket to track the new scope. |
@sabbyanandan Considering all of the noise that happened on this issue, could we open a new one instead? Ideally, I'd like the new issue to focus on the "what" / "why" instead of the "how". |
@hugocaillard: I would repurpose this issue; on that note, I updated the title and description. I would appreciate it if we could scope this first and then decide on the timeline feasibility. This can be impactful for the Platform users. |
Thanks @sabbyanandan |
Closing in favor of #1410 to simplify the thread. /cc @sabbyanandan |
As a user, I want the ability to discover all observable chainhook events in a given project so I can look at the list of events and create the chainhooks easily as opposed to manually defining each predicate by reading the docs, making errors in the process, and wasting so much time.
The rest of additional context is at https://github.com/hirosystems/platform/issues/546, and I am skipping it for brevity here.
Previous context:
We want to use clarity-events in other places, so that requires making this component a JavaScript-readied WASM library.The text was updated successfully, but these errors were encountered: