Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: contracts and project providers + cleanup #597

Merged
merged 36 commits into from
Feb 27, 2023
Merged

Conversation

harrysolovay
Copy link
Contributor

@harrysolovay harrysolovay commented Feb 18, 2023

Resolves #626

This PR introduces two new providers:

  1. A ProjectProvider, which allows easy use within a substrate project. Simply capi -- deno run -A my_script.ts in your Substrate project.

my_script.ts

import { MyCustomPallet } from "http://localhost:4646/frame/project/@latest/mod.ts"
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"

Deno.test("works", async () => {
  assertEquals(expected, await MyCustomPallet.item.run())
})
  1. A contracts provider, which wraps substrate-contracts-node (per the request of @wottpal).
import { ... } from "http://localhost:4646/frame/contracts_dev/@latest/mod.ts"

This PR also...

  • extracts common provider functionality into an abstract FrameBinProvider class
  • changes the shape in which provider factories are passed to Env
  • improved implementation of test provider launch timeouts

Next up: #649

@harrysolovay harrysolovay force-pushed the project-provider branch 2 times, most recently from be0048a to 32001ca Compare February 23, 2023 16:44
@harrysolovay harrysolovay changed the title feat: project provider feat: contracts provider + provider system cleanup Feb 23, 2023
@harrysolovay harrysolovay changed the title feat: contracts provider + provider system cleanup feat: contracts and project providers + cleanup Feb 23, 2023
@kratico kratico self-assigned this Feb 23, 2023
@harrysolovay harrysolovay force-pushed the project-provider branch 2 times, most recently from ce5c0bd to fb16197 Compare February 24, 2023 15:27
@kratico
Copy link
Contributor

kratico commented Feb 24, 2023

substrate-contracts-node does not emit a author_extrinsicUpdate finalized event with result: { finalized: "0x..." }

Perhaps, for instant finality, the inBlock event should be the terminal transaction status.

The following is a work around for local debugging

diff --git a/fluent/ExtrinsicStatusRune.ts b/fluent/ExtrinsicStatusRune.ts
index 52b6c281..02638cb7 100644
--- a/fluent/ExtrinsicStatusRune.ts
+++ b/fluent/ExtrinsicStatusRune.ts
@@ -55,7 +55,7 @@ export class ExtrinsicStatusRune<out U1, out U2, out C extends Chain = Chain>
   }
 
   txEvents() {
-    const block = this.finalized()
+    const block = this.inBlock()
     const txI = Rune
       .tuple([
         block.into(ValueRune).access("block", "extrinsics"),
diff --git a/rpc/known/author.ts b/rpc/known/author.ts
index b41f5297..b107ee84 100644
--- a/rpc/known/author.ts
+++ b/rpc/known/author.ts
@@ -84,7 +84,7 @@ export namespace TransactionStatus {
     return typeof inQuestion === "string"
       ? inQuestion === "invalid" || inQuestion === "dropped"
       : !!(inQuestion.finalized || inQuestion.finalityTimeout || inQuestion.retracted
-        || inQuestion.usurped)
+        || inQuestion.usurped || inQuestion.inBlock)
   }
 }

@harrysolovay
Copy link
Contributor Author

@kratico thank you for the extraordinary contracts fix! The contracts example now executes in less than a second!

@harrysolovay harrysolovay marked this pull request as ready for review February 24, 2023 19:52
@harrysolovay harrysolovay requested a review from tjjfvi as a code owner February 24, 2023 19:52
@@ -23,7 +23,7 @@ export function handler(env: Env): Handler {
return await provider.handle(request, pathInfo)
} catch (e) {
if (e instanceof Response) return e
if (env.dbg) console.error(e)
console.error(e)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can re-add the toggling on/off when we tackle a comprehensive approach to logging from the Capi server (perhaps using Logger from deno_std). I plan to take a pass at this in a PR that also addresses #649.

@wottpal
Copy link

wottpal commented Feb 25, 2023

substrate-contracts-node does not emit a author_extrinsicUpdate finalized event with result: { finalized: "0x..." }

Perhaps, for instant finality, the inBlock event should be the terminal transaction status.

Just for reference, this would probably also fix this implicitly: paritytech/substrate-contracts-node#160

tjjfvi
tjjfvi previously approved these changes Feb 27, 2023
@harrysolovay harrysolovay merged commit 76adf2b into main Feb 27, 2023
@harrysolovay harrysolovay deleted the project-provider branch February 27, 2023 15:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

substrate-contracts-node provider
4 participants