Skip to content

Commit 41d8bac

Browse files
committed
Metamask trying to send transaction
1 parent 67bcb33 commit 41d8bac

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<html>
22
<head>
33
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-scrypt/1.2.0/scrypt.min.js"></script>
4+
45
<script>
56
let s
67
scrypt_module_factory(function (scrypt) {

public/js/app.js

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,38 @@ function showTruebitScrypt(hash) {
66
return "<div>Scrypt Hash from TrueBit solver:</div> <div>" + hash + "</div>"
77
}
88

9-
var fileSystem, scryptSubmitter
9+
var fileSystem, scryptSubmitter, account
1010

1111
function getTruebitScrypt(data) {
1212

13-
let hash = "default"
13+
let hash = "default"
1414

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+
})
2641

2742
return hash
2843
}
@@ -45,8 +60,11 @@ function getArtifacts(networkName) {
4560
//get scrypt submitter artifact
4661
const artifacts = JSON.parse(httpRequest.responseText)
4762

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
5068
}
5169
}
5270

0 commit comments

Comments
 (0)