-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1_1626990818692.html
215 lines (201 loc) · 7.04 KB
/
1_1626990818692.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<!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>1</title>
<style type="text/css">
button {
background-color: #000;
color: #fff;
border: 0;
font-size: 1em;
}
</style>
</head>
<body>
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title>Data Stores</title>
</head>
<body>
<div class="container">
<p>This page shows a list of individual accounts and their individual balances.</p>
<p>Each account entity (each instantiation of the smart contract) is not aware of the other accounts, or their balances</p>
<p>This page demonstrates how the smart contract search engine can provide the sum total of all accounts combined.</p>
<br />
<b>Sum total of all accounts</b>
<table class="table">
<thead>
<tr><th scope="col">Total</th></tr>
</thead>
<tbody id="totalBody"></tbody>
</table>
<br />
<b>Name and balance of individual accounts</b>
<table class="table">
<thead>
<tr>
<th scope="col">Account Name</th>
<th scope="col">Account Balance</th>
<th scope="col"></th>
</tr>
</thead>
<tbody id="individualBody"></tbody>
</table>
</div>
</body>
</html>
<script type="text/javascript">
window.BuidlProviders = {
web3: {
url: "https://rpc.parastate.io:8545",
chainId: "123",
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 type="text/javascript">
/* Don't modify */
var abi = [];
var bytecode = '';
var cAddr = '';
/* Don't modify */
var instance = null;
window.addEventListener('web3Ready', function() {
var contract = web3.ss.contract(abi);
instance = contract.at(cAddr);
});
// esss.shaAbi(JSON.stringify(abi)).then((shaResult) => {
// var sha = JSON.parse(shaResult).abiSha3;
// esss.searchUsingAbi(sha).then((searchResult) => {
// console.log(searchResult);
// });
// });
document.querySelector("#s").addEventListener("click", function() {
var n = window.prompt("Enter the number:");
n && instance.set(n);
});
document.querySelector("#g").addEventListener("click", function() {
instance.get(function(e,d) {
console.log(d.toString());
alert(d.toString());
});
});
var contract = window.web3 && web3.ss && web3.ss.contract(abi);
var instance = contract && contract.at(cAddr);
window.addEventListener('web3Ready', function() {
contract = web3.ss.contract(abi);
instance = contract.at(cAddr);
reload();
});
function reload() {
document.querySelector("#totalBody").innerHTML = "";
document.querySelector("#individualBody").innerHTML = "";
var tbodyInner = "";
esss.shaAbi(JSON.stringify(abi)).then((shaResult) => {
var sha = JSON.parse(shaResult).abiSha3;
esss.searchUsingAbi(sha).then((searchResult) => {
var items = JSON.parse(searchResult);
items.sort(compareItem);
items.forEach(function(item) {
tbodyInner = tbodyInner +
"<tr id='" + item.contractAddress + "'><td>" + item.functionData.getAccountName +
"</td><td>" + item.functionData.getAccountBalance +
"</td><td><button class='btn btn-info' onclick='setNumber(this)'>Update balance</button></td></tr>";
}); // end of JSON iterator
document.querySelector("#individualBody").innerHTML = tbodyInner;
displayTotal();
});
}); // end of esss
}
function displayTotal() {
esss.shaAbi(JSON.stringify(abi)).then((shaResult) => {
var sha = JSON.parse(shaResult).abiSha3;
esss.searchUsingAbi(sha).then((searchResult) => {
var items = JSON.parse(searchResult);
var totalBodyInner = "";
var total = 0;
items.forEach(function(item) {
total = total + parseInt(item.functionData.getAccountBalance);
});
totalBodyInner = totalBodyInner + "<tr id='total'><td>" + total + "</tr>";
document.querySelector("#totalBody").innerHTML = totalBodyInner;
});
}); // end of esss
}
function setNumber(element) {
var tr = element.closest("tr");
instance = contract.at(tr.id);
var n = window.prompt("Input a number:");
n && instance.setAccountBalance(n);
setTimeout(function() {
element.innerHTML = "Sending ...";
esss.updateStateOfContractAddress(JSON.stringify(abi), instance.address).then((c2i) => {
element.innerHTML = "Calculating ...";
setTimeout(function() {
reload();
}, 5 * 1000);
});
}, 1 * 1000);
}
function compareItem(a, b) {
let comparison = 0;
if (a.functionData.getAccountName < b.functionData.getAccountName) {
comparison = -1;
} else if (a.functionData.getAccountName > b.functionData.getAccountName) {
comparison = 1;
}
return comparison;
}
esss.shaAbi(JSON.stringify(abi)).then((shaResult) => {
var sha = JSON.parse(shaResult).abiSha3;
esss.searchUsingAbi(sha).then((searchResult) => {
var items = JSON.parse(searchResult);
// Puts the items into the table
displayTotal();
});
});
function displayTotal() {
esss.shaAbi(JSON.stringify(abi)).then((shaResult) => {
var sha = JSON.parse(shaResult).abiSha3;
esss.searchUsingAbi(sha).then((searchResult) => {
var items = JSON.parse(searchResult);
var totalBodyInner = "";
var total = 0;
items.forEach(function(item) {
total = total + parseInt(item.functionData.getAccountBalance);
});
totalBodyInner = totalBodyInner +
"<tr id='total'><td>" + total + "</tr>";
document.querySelector("#totalBody").innerHTML = totalBodyInner;
});
}); // end of esss
}
function setNumber(element) {
var tr = element.closest("tr");
instance = contract.at(tr.id);
var n = window.prompt("Input a number:");
n && instance.setAccountBalance(n);
setTimeout(function() {
element.innerHTML = "Sending ...";
esss.updateStateOfContractAddress(JSON.stringify(abi), instance.address).then((c2i) => {
element.innerHTML = "Calculating ...";
setTimeout(function() {
reload();
}, 5 * 1000);
});
}, 1 * 1000);
}
</script>
</body>
</html>