mirror of
https://github.com/mudler/edgevpn.git
synced 2025-10-24 00:53:14 +08:00
🎨 Rework UI to show queued blocks
This commit is contained in:
@@ -84,9 +84,9 @@ func API(l string, ledger *blockchain.Ledger) error {
|
|||||||
|
|
||||||
ec.GET("/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
|
ec.GET("/*", echo.WrapHandler(http.StripPrefix("/", assetHandler)))
|
||||||
|
|
||||||
// ec.GET("/api/blockchain", func(c echo.Context) error {
|
ec.GET("/api/blockchain", func(c echo.Context) error {
|
||||||
// return c.JSON(http.StatusOK, ledger.BlockChain())
|
return c.JSON(http.StatusOK, ledger.LastBlock())
|
||||||
// })
|
})
|
||||||
|
|
||||||
ec.GET("/api/ledger", func(c echo.Context) error {
|
ec.GET("/api/ledger", func(c echo.Context) error {
|
||||||
return c.JSON(http.StatusOK, ledger.CurrentData())
|
return c.JSON(http.StatusOK, ledger.CurrentData())
|
||||||
|
@@ -105,28 +105,36 @@
|
|||||||
</section>
|
</section>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var table = $('#table').DataTable( {
|
var resp
|
||||||
"processing": true,
|
var table = $('#table').DataTable()
|
||||||
"ajax": {
|
sync = function() {
|
||||||
"url": "/api/blockchain",
|
$.ajax({
|
||||||
"type": "GET",
|
url: "/api/blockchain",
|
||||||
"dataSrc": '',
|
type: "GET",
|
||||||
},
|
cache: false,
|
||||||
'language':{
|
async: true,
|
||||||
"loadingRecords": " ",
|
|
||||||
"processing": "Loading..."
|
|
||||||
},
|
|
||||||
"columns": [
|
|
||||||
{ "data": "Index" },
|
|
||||||
{ "data": "Timestamp" },
|
|
||||||
{ "data": "Hash" },
|
|
||||||
{ "data": "PrevHash" },
|
|
||||||
],
|
|
||||||
} );
|
|
||||||
|
|
||||||
setInterval( function () {
|
dataType: "json",
|
||||||
table.ajax.reload();
|
success: function (response) {
|
||||||
}, 30000 );
|
// response is JSON
|
||||||
|
if (resp && response.Index <= resp.Index ) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = response
|
||||||
|
table.row.add( [
|
||||||
|
resp.Index,
|
||||||
|
resp.Timestamp,
|
||||||
|
resp.Hash,
|
||||||
|
resp.PrevHash
|
||||||
|
] ).draw( false );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
sync()
|
||||||
|
setInterval( function () {
|
||||||
|
sync()
|
||||||
|
}, 5000 );
|
||||||
} );
|
} );
|
||||||
</script>
|
</script>
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
|
@@ -192,12 +192,12 @@ func (l *Ledger) CurrentData() map[string]map[string]Data {
|
|||||||
return l.blockchain.Last().Storage
|
return l.blockchain.Last().Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
// // BlockChain returns the current blockchain (locking)
|
// LastBlock returns the last block in the blockchain
|
||||||
// func (l *Ledger) BlockChain() Blockchain {
|
func (l *Ledger) LastBlock() Block {
|
||||||
// l.Lock()
|
l.Lock()
|
||||||
// defer l.Unlock()
|
defer l.Unlock()
|
||||||
// return l.blockchain
|
return l.blockchain.Last()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Add data to the blockchain
|
// Add data to the blockchain
|
||||||
func (l *Ledger) Add(b string, s map[string]interface{}) {
|
func (l *Ledger) Add(b string, s map[string]interface{}) {
|
||||||
|
Reference in New Issue
Block a user