@@ -22,21 +22,52 @@ export class Web3ProviderModule extends Plugin {
2222 this . blockchain = blockchain
2323 }
2424
25+ async updateRemix ( txHash ) {
26+ const receipt = await this . tryTillReceiptAvailable ( txHash )
27+ if ( ! receipt . contractAddress ) {
28+ console . log ( 'receipt available but contract address not present' , receipt )
29+ return
30+ }
31+ const contractAddressStr = addressToString ( receipt . contractAddress )
32+ const contractData = await this . call ( 'compilerArtefacts' , 'getContractDataFromAddress' , contractAddressStr )
33+ if ( contractData ) {
34+ const data = await this . call ( 'compilerArtefacts' , 'getCompilerAbstract' , contractData . file )
35+ const contractObject = {
36+ name : contractData . name ,
37+ abi : contractData . contract . abi ,
38+ compiler : data ,
39+ contract : {
40+ file : contractData . file ,
41+ object : contractData . contract
42+ }
43+ }
44+ this . call ( 'udapp' , 'addInstance' , contractAddressStr , contractData . contract . abi , contractData . name , contractObject )
45+ await this . call ( 'compilerArtefacts' , 'addResolvedContract' , contractAddressStr , data )
46+ }
47+ }
48+
49+ async request ( payload ) {
50+ const res = await this . sendAsync ( payload )
51+ if ( res && res . error ) throw new Error ( res . error )
52+ return res . result
53+ }
54+
55+ send ( payload ) {
56+ return this . sendAsync ( payload )
57+ }
58+
2559 /*
2660 that is used by plugins to call the current ethereum provider.
2761 Should be taken carefully and probably not be release as it is now.
2862 */
2963 sendAsync ( payload ) {
30-
3164 return new Promise ( ( resolve , reject ) => {
3265 this . askUserPermission ( 'sendAsync' , `Calling ${ payload . method } with parameters ${ JSON . stringify ( payload . params , replacer , '\t' ) } ` ) . then (
3366 async ( result ) => {
3467 if ( result ) {
35- const provider = this . blockchain . web3 ( )
68+ const provider = this . blockchain . getProviderObject ( ) . provider
3669 const resultFn = async ( error , response ) => {
37- let message
38- // For a non-array of payload, result will be at index 0
39- if ( Array . isArray ( response ) && ! Array . isArray ( payload ) ) message = response [ 0 ]
70+ const message = response && response . result && response . result . jsonrpc ? response . result : response
4071 if ( error ) {
4172 // Handle 'The method "debug_traceTransaction" does not exist / is not available.' error
4273 if ( error . message && error . code && error . code === - 32601 ) {
@@ -55,39 +86,20 @@ export class Web3ProviderModule extends Plugin {
5586 return reject ( errorMsg )
5687 }
5788 if ( payload . method === 'eth_sendTransaction' ) {
58- if ( payload . params . length && ! payload . params [ 0 ] . to && message . result ) {
89+ const txHash = response && response . result && response . result . jsonrpc ? response . result . result : response . result
90+ if ( payload . params . length && ! payload . params [ 0 ] . to && txHash ) {
91+ this . emit ( 'transactionBroadcasted' , txHash )
5992 setTimeout ( async ( ) => {
60- this . emit ( 'transactionBroadcasted' , message . result )
61- const receipt = await this . tryTillReceiptAvailable ( message . result )
62- if ( ! receipt . contractAddress ) {
63- console . log ( 'receipt available but contract address not present' , receipt )
64- return
65- }
66- const contractAddressStr = addressToString ( receipt . contractAddress )
67- const contractData = await this . call ( 'compilerArtefacts' , 'getContractDataFromAddress' , contractAddressStr )
68- if ( contractData ) {
69- const data = await this . call ( 'compilerArtefacts' , 'getCompilerAbstract' , contractData . file )
70- const contractObject = {
71- name : contractData . name ,
72- abi : contractData . contract . abi ,
73- compiler : data ,
74- contract : {
75- file : contractData . file ,
76- object : contractData . contract
77- }
78- }
79- this . call ( 'udapp' , 'addInstance' , contractAddressStr , contractData . contract . abi , contractData . name , contractObject )
80- await this . call ( 'compilerArtefacts' , 'addResolvedContract' , contractAddressStr , data )
81- }
82- } , 50 )
83- await this . call ( 'blockchain' , 'dumpState' )
93+ this . updateRemix ( txHash )
94+ } , 1000 )
95+ this . call ( 'blockchain' , 'dumpState' )
8496 }
8597 }
8698 resolve ( message )
8799 }
88100 try {
89101 // browserProvider._send(payload: JsonRpcPayload | Array<JsonRpcPayload>) => Promise<Array<JsonRpcResult | JsonRpcError>>
90- resultFn ( null , await provider . _send ( payload ) )
102+ resultFn ( null , await provider . send ( payload ) )
91103 } catch ( e ) {
92104 resultFn ( e . error ? e . error : e )
93105 }
0 commit comments