turn true; } 4:查询我的质押 function getMyDeposits(uint256 blockNumber)public view returns(Locked memory){ string memory indexs=getAddNumberStr(msg.sender, blockNumber); Locked memory lock= deposits[indexs]; return lock; } 5: 解除封存 function withdraw(uint blockNumber)public returns(bool){ IERC20 filCoin = IERC20(filAddress); string memory indexs=getAddNumberStr(msg.sender, blockNumber); //查询封存数据 Locked memory lock= deposits[getAddNumberStr(msg.sender, blockNumber)]; //如果余额为0,说明已经解锁 require(lock.amount>0,"The balance is 0, and this pledge has been withdrawn"); //提现解锁条件 require((block.number > lock.withdrawNumber||price > lock.price*35/10),"Pledge not yet due"); //365days or 3.5price //修改解锁数据 uint256 amount= lock.amount; //用户提现后,锁仓余额修改为0 lock.amount=0; //标注提现区块高度 lock.withdrawedNumber=block.number; deposits[indexs]=lock; //解锁 filCoin.transfer(msg.sender,amount); //修改总封存数量 lockedAmount=lockedAmount-amount; return true; } 6: 封存 function deposit(address user,uint amount) public returns (bool) { require(isAuthListed[msg.sender]==true,"Unauthorized operation account"); //记录封存用户地址 locked.useraddress=user; //记录封存时间 locked.depositNumber=block.number; //记录封存数量 locked.amount=amount; //记录最早解锁区块高度 locked.withdrawNumber=block.number+year; deposits[getAddNumberStr(user, block.number)]=locked; //增加封存总数量 lockedAmount=lockedAmount+amount; return true; } 7: 组装索引 function getAddNumberStr(address sender,uint256 blockNumber) private pure returns( string memory){ return string(abi.encodePacked(Strings.toHexString(uint160(sender), 20),"-",Strings.toString(blockNumber))); } 8:获取余额 function getTokenBalance(address contractAddress, address accountAddress) private view returns (uint256) { ERC20 ercToken = ERC20(contractAddress); return ercToken.balanceOf(accountAddress); } 以上就是FILLocked的主要功能,在接下来的文章中,我们将逐一分析FIL2的其他合约,共同验证FIL2如何通过开源技术保证资金的安全和规则的公平。 来源:金色财经lg...