@@ -6,23 +6,38 @@ function showTruebitScrypt(hash) {
6
6
return "<div>Scrypt Hash from TrueBit solver:</div> <div>" + hash + "</div>"
7
7
}
8
8
9
- var fileSystem , scryptSubmitter
9
+ var fileSystem , scryptSubmitter , account
10
10
11
11
function getTruebitScrypt ( data ) {
12
12
13
- let hash = "default"
13
+ let hash = "default"
14
14
15
- scryptSubmitter . methods . submitData ( data ) . send ( { gas : 200000 } , function ( error , txHash ) {
16
- scryptSubmitter . once ( 'GotFiles' , function ( error , event ) {
17
- if ( event ) {
18
- let fileID = event . args . files [ 0 ]
19
-
20
- fileSystem . methods . getData ( fileID ) . call ( function ( error , result ) {
21
- hash = result [ 0 ]
22
- } )
23
- }
24
- } )
25
- } )
15
+ scryptSubmitter . submitData ( data , { gas : 200000 } , function ( error , txHash ) {
16
+ if ( error ) {
17
+ alert ( error )
18
+ } else if ( txHash ) {
19
+
20
+ let f = window . web3 . filter ( )
21
+
22
+ f . watch ( function ( error , result ) {
23
+ if ( error ) {
24
+ alert ( error )
25
+ } else if ( result ) {
26
+ f . stopWatching ( )
27
+
28
+ let fileID = result . args . files [ 0 ]
29
+
30
+ fileSystem . getData . call ( fileID , function ( error , result ) {
31
+ if ( error ) {
32
+ alert ( error )
33
+ } else if ( result ) {
34
+ hash = result [ 0 ]
35
+ }
36
+ } )
37
+ }
38
+ } )
39
+ }
40
+ } )
26
41
27
42
return hash
28
43
}
@@ -45,8 +60,11 @@ function getArtifacts(networkName) {
45
60
//get scrypt submitter artifact
46
61
const artifacts = JSON . parse ( httpRequest . responseText )
47
62
48
- fileSystem = window . web3 . eth . contract ( artifacts . fileSystem . abi , artifacts . fileSystem . address )
49
- scryptSubmitter = window . web3 . eth . contract ( artifacts . scrypt . abi , artifacts . scrypt . address )
63
+ fileSystem = window . web3 . eth . contract ( artifacts . fileSystem . abi ) . at ( artifacts . fileSystem . address )
64
+
65
+ scryptSubmitter = window . web3 . eth . contract ( artifacts . scrypt . abi ) . at ( artifacts . scrypt . address )
66
+
67
+ account = window . web3 . eth . defaultAccount
50
68
}
51
69
}
52
70
0 commit comments