-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use js failure, I will go to new branch to change
- Loading branch information
1 parent
680b737
commit 914f31d
Showing
9 changed files
with
124 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,8 @@ | |
Guide you to understand how blockchain works.<br> | ||
</p> | ||
</div> | ||
<div class="block"> | ||
{{/*GENESIS BLOCK*/}} | ||
<div class="block" onload="loadGenesisHash()"> | ||
<div class="input-group"> | ||
<span class="input-group-addon" id="basic-addon1">DATA</span> | ||
<input type="text" class="form-control" placeholder="" aria-describedby="basic-addon1" | ||
|
@@ -101,7 +102,7 @@ | |
<p style="margin-top: 22px" class="ft-size-12">PREVIOUS HASH | ||
<span class="label label-info">0</span> | ||
</p> | ||
<p style="margin-top: 10px" class="ft-size-12">HASH <span class="label label-info">000dc75a315c77a1f9c98fb6247d03dd18ac52632d7dc6a9920261d8109b37cf</span> | ||
<p style="margin-top: 10px" class="ft-size-12">HASH <span class="label label-info">{{LoadGenesisHash}}</span> | ||
</p> | ||
<div class="clearfix" style="height: 54px"> | ||
<h3 class="pull-left">GENESIS BLOCK | ||
|
@@ -110,6 +111,30 @@ <h3 class="pull-left">GENESIS BLOCK | |
<span class="label label-info pull-right" style="margin-top: 26px;">604</span> | ||
</div> | ||
</div> | ||
{{/*BLOCK# BEGIN*/}} | ||
{{/*隐藏域 用于传递数据*/}} | ||
<span id="span-hidden1" style="visibility: hidden"></span> | ||
<span id="span-hidden3"> | ||
|
||
</span> | ||
|
||
<span id="span-hidden2" style="visibility: hidden"></span> | ||
{{/*BLOCK END*/}} | ||
<div class="add-block"> | ||
<div class="input-group"> | ||
<span class="input-group-addon" id="basic-addon1">DATA</span> | ||
<input type="text" id="addData" class="form-control" placeholder="" aria-describedby="basic-addon1" | ||
value="{{.addData}}" name="addData"> | ||
</div> | ||
<button class="btn-addblock" onclick="addBlock()" style="color: #fff;">ADD NEW BLOCK</button> | ||
</div> | ||
</div> | ||
<script> | ||
const blockHTML = ` | ||
\{\{if .\}\} | ||
<p>There is not object</p> | ||
\{\{end\}\} | ||
<span style="visibility: hidden">\{\{range .blocks\}\}</span> | ||
<div style="text-align: center;"> | ||
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true" | ||
style="font-size: 40px; color: rgba(0,0,0,0.5);"></span> | ||
|
@@ -120,8 +145,8 @@ <h3 class="pull-left">GENESIS BLOCK | |
<input type="text" class="form-control" placeholder="" aria-describedby="basic-addon1" | ||
value="Welcome to Blockchain Demo by TheStarBoys"> | ||
</div> | ||
<p style="margin-top: 22px" class="ft-size-12">PREVIOUS HASH <span class="label label-info">000dc75a315c77a1f9c98fb6247d03dd18ac52632d7dc6a9920261d8109b37cf</span></p> | ||
<p style="margin-top: 10px" class="ft-size-12">HASH <span class="label label-info">000dc75a315c77a1f9c98fb6247d03dd18ac52632d7dc6a9920261d8109b37cf</span> | ||
<p style="margin-top: 22px" class="ft-size-12">PREVIOUS HASH <span class="label label-info">{{.PrevBlockHash}}</span></p> | ||
<p style="margin-top: 10px" class="ft-size-12">HASH <span class="label label-info">{{.Hash}}</span> | ||
</p> | ||
<div class="clearfix" style="height: 54px"> | ||
<h3 class="pull-left">BLOCK#1 | ||
|
@@ -130,21 +155,37 @@ <h3 class="pull-left">BLOCK#1 | |
<span class="label label-info pull-right" style="margin-top: 26px;">604</span> | ||
</div> | ||
</div> | ||
<div class="add-block"> | ||
<form action="/add-block" method="post"> | ||
<div class="input-group"> | ||
<span class="input-group-addon" id="basic-addon1">DATA</span> | ||
<input type="text" class="form-control" placeholder="" aria-describedby="basic-addon1" | ||
value="{{.data}}"> | ||
</div> | ||
<button class="btn-addblock" type="submit" style="color: #fff;">ADD NEW BLOCK</button> | ||
</form> | ||
</div> | ||
</div> | ||
<span style="visibility: hidden">\{\{end\}\}</span>`; | ||
// 添加区块传递数据的函数 | ||
function addBlock() { | ||
var addData = document.getElementById("addData").value; | ||
console.log(addData); // 得到了addData输入框里的值 | ||
var json = {{AddBlockData "addData"}}; // 返回的是一个json | ||
var obj = JSON.parse(json); // 解析json得到对象 | ||
console.log("obj is ----:", obj.Blocks[0].Version); | ||
document.getElementById("span-hidden1").innerHTML = "\{\{with " + obj.Blocks + "\}\}"; | ||
document.getElementById("span-hidden2").innerHTML = "\{\{end\}\}"; | ||
//alert(typeof blockHTML); | ||
// 遍历json对象,得到其中我们需要的属性值 | ||
for (var i = 0; i <obj.Blocks.length;i++) { | ||
var block = obj.Blocks[i]; | ||
var prevhash = block.PrevBlockHash; | ||
var hash = block.Hash; | ||
console.log(obj.Blocks.length); | ||
console.log("for - in obj ----", prevhash + " ", hash); | ||
} | ||
document.getElementById("span-hidden3").innerHTML = blockHTML; | ||
} | ||
// 加载时,获得GenesisBlock的hash | ||
function loadGenesisHash() { | ||
|
||
} | ||
|
||
</script> | ||
|
||
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script> | ||
<script src="../static/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> |