File tree Expand file tree Collapse file tree 8 files changed +85
-17
lines changed
Expand file tree Collapse file tree 8 files changed +85
-17
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export type CompilerInput = {
77 * Name of the file and the content of the file.
88 * e.g. { 'test.sol': { content: 'contract C { function f() public { L.f(); } }' } }
99 */
10- sources : Record < string , { content : string } > ;
10+ sources : ContractSources ;
1111 /**
1212 * Settings for the compiler.
1313 * e.g. { outputSelection: { '*': { '*': ['*'] } }"
@@ -17,4 +17,19 @@ export type CompilerInput = {
1717 } ;
1818} ;
1919
20- export type ImportContents = Record < string , { contents : string } > ;
20+ export type ContractSources = {
21+ [ source : string ] : { content : string } ;
22+ } ;
23+
24+ export function buildCompilerInput ( sources : ContractSources ) : CompilerInput {
25+ return {
26+ sources,
27+ language : 'Solidity' ,
28+ settings : {
29+ outputSelection : {
30+ '*' : { '*' : [ '*' ] }
31+ }
32+ }
33+ } ;
34+ }
35+
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { API } from " $lib/api" ;
3+ import { buildCompilerInput , type ContractSources } from " $lib/models/solc" ;
4+ import { wizardState } from " ../state.svelte" ;
5+
6+ let compilationResult: any ;
7+
8+ async function compile() {
9+ if (! wizardState .sources ) return ;
10+ compilationResult = await API .compile (buildCompilerInput (wizardState .sources ));
11+ }
12+
13+ function getMainContractName(sources ? : ContractSources ) {
14+ if (! sources ) return ' ' ;
15+ // The first name that is not a dependency
16+ return Object .keys (sources ).find (name => ! name .startsWith (' @' ));
17+ }
18+
19+ </script >
20+
21+ <p >
22+ Contract to compile: {getMainContractName (wizardState .sources )}
23+
24+ <button onclick ={compile } >
25+ Compile
26+ </button >
27+ </p >
Original file line number Diff line number Diff line change 1+ import type { ContractSources } from "../models/solc" ;
2+ import { wizardState } from "./state.svelte" ;
3+
4+ export interface DefenderDeployMessage {
5+ kind : 'oz-wizard-defender-deploy' ;
6+ sources : ContractSources ;
7+ }
8+
19export const initWizardPlugin = ( ) => {
10+ // when users configure a contract, the plugin gets the results.
11+ listenToContracts ( ) ;
12+ }
13+
14+ function listenToContracts ( ) {
15+ window . addEventListener ( 'message' , function ( e : MessageEvent < DefenderDeployMessage > ) {
16+ if ( e . data . kind === 'oz-wizard-defender-deploy' ) {
17+ wizardState . sources = e . data . sources ;
18+ }
19+ } ) ;
220}
Original file line number Diff line number Diff line change 1+ import type { ContractSources } from "../models/solc" ;
2+
3+ export const wizardState = $state < { sources : ContractSources | undefined } > ( {
4+ sources : undefined ,
5+ } ) ;
Original file line number Diff line number Diff line change 2020 // assumes that when in dev mode and
2121 // the ancestor origin is localhost, we are in the wizard
2222 if (dev && ancestorOrigin .includes (" localhost" )) {
23- parent = ' wizard' ;
24- return ;
23+ return parent = ' wizard' ;
2524 }
2625
27- if (ancestorOrigin .includes (" remix.ethereum" )) {
28- parent = ' remix' ;
29- return initRemixPlugin ();
26+ if (ancestorOrigin .includes (" wizard.openzeppelin" )) {
27+ return parent = ' wizard' ;
3028 }
3129
32- if (ancestorOrigin .includes (" wizard.openzeppelin" )) {
33- parent = ' wizard' ;
34- // TODO: init wizard plugin
35- return ;
30+ if (ancestorOrigin .includes (" remix.ethereum" )) {
31+ return parent = ' remix' ;
3632 }
33+
3734 });
3835 </script >
3936
Original file line number Diff line number Diff line change 11import solc from 'solc' ;
22
3- import type { ImportContents } from "$lib/models/solc" ;
3+ import type { ContractSources } from "$lib/models/solc" ;
44import type { CompilerInput } from "$lib/models/solc" ;
55
66export class SolidityCompiler {
7- getContent ( path : string , contents : Record < string , { contents : string } > ) {
7+ getContent ( path : string , contents : ContractSources ) {
88 if ( contents [ path ] ) {
99 return contents [ path ] ;
1010 }
1111 return { error : 'File not found' } ;
1212 }
1313
14- compile ( input : CompilerInput , contents ?: ImportContents ) {
14+ compile ( input : CompilerInput , contents ?: ContractSources ) {
1515 const shouldFindImports = contents !== undefined ;
1616 const findImports = ( path : string ) => shouldFindImports ? this . getContent ( path , contents ) : undefined ;
1717 const output = solc . compile ( JSON . stringify ( input ) , shouldFindImports ? { import : findImports } : undefined ) ;
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2+ import { onMount } from " svelte" ;
3+ import { initRemixPlugin } from " $lib/remix" ;
24 import { globalState } from " $lib/remix/state/state.svelte" ;
35 import Setup from " $lib/remix/components/Setup.svelte" ;
46 import Network from " $lib/remix/components/Network.svelte" ;
4850
4951 return false ;
5052 });
53+
54+ onMount (initRemixPlugin );
5155 </script >
5256
5357<p >
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { onMount } from " svelte" ;
32 import { initWizardPlugin } from " $lib/wizard" ;
3+ import { onMount } from " svelte" ;
4+ import Configure from " $lib/wizard/components/Configure.svelte" ;
45
5- let output = $state < any >( null );
6+ onMount ( initWizardPlugin );
67 </script >
78
8- <p >Defender Deploy in Wizard</p >
9+ <Configure />
10+
You can’t perform that action at this time.
0 commit comments