Last active
December 14, 2019 01:24
-
-
Save juntao/e76e4fad1744222901aa8eb266d76cee to your computer and use it in GitHub Desktop.
# SIG 2019
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
Add the following to "dapp -- Resources" | |
* JavaScript: https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js | |
* CSS: https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css | |
The "dapp -- CSS" should be empty | |
https://opendapps.secondstate.io/SIG2019_1576286389667.html | |
<p>欢迎参加2019海纳亚洲大会!请各位嘉宾在下方输入名字领取 Addison-Wesley 新出版的 <a href="https://www.amazon.com/Building-Blockchain-Apps-Michael-Yuan/dp/0135172322/">Buidling Blockchain App</a> 一书</p><p><center><img width="320px" src="https://blog.secondstate.io/images/20191002-book-etc-01.png"></center></p> | |
<p>Sponsored by Second State</p><ul><li>全球领先的区块链技术,为多个全球著名公链提供技术</li><li>无币联盟公链</li><li>为AI,云计算,区块链优化的下一代计算基础设施</li><li>为云原生为服务而生</li></ul> |
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
<div class="container"> | |
<br/> | |
<div class="jumbotron"> | |
<p class="lead" id="greeting">欢迎参加2019海纳亚洲大会!请各位嘉宾在下方输入名字领取 Addison-Wesley 新出版的 <a href="https://www.amazon.com/Building-Blockchain-Apps-Michael-Yuan/dp/0135172322/">Buidling Blockchain App</a> 一书</p> | |
<hr/> | |
<form id="form"> | |
<div class="form-group"> | |
<label for="name">您的姓名</label> | |
<input type="text" class="form-control" id="name" placeholder=""> | |
</div> | |
<div class="form-group"> | |
<label for="organization">您的联系方式</label> | |
<input type="text" class="form-control" id="organization" placeholder=""> | |
</div> | |
<button type="button" id="submit" class="btn btn-primary">发送</button> | |
</form> | |
<div id="formSubmitted" style="display:none">共识上链中,请等 20 秒 ...</div> | |
<p id="me" style="display:none"><span id="myname" class="badge badge-info"></span> 已经签到,谢谢!链上地址 <span id='addr'></span></p> | |
</div> | |
<h4>已经签到</h4> | |
<table class="table table-striped"> | |
<thead> | |
<tr> | |
<th scope="col">链上地址</th> | |
<th scope="col">姓名</th> | |
<th scope="col">联系方式</th> | |
</tr> | |
</thead> | |
<tbody id="checkins"> | |
</tbody> | |
</table> | |
<p style="text-align:center">永久记录在 <a target="_blank" href="https://app.cybermiles.io/">CyberMiles</a> 公链</p> | |
</div> |
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
/* Don't modify */ | |
var instance = null; | |
window.addEventListener('web3Ready', function() { | |
var contract = web3.ss.contract(abi); | |
instance = contract.at(cAddr); | |
reload(); | |
}); | |
function reload() { | |
var greeting = ""; | |
var success = ""; | |
instance.getGreeting(function (e, r) { | |
greeting = r[0]; | |
success = r[1]; | |
$("#greeting").html(greeting); | |
}); | |
$("#formSubmitted").css("display", "none"); | |
$("#me").css("display", "none"); | |
web3.ss.getAccounts(function (e, address) { | |
if (!e) { | |
instance.getCheckin(address, function (ee, result) { | |
if (result[0]) { | |
$("#greeting").html(success); | |
$("#greeting").css("font-size", "14px"); | |
$("#form").css("display", "none"); | |
$("#me").css("display", "block"); | |
$("#myname").html(result[0]); | |
$("#addr").html(shorten(address.toString())); | |
} | |
}); | |
var checkins = ""; | |
instance.getAddrs(function (ee, addrs) { | |
addrs.forEach(function(addr) { | |
instance.getCheckin(addr, function (ee, r) { | |
if (!ee) { | |
var content = $("#checkins").html(); | |
if (content.indexOf(r[0])!==-1 && content.indexOf(r[1])!==-1) { | |
// skip | |
} else { | |
checkins = "<tr><td><a href='https://www.cmttracking.io/address/" + addr + "'>" + shorten(addr) + "</a></td><td>" + r[0] + "</td><td>" + r[1] + "</td></tr>" + checkins; | |
$("#checkins").html(checkins); | |
} | |
} | |
}); | |
}); | |
}); | |
$("#checkins").html(checkins); | |
} | |
}); | |
} | |
$("#submit").click(function() { | |
var n = $("#name").val().trim(); | |
var o = $("#organization").val().trim(); | |
if (!o) { | |
o = " "; | |
} | |
if (!n) { | |
alert("请输入姓名"); | |
return false; | |
} | |
web3.ss.getAccounts(function (e, address) { | |
if (!e) { | |
if (confirm("确认 " + n + " [" + o + "]")) { | |
$("#formSubmitted").css("display", "block"); | |
instance.addCheckin (n, o, { | |
gas: 499000, | |
gasPrice: 0 | |
}, function (ee, r) { | |
if (ee) { | |
window.alert("Failed at " + address); | |
} | |
}); | |
setTimeout(function () { | |
reload (); | |
}, 20 * 1000); | |
} | |
} | |
}); | |
return false; | |
}); | |
function shorten (addr) { | |
return addr.replace(/(.{7})..+/, "$1…"); | |
} |
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
pragma solidity >= 0.4.0; | |
contract CheckIns { | |
address owner; | |
string public greeting; | |
string public success; | |
struct Checkin { | |
string name; | |
string organization; | |
} | |
mapping (address => Checkin) checkins; | |
address [] addrs; | |
constructor (string _greeting, string _success) public { | |
owner = msg.sender; | |
greeting = _greeting; | |
success = _success; | |
} | |
function setGreeting (string _greeting, string _success) public { | |
require (msg.sender == owner); | |
greeting = _greeting; | |
success = _success; | |
} | |
function getGreeting () public constant returns(string, string) { | |
return (greeting, success); | |
} | |
function addCheckin (string _name, string _organization) public { | |
checkins[msg.sender] = Checkin(_name, _organization); | |
addrs.push(msg.sender); | |
} | |
function getCheckin (address _addr) public constant returns(string, string) { | |
return (checkins[_addr].name, checkins[_addr].organization); | |
} | |
function getAddrs () public constant returns (address []) { | |
return addrs; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment