如何做一个delay和"to bind"两个变量?
How to make a delay and "to bind" two variables?
我有合同“行李”。车主(比如我)需要把它转移到行李房一段时间。他不能早于规定的时间得到它。
请告诉我:
a) 如何“延期”(延期结束前无法领取行李)
b) 将主人地址与行李地址绑定(可查看行李是否为主人所要求)
contract LuggageStorage
{
Luggage luggage;
address owner;
constructor(LuggageStorage _luggage) public
{
luggage = _luggage;
owner = msg.sender;
}
function storeLuggage (uint lAddress, uint time) public
{
luggage.transferFrom(msg.sender, owner, lAddress); //the function transfers luggage to new owner
}
function retrieveLuggage(uint lAddress) public
{
luggage.transferFrom(owner, msg.sender, lAddress);
}
}
对于延迟,您可以将 block.timestamp 全局变量(returns 当前时间戳)与之前存储的时间戳进行比较。
pragma solidity ^0.8.0;
contract LuggageStorage {
uint256 releaseDate;
constructor(uint256 _releaseDate) {
releaseDate = _releaseDate;
}
function retrieveLuggage() public {
/*
* `block.timestamp` is timestamp of the current transaction
* `releaseDate` is the manually defined timestamp
*/
require(block.timestamp >= releaseDate, "You're too early");
// ... and here goes your retrieve implementation
}
}
检查所有者几乎是一样的。您需要定义 owner
地址并根据 msg.sender.
进行验证
pragma solidity ^0.8.0;
contract LuggageStorage {
address owner;
constructor(address _owner) {
owner = _owner;
}
function retrieveLuggage() public {
require(msg.sender == owner, "Can by only requested by the owner");
// ... here goes your retrieve implementation
}
}
我有合同“行李”。车主(比如我)需要把它转移到行李房一段时间。他不能早于规定的时间得到它。 请告诉我:
a) 如何“延期”(延期结束前无法领取行李)
b) 将主人地址与行李地址绑定(可查看行李是否为主人所要求)
contract LuggageStorage
{
Luggage luggage;
address owner;
constructor(LuggageStorage _luggage) public
{
luggage = _luggage;
owner = msg.sender;
}
function storeLuggage (uint lAddress, uint time) public
{
luggage.transferFrom(msg.sender, owner, lAddress); //the function transfers luggage to new owner
}
function retrieveLuggage(uint lAddress) public
{
luggage.transferFrom(owner, msg.sender, lAddress);
}
}
对于延迟,您可以将 block.timestamp 全局变量(returns 当前时间戳)与之前存储的时间戳进行比较。
pragma solidity ^0.8.0;
contract LuggageStorage {
uint256 releaseDate;
constructor(uint256 _releaseDate) {
releaseDate = _releaseDate;
}
function retrieveLuggage() public {
/*
* `block.timestamp` is timestamp of the current transaction
* `releaseDate` is the manually defined timestamp
*/
require(block.timestamp >= releaseDate, "You're too early");
// ... and here goes your retrieve implementation
}
}
检查所有者几乎是一样的。您需要定义 owner
地址并根据 msg.sender.
pragma solidity ^0.8.0;
contract LuggageStorage {
address owner;
constructor(address _owner) {
owner = _owner;
}
function retrieveLuggage() public {
require(msg.sender == owner, "Can by only requested by the owner");
// ... here goes your retrieve implementation
}
}