Cyber Security researcher
Cyber Security researcher

Subscribe to R0chGh0st

Subscribe to R0chGh0st
Share Dialog
Share Dialog
(1)Alchemy Week6代码编写,solidity代码为自行编写,前端代码copy的是已经做完的大佬编写的代码,前端代码与样例代码之间相比改动不多,重点仍然是理解solidty代码。通过最近这段时间的实践,感觉前端代码的迭代太快,有些跟不上,solidty相对比较稳定,应当作为重点学习的内容。今天是用gitpod做的开发,主要也是不太想在本地弄环境了,就弄了个在线环境,有一些操作不太习惯,还要慢慢来:感觉自己现在是hardhat也会用,yarn也能用,但是没有精通,甚至没有理解相关包之间的关系。
(2)ying开图,通过refund退款及开盲盒开到了自己喜欢的图,稀有度还可以,目前排17名,重要的是她很喜欢。527的寓意也很好:吾爱妻。

(3)论文编写:编写社交安全部分内容
(4)参与 souffl3 的 Aptos 网络测试活动,赢取空投,获得4级Discord角色

项目链接如下:
参考的是下述教程:
今日理解并掌握了 modifier 的一种新写法,通过引入一个bool参数变量,控制断言执行分支
// 剩余提取时间,到时间了返回0,没到时间返回还有多久到时间
function withdrawalTimeLeft() public view returns (uint256 withdrawalTimeLeft) {
if( block.timestamp >= withdrawalDeadline) {
return (0);
} else {
return (withdrawalDeadline - block.timestamp);
}
}
//带参数的modifier修饰器
modifier withdrawalDeadlineReached( bool requireReached ) {
uint256 timeRemaining = withdrawalTimeLeft();
if( requireReached ) {
require(timeRemaining == 0, "Withdrawal period is not reached yet");
} else {
require(timeRemaining > 0, "Withdrawal period has been reached");
}
_;
}
//质押函数
function stake() public payable withdrawalDeadlineReached(false) claimDeadlineReached(false){
balances[msg.sender] = balances[msg.sender] + msg.value;
depositTimestamps[msg.sender] = block.timestamp;
emit Stake(msg.sender, msg.value);
}
//提取函数
function withdraw() public withdrawalDeadlineReached(true) claimDeadlineReached(false) notCompleted{
require(balances[msg.sender] > 0, "You have no balance to withdraw!");
uint256 individualBalance = balances[msg.sender];
uint256 indBalanceRewards = individualBalance + ((block.timestamp-depositTimestamps[msg.sender])*rewardRatePerSecond);
balances[msg.sender] = 0;
// Transfer all ETH via call! (not transfer) cc: https://solidity-by-example.org/sending-ether
(bool sent, bytes memory data) = msg.sender.call{value: indBalanceRewards}("");
require(sent, "RIP; withdrawal failed :( ");
}
分支1:当 requireReached 为 true (开发者希望到了时间)时,走上面的分支,require 断言要求 timeReamaining 为 0 也就是到了提取时间,那么假设此时没到提取时间,将不符合断言要求被revert。
分支2:当 requireReached 为 false (开发者希望没到时间)时,走下面的分支,require 断言要求 timeReamaining > 0 也就是没到提取时间,那么假设此时到了提取时间(返回值为0),将不符合断言要求被revert。
withdraw 函数在定义时使用了 withdrawalDeadlineReached(true) 修饰器,也就是说没到提取时间,则肯定不能调用withdraw函数提取代币。当到了提取时间,则可以提取对应代币。
(1)Alchemy Week6代码编写,solidity代码为自行编写,前端代码copy的是已经做完的大佬编写的代码,前端代码与样例代码之间相比改动不多,重点仍然是理解solidty代码。通过最近这段时间的实践,感觉前端代码的迭代太快,有些跟不上,solidty相对比较稳定,应当作为重点学习的内容。今天是用gitpod做的开发,主要也是不太想在本地弄环境了,就弄了个在线环境,有一些操作不太习惯,还要慢慢来:感觉自己现在是hardhat也会用,yarn也能用,但是没有精通,甚至没有理解相关包之间的关系。
(2)ying开图,通过refund退款及开盲盒开到了自己喜欢的图,稀有度还可以,目前排17名,重要的是她很喜欢。527的寓意也很好:吾爱妻。

(3)论文编写:编写社交安全部分内容
(4)参与 souffl3 的 Aptos 网络测试活动,赢取空投,获得4级Discord角色

项目链接如下:
参考的是下述教程:
今日理解并掌握了 modifier 的一种新写法,通过引入一个bool参数变量,控制断言执行分支
// 剩余提取时间,到时间了返回0,没到时间返回还有多久到时间
function withdrawalTimeLeft() public view returns (uint256 withdrawalTimeLeft) {
if( block.timestamp >= withdrawalDeadline) {
return (0);
} else {
return (withdrawalDeadline - block.timestamp);
}
}
//带参数的modifier修饰器
modifier withdrawalDeadlineReached( bool requireReached ) {
uint256 timeRemaining = withdrawalTimeLeft();
if( requireReached ) {
require(timeRemaining == 0, "Withdrawal period is not reached yet");
} else {
require(timeRemaining > 0, "Withdrawal period has been reached");
}
_;
}
//质押函数
function stake() public payable withdrawalDeadlineReached(false) claimDeadlineReached(false){
balances[msg.sender] = balances[msg.sender] + msg.value;
depositTimestamps[msg.sender] = block.timestamp;
emit Stake(msg.sender, msg.value);
}
//提取函数
function withdraw() public withdrawalDeadlineReached(true) claimDeadlineReached(false) notCompleted{
require(balances[msg.sender] > 0, "You have no balance to withdraw!");
uint256 individualBalance = balances[msg.sender];
uint256 indBalanceRewards = individualBalance + ((block.timestamp-depositTimestamps[msg.sender])*rewardRatePerSecond);
balances[msg.sender] = 0;
// Transfer all ETH via call! (not transfer) cc: https://solidity-by-example.org/sending-ether
(bool sent, bytes memory data) = msg.sender.call{value: indBalanceRewards}("");
require(sent, "RIP; withdrawal failed :( ");
}
分支1:当 requireReached 为 true (开发者希望到了时间)时,走上面的分支,require 断言要求 timeReamaining 为 0 也就是到了提取时间,那么假设此时没到提取时间,将不符合断言要求被revert。
分支2:当 requireReached 为 false (开发者希望没到时间)时,走下面的分支,require 断言要求 timeReamaining > 0 也就是没到提取时间,那么假设此时到了提取时间(返回值为0),将不符合断言要求被revert。
withdraw 函数在定义时使用了 withdrawalDeadlineReached(true) 修饰器,也就是说没到提取时间,则肯定不能调用withdraw函数提取代币。当到了提取时间,则可以提取对应代币。
<100 subscribers
<100 subscribers
No activity yet