ParserError: Source "project:/src/contracts/Interfaces/Libraries/IERC165.sol" not found - import

I have an error. I am trying to import my 'IERC165.sol' file to my 'ERC165.sol' and to my 'ERC721'. And I am receiving this error a long with two more error's that are the same just with different files.
I also made sure that the file was in the folder where it should be. And now I am just confused.
here is the code for the 'IERC165'
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IERC165 {
// #notice Query if a contract implements an interface
// #param interfaceID The interface identifier, as specified in ERC-165
// #dev Interface identification is specified in ERC-165. This function
// uses less than 30,000 gas.
// #retrun 'true' if the contract implements 'interfaceID' and
// 'interfaceId' is not 0xffffffff, 'false' otherwise
function supportsInterface(bytes4 interfaceID) external view returns (bool);
}
here is the code for ERC165
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import './IERC165.sol';
contract ERC165 is IERC165 {
mapping (bytes4 => bool) private _supportedInterfaces;
constructor() {
_registerInterface(bytes4(keccak256('supportsInterface(bytes4)')));
}
function supportsInterface(bytes4 interfaceID) external view returns (bool) {
return _supportedInterfaces[interfaceID];
}
function _registerInterface(bytes4 interfaceId) internal{
require(interfaceId != 0xfffffff, 'Invalid interface request');
_supportedInterfaces[interfaceId] = true;
}
}
Here is the code for ERC721
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import '/.ERC165.sol';
import '/.IERC721.sol';
/*
Building out the minting function
a. nft to point an address
b. keep track of the token ids
c. keep track of token owner addresses to token ids
d. keep track of how many tokens an owner address has
e. create an event that emits a transfer log-
contact address, where it is being minted to, the id
*/
contract ERC721 is ERC165, IERC721 {
// mapping solidity creates a hash table of key
// pair values
// Mapping from token id to the owner
mapping(uint => address) private _tokenOwner;
// Mapping from owner to number of owned tokens
mapping(address => uint) private _OwnedTokensCount;
// Mapping from token id to approved addresses
mapping(uint256 => address) private _tokenApprovals;
/// #notice Count all NFTs assigned to an owner
/// #dev NFTs assigned to zero address are considered invalid
/// function throws for queries about the zero address.
/// #param _owner An address for whom to query the balance
/// #return The number of NFTs owned by '_owner', possibly zero
function balanceOf(address _owner) public override view returns(uint256) {
require(_owner != address(0), 'owner query for nonexistent token');
return _OwnedTokensCount[_owner];
}
/// #notice Find the owner of an NFT
/// #dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// #param _tokenId The identifier for an NFT
/// #return The address of the owner of the NFT
function ownerOf(uint256 _tokenId) public view override returns (address) {
address owner = _tokenOwner[_tokenId];
require(owner != address(0), 'owner query for nonexistent token');
return owner;
}
function _exists(uint256 tokenId) internal view returns (bool){
// setting the address of nft owner to check the mapping
// of the addres from the token owner at the tokenId
address owner = _tokenOwner[tokenId];
// return truthiness that address in not zero
return owner != address (0);
}
function _mint(address to, uint256 tokenId) internal virtual {
// requires the address isn't zero
require(to != address(0), 'ERC721: minting to the zero address');
// requires that he token does not already exist
require(!_exists(tokenId), 'ERC721: token already minted');
// we are adding a new address with a token id for minting
_tokenOwner[tokenId] = to;
// keeping track of each address that is minting and adding one to the count
_OwnedTokensCount[to] += 1;
emit Transfer(address (0), to, tokenId);
}
// #notice Transfer owner ship of an NFT -- THE REAL CALLER IS RESPOSIBLE
// TO CONFIRM THAT '_to' IS CAPABLE OF RECEIVING NFTS OR ELSE
// THEY MAY BE PERMANENTLY LOST
// #dev Throws untess 'msg.sender' is the current owner, an authorized
// operator, or the approved address for this NFT. Throws if '_from' is
// not current owner, Throws if '_to' is the zero address. Throws if
// '_tokenId' is not a valid NFT.
// #param _from The current owner of the NFT
// #param _to the new owner
// #param _tokenId The NFT to transfer
function _transferFrom(address _from, address _to, uint256 _tokenId) internal {
require(_to != address(0), 'Error - ERC721 Tr.ansfer to the zero address');
require(ownerOf(_tokenId) == _from, 'Trying to transfer a token address does not own');
_OwnedTokensCount[_from] -= 1;
_OwnedTokensCount[_to] += 1;
_tokenOwner[_tokenId] = _to;
emit Transfer(_from, _to, _tokenId);
}
function transferFrom(address _from, address _to, uint256 _tokenId) override public {
_transferFrom(_from, _to, _tokenId);
}
}

