-
Notifications
You must be signed in to change notification settings - Fork 2
/
1024_1571831483217.html
121 lines (115 loc) · 8.42 KB
/
1024_1571831483217.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
<!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>1024</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
<style type="text/css">
button {
background-color: #000;
color: #fff;
border: 0;
font-size: 1em;
}
</style>
</head>
<body>
<div class="container">
<br/>
<div class="jumbotron">
<p class="lead" id="greeting"></p>
<hr/>
<form id="form" class="form-inline">
<div class="form-group mx-sm-3 mb-2">
<input type="text" class="form-control" id="name" placeholder="Your Name">
</div>
<div class="alert alert-primary" role="alert" id="recording" style="display:none">
Recording on the Second State DevChain.Please wait up to 5 seconds for confirmation.
</div>
<button type="button" id="submit" onclick="like();" class="btn btn-primary mb-2">Like👍</button>
</form>
<p id="me" style="display:none">Thank you, <span id="myname" class="badge badge-info"></span></p>
</div>
<p id="likes"></p>
</div>
<div style="text-align:center">
<br/><br/>
Created by the <a href="https://buidl.secondstate.io/">BUIDL IDE</a>
<br/><br/>
[<a href="https://docs.secondstate.io/buidl-developer-tool/why-buidl">了解更多</a> | <a href="https://blog.secondstate.io/post/20191024-build-website-zh/">教程</a>]
</div>
<script type="text/javascript">
window.BuidlProviders = {
web3: {
url: "https://devchain.secondstate.io:8545",
chainId: "27183",
gasPrice: "0",
gasLimit: "8192000000",
},
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":true,"inputs":[],"name":"getAddrs","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_addr","type":"address"}],"name":"getLikeName","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_addr","type":"address"},{"name":"_name","type":"string"}],"name":"addLike","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greeting","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}];
var bytecode = '608060405234801561001057600080fd5b50604051610748380380610748833981018060405281019080805182019291905050508060009080519060200190610049929190610050565b50506100f5565b82805460018160011615610100020d166002900490600052602060002090601f016020900481019282601f1061009157805160ff19168380011785556100bf565b828001600101855582156100bf579182015b828111156100be5782518255916020019190600101906100a3565b5b5090506100cc91906100d0565b5090565b6100f291905b808211156100ee5760008160009055506001016100d6565b5090565b90565b610644806101046000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633f416eb31461006757806393f933dd146100d3578063cfa570941461018f578063ef690cc014610218575b600080fd5b34801561007357600080fd5b5061007c6102a8565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156100bf5780820151818401526020810190506100a4565b505050509050019250505060405180910390f35b3480156100df57600080fd5b50610114600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610336565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610154578082015181840152602081019050610139565b50505050905090810190601f1680156101815780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b34801561019b57600080fd5b50610216600480360381019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610417565b005b34801561022457600080fd5b5061022d6104d5565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561026d578082015181840152602081019050610252565b50505050905090810190601f16801561029a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b6060600280548060200260200160405190810160405280929190818152602001828054801561032c57602002820191906000526020600020905b8160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190600101908083116102e2575b5050505050905090565b6060600160008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805460018160011615610100020d166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020d1660029004801561040b5780601f106103e05761010080835404028352916020019161040b565b820191906000526020600020905b8154815290600101906020018083116103ee5782900d601f168201915b50505050509050919050565b80600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020908051906020019061046a929190610573565b5060028290806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505050565b6000805460018160011615610100020d166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020d1660029004801561056b5780601f106105405761010080835404028352916020019161056b565b820191906000526020600020905b81548152906001019060200180831161054e5782900d601f168201915b505050505081565b82805460018160011615610100020d166002900490600052602060002090601f016020900481019282601f106105b457805160ff19168380011785556105e2565b828001600101855582156105e2579182015b828111156105e15782518255916020019190600101906105c6565b5b5090506105ef91906105f3565b5090565b61061591905b808211156106115760008160009055506001016105f9565b5090565b905600a165627a7a72305820e9fe4f40338313e1bf22d049124e4325f40eefa014e2626f9d155ebb5b19f3af0029';
var cAddr = '0xf5dfb2f7c85f50eecaa75d58998525c85a7cbcff';
/* Don't modify */
var instance = null;
window.addEventListener('web3Ready', function() {
var contract = web3.ss.contract(abi);
instance = contract.at(cAddr);
reload();
});
function reload() {
document.querySelector("#greeting").innerHTML = instance.greeting();
web3.ss.getAccounts(function (e, address) {
if (!e) {
var myName = instance.getLikeName(address);
if (myName) {
document.querySelector("#form").style.display = "none";
document.querySelector("#me").style.display = "block";
document.querySelector("#myname").innerHTML = myName;
}
var likes = "Liked by ";
var addrs = instance.getAddrs();
addrs.forEach(function(addr) {
instance.getLikeName(addr, function (ee, r) {
if (!ee) {
likes = likes + "<span class=\"badge badge-success\">" + r + "</span> ";
document.querySelector("#likes").innerHTML = likes;
}
});
});
}
});
}
function like () {
document.querySelector("#submit").disabled = true;
web3.ss.getAccounts(function (e, address) {
if (!e) {
document.querySelector("#recording").style.display = "block";
document.querySelector("#submit").innerHTML = "Please Wait ...";
instance.addLike(address, document.querySelector("#name").value, {
gas: 400000,
gasPrice: 0
}, function (e, result) {
console.log(e + " : " + result);
// ... ...
});
setTimeout(function () {
reload ();
}, 2 * 1000);
}
});
return false;
}
</script>
</body>
</html>