Skip to content

Commit 2cf370b

Browse files
committed
Fleshed out data submission, and sending TRU to scrypt submitter contract
1 parent 218c111 commit 2cf370b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

deploy.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ async function deploy() {
3434
let options = {from: accounts[0].toLowerCase(), gas: 2000000}
3535

3636
let args = [
37-
artifacts.incentiveLayer.address.toLowerCase(),
38-
artifacts.tru.address.toLowerCase(),
39-
artifacts.fileSystem.address.toLowerCase(),
37+
artifacts.incentiveLayer.address,
38+
artifacts.tru.address,
39+
artifacts.fileSystem,
4040
info.ipfshash,
4141
info.codehash
4242
]
@@ -45,6 +45,10 @@ async function deploy() {
4545

4646
let c = await contract.deploy({data: "0x" + bin, arguments: args}).send(options)
4747

48+
let tru = new web3.eth.Contract(artifacts.tru.abi, artifacts.tru.address)
49+
50+
tru.transfer(c._address, "100000000000", {from: accounts[0], gas:200000})
51+
4852
fs.writeFileSync("export.json", JSON.stringify({
4953
address: c._address,
5054
abi: c._jsonInterface

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const fs = require('fs')
77
app.use(express.static('public'))
88

99
app.get('/contracts', function (req, res) {
10-
let artifacts = fs.readFileSync(__dirname + "/truebit-os/wasm-client/" + req.query.network + ".json")
11-
res.send(artifacts)
10+
let artifacts = JSON.parse(fs.readFileSync(__dirname + "/truebit-os/wasm-client/" + req.query.network + ".json"))
11+
12+
artifacts["scrypt"] = JSON.parse(fs.readFileSync(__dirname + "/export.json"))
13+
14+
res.send(JSON.stringify(artifacts))
1215
})
1316

1417
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

public/js/app.js

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

9-
var incentiveLayer, fileSystem
10-
11-
const taskInfo = {
12-
"ipfshash":"QmZGf6QCViGi7VPZSp97EkvDX9NuNyspZvgpXs1Wq73u4L",
13-
"codehash":"0xcb1f3611566c137482d4a5b560896d2142a13450915d8e17e7dd9c24736a164c",
14-
"memsize":20
15-
}
9+
var fileSystem, scryptSubmitter
1610

1711
function getTruebitScrypt(data) {
1812

19-
//handle file system work
13+
let hash = "default"
2014

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+
})
26+
27+
return hash
2128
}
2229

2330
function runScrypt() {
2431
data = document.getElementById('input-data').value
2532
hash = s.crypto_scrypt(data, "foo", 1024, 1, 1, 256)
2633
document.getElementById('js-scrypt').innerHTML = showJSScrypt(s.to_hex(hash))
2734

28-
document.getElementById('tb-scrypt').innerHTML = showTruebitScrypt("foobar")
35+
truHash = getTruebitScrypt(data)
36+
37+
document.getElementById('tb-scrypt').innerHTML = showTruebitScrypt(truHash)
2938
}
3039

3140
function getArtifacts(networkName) {
@@ -34,6 +43,10 @@ function getArtifacts(networkName) {
3443
httpRequest.onreadystatechange = function() {
3544
if (httpRequest.readyState === XMLHttpRequest.DONE) {
3645
//get scrypt submitter artifact
46+
const artifacts = JSON.parse(httpRequest.responseText)
47+
48+
fileSystem = window.web3.eth.contract(artifacts.fileSystem.abi, artifacts.fileSystem.address)
49+
scryptSubmitter = window.web3.eth.contract(artifacts.scrypt.abi, artifacts.scrypt.address)
3750
}
3851
}
3952

0 commit comments

Comments
 (0)