-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
369 lines (357 loc) · 15.8 KB
/
index.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!--
This is the integral part of the ui where we manage whole system of the blockchain
of mining and displaying the blockchain and working with the transaction and mining
the system coins and transfering the funds.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Blockchain Management</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
crossorigin="anonymous">
<style>
.lds-ring {
display: inline-block;
position: relative;
width: 64px;
height: 64px;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 51px;
height: 51px;
margin: 6px;
border: 6px solid #fa923f;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #fa923f transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<div class="row mb-3">
<div class="col">
<h1>Manage your Blockchain</h1>
</div>
</div>
<div class="row">
<div class="col">
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="/">Wallet & Node</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/network">Network</a>
</li>
</ul>
</div>
</div>
<hr>
<div v-if="error" class="alert alert-danger" role="alert">
{{ error }}
</div>
<div v-if="success" class="alert alert-success" role="alert">
{{ success }}
</div>
<div class="row">
<div class="col">
<div v-if="!walletLoading">
<button class="btn btn-primary" @click="onCreateWallet">
Create new Wallet
</button>
<button class="btn btn-primary" @click="onLoadWallet">
Load Wallet
</button>
</div>
<div v-if="walletLoading" class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
<div class="col text-right">
<h2>Funds: {{ funds.toFixed(2) }}</h2>
</div>
</div>
<hr>
<div v-if="!wallet" class="row">
<div class="col">
<div class="alert alert-warning">Create a Wallet to start sending coins or to mine coins!</div>
</div>
</div>
<div v-if="wallet" class="row">
<div class="col">
<form @submit.prevent="onSendTx">
<div class="form-group">
<label for="recipient">Recipient Key</label>
<input v-model="outgoingTx.recipient" type="text" class="form-control" id="recipient" placeholder="Enter key">
</div>
<div class="form-group">
<label for="amount">Amount of Coins</label>
<input v-model.number="outgoingTx.amount" type="number" step="0.001" class="form-control" id="amount">
<small class="form-text text-muted">Fractions are possible (e.g. 5.67)</small>
</div>
<div v-if="txLoading" class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<button :disabled="txLoading || outgoingTx.recipient.trim() === '' || outgoingTx.amount <= 0" type="submit" class="btn btn-primary">Send</button>
</form>
</div>
</div>
<hr>
<div class="row">
<div class="col">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" :class="{active: view === 'chain'}" href="#" @click="view = 'chain'">Blockchain</a>
</li>
<li class="nav-item">
<a class="nav-link" :class="{active: view === 'tx'}" href="#" @click="view = 'tx'">Open Transactions</a>
</li>
</ul>
</div>
</div>
<div class="row my-3">
<div class="col">
<button class="btn btn-primary" @click="onLoadData">{{ view === 'chain' ? 'Load Blockchain' : 'Load Transactions' }}</button>
<button v-if="view === 'chain' && wallet" class="btn btn-success" @click="onMine">Mine Coins</button>
<button class="btn btn-warning" @click="onResolve">Resolve Conflicts</button>
</div>
</div>
<div class="row">
<div class="col">
<div v-if="dataLoading" class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div v-if="!dataLoading" class="accordion">
<div class="card" v-for="(data, index) in loadedData">
<div v-if="view === 'chain'" class="card-header">
<h5 class="mb-0">
<button class="btn btn-link" type="button" @click="showElement === index ? showElement = null : showElement = index">
Block #{{ data.index }}
</button>
</h5>
</div>
<div v-if="view === 'chain'" class="collapse" :class="{show: showElement === index}">
<div class="card-body">
<p>Previous Hash: {{ data.previous_hash }}</p>
<div class="list-group">
<div v-for="tx in data.transactions" class="list-group-item flex-column align-items-start">
<div>Sender: {{ tx.sender }}</div>
<div>Recipient: {{ tx.recipient }}</div>
<div>Amount: {{ tx.amount }}</div>
</div>
</div>
</div>
</div>
<div v-if="view === 'tx'" class="card-header">
<h5 class="mb-0">
<button class="btn btn-link" type="button" @click="showElement === index ? showElement = null : showElement = index">
Transaction #{{ index }}
</button>
</h5>
</div>
<div v-if="view === 'tx'" class="collapse" :class="{show: showElement === index}">
<div class="card-body">
<div class="list-group">
<div class="list-group-item flex-column align-items-start">
<div>Sender: {{ data.sender }}</div>
<div>Recipient: {{ data.recipient }}</div>
<div>Amount: {{ data.amount }}</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
new Vue({
el: '#app',
data: {
blockchain: [],
openTransactions: [],
wallet: null,
view: 'chain',
walletLoading: false,
txLoading: false,
dataLoading: false,
showElement: null,
error: null,
success: null,
funds: 0,
outgoingTx: {
recipient: '',
amount: 0
}
},
computed: {
loadedData: function () {
if (this.view === 'chain') {
return this.blockchain;
} else {
return this.openTransactions;
}
}
},
methods: {
onCreateWallet: function () {
// Send Http request to create a new wallet (and return keys)
var vm = this;
this.walletLoading = true
axios.post('/wallet')
.then(function (response) {
vm.error = null;
vm.success = 'Created Wallet! Public Key: ' + response.data.public_key + ', Private Key: ' + response.data.private_key;
vm.wallet = {
public_key: response.data.public_key,
private_key: response.data.private_key
}
vm.funds = response.data.funds;
vm.walletLoading = false
})
.catch(function (error) {
vm.success = null;
vm.error = error.response.data.message
vm.wallet = null
vm.walletLoading = false
});
},
onLoadWallet: function () {
// Send Http request to load an existing wallet (from a file on the server)
var vm = this;
this.walletLoading = true
axios.get('/wallet')
.then(function (response) {
vm.error = null;
vm.success = 'Created Wallet! Public Key: ' + response.data.public_key + ', Private Key: ' + response.data.private_key;
vm.wallet = {
public_key: response.data.public_key,
private_key: response.data.private_key
}
vm.funds = response.data.funds;
vm.walletLoading = false;
})
.catch(function (error) {
vm.success = null;
vm.error = error.response.data.message;
vm.wallet = null;
vm.walletLoading = false;
});
},
onSendTx: function () {
// Send Transaction to backend
this.txLoading = true;
var vm = this;
axios.post('/transaction', {
recipient: this.outgoingTx.recipient,
amount: this.outgoingTx.amount
})
.then(function(response) {
vm.error = null;
vm.success = response.data.message;
console.log(response.data);
vm.funds = response.data.funds;
vm.txLoading = false;
})
.catch(function (error) {
vm.success = null;
vm.error = error.response.data.message;
vm.txLoading = false;
});
},
onMine: function () {
var vm = this
axios.post('/mine')
.then(function(response) {
vm.error = null;
vm.success = response.data.message;
console.log(response.data);
vm.funds = response.data.funds;
})
.catch(function (error) {
vm.success = null;
vm.error = error.response.data.message;
});
},
onResolve: function() {
var vm = this
axios.post('/resolve-conflicts')
.then(function(response) {
vm.error = null;
vm.success = response.data.message;
})
.catch(function (error) {
vm.success = null;
vm.error = error.response.data.message;
});
},
onLoadData: function () {
if (this.view === 'chain') {
// Load blockchain data
var vm = this
this.dataLoading = true
axios.get('/chain')
.then(function (response) {
vm.blockchain = response.data
vm.dataLoading = false
})
.catch(function (error) {
vm.dataLoading = false
vm.error = 'Something went wrong.'
});
} else {
// Load transaction data
var vm = this
axios.get('/transactions')
.then(function (response) {
vm.openTransactions = response.data
vm.dataLoading = false
})
.catch(function (error) {
vm.dataLoading = false
vm.error = 'Something went wrong.'
});
}
}
}
})
</script>
</body>
</html>