I,m trying to block the call to the getOrigin function to accounts that are not equal to the account that is set in setOrigin function.

Now the first account that call to setOrigin is the unique that can call and see all the information of all the new values.

How can I change the constructor account value in each call that I do to the contract??

pragma solidity ^0.4.24;

import "browser/DateTime.sol";

contract Travel {

address private owner;

modifier isOwner
    require (owner == msg.sender);

struct TravelStruct 
    address clientAddress;
    string originAirportName;
    uint32 originTime; //In timestamp
    uint16 originBagWeight;
    uint32 tapeArrivedTime; //In timestamp
    string flyCode;
    uint32 takeOffTime; //In timestamp
    string destinationAirportName;
    uint32 destinyTime; //In timestamp
    uint16 destinyBagWeight;

mapping(uint => TravelStruct) travels;
uint public travelsRegistryCount;

    owner = msg.sender;
    travelsRegistryCount = 1;

function setOrigin (string _originAirportName, uint32 _originTime, uint16 _originBagWeight) public
    travels[travelsRegistryCount].clientAddress = owner;
    travels[travelsRegistryCount].originAirportName = _originAirportName;
    travels[travelsRegistryCount].originTime = _originTime;
    travels[travelsRegistryCount].originBagWeight = _originBagWeight;

function getOrigin (uint _id) isOwner public constant returns (address, string, uint32, uint16)
    return (travels[_id].clientAddress, travels[_id].originAirportName ,travels[_id].originTime ,travels[_id].originBagWeight);

The problem that I have is that the constructor parameters are setted in the fist time that I call to a function. But my idea is to renew the constructor parametes each time that the call is made from another account.

Is that possible??


As per solidity documentation:

When a contract is created, its constructor (a function declared with the constructor keyword) is executed once.

Constructor runs only once at the time of deployment. Afterwards you cannot trigger it anyhow. That is a functionality of constructor

You can design the required logic using the regular functions of contract.

| improve this answer | |
  • Thx for the answer A.K. – UnexpectedCharacter Nov 26 '18 at 7:40
  • If it answers your question correctly, please mark it as right answer – Aniket Nov 26 '18 at 7:46

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.