Running out of gas error when trying to deploy my solidity smart contract

Hi, I have asked on gitHub and I obtained a reply that suggested asking for help here.
I have the following contract and I am not being able to deploy it on the network (I have tried it on ganache and on my private network). Also, I would like to know if on my migrations file (I am working with truffle) I should specify something about the library I have defined on the same file than the contract, or it is getting deployed anyway?

My migrations file is (apart from the 1_initial_migrations.js that comes by default with truffle)

    var CrudAEOStructures= artifacts.require("./CrudAEOStructures.sol");
    var CrudAEOCreateAndRead= artifacts.require("./CrudAEOCreateAndRead.sol");
    var CrudAEOUpdateAndDelete = artifacts.require("./CrudAEOUpdateAndDelete.sol");

    module.exports = function(deployer){
    /*
      deployer.deploy(CrudAEOStructures, { from: "0x1caFCe8fF232515Dcb07eE7901D49cFF8397eF7c", overwrite: false })
        .then(() => {
          return deployer.deploy(CrudAEOCreateAndRead, CrudAEOStructures.address, { from: "0x1caFCe8fF232515Dcb07eE7901D49cFF8397eF7c" })
        });
    */

     deployer.deploy(CrudAEOStructures);

    };

And my contract file is:

pragma solidity ^0.4.23;

pragma experimental ABIEncoderV2;

 
 library StructuresAndVariables{

   struct MasterDataRecipient{
    string recipientType; /* identify the type of regulatory office that
                receives the Master Data*/
    string recipient;
  }

  struct MasterDataSender{
    string senderType; /* identify the type of regulatory office that
                sends the Master Data*/
    string sender;
  }

  struct MasterDataParty{
    string partyName;
    string partyShortName;
    string businessType;
    uint256 partyId;
    string identificationIssuingCountry; //ISO alpha code 2 digits
    string roleCode;
  }

  struct AEOMasterData{
    uint256 messageFunctionCode;
    string functionalReferenceNumber; /*Reference number identifying a
                      specific information exchange*/
    string documentName;
   MasterDataRecipient masterDataRec;
   MasterDataSender masterDataSen;
    string endDate;

  }

  struct MasterDataPartyAddress{
    string typeOfAddress;
    string cityName;
    string countryCode; // ISO alpha code 2 digit
    string countryName;
    string countrySubEntityIdentification;
    string street;
    uint256 number;
    string postCodeId;
  }

  struct MasterDataPartyContactCommunication{
    string communicationNumber;
    string communicationNumberType;
  }
 struct MasterDataPartyContact{
    string contactName;
    string contactFunctionCode;
  }

  struct MasterDataPartyCommunication{
    string partyCommunicationNumber;
    string partyCommunicationNumberType;
  }

  struct MasterDataPartyAdditionalIdentifier{
    uint256 sequenceNumber;
    string additionalIdentificationCode;
    string additionalIdentificationIssuingCountry; //ISO alpha code 2 digits
  }

  struct MasterDataPartyAdditionalDocument{
    string documentCategoryCode;
    string documentEffectiveDate;
    string documentExpirationDate;
    string additionalDocumentReferenceNumber; //esto?
    string documentMessageStatus;
    string additionalDocumentType;
    string manufacturingLocation;
  }

 }


