-
Notifications
You must be signed in to change notification settings - Fork 1
feat: deploy from wasm #23
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
779e811
feat: deploy from wasm
chadoh 0112ea5
feat: implement deploy-from-wasm button
pselle ddf20e4
fix: cache wallet restore probe to stop close-listener leak
pselle 687895a
Style tweak for copy dialog
pselle 7323ba1
Update mainnet URLs
pselle 746c250
Correct comment to be more accurate
pselle 00414dc
refactor: deploy via generated registry-client instead of raw XDR
pselle 875d01f
Adjust so that we can disconnect a connected wallet, and if we change…
pselle ac9055d
Fixup modal overlay issue again
pselle 3d6791f
Inline deploy logic, cache RegistryClient across deploy clicks
pselle 7d07609
Address second review round: allowHttp, client reuse, generate:regist…
pselle 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
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 |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| .overlay { | ||
| position: fixed; | ||
| inset: 0; | ||
| background-color: rgb(0 0 0 / 0.5); | ||
| z-index: 50; | ||
|
|
||
| &[data-state="open"] { | ||
| animation: overlayShow 150ms var(--default-transition-timing-function); | ||
| } | ||
| } | ||
|
|
||
| .content { | ||
| position: fixed; | ||
| top: 50%; | ||
| left: 50%; | ||
| translate: -50% -50%; | ||
| width: calc(100% - calc(var(--spacing) * 8)); | ||
| max-width: 28rem; | ||
| max-height: 85vh; | ||
| overflow-y: auto; | ||
| background-color: var(--color-background); | ||
| color: var(--color-foreground); | ||
| border: 1px solid var(--color-border); | ||
| border-radius: var(--radius-lg); | ||
| box-shadow: var(--shadow-xs); | ||
| padding: calc(var(--spacing) * 6); | ||
| z-index: 51; | ||
|
|
||
| &[data-state="open"] { | ||
| animation: contentShow 150ms var(--default-transition-timing-function); | ||
| } | ||
| } | ||
|
|
||
| .close { | ||
| position: absolute; | ||
| top: calc(var(--spacing) * 4); | ||
| right: calc(var(--spacing) * 4); | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: calc(var(--spacing) * 7); | ||
| height: calc(var(--spacing) * 7); | ||
| border: none; | ||
| border-radius: var(--radius-sm); | ||
| background: transparent; | ||
| color: var(--color-muted-foreground); | ||
| cursor: pointer; | ||
|
|
||
| &:hover { | ||
| background-color: var(--color-accent); | ||
| color: var(--color-accent-foreground); | ||
| } | ||
| } | ||
|
|
||
| .header { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: calc(var(--spacing) * 1); | ||
| margin-bottom: calc(var(--spacing) * 4); | ||
| padding-right: calc(var(--spacing) * 6); | ||
| } | ||
|
|
||
| .title { | ||
| font-family: var(--font-display); | ||
| font-size: 1.25rem; | ||
| font-weight: 500; | ||
| margin: 0; | ||
| } | ||
|
|
||
| .description { | ||
| font-size: var(--text-sm); | ||
| color: var(--color-muted-foreground); | ||
| margin: 0; | ||
| } | ||
|
|
||
| .footer { | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| gap: calc(var(--spacing) * 2); | ||
| margin-top: calc(var(--spacing) * 6); | ||
| } | ||
|
|
||
| @keyframes overlayShow { | ||
| from { | ||
| opacity: 0; | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| @keyframes contentShow { | ||
| from { | ||
| opacity: 0; | ||
| translate: -50% calc(-50% + 8px); | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| translate: -50% -50%; | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import * as DialogPrimitive from "@radix-ui/react-dialog" | ||
| import { X } from "lucide-react" | ||
| import { type ComponentProps } from "react" | ||
| import styles from "./dialog.module.css" | ||
|
|
||
| const Dialog = DialogPrimitive.Root | ||
| const DialogTrigger = DialogPrimitive.Trigger | ||
|
|
||
| function DialogContent({ | ||
| className, | ||
| children, | ||
| ...props | ||
| }: ComponentProps<typeof DialogPrimitive.Content>) { | ||
| return ( | ||
| <DialogPrimitive.Portal> | ||
| <DialogPrimitive.Overlay className={styles.overlay} /> | ||
| <DialogPrimitive.Content | ||
| className={`${styles.content} ${className ?? ""}`.trim()} | ||
| {...props} | ||
| > | ||
| {children} | ||
| <DialogPrimitive.Close className={styles.close} aria-label="Close"> | ||
| <X size={16} /> | ||
| </DialogPrimitive.Close> | ||
| </DialogPrimitive.Content> | ||
| </DialogPrimitive.Portal> | ||
| ) | ||
| } | ||
|
|
||
| function DialogHeader({ className, ...props }: ComponentProps<"div">) { | ||
| return ( | ||
| <div className={`${styles.header} ${className ?? ""}`.trim()} {...props} /> | ||
| ) | ||
| } | ||
|
|
||
| function DialogTitle({ | ||
| className, | ||
| ...props | ||
| }: ComponentProps<typeof DialogPrimitive.Title>) { | ||
| return ( | ||
| <DialogPrimitive.Title | ||
| className={`${styles.title} ${className ?? ""}`.trim()} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function DialogDescription({ | ||
| className, | ||
| ...props | ||
| }: ComponentProps<typeof DialogPrimitive.Description>) { | ||
| return ( | ||
| <DialogPrimitive.Description | ||
| className={`${styles.description} ${className ?? ""}`.trim()} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function DialogFooter({ className, ...props }: ComponentProps<"div">) { | ||
| return ( | ||
| <div className={`${styles.footer} ${className ?? ""}`.trim()} {...props} /> | ||
| ) | ||
| } | ||
|
|
||
| export { | ||
| Dialog, | ||
| DialogTrigger, | ||
| DialogContent, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Builds, simulates, signs, and submits the `deploy_unnamed` invocation | ||
| // against the Registry contract, via the generated `registry-client` | ||
| // bindings (see clients/registry-client — regenerate with | ||
| // `npm run generate:registry-client`). Client-only — dynamically imports | ||
| // @stellar/stellar-sdk and registry-client so neither is ever pulled into | ||
| // the SSR bundle. | ||
| // | ||
| // See stellar-registry/contracts registry::contract::deploy_unnamed: | ||
| // fn deploy_unnamed(wasm_name, version, init, salt, deployer) -> Address | ||
| // (deployer.require_auth() only, so any connected wallet can call it.) | ||
|
|
||
| import { type SupportedSpecType, parseArgValue } from "./scval" | ||
|
|
||
| export type ConstructorArg = { | ||
| name: string | ||
| type: SupportedSpecType | ||
| rawValue: string | ||
| } | ||
|
|
||
| export type DeployResult = { contractId: string } | ||
|
|
||
| export async function deployFromWasm({ | ||
| rpcUrl, | ||
| networkPassphrase, | ||
| registryContractId, | ||
| wasmName, | ||
| wasmVersion, | ||
| constructorArgs, | ||
| deployerAddress, | ||
| signTransaction, | ||
| }: { | ||
| rpcUrl: string | ||
| networkPassphrase: string | ||
| registryContractId: string | ||
| wasmName: string | ||
| wasmVersion?: string | ||
| /** undefined = no constructor to call (init passed as void) */ | ||
| constructorArgs: ConstructorArg[] | undefined | ||
| deployerAddress: string | ||
| signTransaction: (xdr: string) => Promise<string> | ||
| }): Promise<DeployResult> { | ||
| const [{ nativeToScVal }, { Client: RegistryClient }] = await Promise.all([ | ||
| import("@stellar/stellar-sdk"), | ||
| import("registry-client"), | ||
| ]) | ||
|
|
||
| const salt = crypto.getRandomValues(new Uint8Array(32)) | ||
|
|
||
| const init = constructorArgs | ||
| ? constructorArgs.map((arg) => { | ||
| const value = parseArgValue(arg.type, arg.rawValue) | ||
| // "bool" isn't a valid nativeToScVal type hint — a JS boolean | ||
| // converts to scvBool unambiguously without one. | ||
| return arg.type === "bool" | ||
| ? nativeToScVal(value) | ||
| : nativeToScVal(value, { type: arg.type }) | ||
| }) | ||
| : undefined | ||
|
|
||
| const registry = new RegistryClient({ | ||
| contractId: registryContractId, | ||
| networkPassphrase, | ||
| rpcUrl, | ||
| allowHttp: true, | ||
| publicKey: deployerAddress, | ||
| // registry-client's ClientOptions expects the Freighter-shaped signer | ||
| // (xdr, opts) => Promise<{ signedTxXdr }>; wallet.ts's signTransaction is | ||
| // the simpler (xdr) => Promise<string> shape used throughout the deploy | ||
| // dialog, so adapt it here rather than changing that call site. | ||
| signTransaction: async (xdr) => ({ | ||
| signedTxXdr: await signTransaction(xdr), | ||
| }), | ||
| }) | ||
|
pselle marked this conversation as resolved.
Outdated
|
||
|
|
||
| let tx | ||
| try { | ||
| tx = await registry.deploy_unnamed({ | ||
| wasm_name: wasmName, | ||
| version: wasmVersion, | ||
| init, | ||
| salt: Buffer.from(salt), | ||
| deployer: deployerAddress, | ||
| }) | ||
| } catch (e) { | ||
| throw new Error( | ||
| `Failed to prepare the deploy transaction: ${e instanceof Error ? e.message : String(e)}`, | ||
| ) | ||
| } | ||
|
|
||
| let sent | ||
| try { | ||
| sent = await tx.signAndSend() | ||
| } catch (e) { | ||
| const message = e instanceof Error ? e.message : String(e) | ||
| // txBadAuth almost always means the connected wallet's account changed | ||
| // (in the extension, out of band) between building and submitting the | ||
| // transaction — surface that instead of the raw RPC failure JSON. | ||
| if (message.includes("txBadAuth")) { | ||
| throw new Error( | ||
| "The network rejected the transaction's signature (txBadAuth) — this usually means the connected wallet account changed. Disconnect and reconnect your wallet, then try deploying again.", | ||
| ) | ||
| } | ||
| throw new Error(`Failed to send the deploy transaction: ${message}`) | ||
| } | ||
|
pselle marked this conversation as resolved.
Outdated
|
||
| // `result` is a Rust-style Result<Address, Error> — unwrap() throws the | ||
| // contract's own error message (e.g. "NoSuchWasmPublished") on failure. | ||
| const { result } = sent | ||
| return { contractId: result.unwrap() } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.