@@ -97,57 +97,82 @@ export function Step2() {
9797 useEffect ( ( ) : void => {
9898 async function dryRun ( ) {
9999 try {
100- const result = await ( version === 'v6'
101- ? api . call . reviveApi . instantiate ( ...params )
102- : api . call . contractsApi . instantiate ( ...params ) ) ;
103-
104100 // default is no revert
105101 let convertedFlags = api . registry . createType ( 'ContractReturnFlags' , 0 ) ;
106- let instantiateResult ;
107102
108- // auto-generated @polkadot/type-augment data uses slightly different types
109- if ( result . result . isOk ) {
110- const okResult = result . result . asOk ;
111- const flags = okResult . result . flags ;
112- const isRevert = flags . bits . toNumber ( ) ;
113- convertedFlags = api . registry . createType ( 'ContractReturnFlags' , isRevert ) ;
114- instantiateResult = {
115- Ok : {
116- result : { flags : convertedFlags , data : okResult . result . data } ,
117- } ,
118- } ;
103+ if ( version === 'v6' ) {
104+ const result = await api . call . reviveApi . instantiate ( ...params ) ;
105+ let instantiateResult ;
106+
107+ // auto-generated @polkadot/type-augment data uses slightly different types
108+ if ( result . result . isOk ) {
109+ const okResult = result . result . asOk ;
110+ const flags = okResult . result . flags ;
111+ const isRevert = flags . bits . toNumber ( ) ;
112+ convertedFlags = api . registry . createType ( 'ContractReturnFlags' , isRevert ) ;
113+ instantiateResult = {
114+ Ok : {
115+ result : { flags : convertedFlags , data : okResult . result . data } ,
116+ } ,
117+ } ;
118+ } else {
119+ instantiateResult = { Err : result . result . asErr } ;
120+ }
121+
122+ const convertedOutcome = api . registry . createType ( 'ContractInstantiateResult' , {
123+ gasConsumed : result . gasConsumed ,
124+ gasRequired : result . gasRequired ,
125+ storageDeposit : result . storageDeposit ,
126+ result : instantiateResult ,
127+ } ) ;
128+
129+ const resultJson = JSON . stringify ( convertedOutcome . toJSON ( ) ) ;
130+ const dryRunResultJson = JSON . stringify ( dryRunResult ?. toJSON ( ) ) ;
131+ if ( dryRunResultJson !== resultJson ) {
132+ setDryRunResult ( convertedOutcome ) ;
133+ }
119134 } else {
120- instantiateResult = { Err : result . result . asErr } ;
121- }
135+ console . log ( 'Using v5 contractsApi' ) ;
136+ const result = await api . call . contractsApi . instantiate ( ...params ) ;
137+ console . log ( result ) ;
138+ let instantiateResult ;
122139
123- const convertedOutcome =
124- version === 'v6'
125- ? api . registry . createType ( 'ContractInstantiateResult' , {
126- gasConsumed : result . gasConsumed ,
127- gasRequired : result . gasRequired ,
128- storageDeposit : result . storageDeposit ,
129- result : instantiateResult ,
130- } )
131- : api . registry . createType ( 'ContractInstantiateResult' , {
132- gasConsumed : result . gasConsumed ,
133- gasRequired : result . gasRequired ,
134- storageDeposit : result . storageDeposit ,
135- // debugMessage is Bytes, must convert to Text
136- debugMessage : api . registry . createType ( 'Text' , result . debugMessage . toU8a ( ) ) ,
137- result : instantiateResult ,
138- } ) ;
140+ // auto-generated @polkadot/type-augment data uses slightly different types
141+ if ( result . result . isOk ) {
142+ const okResult = result . result . asOk ;
143+ const flags = okResult . result . flags ;
144+ const isRevert = flags . bits . toNumber ( ) ;
145+ convertedFlags = api . registry . createType ( 'ContractReturnFlags' , isRevert ) ;
146+ instantiateResult = {
147+ Ok : {
148+ result : { flags : convertedFlags , data : okResult . result . data } ,
149+ } ,
150+ } ;
151+ } else {
152+ instantiateResult = { Err : result . result . asErr } ;
153+ }
154+ const convertedOutcome = api . registry . createType ( 'ContractInstantiateResult' , {
155+ gasConsumed : result . gasConsumed ,
156+ gasRequired : result . gasRequired ,
157+ storageDeposit : result . storageDeposit ,
158+ // debugMessage is Bytes, must convert to Text
159+ debugMessage : api . registry . createType ( 'Text' , result . debugMessage . toU8a ( ) ) ,
160+ result : instantiateResult ,
161+ } ) ;
139162
140- const resultJson = JSON . stringify ( convertedOutcome . toJSON ( ) ) ;
141- const dryRunResultJson = JSON . stringify ( dryRunResult ?. toJSON ( ) ) ;
142- if ( dryRunResultJson !== resultJson ) {
143- setDryRunResult ( convertedOutcome ) ;
163+ const resultJson = JSON . stringify ( convertedOutcome . toJSON ( ) ) ;
164+ const dryRunResultJson = JSON . stringify ( dryRunResult ?. toJSON ( ) ) ;
165+
166+ if ( dryRunResultJson !== resultJson ) {
167+ setDryRunResult ( convertedOutcome ) ;
168+ }
144169 }
145170 } catch ( e ) {
146171 console . error ( e ) ;
147172 }
148173 }
149174 dryRun ( ) . catch ( e => console . error ( e ) ) ;
150- } , [ api . call . contractsApi , dryRunResult , params , setDryRunResult ] ) ;
175+ } , [ api , dryRunResult , params , setDryRunResult ] ) ;
151176
152177 const onSubmit = ( ) => {
153178 if ( ! dryRunResult ) return ;
0 commit comments