0

I am very new to solidity programming, I have issue while running one solidity smart contract.

 pragma solidity >= 0.4 .22 < 0.6 .0;

 contract DocumentManager {

 mapping(uint => Document) documents;
 uint public nbDocuments;
 address public owner;

 enum Status {
    UNKNOWN,
    OPEN,
    DONE,
    DENIED
 }

struct Document {
    address owner;
    string document;
    string name;
    uint nbRequests;
    string privateKey;
    mapping(uint => Request) requests;
}

struct Request {
    address owner;
    Status status;
    string key;
}

constructor() public {
    owner = msg.sender;
}

function newDocument(string memory hash, string memory name) public {
    nbDocuments++;
    documents[nbDocuments].owner = msg.sender;
    documents[nbDocuments].document = hash;
    documents[nbDocuments].name = name;
    documents[nbDocuments].nbRequests = 0;
}

  function grantAccess(uint documentId, uint requestId, string memory 
   encryptedKey) public {
    uint256 document = documents[documentId];
    if (document.owner == msg.sender) {
        document.requests[requestId].status = Status.DONE;
        document.requests[requestId].key = encryptedKey;
     }
  }

 function denyAccess(uint documentId, uint requestId) public {
    uint256 document = documents[documentId];
    if (document.owner == msg.sender) {
        document.requests[requestId].status = Status.DENIED;
    }
 }

   function requestDocument(uint documentId, string memory publicKey) 
    public {
    uint256 document = documents[documentId];
    document.nbRequests++;
    uint256 request = document.requests[document.nbRequests];
    request.status = Status.OPEN;
    request.owner = msg.sender;
    request.key = publicKey;
  }

  function getLastRequestId(uint documentId) public returns(uint) {
    return documents[documentId].nbRequests;
   }

  function getOpenRequestPublicKey(uint documentId, uint requestId) 
   public returns(string memory) {
    uint256 request = documents[documentId].requests[requestId];
    if (request.status == Status.OPEN) {
        return request.key;
    }
    return "";
  }

function getRequestOwner(uint documentId, uint requestId) public 
  returns(address) {
    uint256 document = documents[documentId];
    if (document.owner == msg.sender) {
        return document.requests[requestId].owner;
    }
 }

function getDocument(uint documentId) public returns(string memory 
  hash) {
    return documents[documentId].document;
}

function getDocumentName(uint documentId) public returns(string memory 
 name) {
    return documents[documentId].name;
}

function getEncryptedKeyFromRequest(uint documentId, uint requestId) 
 public returns(string memory) {
    uint256 request = documents[documentId].requests[requestId];
    if (request.status == Status.DONE) {
        return request.key;
    }
    return "";
}

function getDocumentHash(uint documentId) public returns(string 
 memory) {
    return documents[documentId].document;
}

function getRequestStatus(uint documentId, uint requestId) public 
 returns(Status) {
    return documents[documentId].requests[requestId].status;
 }

}

When I am getting issue like below issue

   on line number 39-40 
     browser/ballot.sol:39:9: TypeError: Type struct 
  DocumentManager.Document storage ref is not implicitly convertible 
   to expected type uint256.
    uint256 document = documents[documentId];
    ^--------------------------------------^

  browser/ballot.sol:40:12: TypeError: Member "owner" not found or not 
  visible after argument-dependent lookup in uint256.
    if(document.owner == msg.sender) {
       ^------------^

When I tried old version of solidity it is running fine(pragma 4.22 version).

Thanks in advance

1

Change every occurrence of this:

uint256 document

To this:

Document document

And every occurrence of this:

uint256 request

To this:

Request request
  • As a side note, I would say that I cannot see how your code could possibly compile successfully in an "old version of solidity". – goodvibration Mar 23 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.