-
Notifications
You must be signed in to change notification settings - Fork 2
/
101du_Task1_1603283399293.html
148 lines (135 loc) · 14.1 KB
/
101du_Task1_1603283399293.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>101du_Task1</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<br/>
<div class="jumbotron">
<div class="view overlay rounded-top text-center">
<img src="" class="img-fluid" id="image">
</div>
<div class="card-body text-center mb-3">
<p class="card-text py-2" id="message"></p>
</div>
<hr/>
<form id="form">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" placeholder="">
</div>
<div class="form-group">
<label for="comment">Comment</label>
<input type="text" class="form-control" id="comment" placeholder="">
</div>
<p><span id="balance"></span><span id="pricealert"></span></p>
<button type="button" id="submit" class="btn btn-primary">Pay & Comment</button>
</form>
<div id="formSubmitted" style="display:none">Please wait up to 10 seconds for confirmation ...</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Comment</th>
</tr>
</thead>
<tbody id="comments">
</tbody>
</table>
<p style="text-align:center">All data recorded on the <a target="_blank" href="https://www.oasiseth.org">Oasis Ethereum</a> blockchain network.</p>
</div>
<script type="text/javascript">
window.BuidlProviders = {
web3: {
url: "https://rpc.oasiseth.org:8545",
chainId: "69",
gasPrice: "1",
gasLimit: "8000000",
},
es: {
url: "https://devchain.ss.search.secondstate.io"
}
}
</script>
<script type="text/javascript" src="https://buidl.secondstate.io/embed/main.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
/* Don't modify */
var abi = [{"constant":false,"inputs":[{"name":"_message","type":"string"}],"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getAddrs","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_image","type":"string"}],"name":"setImage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_price","type":"uint256"}],"name":"setPrice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"price","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_name","type":"string"},{"name":"_comment","type":"string"}],"name":"addComment","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"image","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"getComment","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_message","type":"string"},{"name":"_image","type":"string"},{"name":"_price","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];
var bytecode = '608060405234801561001057600080fd5b50604051610f5c380380610f5c833981018060405281019080805182019291906020018051820192919060200180519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555082600190805190602001906100a09291906100c7565b5081600290805190602001906100b79291906100c7565b508060038190555050505061016c565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061010857805160ff1916838001178555610136565b82800160010185558215610136579182015b8281111561013557825182559160200191906001019061011a565b5b5090506101439190610147565b5090565b61016991905b8082111561016557600081600090555060010161014d565b5090565b90565b610de18061017b6000396000f3006080604052600436106100a4576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063368b8772146100a95780633ccfd60b146101125780633f416eb31461012957806371adb5e61461019557806391b7f5ed146101fe578063a035b1fe1461022b578063ae5ff90514610256578063e21f37ce146102f8578063f3ccaac014610388578063f6bb0cf114610418575b600080fd5b3480156100b557600080fd5b50610110600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610540565b005b34801561011e57600080fd5b506101276105b5565b005b34801561013557600080fd5b5061013e610691565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b83811015610181578082015181840152602081019050610166565b505050509050019250505060405180910390f35b3480156101a157600080fd5b506101fc600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061071f565b005b34801561020a57600080fd5b5061022960048036038101908080359060200190929190505050610794565b005b34801561023757600080fd5b506102406107f9565b6040518082815260200191505060405180910390f35b6102f6600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091929192905050506107ff565b005b34801561030457600080fd5b5061030d61098c565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561034d578082015181840152602081019050610332565b50505050905090810190601f16801561037a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561039457600080fd5b5061039d610a2a565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103dd5780820151818401526020810190506103c2565b50505050905090810190601f16801561040a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561042457600080fd5b50610459600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610ac8565b604051808060200180602001838103835285818151815260200191508051906020019080838360005b8381101561049d578082015181840152602081019050610482565b50505050905090810190601f1680156104ca5780820380516001836020036101000a031916815260200191505b50838103825284818151815260200191508051906020019080838360005b838110156105035780820151818401526020810190506104e8565b50505050905090810190601f1680156105305780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561059b57600080fd5b80600190805190602001906105b1929190610c90565b5050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561061057600080fd5b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f1935050505015801561068e573d6000803e3d6000fd5b50565b6060600580548060200260200160405190810160405280929190818152602001828054801561071557602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116106cb575b5050505050905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561077a57600080fd5b8060029080519060200190610790929190610c90565b5050565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415156107ef57600080fd5b8060038190555050565b60035481565b600354341015151561081057600080fd5b600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060020160009054906101000a900460ff1615156108cd5760053390806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b60606040519081016040528083815260200182815260200160011515815250600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000820151816000019080519060200190610947929190610d10565b506020820151816001019080519060200190610964929190610d10565b5060408201518160020160006101000a81548160ff0219169083151502179055509050505050565b60018054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610a225780601f106109f757610100808354040283529160200191610a22565b820191906000526020600020905b815481529060010190602001808311610a0557829003601f168201915b505050505081565b60028054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610ac05780601f10610a9557610100808354040283529160200191610ac0565b820191906000526020600020905b815481529060010190602001808311610aa357829003601f168201915b505050505081565b606080600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600001600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101818054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610be45780601f10610bb957610100808354040283529160200191610be4565b820191906000526020600020905b815481529060010190602001808311610bc757829003601f168201915b50505050509150808054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610c805780601f10610c5557610100808354040283529160200191610c80565b820191906000526020600020905b815481529060010190602001808311610c6357829003601f168201915b5050505050905091509150915091565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610cd157805160ff1916838001178555610cff565b82800160010185558215610cff579182015b82811115610cfe578251825591602001919060010190610ce3565b5b509050610d0c9190610d90565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610d5157805160ff1916838001178555610d7f565b82800160010185558215610d7f579182015b82811115610d7e578251825591602001919060010190610d63565b5b509050610d8c9190610d90565b5090565b610db291905b80821115610dae576000816000905550600101610d96565b5090565b905600a165627a7a7230582038cdaec1ac5acfa488a799554995052838b17c3fcab329b2890d3722ff3cb8460029';
var cAddr = '0xbe804ed554bb83328164bac254bbac6d09974b7d';
/* Don't modify */
var instance = null;
window.addEventListener('web3Ready', function() {
var contract = web3.ss.contract(abi);
instance = contract.at(cAddr);
reload();
});
var price = "0"; // This is in the unit of OETH. e.g., 0.01
function reload() {
instance.message(function (e, r) {
$("#message").html(r);
});
instance.image(function (e, r) {
$("#image").prop("src", r);
});
instance.price(function (e, r) {
price = r;
$("#pricealert").html("Requires " + price + " wei to comment");
});
$("#formSubmitted").css("display", "none");
web3.ss.getAccounts(function (e, address) {
if (!e) {
var balance = web3.ss.getBalance(address[0]);
$("#balance").html("You have " + balance + " wei OETH in your current account. ");
var comments = "";
instance.getAddrs(function (ee, addrs) {
addrs.forEach(function(addr) {
instance.getComment(addr, function (ee, r) {
if (!ee) {
comments = comments + "<tr><td>" + r[0] + "</td><td>" + r[1] + "</td></tr>";
$("#comments").html(comments);
}
});
});
});
$("#comments").html(comments);
}
});
}
$("#submit").click(function() {
if ((!$("#name").val().trim()) || (!$("#comment").val().trim())) {
alert("Please enter both a name and a comment");
return false;
}
web3.ss.getAccounts(function (e, address) {
if (!e) {
$("#form").css("display", "none");
$("#formSubmitted").css("display", "block");
instance.addComment ($("#name").val(), $("#comment").val(), {
value: price,
gas: 499000,
gasPrice: 1
}, function (ee, r) {
if (ee) {
window.alert("You need to pay " + price + " OETH to comment. Make sure that you have it in your address.");
}
});
setTimeout(function () {
reload ();
}, 10 * 1000);
}
});
return false;
});
</script>
</body>
</html>