contract CrudAEOStructures {
 
   //mapping to save index associated to each functionalRefNumber
   mapping (string=>uint256)  masterDataAEOs;
   //mapping functionalReferenceNumber->MasterDataParty
   mapping (string => StructuresAndVariables.MasterDataParty[])  masterDataPartiesAEO;
   mapping (string => bool)  masterDataPartiesExists;
   //mapping idAEO->Address
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAddress[])  addressesAEO;
   mapping (uint256 => bool)  addressExists;
   //mapping idAEO->MasterDataPartyContact
   mapping (uint256 => StructuresAndVariables.MasterDataPartyContact[])  partiesContAEO;
   mapping (uint256 => bool)  partiesContExists;
   //mapping contactName->MasterDataPartyContactComm
   mapping (string => StructuresAndVariables.MasterDataPartyContactCommunication[])  partiesContCommAEO;
   mapping (string => bool)  partiesContCommExists;
    //mapping idAEO->MasterDataPartyCommunication
   mapping (uint256 => StructuresAndVariables.MasterDataPartyCommunication[])  partiesCommAEO;
   mapping (uint256 => bool)  partiesCommExists;
   //mapping idAEO->AdditionalIdentifier
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAdditionalIdentifier[])  additionalIdentifiersAEO;
   mapping (uint256 => bool)  additionalIdentifiersExists;
   //mapping idAEO->AdditionalDocument
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAdditionalDocument[])  additionalDocumentsAEO;
   mapping (uint256 => bool)  additionalDocumentExists;
   
    StructuresAndVariables.AEOMasterData[] public AEOs;

   uint256 public totalAEOs;

   constructor() public {
       totalAEOs = 0;
   }

  
   event AEOExpDateUpdate(string AEOpartyName, string AEONewExpDate);

   event AEODelete(string AEOfunctionalReferenceNumber);

   
  function compareStrings (string a, string b) internal pure returns (bool){
       return keccak256(a) == keccak256(b);
  }   
   
   function getTotalAEOs() public view returns (uint256 length){
      return AEOs.length;
  }

  function retrieveFRN (uint256 i) public view returns (string fnr){

    return AEOs[i].functionalReferenceNumber; 
  }

  function retrievePartyName(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string name){
    return mdpArray[i].partyName; 
  }

  function retrievePartyShortName(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].partyShortName; 
  }

  function retrieveBusinessType(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].businessType; 
  }

  function retrieveIssuingCountry(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].identificationIssuingCountry;
  }

  function retrieveStreetAddress(StructuresAndVariables.MasterDataPartyAddress[] mdpaArray, uint256 i)public view returns(string street){
    return mdpaArray[i].street;
  }

  function retrieveNumberAddress(StructuresAndVariables.MasterDataPartyAddress[] mdpaArray, uint256 i)public view returns(uint256 number){
    return mdpaArray[i].number;
  }

  function retrieveContactName(StructuresAndVariables.MasterDataPartyContact[] mdpcArray, uint256 i)public view returns(string contactName){
    return mdpcArray[i].contactName;
  }

  function retrieveCommNumber(StructuresAndVariables.MasterDataPartyContactCommunication[] mdpccommArray, uint256 i)public view returns(string commNum){
    return mdpccommArray[i].communicationNumber;
  }

  function retrievePartyCommNumber(StructuresAndVariables.MasterDataPartyCommunication[] mdpcommArray, uint256 i)public view returns(string partyCommNum){
    return mdpcommArray[i].partyCommunicationNumber;
  }

  function retrieveSequenceNumber(StructuresAndVariables.MasterDataPartyAdditionalIdentifier[] mdpaiArray, uint256 i)public view returns(uint256 seqNum){
    return mdpaiArray[i].sequenceNumber;
  }

  function retrieveADocRefNum(StructuresAndVariables.MasterDataPartyAdditionalDocument[] mdpadArray, uint256 i)public view returns(string addDocRefNum){
    return mdpadArray[i].additionalDocumentReferenceNumber;
  }

  function retrieveIndexAEO (string fnr) public returns (uint256 index) {
    return masterDataAEOs[fnr];
  }

  function retrieveEnDate (uint256 id) public returns (string date) {
    return AEOs[id].endDate;
  }


  function increaseTotalAEOs ()public{
    totalAEOs= totalAEOs++;

  }

  function insertNewAEO (StructuresAndVariables.AEOMasterData newAEOToInsert) public{
    AEOs.push(newAEOToInsert); 
  }

  function masterDataAEOsmapping (string fnr, uint256 i) public{
     masterDataAEOs[fnr]=i; 
  }

  function masterDataPartiesAEOmapping (string fnr, StructuresAndVariables.MasterDataParty mdp) public{
     masterDataPartiesAEO[fnr].push(mdp); 
  }

   function addressesAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAddress mdpa) public{
     addressesAEO[id].push(mdpa); 
  }

   function partiesContAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyContact mdpc) public{
     partiesContAEO[id].push(mdpc); 
  }

   function partiesContCommAEOmapping (string fnr, StructuresAndVariables.MasterDataPartyContactCommunication mdpcc) public{
     partiesContCommAEO[fnr].push(mdpcc); 
  }

   function partiesCommAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyCommunication mdpcom) public{
     partiesCommAEO[id].push(mdpcom); 
  }

   function additionalIdentifiersAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAdditionalIdentifier mdpai) public{
     additionalIdentifiersAEO[id].push(mdpai); 
  }

   function additionalDocumentsAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAdditionalDocument mdpad) public{
     additionalDocumentsAEO[id].push(mdpad); 
  }

  function setExistanceForCertainId(uint256 idArray, uint256 id) public{

    if(idArray==1){
       addressExists[id]=true;
    }
    if(idArray==2){
      partiesContExists[id]=true;
    }
    if(idArray==3){
     partiesCommExists[id]=true;
    }
    if(idArray==4){
     additionalIdentifiersExists[id]=true;
    }
    if(idArray==5){
     additionalDocumentExists[id]=true;
    }
   }

   function setExistance(uint256 id, string fnr) public{

    if(id==1){
       masterDataPartiesExists[fnr]=true; 
    }
    if(id==2){
      partiesContCommExists[fnr]=true;
    }
    
   }

   function checkExistance(uint256 idArray, string key, uint256 keyInt)public view returns(bool answer){
   
    if(idArray==1){
     return masterDataPartiesExists[key];
    }
    if(idArray==2){
     return addressExists[keyInt];
    }
    if(idArray==3){
     return partiesContExists[keyInt];
    }
    if(idArray==4){
     return partiesContCommExists[key];
    }
    if(idArray==5){
     return partiesCommExists[keyInt];
    }
    if(idArray==6){
     return additionalIdentifiersExists[keyInt];
    }
    if(idArray==7){
     return additionalDocumentExists[keyInt];
    }    

   }

   function getLenght (uint256 id, string key, uint256 keyInt) public returns (uint256 arrayLenght){
    if(id==1){
     return masterDataPartiesAEO[key].length;
    }
    if(id==2){
     return addressesAEO[keyInt].length;
    }
    if(id==3){
     return partiesContAEO[keyInt].length;
    }
    if(id==4){
     return partiesContCommAEO[key].length;
    }
    if(id==5){
     return partiesCommAEO[keyInt].length;
    }
    if(id==6){
     return additionalIdentifiersAEO[keyInt].length;
    }
    if(id==7){
     return additionalDocumentsAEO[keyInt].length;
  }

}

  function retrieveMasterDataPartyArray (string key) public returns (StructuresAndVariables.MasterDataParty[] ){
    return masterDataPartiesAEO[key];
  }

  function retrieveAddressesArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAddress[]){
    return addressesAEO[key];
  }

  function retrievePartyContArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyContact[]){
    return partiesContAEO[key];
  }

  function retrieveMasterDataPartyContCommArray (string key) public returns(StructuresAndVariables.MasterDataPartyContactCommunication[]){
    return partiesContCommAEO[key];
  }

  function retrieveMasterDataPartyCommArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyCommunication[]){
    return partiesCommAEO[key];
  }

  function retrieveMasterDataPartyAdIdArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAdditionalIdentifier[]){
    return additionalIdentifiersAEO[key];
  }

  function retrieveMasterDataPartyAdDocArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAdditionalDocument[]){
    return additionalDocumentsAEO[key];
  }


    //retrieve functons give me error 
   function checkMasterDataPartyExistance (string fnr, string partyNameAEO) public returns (bool exists){

       exists=false;
       uint256 masterDataPartyLength = getLenght(1,fnr,0);
       StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= retrieveMasterDataPartyArray(fnr);

      for(uint256 i =0; i< masterDataPartyLength; i++){
        //aca posible cambio para retrieve name 
        if(compareStrings(retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
            exists=true;
           // return false;
          }
       }
       return exists;   
   }

   function checkAddressExistance(uint256 partyIdAEO,string streetAEO, uint256 numberAEO ) public returns (bool exists){
        exists=false;
       uint256 addressLength = getLenght(2,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAddress[] memory temporaryMasterDataPartyAddressArray= retrieveAddressesArray(partyIdAEO);

      for(uint256 i =0; i< addressLength; i++){
        
        if(compareStrings(retrieveStreetAddress(temporaryMasterDataPartyAddressArray,i),streetAEO) && (retrieveNumberAddress(temporaryMasterDataPartyAddressArray,i)==numberAEO)) {
            exists=true;
            
          }
       }
       return exists; 
   }

   function checkContactExistance(uint256 partyIdAEO, string contactNameAEO) public returns (bool exists){
       exists=false;
       uint256 partiesContLength = getLenght(3,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyContact[] memory temporaryMasterDataPartyContactArray= retrievePartyContArray(partyIdAEO);

      for(uint256 i =0; i< partiesContLength; i++){
        if(compareStrings( retrieveContactName(temporaryMasterDataPartyContactArray,i), contactNameAEO)){
            exists=true;
            return false;
          }
   }
   return exists;
  }

  function checkContCommExistance(string contactNameAEO, string communicationContNumberAEO) public returns (bool exists){
       exists=false;
       uint256 partiesContCommLength = getLenght(4,contactNameAEO,0);
       StructuresAndVariables.MasterDataPartyContactCommunication[] memory temporaryMasterDataPartyContactCommArray= retrieveMasterDataPartyContCommArray(contactNameAEO);

      for(uint256 i =0; i< partiesContCommLength; i++){
        if(compareStrings(retrieveCommNumber(temporaryMasterDataPartyContactCommArray,i), communicationContNumberAEO)){
            exists=true;
            return false;
          }
       }
       return exists;
  }

  function checkCommExistance(uint256 partyIdAEO,string communicationNumberAEO) public returns (bool exists){
       exists=false;
       uint256 partiesCommLength = getLenght(5,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyCommunication[] memory temporaryMasterDataPartyCommArray= retrieveMasterDataPartyCommArray(partyIdAEO);

      for(uint256 i =0; i< partiesCommLength; i++){
        if(compareStrings(retrievePartyCommNumber(temporaryMasterDataPartyCommArray,i),communicationNumberAEO)){
            exists=true;
          }
  }
  return exists;
}

function checkAddIdExistance(uint256 partyIdAEO,uint256 sequenceNumberAEO) public returns (bool exists){
       exists=false;
       uint256 additionalIdLength = getLenght(6,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalIdentifier[] memory temporaryMasterDataPartyAdditionalIdentifierArray= retrieveMasterDataPartyAdIdArray(partyIdAEO);

      for(uint256 i =0; i< additionalIdLength; i++){
        if(retrieveSequenceNumber(temporaryMasterDataPartyAdditionalIdentifierArray,i)== sequenceNumberAEO){
            exists=true;
            return false;
         }
    }
return exists;
}

function checkAddDocExistance(uint256 partyIdAEO,string additionalDocumentReferenceNumberAEO) public returns (bool exists){
       exists=false;
       uint256 additionalDocLength = getLenght(7,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalDocument[] memory temporaryMasterDataPartyAdditionalDocumentArray= retrieveMasterDataPartyAdDocArray(partyIdAEO);

      for(uint256 i =0; i< additionalDocLength; i++){
        if(compareStrings(retrieveADocRefNum(temporaryMasterDataPartyAdditionalDocumentArray,i), additionalDocumentReferenceNumberAEO)){
            exists=true;
            return false;
          }
       }
return exists;
}

function neededForReadOp(string functionalReferenceNumberAEO, string partyNameAEO) 
                        public view returns(string endDateAEO, string memory recipientAEO,
                                    string memory partyShortNameAEO, string memory businessTypeAEO, string memory identificationIssuingCountryAEO){
  uint256 indexAEO= retrieveIndexAEO(functionalReferenceNumberAEO);
  StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= retrieveMasterDataPartyArray(functionalReferenceNumberAEO);
  endDateAEO= retrieveEnDate(indexAEO);
  recipientAEO="Custom";
      //recipientAEO= AEOs[indexAEO].masterDataRec.recipient;
      for(uint256 i =0; i< temporaryMasterDataPartyArray.length; i++){
        if(compareStrings(retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
           partyShortNameAEO=retrievePartyName(temporaryMasterDataPartyArray,i);
           businessTypeAEO=retrieveBusinessType(temporaryMasterDataPartyArray,i);
           identificationIssuingCountryAEO=retrieveIssuingCountry(temporaryMasterDataPartyArray,i);
       
          return (endDateAEO,recipientAEO,partyShortNameAEO,businessTypeAEO,identificationIssuingCountryAEO);

        }
      }
}

  

 }
1 Like

Can not deploy? Is there any errors message?

2 Likes

Hi @romis

Welcome to the forum.

When I attempted to deploy to ganache-cli as is, I received "CrudAEOStructures" ran out of gas. Simply, the contract’s gas requirement is larger than the block gas limit, which (the default) for ganache-cli is 6,721,975.

Compiling in Remix shows the following Gas estimates for your code.

StructuresAndVariables library:

	"Creation": {
		"codeDepositCost": "18000",
		"executionCost": "119",
		"totalCost": "18119"
	}

CrudAEOStructures contract

    "Creation": {
        "codeDepositCost": "5051400",
        "executionCost": "11023",
        "totalCost": "5062423"
    },

In truffle I turned on the optimizer with 200 runs which then allowed me to deploy your contract and library to ganache-cli.

truffle-config.js

  compilers: {
    solc: {
       version: "0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: true,
         runs: 200
       },
       evmVersion: "byzantium"
      }
    }
  }

I would look to see how you could break up your contract and separate out the library.

I suggest reading the OpenZeppelin Guidelines and think about how you might be able to simplify your contracts.

I would also look at the version of compiler you are using, as 0.4.23 was released in April 2018. There was a recent discussion in the forum on What compiler version to use?

Note: I used markdown to improve the display of your code in the forum.

3 Likes

Hi @abcoathup , thank you a lot for your help! :raised_hands:

You are suggesting me to break up my contract and separate the library or you were saying that you were going to give a look on how could that be done?
In the case I separate the library into another file, I would need to import the library into my contract file, wouldn’t I? Would that represent a significant reduction on the gas cost?

I tried turning on the optimizer with less runs but I am not being able to deploy anyway, what can be happening? This is the configuration I have:

truffle-config.js

 networks: {

development: {
        host: "192.168.26.9",     // Localhost (default: none)
        port: 22000,            // Standard Ethereum port (default: none)
        network_id: "73053",       // Any network (default: none)
        gasPrice: 0,
        gas:450000000,
        type: "quorum",
    //    from: '0x0252e5482545d09469b50794ae99889bed0079cc',
    //    websockets: true

    },
  compilers: {
solc: {
 version: "^0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)
  // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
   settings: {          // See the solidity docs for advice about optimization and evmVersion
   optimizer: {
     enabled: true,
     runs: 200
   },
  //  evmVersion: "byzantium"
   }
}
  }
}

I am going to read the guidelines you posted before trying to separate my contract, maybe there is a way to avoid keeping breaking up my contract.

@abcoathup I have moved the library to another file and now I am being able to deploy :open_hands: . I am using truffle console to test my contract functions and I am not being able to execute them, the transaction results in false but I don’t know how to find the reason. Can it be something related to how I define the contract instance? Maybe I am not accessing the functions correctly or maybe something related to the library that I linked. How can I discover the reason?

Also, I would like to know if you could give me a hand with using truffle-contract. I need to consume the smart contract functions from a third party and I believe that the approach would be using truffle-contract, but I think I should set up an express.js server or something like that, shouldn’t I? Or do you know any other approach?

Thank you!

1 Like

Hi @romis

Separating the library into another file just reduces the gas required for deploying the contract as the library is deployed separately, but doesn’t reduce the overall gas used in the deploy transactions.

When deploying a library and then a contract that uses the library, you need to link them. See the Truffle documentation on deployer.link

I can deploy the contract with the library in the same file to ganache-cli with the following config in the truffle-config.js

  networks: {
    development: {
     host: "127.0.0.1",     // Localhost (default: none)
     port: 8545,            // Standard Ethereum port (default: none)
     network_id: "*",       // Any network (default: none)
    },
  },

  // Configure your compilers
  compilers: {
    solc: {
       version: "0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)
      // docker: true,        // Use "0.5.1" you've installed locally with docker (default: false)
      settings: {          // See the solidity docs for advice about optimization and evmVersion
       optimizer: {
         enabled: true,
         runs: 200
       },
       evmVersion: "byzantium"
      }
    }
  }

It would be great if you could tell us What are you working on? This would give some context for your contract. Also interested what network you are looking to deploy on (mainnet or a private network), especially given some of the information you want to include e.g. postal addresses.

Regards truffle console I was able to do the following using the version of the contract including the library (with the optimizer). I would start there to check you can access the contract:

truffle(development)> crud = await CrudAEOStructures.deployed()
truffle(development)> (await crud.totalAEOs()).toString()
'0'

If you don’t have already, suggest you create tests for your smart contract functions. See the Truffle documentation on writing tests in JavaScript
You can look at the OpenZeppelin tests for how these are done. e.g. SimpleToken.test.js

Regards a front end it depends what front end technologies you already know (e.g. React). We had a discussion recently about web3 front end libraries.
For just interacting with a contract from a desktop you could use Remix, uDapp or OneClickDapp

1 Like

Hi @abcoathup, thanks again.

First of all,

is working fine on truffle console and I have separated the library to another file. The problem I have is with trying to execute the methods of a contract which intends to use an instance of this CrudAEOStructures.sol contract and the StructuresAndVariables.sol library. Maybe I am defining in a wrong way the contract instance on my contract constructor? Maybe you have some time to have a look at this third contract and recognize the mistake rapidly.

I am working on a POC which intends to show the advantages of using blockchain technology. I want to deploy contracts which all together acts as a CRUD contract. What made me split theCRUD contract into 4 files was that I was exceeding gas limits. Thats why I ended up with one contract to manage Create and Read operations, another one to manage Update and Delete operations, one to define and storage all the mappings/arrays/etc which are going to be modified and accessed through the other contracts.

I am deploying on a Quorum network, created with Quorum Maker.

1 Like

If you share the contract and the migrations script to deploy it I am happy to have a look.

The reason why I asked which network, is that this could influence what data you may or may not want to store in your smart contracts, for privacy/security and cost. Things like addresses I wouldn’t put on a public network and I would only store the minimum data required onchain. For a private network this may be less of an issue.

Apologies @Skyge, I didn’t mean to cut you off there.

Thanks for your help. It is really appreciated!

2 Likes

@abcoathup Thank you! Yes, sure I can share my code. Everything is on this repository: https://github.com/romisalve/Quorum-POC.git

The CrudAEOUpdateAndDelete.sol has not been changed yet so I was not even trying to deploy it, that is why it does not appears on the migrations file.

If you don’t want to go to the repository, the files are the following. I am working with truffle and on my migrations file there is a “from” specified which represents one of the accounts of my network that in order for you to try it, it should be removed.

MY CONTRACTS:
Migrations.sol:

pragma solidity >=0.4.21 <0.6.0;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

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

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }

  function upgrade(address new_address) public restricted {
    Migrations upgraded = Migrations(new_address);
    upgraded.setCompleted(last_completed_migration);
  }
}

StructuresAndVariables.sol: (the library)

pragma solidity ^0.4.23;

 library StructuresAndVariables{

   struct MasterDataRecipient{
string recipientType; /* identify the type of regulatory office that
            receives the Master Data*/
string recipient;
  }

  struct MasterDataSender{
string senderType; /* identify the type of regulatory office that
            sends the Master Data*/
string sender;
  }

  struct MasterDataParty{
string partyName;
string partyShortName;
string businessType;
uint256 partyId;
string identificationIssuingCountry; //ISO alpha code 2 digits
string roleCode;
  }

  struct AEOMasterData{
uint256 messageFunctionCode;
string functionalReferenceNumber; /*Reference number identifying a
                  specific information exchange*/
string documentName;
   MasterDataRecipient masterDataRec;
   MasterDataSender masterDataSen;
string endDate;

  }

  struct MasterDataPartyAddress{
string typeOfAddress;
string cityName;
string countryCode; // ISO alpha code 2 digit
string countryName;
string countrySubEntityIdentification;
string street;
uint256 number;
string postCodeId;
  }

  struct MasterDataPartyContactCommunication{
string communicationNumber;
string communicationNumberType;
  }
 struct MasterDataPartyContact{
string contactName;
string contactFunctionCode;
  }

  struct MasterDataPartyCommunication{
string partyCommunicationNumber;
string partyCommunicationNumberType;
  }

  struct MasterDataPartyAdditionalIdentifier{
uint256 sequenceNumber;
string additionalIdentificationCode;
string additionalIdentificationIssuingCountry; //ISO alpha code 2 digits
  }

  struct MasterDataPartyAdditionalDocument{
string documentCategoryCode;
string documentEffectiveDate;
string documentExpirationDate;
string additionalDocumentReferenceNumber; //esto?
string documentMessageStatus;
string additionalDocumentType;
string manufacturingLocation;
  }

 }

CrudAEOStructures.sol :

pragma solidity ^0.4.23;

pragma experimental ABIEncoderV2;

/*
 library StructuresAndVariables{

   struct MasterDataRecipient{
    string recipientType; /* identify the type of regulatory office that
                receives the Master Data*/
 /*   string recipient;
  }

  struct MasterDataSender{
    string senderType; /* identify the type of regulatory office that
                sends the Master Data*/
   /* string sender;
  }

  struct MasterDataParty{
    string partyName;
    string partyShortName;
    string businessType;
    uint256 partyId;
    string identificationIssuingCountry; //ISO alpha code 2 digits
    string roleCode;
  }

  struct AEOMasterData{
    uint256 messageFunctionCode;
    string functionalReferenceNumber; /*Reference number identifying a
                      specific information exchange*/
   /* string documentName;
   MasterDataRecipient masterDataRec;
   MasterDataSender masterDataSen;
    string endDate;

  }

  struct MasterDataPartyAddress{
    string typeOfAddress;
    string cityName;
    string countryCode; // ISO alpha code 2 digit
    string countryName;
    string countrySubEntityIdentification;
    string street;
    uint256 number;
    string postCodeId;
  }

  struct MasterDataPartyContactCommunication{
    string communicationNumber;
    string communicationNumberType;
  }
 struct MasterDataPartyContact{
    string contactName;
    string contactFunctionCode;
  }

  struct MasterDataPartyCommunication{
    string partyCommunicationNumber;
    string partyCommunicationNumberType;
  }

  struct MasterDataPartyAdditionalIdentifier{
    uint256 sequenceNumber;
    string additionalIdentificationCode;
    string additionalIdentificationIssuingCountry; //ISO alpha code 2 digits
  }

  struct MasterDataPartyAdditionalDocument{
    string documentCategoryCode;
    string documentEffectiveDate;
    string documentExpirationDate;
    string additionalDocumentReferenceNumber; //esto?
    string documentMessageStatus;
    string additionalDocumentType;
    string manufacturingLocation;
  }

 }

 */ 
import { StructuresAndVariables } from "./StructuresAndVariables.sol" ;


contract CrudAEOStructures {
 
   //mapping to save index associated to each functionalRefNumber
   mapping (string=>uint256)  masterDataAEOs;
   //mapping functionalReferenceNumber->MasterDataParty
   mapping (string => StructuresAndVariables.MasterDataParty[])  masterDataPartiesAEO;
   mapping (string => bool)  masterDataPartiesExists;
   //mapping idAEO->Address
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAddress[])  addressesAEO;
   mapping (uint256 => bool)  addressExists;
   //mapping idAEO->MasterDataPartyContact
   mapping (uint256 => StructuresAndVariables.MasterDataPartyContact[])  partiesContAEO;
   mapping (uint256 => bool)  partiesContExists;
   //mapping contactName->MasterDataPartyContactComm
   mapping (string => StructuresAndVariables.MasterDataPartyContactCommunication[])  partiesContCommAEO;
   mapping (string => bool)  partiesContCommExists;
    //mapping idAEO->MasterDataPartyCommunication
   mapping (uint256 => StructuresAndVariables.MasterDataPartyCommunication[])  partiesCommAEO;
   mapping (uint256 => bool)  partiesCommExists;
   //mapping idAEO->AdditionalIdentifier
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAdditionalIdentifier[])  additionalIdentifiersAEO;
   mapping (uint256 => bool)  additionalIdentifiersExists;
   //mapping idAEO->AdditionalDocument
   mapping (uint256 => StructuresAndVariables.MasterDataPartyAdditionalDocument[])  additionalDocumentsAEO;
   mapping (uint256 => bool)  additionalDocumentExists;
   
    StructuresAndVariables.AEOMasterData[] public AEOs;

   uint256 public totalAEOs;

   constructor() public {
       totalAEOs = 0;
   }

  
   event AEOExpDateUpdate(string AEOpartyName, string AEONewExpDate);

   event AEODelete(string AEOfunctionalReferenceNumber);

   
  function compareStrings (string a, string b) internal pure returns (bool){
       return keccak256(a) == keccak256(b);
  }   
   
   function getTotalAEOs() public view returns (uint256 length){
      return AEOs.length;
  }

  function retrieveFRN (uint256 i) public view returns (string fnr){

    return AEOs[i].functionalReferenceNumber; 
  }

  function retrievePartyName(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string name){
    return mdpArray[i].partyName; 
  }

  function retrievePartyShortName(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].partyShortName; 
  }

  function retrieveBusinessType(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].businessType; 
  }

  function retrieveIssuingCountry(StructuresAndVariables.MasterDataParty[] mdpArray, uint256 i)public view returns(string shortName){
    return mdpArray[i].identificationIssuingCountry;
  }

  function retrieveStreetAddress(StructuresAndVariables.MasterDataPartyAddress[] mdpaArray, uint256 i)public view returns(string street){
    return mdpaArray[i].street;
  }

  function retrieveNumberAddress(StructuresAndVariables.MasterDataPartyAddress[] mdpaArray, uint256 i)public view returns(uint256 number){
    return mdpaArray[i].number;
  }

  function retrieveContactName(StructuresAndVariables.MasterDataPartyContact[] mdpcArray, uint256 i)public view returns(string contactName){
    return mdpcArray[i].contactName;
  }

  function retrieveCommNumber(StructuresAndVariables.MasterDataPartyContactCommunication[] mdpccommArray, uint256 i)public view returns(string commNum){
    return mdpccommArray[i].communicationNumber;
  }

  function retrievePartyCommNumber(StructuresAndVariables.MasterDataPartyCommunication[] mdpcommArray, uint256 i)public view returns(string partyCommNum){
    return mdpcommArray[i].partyCommunicationNumber;
  }

  function retrieveSequenceNumber(StructuresAndVariables.MasterDataPartyAdditionalIdentifier[] mdpaiArray, uint256 i)public view returns(uint256 seqNum){
    return mdpaiArray[i].sequenceNumber;
  }

  function retrieveADocRefNum(StructuresAndVariables.MasterDataPartyAdditionalDocument[] mdpadArray, uint256 i)public view returns(string addDocRefNum){
    return mdpadArray[i].additionalDocumentReferenceNumber;
  }

  function retrieveIndexAEO (string fnr) public returns (uint256 index) {
    return masterDataAEOs[fnr];
  }

  function retrieveEnDate (uint256 id) public returns (string date) {
    return AEOs[id].endDate;
  }


  function increaseTotalAEOs ()public{
    totalAEOs= totalAEOs++;

  }

  function insertNewAEO (StructuresAndVariables.AEOMasterData newAEOToInsert) public{
    AEOs.push(newAEOToInsert); 
  }

  function masterDataAEOsmapping (string fnr, uint256 i) public{
     masterDataAEOs[fnr]=i; 
  }

  function masterDataPartiesAEOmapping (string fnr, StructuresAndVariables.MasterDataParty mdp) public{
     masterDataPartiesAEO[fnr].push(mdp); 
  }

   function addressesAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAddress mdpa) public{
     addressesAEO[id].push(mdpa); 
  }

   function partiesContAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyContact mdpc) public{
     partiesContAEO[id].push(mdpc); 
  }

   function partiesContCommAEOmapping (string fnr, StructuresAndVariables.MasterDataPartyContactCommunication mdpcc) public{
     partiesContCommAEO[fnr].push(mdpcc); 
  }

   function partiesCommAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyCommunication mdpcom) public{
     partiesCommAEO[id].push(mdpcom); 
  }

   function additionalIdentifiersAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAdditionalIdentifier mdpai) public{
     additionalIdentifiersAEO[id].push(mdpai); 
  }

   function additionalDocumentsAEOmapping (uint256 id, StructuresAndVariables.MasterDataPartyAdditionalDocument mdpad) public{
     additionalDocumentsAEO[id].push(mdpad); 
  }

  function setExistanceForCertainId(uint256 idArray, uint256 id) public{

    if(idArray==1){
       addressExists[id]=true;
    }
    if(idArray==2){
      partiesContExists[id]=true;
    }
    if(idArray==3){
     partiesCommExists[id]=true;
    }
    if(idArray==4){
     additionalIdentifiersExists[id]=true;
    }
    if(idArray==5){
     additionalDocumentExists[id]=true;
    }
   }

   function setExistance(uint256 id, string fnr) public{

    if(id==1){
       masterDataPartiesExists[fnr]=true; 
    }
    if(id==2){
      partiesContCommExists[fnr]=true;
    }
    
   }

   function checkExistance(uint256 idArray, string key, uint256 keyInt)public view returns(bool answer){
   
    if(idArray==1){
     return masterDataPartiesExists[key];
    }
    if(idArray==2){
     return addressExists[keyInt];
    }
    if(idArray==3){
     return partiesContExists[keyInt];
    }
    if(idArray==4){
     return partiesContCommExists[key];
    }
    if(idArray==5){
     return partiesCommExists[keyInt];
    }
    if(idArray==6){
     return additionalIdentifiersExists[keyInt];
    }
    if(idArray==7){
     return additionalDocumentExists[keyInt];
    }    

   }

   function getLenght (uint256 id, string key, uint256 keyInt) public returns (uint256 arrayLenght){
    if(id==1){
     return masterDataPartiesAEO[key].length;
    }
    if(id==2){
     return addressesAEO[keyInt].length;
    }
    if(id==3){
     return partiesContAEO[keyInt].length;
    }
    if(id==4){
     return partiesContCommAEO[key].length;
    }
    if(id==5){
     return partiesCommAEO[keyInt].length;
    }
    if(id==6){
     return additionalIdentifiersAEO[keyInt].length;
    }
    if(id==7){
     return additionalDocumentsAEO[keyInt].length;
  }

}

  function retrieveMasterDataPartyArray (string key) public returns (StructuresAndVariables.MasterDataParty[] ){
    return masterDataPartiesAEO[key];
  }

  function retrieveAddressesArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAddress[]){
    return addressesAEO[key];
  }

  function retrievePartyContArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyContact[]){
    return partiesContAEO[key];
  }

  function retrieveMasterDataPartyContCommArray (string key) public returns(StructuresAndVariables.MasterDataPartyContactCommunication[]){
    return partiesContCommAEO[key];
  }

  function retrieveMasterDataPartyCommArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyCommunication[]){
    return partiesCommAEO[key];
  }

  function retrieveMasterDataPartyAdIdArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAdditionalIdentifier[]){
    return additionalIdentifiersAEO[key];
  }

  function retrieveMasterDataPartyAdDocArray (uint256 key) public returns(StructuresAndVariables.MasterDataPartyAdditionalDocument[]){
    return additionalDocumentsAEO[key];
  }


    //retrieve functons give me error 
   function checkMasterDataPartyExistance (string fnr, string partyNameAEO) public returns (bool exists){

       exists=false;
       uint256 masterDataPartyLength = getLenght(1,fnr,0);
       StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= retrieveMasterDataPartyArray(fnr);

      for(uint256 i =0; i< masterDataPartyLength; i++){
        //aca posible cambio para retrieve name 
        if(compareStrings(retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
            exists=true;
           // return false;
          }
       }
       return exists;   
   }

   function checkAddressExistance(uint256 partyIdAEO,string streetAEO, uint256 numberAEO ) public returns (bool exists){
        exists=false;
       uint256 addressLength = getLenght(2,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAddress[] memory temporaryMasterDataPartyAddressArray= retrieveAddressesArray(partyIdAEO);

      for(uint256 i =0; i< addressLength; i++){
        
        if(compareStrings(retrieveStreetAddress(temporaryMasterDataPartyAddressArray,i),streetAEO) && (retrieveNumberAddress(temporaryMasterDataPartyAddressArray,i)==numberAEO)) {
            exists=true;
            
          }
       }
       return exists; 
   }

   function checkContactExistance(uint256 partyIdAEO, string contactNameAEO) public returns (bool exists){
       exists=false;
       uint256 partiesContLength = getLenght(3,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyContact[] memory temporaryMasterDataPartyContactArray= retrievePartyContArray(partyIdAEO);

      for(uint256 i =0; i< partiesContLength; i++){
        if(compareStrings( retrieveContactName(temporaryMasterDataPartyContactArray,i), contactNameAEO)){
            exists=true;
            return false;
          }
   }
   return exists;
  }

  function checkContCommExistance(string contactNameAEO, string communicationContNumberAEO) public returns (bool exists){
       exists=false;
       uint256 partiesContCommLength = getLenght(4,contactNameAEO,0);
       StructuresAndVariables.MasterDataPartyContactCommunication[] memory temporaryMasterDataPartyContactCommArray= retrieveMasterDataPartyContCommArray(contactNameAEO);

      for(uint256 i =0; i< partiesContCommLength; i++){
        if(compareStrings(retrieveCommNumber(temporaryMasterDataPartyContactCommArray,i), communicationContNumberAEO)){
            exists=true;
            return false;
          }
       }
       return exists;
  }

  function checkCommExistance(uint256 partyIdAEO,string communicationNumberAEO) public returns (bool exists){
       exists=false;
       uint256 partiesCommLength = getLenght(5,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyCommunication[] memory temporaryMasterDataPartyCommArray= retrieveMasterDataPartyCommArray(partyIdAEO);

      for(uint256 i =0; i< partiesCommLength; i++){
        if(compareStrings(retrievePartyCommNumber(temporaryMasterDataPartyCommArray,i),communicationNumberAEO)){
            exists=true;
          }
  }
  return exists;
}

function checkAddIdExistance(uint256 partyIdAEO,uint256 sequenceNumberAEO) public returns (bool exists){
       exists=false;
       uint256 additionalIdLength = getLenght(6,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalIdentifier[] memory temporaryMasterDataPartyAdditionalIdentifierArray= retrieveMasterDataPartyAdIdArray(partyIdAEO);

      for(uint256 i =0; i< additionalIdLength; i++){
        if(retrieveSequenceNumber(temporaryMasterDataPartyAdditionalIdentifierArray,i)== sequenceNumberAEO){
            exists=true;
            return false;
         }
    }
return exists;
}

function checkAddDocExistance(uint256 partyIdAEO,string additionalDocumentReferenceNumberAEO) public returns (bool exists){
       exists=false;
       uint256 additionalDocLength = getLenght(7,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalDocument[] memory temporaryMasterDataPartyAdditionalDocumentArray= retrieveMasterDataPartyAdDocArray(partyIdAEO);

      for(uint256 i =0; i< additionalDocLength; i++){
        if(compareStrings(retrieveADocRefNum(temporaryMasterDataPartyAdditionalDocumentArray,i), additionalDocumentReferenceNumberAEO)){
            exists=true;
            return false;
          }
       }
return exists;
}

function neededForReadOp(string functionalReferenceNumberAEO, string partyNameAEO) 
                        public view returns(string endDateAEO, string memory recipientAEO,
                                    string memory partyShortNameAEO, string memory businessTypeAEO, string memory identificationIssuingCountryAEO){
  uint256 indexAEO= retrieveIndexAEO(functionalReferenceNumberAEO);
  StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= retrieveMasterDataPartyArray(functionalReferenceNumberAEO);
  endDateAEO= retrieveEnDate(indexAEO);
  recipientAEO="Custom";
      //recipientAEO= AEOs[indexAEO].masterDataRec.recipient;
      for(uint256 i =0; i< temporaryMasterDataPartyArray.length; i++){
        if(compareStrings(retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
           partyShortNameAEO=retrievePartyName(temporaryMasterDataPartyArray,i);
           businessTypeAEO=retrieveBusinessType(temporaryMasterDataPartyArray,i);
           identificationIssuingCountryAEO=retrieveIssuingCountry(temporaryMasterDataPartyArray,i);
       
          return (endDateAEO,recipientAEO,partyShortNameAEO,businessTypeAEO,identificationIssuingCountryAEO);

        }
      }
}

  

 }
1 Like

@abcoathup and finally:

CrudAEOCreateAndRead.sol :
pragma solidity ^0.4.23;

import "./CrudAEOStructures.sol" ;

import { StructuresAndVariables } from "./StructuresAndVariables.sol" ;


contract CrudAEOCreateAndRead //is CrudAEOStructures 

{

event AEOEvent(string AEOfunctionalReferenceNumber, uint256 messageFunctionCodeAEO);

event AEOUNamepdate(string AEOpartyOldName , string AEOpartyNewName);  

CrudAEOStructures public contractNeeded;  

constructor(address addressOfDeployedCrudAEOStructures) public {
       // bytecode will be loaded into memory from an existing deployment
       contractNeeded= CrudAEOStructures(addressOfDeployedCrudAEOStructures);
   }

 function createMasterDataAEO (uint256 messageFunctionCodeAEO, string memory functionalReferenceNumberAEO, string memory documentNameAEO,
                                 string memory recipientTypeAEO, string memory recipientAEO,
                                 string memory senderTypeAEO, string memory senderAEO,
                                 string endDateAEO)
                                 public returns (uint256 newTotalAEOs){
    bool exists= false;

    StructuresAndVariables.MasterDataRecipient memory newMasterDataRecipient= StructuresAndVariables.MasterDataRecipient(recipientTypeAEO, recipientAEO);
    StructuresAndVariables.MasterDataSender memory newMasterDataSender= StructuresAndVariables.MasterDataSender(senderTypeAEO, senderAEO);
    StructuresAndVariables.AEOMasterData memory newAEO = StructuresAndVariables.AEOMasterData(messageFunctionCodeAEO, functionalReferenceNumberAEO, documentNameAEO, newMasterDataRecipient, newMasterDataSender, endDateAEO);

    for(uint256 i =0; i< contractNeeded.totalAEOs(); i++){

      if(compareStrings(contractNeeded.retrieveFRN(i), functionalReferenceNumberAEO)){
          exists=true;
        }
     }
      if (!exists){
             contractNeeded.insertNewAEO(newAEO);
             contractNeeded.increaseTotalAEOs();
             contractNeeded.masterDataAEOsmapping(functionalReferenceNumberAEO,contractNeeded.totalAEOs());
             //emit event
             emit AEOEvent (functionalReferenceNumberAEO, messageFunctionCodeAEO);
          }

        return contractNeeded.totalAEOs();
   }
   
    //associate a Master Data Party to a Master Data
   function associateMasterDataParty(string memory functionalReferenceNumberAEO, string memory partyNameAEO, string memory partyShortNameAEO, string memory businessTypeAEO, uint256 partyIdAEO, string memory identificationIssuingCountryAEO, string memory roleCodeAEO)
                   public returns(bool){



    StructuresAndVariables.MasterDataParty memory newMasterDataParty= StructuresAndVariables.MasterDataParty(partyNameAEO, partyShortNameAEO, businessTypeAEO, partyIdAEO, identificationIssuingCountryAEO, roleCodeAEO);


    if(contractNeeded.checkExistance(1,functionalReferenceNumberAEO,0)){
       bool exists=contractNeeded.checkMasterDataPartyExistance(functionalReferenceNumberAEO,partyNameAEO);

      /* bool exists=false;
       uint256 masterDataPartyLength = contractNeeded.getLenght(1,functionalReferenceNumberAEO,0);
       StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= contractNeeded.retrieveMasterDataPartyArray(functionalReferenceNumberAEO);

      for(uint256 i =0; i< masterDataPartyLength; i++){
        //aca posible cambio para retrieve name 
        if(compareStrings(contractNeeded.retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
            exists=true;
            return false;
          }
       }*/
        if(exists){
          return false;
        }
        if (!exists){
                contractNeeded.masterDataPartiesAEOmapping(functionalReferenceNumberAEO, newMasterDataParty);
                return true;
          }

    } else{

        contractNeeded.masterDataPartiesAEOmapping(functionalReferenceNumberAEO, newMasterDataParty);
        contractNeeded.setExistance(1,functionalReferenceNumberAEO);
        return true;
    }

    return false;
   }
   
    //stack too deep compile error, couldnt set it inside func associate address


   //Associate an AddressAndContact to certain masterDataParty si le agrego un error da stack too deep compile error
   //Cant add return value, stack too deep error compile
   
    function associateAddress(uint256 partyIdAEO, string memory typeOfAddressAEO, string memory cityNameAEO, string memory countryCodeAEO, string memory countryNameAEO, string memory countrySubEntityIdentificationAEO, string memory streetAEO, uint256 numberAEO, string memory postCodeIdAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it         
    StructuresAndVariables.MasterDataPartyAddress memory newMasterDataPartyAddress= StructuresAndVariables.MasterDataPartyAddress(typeOfAddressAEO, cityNameAEO, countryCodeAEO, countryNameAEO, countrySubEntityIdentificationAEO, streetAEO, numberAEO, postCodeIdAEO);

    if(contractNeeded.checkExistance(2,"",partyIdAEO)){
       bool exists=contractNeeded.checkAddressExistance(partyIdAEO,streetAEO,numberAEO);
       
       /*
       //bool exists=false;
       uint256 addressLength = contractNeeded.getLenght(2,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAddress[] memory temporaryMasterDataPartyAddressArray= contractNeeded.retrieveAddressesArray(partyIdAEO);

      for(uint256 i =0; i< addressLength; i++){
        //posible cambio retrieve address
        if(compareStrings(contractNeeded.retrieveStreetAddress(temporaryMasterDataPartyAddressArray,i),streetAEO) && (contractNeeded.retrieveNumberAddress(temporaryMasterDataPartyAddressArray,i)==numberAEO)) {
            //exists=true;
            return false;
          }
              */
        

        if(exists){
          return false;
        }
        if (!exists){
                contractNeeded.addressesAEOmapping(partyIdAEO, newMasterDataPartyAddress);
                return true;
          }

    } else{

        contractNeeded.addressesAEOmapping(partyIdAEO, newMasterDataPartyAddress);
        contractNeeded.setExistanceForCertainId(1,partyIdAEO);
        return true;
    }

    //return false;
  }
  
   function associateContact(uint256 partyIdAEO, string memory contactNameAEO, string memory contactFunctionCodeAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it
    StructuresAndVariables.MasterDataPartyContact memory newMasterDataPartyContact= StructuresAndVariables.MasterDataPartyContact(contactNameAEO,contactFunctionCodeAEO);

    if(contractNeeded.checkExistance(3,"",partyIdAEO)){
      bool exists=contractNeeded.checkContactExistance(partyIdAEO,contactNameAEO);
       
      /*
       bool exists=false;
       uint256 partiesContLength = contractNeeded.getLenght(3,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyContact[] memory temporaryMasterDataPartyContactArray= contractNeeded.retrievePartyContArray(partyIdAEO);

      for(uint256 i =0; i< partiesContLength; i++){
        if(compareStrings( contractNeeded.retrieveContactName(temporaryMasterDataPartyContactArray,i), contactNameAEO)){
            exists=true;
            return false;
          }

          */
       
       if(exists){
          return false;
        }
        if (!exists){
            contractNeeded.partiesContAEOmapping(partyIdAEO,newMasterDataPartyContact);
            return true;
          }

    } else{

        contractNeeded.partiesContAEOmapping(partyIdAEO,newMasterDataPartyContact);
        contractNeeded.setExistanceForCertainId(2,partyIdAEO);
        return true;
    }

    return false;
   }
   
   function associateContactComm(string memory contactNameAEO, string memory communicationContNumberAEO, string memory communicationContNumberTypeAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it
    StructuresAndVariables.MasterDataPartyContactCommunication memory newMasterDataPartyContactCommunication= StructuresAndVariables.MasterDataPartyContactCommunication(communicationContNumberAEO,communicationContNumberTypeAEO);

    if(contractNeeded.checkExistance(4,contactNameAEO,0)){
      bool exists=contractNeeded.checkContCommExistance(contactNameAEO,communicationContNumberAEO);
       /*
       bool exists=false;
       uint256 partiesContCommLength = contractNeeded.getLenght(4,contactNameAEO,0);
       StructuresAndVariables.MasterDataPartyContactCommunication[] memory temporaryMasterDataPartyContactCommArray= contractNeeded.retrieveMasterDataPartyContCommArray(contactNameAEO);

      for(uint256 i =0; i< partiesContCommLength; i++){
        if(compareStrings(contractNeeded.retrieveCommNumber(temporaryMasterDataPartyContactCommArray,i), communicationContNumberAEO)){
            exists=true;
            return false;
          }

          */
       
       if(exists){
          return false;
        }       
        if (!exists){
            contractNeeded.partiesContCommAEOmapping(contactNameAEO, newMasterDataPartyContactCommunication);
            return true;
          }

    } else{

        contractNeeded.partiesContCommAEOmapping(contactNameAEO, newMasterDataPartyContactCommunication);
        contractNeeded.setExistance(2,contactNameAEO);
        return true;
    }

    return false;
   }
   function associateComm(uint256 partyIdAEO, string memory communicationNumberAEO, string memory communicationNumberTypeAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it
    StructuresAndVariables.MasterDataPartyCommunication memory newMasterDataPartyCommunication= StructuresAndVariables.MasterDataPartyCommunication(communicationNumberAEO,communicationNumberTypeAEO);

    if(contractNeeded.checkExistance(5,"",partyIdAEO)){
      bool exists=contractNeeded.checkCommExistance(partyIdAEO,communicationNumberAEO);
      /*
       bool exists=false;
       uint256 partiesCommLength = contractNeeded.getLenght(5,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyCommunication[] memory temporaryMasterDataPartyCommArray= contractNeeded.retrieveMasterDataPartyCommArray(partyIdAEO);

      for(uint256 i =0; i< partiesCommLength; i++){
        if(compareStrings(contractNeeded.retrievePartyCommNumber(temporaryMasterDataPartyCommArray,i),communicationNumberAEO)){
            exists=true;
            return false;
          }
       }*/
       if(exists){
          return false;
        }       
        if (!exists){
            contractNeeded.partiesCommAEOmapping(partyIdAEO, newMasterDataPartyCommunication);
            return true;
          }

    } else{

        contractNeeded.partiesCommAEOmapping(partyIdAEO, newMasterDataPartyCommunication);
        contractNeeded.setExistanceForCertainId(3,partyIdAEO);
        return true;
    }

    return false;
   }
   
    function associateAdditionalId(uint256 partyIdAEO, uint256 sequenceNumberAEO,string memory additionalIdentificationCodeAEO, string memory additionalIdentificationIssuingCountryAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it
    StructuresAndVariables.MasterDataPartyAdditionalIdentifier memory newMasterDataPartyAdditionalIdentifier= StructuresAndVariables.MasterDataPartyAdditionalIdentifier(sequenceNumberAEO,additionalIdentificationCodeAEO,additionalIdentificationIssuingCountryAEO);

    if(contractNeeded.checkExistance(6,"",partyIdAEO)){
      bool exists=contractNeeded.checkAddIdExistance(partyIdAEO,sequenceNumberAEO);
      /*
       bool exists=false;
       uint256 additionalIdLength = contractNeeded.getLenght(6,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalIdentifier[] memory temporaryMasterDataPartyAdditionalIdentifierArray= contractNeeded.retrieveMasterDataPartyAdIdArray(partyIdAEO);

      for(uint256 i =0; i< additionalIdLength; i++){
        if(contractNeeded.retrieveSequenceNumber(temporaryMasterDataPartyAdditionalIdentifierArray,i)== sequenceNumberAEO){
            exists=true;
            return false;
          }
       }*/
        if(exists){
          return false;
        }
        if (!exists){
            contractNeeded.additionalIdentifiersAEOmapping(partyIdAEO,newMasterDataPartyAdditionalIdentifier);
            return true;
          }

    } else{
        contractNeeded.additionalIdentifiersAEOmapping(partyIdAEO,newMasterDataPartyAdditionalIdentifier);
        contractNeeded.setExistanceForCertainId(4,partyIdAEO);
        return true;
    }

    return false;
   }
   
    function associateAdditionalDoc(uint256 partyIdAEO, string memory documentCategoryCodeAEO, string memory documentEffectiveDateAEO, string memory documentExpirationDateAEO, string memory additionalDocumentReferenceNumberAEO, string memory documentMessageStatusAEO, string memory additionalDocumentTypeAEO, string memory manufacturingLocationAEO)
                             public returns (bool) {
    //A variable declaration could be avoided by setting the struct directly when pushing it
    StructuresAndVariables.MasterDataPartyAdditionalDocument memory newMasterDataPartyAdditionalDocument= StructuresAndVariables.MasterDataPartyAdditionalDocument(documentCategoryCodeAEO,documentEffectiveDateAEO,documentExpirationDateAEO, additionalDocumentReferenceNumberAEO, documentMessageStatusAEO, additionalDocumentTypeAEO, manufacturingLocationAEO);

    if(contractNeeded.checkExistance(7,"",partyIdAEO)){
      bool exists=contractNeeded.checkAddDocExistance(partyIdAEO,additionalDocumentReferenceNumberAEO);
      /*
       bool exists=false;
       uint256 additionalDocLength = contractNeeded.getLenght(7,"",partyIdAEO);
       StructuresAndVariables.MasterDataPartyAdditionalDocument[] memory temporaryMasterDataPartyAdditionalDocumentArray= contractNeeded.retrieveMasterDataPartyAdDocArray(partyIdAEO);

      for(uint256 i =0; i< additionalDocLength; i++){
        if(compareStrings(contractNeeded.retrieveADocRefNum(temporaryMasterDataPartyAdditionalDocumentArray,i), additionalDocumentReferenceNumberAEO)){
            exists=true;
            return false;
          }
       } */
        if(exists){
          return false;
        }
        if (!exists){
            contractNeeded.additionalDocumentsAEOmapping(partyIdAEO,newMasterDataPartyAdditionalDocument);
            return true;
          }

    } else{
        contractNeeded.additionalDocumentsAEOmapping(partyIdAEO,newMasterDataPartyAdditionalDocument);
        contractNeeded.setExistanceForCertainId(5,partyIdAEO);
        return true;
    }
    return false;
   }
   
    function readAEO(string memory functionalReferenceNumberAEO, //string memory senderAEO,
                   string memory partyNameAEO) //uint256 partyIdAEO, string memory roleCodeAEO)
                   public view returns(string endDateAEO, string memory recipientAEO,
                                    string memory partyShortNameAEO, string memory businessTypeAEO, string memory identificationIssuingCountryAEO)
{

  return contractNeeded.neededForReadOp(functionalReferenceNumberAEO,partyNameAEO);
  /*

    if(contractNeeded.checkExistance(1,functionalReferenceNumberAEO,0)){
      uint256 indexAEO= contractNeeded.retrieveIndexAEO(functionalReferenceNumberAEO);
      StructuresAndVariables.MasterDataParty[] memory temporaryMasterDataPartyArray= contractNeeded.retrieveMasterDataPartyArray(functionalReferenceNumberAEO);
      endDateAEO= contractNeeded.retrieveEnDate(indexAEO);
      recipientAEO="Custom";
      //recipientAEO= AEOs[indexAEO].masterDataRec.recipient;
      for(uint256 i =0; i< temporaryMasterDataPartyArray.length; i++){
        if(compareStrings(contractNeeded.retrievePartyName(temporaryMasterDataPartyArray,i),partyNameAEO)){
           partyShortNameAEO=contractNeeded.retrievePartyName(temporaryMasterDataPartyArray,i);
           businessTypeAEO=contractNeeded.retrieveBusinessType(temporaryMasterDataPartyArray,i);
           identificationIssuingCountryAEO=contractNeeded.retrieveIssuingCountry(temporaryMasterDataPartyArray,i);
       
          return (endDateAEO,recipientAEO,partyShortNameAEO,businessTypeAEO,identificationIssuingCountryAEO);

        }
      }
      */
    revert('AEO not found');

  }


   function compareStrings (string memory a, string memory b) internal pure returns (bool){
       return keccak256(abi.encode(a)) == keccak256(abi.encode(b));
       return true;
  }

}
MY MIGRATIONS FILES:

1_initial_migration.js

const Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
  deployer.deploy(Migrations, {from: "0x1caFCe8fF232515Dcb07eE7901D49cFF8397eF7c"});
};

2_deploy_contracts.js:

  var StructuresAndVariables= artifacts.require("./StructuresAndVariables.sol");
var CrudAEOStructures= artifacts.require("./CrudAEOStructures.sol");
var CrudAEOCreateAndRead= artifacts.require("./CrudAEOCreateAndRead.sol");
var CrudAEOUpdateAndDelete = artifacts.require("./CrudAEOUpdateAndDelete.sol");

module.exports = function(deployer){

  deployer.deploy(StructuresAndVariables);
  deployer.link(StructuresAndVariables,CrudAEOStructures);
  deployer.link(StructuresAndVariables,CrudAEOCreateAndRead);

  deployer.deploy(CrudAEOStructures,{from: "0x1caFCe8fF232515Dcb07eE7901D49cFF8397eF7c"}, {overwrite: false}).then(function() {
  	return deployer.deploy(CrudAEOCreateAndRead, CrudAEOStructures.address, {from: "0x1caFCe8fF232515Dcb07eE7901D49cFF8397eF7c"});
 });



};

Thank you a lot!

1 Like

@abcoathup , thank you!!

I have posted a reply but it was hidden. On that post I copied my files, but at the beginning I shared a link to a repository that contains all my files and explaining that the contract CrudAEOUpdateAndDelete.sol has not been modified yet and that is why is not inlcuded on the migration file and is not getting deployed.

My repository is: https://github.com/romisalve/Quorum-POC.git
However, I assume that my post is going to stop being hidden but meanwhile.

1 Like

Hi @romis

You can use await/async in your migrations if you want

Your truffle-config.js in the repo had a missing } after the network section.

In your truffle-config.js you currently have

version: "^0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)

This should be a specific version of solc:

version: "0.4.23",    // Fetch exact version from solc-bin (default: truffle's version)

It looks like you are passing in the contract ok into your constructor, but your contracts aren’t compiling currently as is.

Simplifying the logic to test out:

A.sol

pragma solidity ^0.4.23;

contract A {

    function getValue() public pure returns(string memory) {
        return "hello";
    }
}

B.sol

pragma solidity ^0.4.23;

import "./A.sol";

contract B {

    A private _a;

    constructor (A a) public {
        _a = a;
    }

    function getValue() public view returns(string memory) {
        return _a.getValue();
    }
}

2_deploy.js

const A = artifacts.require("A");
const B = artifacts.require("B");

module.exports = async function(deployer) {

deployer.deploy(A).then(function() {
    console.log(A.address);
    return deployer.deploy(B, A.address);
  });
};

truffle console

truffle(development)> b = await B.deployed()
truffle(development)> b.getValue()
'hello'

@abcoathup thank you!

I believe the problem was trying to pass an struct as an input argument to a function of the other contract.

Now my problem is that I believe the for loop tends to break things, can that be happening? if it has to take for example 20 turns, it breaks.

1 Like

Is the for loop used in a transaction, then are you running out of gas?

When I have a problem, I find it useful to create a sample contract that just has the issue I am working on.

@abcoathup the loop is used in one of the functions I am trying to execute and I believe every interaction with the netwrok is considered as a transaction, isn’t it?
The for loop depends on the extension of an array, but it is a bad practice to include loops?

Thank you!

1 Like

@abcoathup I am getting
reason: ‘overflow’,
code: ‘NUMERIC_FAULT’,
operation: ‘setValue’,
fault: ‘overflow’,
details: ‘Number can only safely store up to 53 bits’

when trying to execute this function:

    function readAEO(string memory functionalReferenceNumberAEO) //string memory senderAEO,
                   //string memory partyNameAEO, uint256 partyIdAEO)// string memory roleCodeAEO)
                   public view returns(string memory endDateAEO, string memory recipientAEO,
                                    string memory partyShortNameAEO, string memory businessTypeAEO, string memory identificationIssuingCountryAEO)
{
  //check if that fnr exists 
  if(totalAEOs>0){
      if(masterDataAEOs[functionalReferenceNumberAEO]!=0){
        //means fnr exists
        if(masterDataPartiesAEO[functionalReferenceNumberAEO].partyId!=0){
          //means MDP exists, otherwise it couldn't be read
         endDateAEO=AEOs[masterDataAEOs[functionalReferenceNumberAEO]].endDate;
          recipientAEO="Custom";
          partyShortNameAEO=masterDataPartiesAEO[functionalReferenceNumberAEO].partyShortName;
          businessTypeAEO=masterDataPartiesAEO[functionalReferenceNumberAEO].businessType;
          identificationIssuingCountryAEO=masterDataPartiesAEO[functionalReferenceNumberAEO].identificationIssuingCountry;
         
     
          return (endDateAEO,recipientAEO,partyShortNameAEO,businessTypeAEO,identificationIssuingCountryAEO);

        }else{
        revert ('MDP not found');
      }
      }else{
        revert ('AEO not found');
      }

 }else{
 revert('No AEOs');
}
}

What does that error means? Thank you!

1 Like

Hi @romis

Regards the difference between transactions and calls, see the Truffle documentation:

https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts#reading-and-writing-data
The Ethereum network makes a distinction between writing data to the network and reading data from it, and this distinction plays a significant part in how you write your application. In general, writing data is called a transaction whereas reading data is called a call . Transactions and calls are treated very differently, and have the following characteristics.

Loops need to be used carefully, see the Solidity documentation:

https://solidity.readthedocs.io/en/latest/security-considerations.html#gas-limit-and-loops
Loops that do not have a fixed number of iterations, for example, loops that depend on storage values, have to be used carefully: Due to the block gas limit, transactions can only consume a certain amount of gas. Either explicitly or just due to normal operation, the number of iterations in a loop can grow beyond the block gas limit which can cause the complete contract to be stalled at a certain point. This may not apply to view functions that are only executed to read data from the blockchain. Still, such functions may be called by other contracts as part of on-chain operations and stall those. Please be explicit about such cases in the documentation of your contracts.

For example, your contract includes the following for loop in a function that modifies state and could grow beyond the block gas limit.

for(uint256 i =0; i< contractNeeded.totalAEOs(); i++){ 

    if(compareStrings(contractNeeded.retrieveFRN(i), functionalReferenceNumberAEO)){
        exists=true;
    }
}

Hi @romis

I assume you are attempting to covert a big number that is larger than the maximum size of a JavaScript number and this is causing the overflow error. Can you provide the JavaScript you are using?

In future it might be best to create a new topic per issue (unless the issues are related), so that they are easier for the rest of the community to answer. :smile:

Thank you for all your answers @abcoathup.

In regard to the problem of overflor, what happened was that I was trying to use an array of MasterDataAEO (MasterDataAEO AEOs) which is a struct I created and when trying to push new elements it didn’t retrieve any error, but when I tried to access an element for example AEOs[1], it gave overflow error. I ended up changing it to store them in mappings because actually there was no specific reason for trying to use an array. And in fact, with mapping I could search using the key which is something that can’t be done in arrays.

I have another issue now, but I’ll follow your recommendation and create a new topic.

Thank you!!

1 Like