Typo error in the import of interfaces..
import './ERC165.sol';
import './IERC721.sol';
instead of
import '/.ERC165.sol';
import '/.IERC721.sol';

Related

when trying to withdraw BUSD from a smart contract am gettting Gas Estimate Error - JSON-RPC : 32000

i would like to send BUSD to a smart contract and then only owner can withdraw these BUSD from this smart contract. can someone help me to program the same?
i tried below but doesn't think it will work.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../IERC20.sol";
contract TestBUSD {
IERC20 tokenContract;
address private owner;
uint bal;
constructor() payable {
tokenContract = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56);
owner = msg.sender;
}
receive() external payable {}
modifier OnlyOwner() {
require(msg.sender == owner);
_;
}
function Approvetokens(uint256 _tokenamount) public returns(bool){
tokenContract.approve(address(this), _tokenamount);
return true;
}
function GetUserTokenBalance() public view returns(uint256){
return tokenContract.balanceOf(msg.sender);
}
function deposit(uint256 _tokenamount) payable public {
tokenContract.transferFrom(msg.sender, address(this), _tokenamount);
bal += msg.value;
}
function getOwner() public view returns (address) {
return owner;
}
function withdrawToken(address _tokenContract, uint256 _amount) payable external {
require(msg.sender == owner, "Only owner can withdraw!");
IERC20(_tokenContract);
tokenContract.transfer(msg.sender, _amount);
}
}
The tokenContract address does not hold any smart contract on the BSC testnet (there is the BUSD token on the same address on the mainnet).
Your withdrawToken() function sends an internal transaction to the tokenContract address, trying to execute its function transfer(), and expects to be returned a bool (as declared in the IERC20 interface) from this internal transaction. However, since there's no contract on this address, no response is generated - the internal transaction fails, which makes the main transaction fail as well.
If you want to test your contract specifically on the BSC testnet, you need to use a token address that has an ERC20 token deployed. As far as I'm aware, there's currently no official BUSD release on the testnet, so you might have to use another token or your own dummy token instead.
Or if you want to just test the contract interacting with BSUD on a non-mainnet network, I'd recommend you to fork the mainnet in your local emulator.

How to storage and get token when custom ClientDetailsService?

This is my code.
The clientService implements ClientDetailsService , but not found the token storage.
How to storage and get token when custom(e.g. database) ClientDetailsService?
When we have a custom implementation of ClientDetailsService, we essentially override its loadClientByClientId(..) method. This method takes clientId in parameter i.e. the username of the client. In that custom implementation class, all we need to do is check if the given client name exists in database or not. If it does exist, then load all its data and return the object. This class needs be injected with DAO or Repository's dependency to talk to database.
#Override
public ClientDetails loadClientByClientId(final String clientId) throws ClientRegistrationException {
Objects.requireNonNull(clientId, "Client ID must not be null");
final com.ex.auth.domain.ClientDetails clientDetails = clientDetailsRepository.findOne(clientId);
if (clientDetails == null) {
throw new NoSuchClientException(String.format("Client %s does not exist.", clientId));
}
return convertToDmo(clientDetails);
}

Know specified fields on serverside in GraphQL / Sangria-Graphql

When a client sends a request, I want to know what are the fields client has requested for data. For example,
{
user {
name
address
}
}
In the above request, client has requested name field and address field of the user. how do I know/get these specified fields i.e. name and address in the sangria-graphql Server while executing the query?
you have to use 4th parameter in resolve()
resolve: (obj, args, auth, fieldASTs) => {
/* all your fields are present in selections
please check the fieldASTs JSON path it may vary if you are using relay
connections */
const requiredFields = fieldASTs.fieldNodes[0].selectionSet.selections.map(
(set) => set.name.value
);
// requiredFields will contain the name and address
}
/* fieldASTs contains fieldNames, fieldNodes and every details about your Schema
you can get your specified fields inside fieldNodes like */

How to authenticate and redirect a user to his 'own' page in Jersey REST service

