ParserError: Expected ',' but got identifier in the first functon parameter (bytes32 _username)
ParserError: Expected ',' but got identifier in the first functon parameter (bytes32 _username)
我不明白为什么在 checkRegisterability 函数中出现这个错误。终端显示“ParserError: Expected ',' but got identifier”并指示 bytes32 _username。谢谢大家
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/ownership/Ownable.sol";
contract SocialNetwork is Ownable {
struct Post {
string content;
address author;
}
struct User {
uint registerDate;
bytes32 username;
bytes32 password;
bytes32 email;
}
User[] users;
uint256 userId;
mapping(uint256 => User) usersId;
bool usernameAvaiable;
bool emailAvaiable;
function checkRegisterability(bytes32 _username, bytes32 _password, bytes32 _email) internal view onlyOwner returns(bool registerability) {
for(uint i; i <= users.length; i++) {
if(usersId[i].username != _username) {
usernameAvaiable;
} else {usernameAvaiable = false;}
if(usersId[i].email != _email) {
emailAvaiable;
} else {emailAvaiable = false;}
}
require(usernameAvaiable == false, "This username is unavaiable");
require(emailAvaiable == false, "This email is unavaiable");
require(usernameAvaiable && emailAvaiable);
registerability;
return registerability;
}
你错过了最后一个}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/ownership/Ownable.sol";
contract SocialNetwork is Ownable {
struct Post {
string content;
address author;
}
struct User {
uint registerDate;
bytes32 username;
bytes32 password;
bytes32 email;
}
User[] users;
uint256 userId;
mapping(uint256 => User) usersId;
bool usernameAvaiable;
bool emailAvaiable;
function checkRegisterability(bytes32 _username, bytes32 _password, bytes32 _email) internal view onlyOwner returns(bool registerability) {
for(uint i; i <= users.length; i++) {
if(usersId[i].username != _username) {
usernameAvaiable;
} else {usernameAvaiable = false;}
if(usersId[i].email != _email) {
emailAvaiable;
} else {emailAvaiable = false;}
}
require(usernameAvaiable == false, "This username is unavaiable");
require(emailAvaiable == false, "This email is unavaiable");
require(usernameAvaiable && emailAvaiable);
registerability;
return registerability;
}
}
请注意,您的代码无法编译,因为 checkRegisterability
被声明为视图,但是状态被修改 emailAvaiable = false;
我不明白为什么在 checkRegisterability 函数中出现这个错误。终端显示“ParserError: Expected ',' but got identifier”并指示 bytes32 _username。谢谢大家
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/ownership/Ownable.sol";
contract SocialNetwork is Ownable {
struct Post {
string content;
address author;
}
struct User {
uint registerDate;
bytes32 username;
bytes32 password;
bytes32 email;
}
User[] users;
uint256 userId;
mapping(uint256 => User) usersId;
bool usernameAvaiable;
bool emailAvaiable;
function checkRegisterability(bytes32 _username, bytes32 _password, bytes32 _email) internal view onlyOwner returns(bool registerability) {
for(uint i; i <= users.length; i++) {
if(usersId[i].username != _username) {
usernameAvaiable;
} else {usernameAvaiable = false;}
if(usersId[i].email != _email) {
emailAvaiable;
} else {emailAvaiable = false;}
}
require(usernameAvaiable == false, "This username is unavaiable");
require(emailAvaiable == false, "This email is unavaiable");
require(usernameAvaiable && emailAvaiable);
registerability;
return registerability;
}
你错过了最后一个}
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/ownership/Ownable.sol";
contract SocialNetwork is Ownable {
struct Post {
string content;
address author;
}
struct User {
uint registerDate;
bytes32 username;
bytes32 password;
bytes32 email;
}
User[] users;
uint256 userId;
mapping(uint256 => User) usersId;
bool usernameAvaiable;
bool emailAvaiable;
function checkRegisterability(bytes32 _username, bytes32 _password, bytes32 _email) internal view onlyOwner returns(bool registerability) {
for(uint i; i <= users.length; i++) {
if(usersId[i].username != _username) {
usernameAvaiable;
} else {usernameAvaiable = false;}
if(usersId[i].email != _email) {
emailAvaiable;
} else {emailAvaiable = false;}
}
require(usernameAvaiable == false, "This username is unavaiable");
require(emailAvaiable == false, "This email is unavaiable");
require(usernameAvaiable && emailAvaiable);
registerability;
return registerability;
}
}
请注意,您的代码无法编译,因为 checkRegisterability
被声明为视图,但是状态被修改 emailAvaiable = false;