此文已由作者苏州授权网易云社区发布。
欢迎访问网易云社区,了解更多网易技术产品运营经验
#!/bin/sh
sol_directory="../src/main/resources/solidity"
abi_bin_directory="../src/main/resources/solidity/build"
java_directory="../src/main/java"
java_package="com.netease.blockchainsdk.contracts.generated"
for file in ${sol_directory}/*
do
if test -f $file
then
if [ "${file##*.}"x = "sol"x ];then
tmp=${file##*/}
filename=${tmp%.*}
echo ${filename}
echo "Compiling Solidity file ${filename}.sol"
solc --bin --abi --optimize --overwrite \
--allow-paths "$(pwd)" \
soldirectory/{filename}.sol -o ${abi_bin_directory}/
echo "Complete"
echo "Generating contract bindings"
web3j-3.2.0/bin/web3j solidity generate \
abibindirectory/{filename}.bin \
abibindirectory/{filename}.abi \
-p ${java_package} \
-o ${java_directory} > /dev/null
echo "Complete"
fi
fi
if test -d $file
then
echo $file 是目录
fi
done
|
Library SafeMath{
function mul(uint256 a,uint256 b) internal constant returns(uint256){
uint256 c=a *b;
assert(a==0||c/a==b);
return c;
}
function div(uint256 a,uint256 b) internal constant returns(uint256){
uint256 c=a/b;
return c;
}
function sub(uint256 a,uint256 b) internal constant returns(uint256){
uint256 c=a/b;
return c;
}
function add(uint256 a,uint256 b) internal constant returns(uint256){
uint256 c=a+b;
assert(c>=a);
return c;
}
}
|
contract auction{
mapping(address=>uint) refunds;
//....
function withDrawReFund(address receipt){
uint refund=refunds[receipt];
refunds[receipt]=0;
receipt.send(refund);
}
}
|
mapping(address=>uint) private userBalances;
//....
function withDrawBalance() public {
uint amountToWithDraw=userBalances[msg.sender];
If(!(msg.sender.call.value(amountToWithDraw))){throw;}
userBalances[msg.sender]=0;
}
|
mapping(address=>uint) private userBalances;
//....
function transfer(address to,uint amount){
If(userBalances[msg.sender]>=amount){
userBalances[to]+=amount;
userBalances[msg.sender]-=amount;
}
}
function withDrawBalance() public {
uint amountToWithDraw=userBalances[msg.sender];
If(!(msg.sender.call.value(amountToWithDraw))){throw;}
userBalances[msg.sender]=0;
}
|
Contract Auction{
Address currentLeader;
Uint highestBid;
Function bid(){
If(msg.value<=highestBid){throw;}
If(!currentLeader.send(highestBid)){throw;}
currentLeader=msg.sender;
highestBid=msg.value;
}
}
|
Uint startTime=x;
If(now>startTime +1 week){//do...}
|
免费领取验证码、内容安全、短信发送、直播点播体验包及云服务器等套餐
更多网易技术、产品、运营经验分享请点击。