How to authenticate and redirect a user to his own page i.e to www.mysite.com/"user's email".
I am using the following algo which is not working...
userDB in User class:
Map<String,String> userdata=new HashMap<String,String>();
First my login process form :
#Path("/login")
#POST
#Produces(MediaType.TEXT_HTML)
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void login(
#FormParam("email") String emailc,
#FormParam("password") String pass,
#Context HttpServletResponse servletResponse
) throws IOException,RuntimeException {
User u1=new User();
pass=u1.getPassword();
emailc=u1.getEmailaddrs();
boolean checked=false;
boolean exists;
exists=u1.userdata.containsKey(emailc);
if(exists){
String mypass =u1.userdata.get(emailc);
if(mypass==pass){
checked=true;
}else{
checked=false;
}
}else{
checked=false;
}
if(!checked){
//User Doesn't exists
servletResponse.sendRedirect("http://localhost:8080/MySite/pages/Create_Profile.html");
}else{
servletResponse.sendRedirect("http://localhost:8080/MySite/{email}"); <<<< How to redirect using #FormParam("email")
}
}
createprofile
#POST
#Produces(MediaType.TEXT_HTML)
#Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public void newUser(
#FormParam("email") String email,
#FormParam("password") String password,
#Context HttpServletResponse servletResponse
) throws IOException {
User u = new User(email,password);
User.userdata.put(email,password);
}
Your usage of userdata [Map] looks wrong to me. Is it a part of user class, is it non static or static ?
If it is non static then every time you will do new User() .. that map will be initialized and it will have no data in it. Hence u1.userdata.containsKey(emailc); will be always false.
If you are using a hashmap as a temporary database for dev purposes then, make it static rather keep it in a different class like UserStore or some DB access layer. Exmaple below:
public class UserDAO(){
private static Map<String,User> userdata = new HashMap<String,User>();
public boolean hasUser(String email){
return userdata.contains(email);
}
public User saveUser(String email, String password ...){
//make user object save it in map and return the same
}
// more methods for delete and edit etc.
}
And use this in your REST layer classes like this
exists = userDao.hasUser(email);
Advantages :
Your problem will be solved.
Later on when you move to actual db implementation you will just have to change your UserDao code and rest application code will be just fine. -- Loose coupling :)
Also regarding forward using email
servletResponse.sendRedirect("http://localhost:8080/MySite/{email}"); <<<< How to redirect using #FormParam("email")
add the email parameter there in the url only, if thats what you want:
servletResponse.sendRedirect("http://localhost:8080/MySite/"+emailc);
UPDATE :
See the fundamental thing is that you get request parameters [email , password]. You check it whether it is present in map or not. Now what you are doing wrong here is you create a new user like this User u = new User(); and then get email and password from it emailc = u.getEmail();. This emailc will always be null and your userdata map will always return false for that. You have two choices :
Either set email and password in user object and then get the data from user object.
Use the email and password obtained from request parameters for your logic. Do not alter them
One good practice to follow while programming is that at all times think of your method parameters as final parameters.
UPDATE 2 :
if(mypass==pass){
checked=true;
}else{
checked=false;
}
Change == to equals method. String matching should be done by equals or equalsIgnoreCase method not ==.
You always create a new User without any parameters: User u1=new User();. All these User instances will have the same property values and probably exists is always false.

How to trigger change detection / validation in Entity Framework with POCO classes

We are using the Entity Framework 4.3.1 with POCO classes (no proxies).
Our User class stores an email address which should be not be used by any other user.
The following test is used to check the validation of this:
[TestMethod]
public void UserEmailNotUniqueTest()
{
// arrange
// - create user one and store in db
User userOne = TIF.GetUser(model, true);
// - create user two and store in db
User userTwo = TIF.GetUserTwo(model, true);
// act
// - change user one email to user two email
userOne.EmailAddress = userTwo.EmailAddress;
// - save
model.SaveChanges();
The test initialize creates an empty database and hooks it up to the “model” DbContext decendant. The TIF class creates the test instances of users and stores them in database. This works, both users are present in the database.
This validation requires the state of the database to be unchanged, so we have an overridden SaveChanges method so we can pass in serializable transaction:
public virtual int SaveChanges(bool commitWhenDone)
{
try
{
saving = true;
int result;
TransactionScope scope;
using (scope = new TransactionScope( modelTransaction.Get() ))
{
//… open connection etc.
ChangeTracker.DetectChanges();
IEnumerable<DbEntityValidationResult> validationResults =
GetValidationErrors();
//… handle the errors
result = base.SaveChanges();
The test fails as not any change is detected. No validation code is executed. Inspecting model.Entity(userOne).State returns “Unchanged”, and yet the CurrentValues contains the proper value i.e. the userOne has the email address of userTwo.
What are we missing?