Mapping with iterating uint as identifier - multiple transactions in the same blockStruct not being stored in mapping when it contains more than two 'string' properties. Bug?Wrong value returned from functionDeploying a contract multiple times with the same LibraryThis contract does not implement all functions and thus cannot be createdProblems with mapping in soliditySolidity if condition based mapping with multiple structMapping address to multidimensional uintGas cost difference between uint[] and mapping(uint => uint)Multiple Array[] along with mapping handlingremix ERC223: This contract does not implement all functions and thus cannot be created

Fitting a mixture of two normal distributions for a data set?

How many satellites can stay in a Lagrange point?

What is this opening trap called, and how should I play afterwards? How can I refute the gambit, and play if I accept it?

Layout of complex table

What do you call the action of someone tackling a stronger person?

How could mana leakage be dangerous to a elf?

What is the line crossing the Pacific Ocean that is shown on maps?

First-year PhD giving a talk among well-established researchers in the field

Averting Real Women Don’t Wear Dresses

C-152 carb heat on before landing in hot weather?

Does image quality of the lens affect "focus and recompose" technique?

How can I set command-line parameters through `.emacs` file?

Does the Paladin's Aura of Protection affect only either her or ONE ally in range?

How to positively portray high and mighty characters?

How to determine what is the correct level of detail when modelling?

Why cruise at 7000' in an A319?

Intuitively, why does putting capacitors in series decrease the equivalent capacitance?

Why is C++ initial allocation so much larger than C's?

Mount a folder with a space on Linux

What would Earth look like at night in medieval times?

Use color ramp to mix materials

Does Hubble need to dump momentum of its reaction wheels?

Why isn’t the tax system continuous rather than bracketed?

What are the penalties for overstaying in USA?



Mapping with iterating uint as identifier - multiple transactions in the same block


Struct not being stored in mapping when it contains more than two 'string' properties. Bug?Wrong value returned from functionDeploying a contract multiple times with the same LibraryThis contract does not implement all functions and thus cannot be createdProblems with mapping in soliditySolidity if condition based mapping with multiple structMapping address to multidimensional uintGas cost difference between uint[] and mapping(uint => uint)Multiple Array[] along with mapping handlingremix ERC223: This contract does not implement all functions and thus cannot be created






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



pragma solidity ^0.5.8;

contract Names

uint lastId;
mapping(uint => string) public numberedNames;

constructor() public
lastId = 0;


function setName(string memory name) public
numberedNames[lastId] = name;
lastId++;




My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










share|improve this question




























    1















    I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



    pragma solidity ^0.5.8;

    contract Names

    uint lastId;
    mapping(uint => string) public numberedNames;

    constructor() public
    lastId = 0;


    function setName(string memory name) public
    numberedNames[lastId] = name;
    lastId++;




    My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










    share|improve this question
























      1












      1








      1








      I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



      pragma solidity ^0.5.8;

      contract Names

      uint lastId;
      mapping(uint => string) public numberedNames;

      constructor() public
      lastId = 0;


      function setName(string memory name) public
      numberedNames[lastId] = name;
      lastId++;




      My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?










      share|improve this question














      I want to use an iterating uint as an identifying number, but I have a simple question to make sure I can do this safely on the mainnet. Here's a simple example to demonstrate the issue:



      pragma solidity ^0.5.8;

      contract Names

      uint lastId;
      mapping(uint => string) public numberedNames;

      constructor() public
      lastId = 0;


      function setName(string memory name) public
      numberedNames[lastId] = name;
      lastId++;




      My question is that if setName gets called multiple times within the same block, is it possible that lastId does not get updated after the first call, thus overriding the previous numberedNames element?







      solidity mapping uint256






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 16 at 21:00









      SuperCodeBrahSuperCodeBrah

      1556 bronze badges




      1556 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "642"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f71917%2fmapping-with-iterating-uint-as-identifier-multiple-transactions-in-the-same-bl%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37















          2














          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer























          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37













          2












          2








          2







          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.






          share|improve this answer













          No, it doesn't matter whether transactions are in the same block or not. Each transaction is processed on its own, sequentially. The code you propose is fine, though an array may make more sense.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 16 at 21:25









          smarxsmarx

          20.7k1 gold badge8 silver badges20 bronze badges




          20.7k1 gold badge8 silver badges20 bronze badges












          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37

















          • In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

            – SuperCodeBrah
            Jun 16 at 21:33











          • Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

            – smarx
            Jun 16 at 21:37
















          In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

          – SuperCodeBrah
          Jun 16 at 21:33





          In terms of an array making more sense, are you suggesting just to push the name onto the end of the array and use array indexes as as the identifier? Part of the reason I wanted to use a mapping is to allow for easier deleting. I'm not totally sure that I'll need to delete anything yet, but I'd think having to delete from an array while also maintaining the identifier would be messier.

          – SuperCodeBrah
          Jun 16 at 21:33













          Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

          – smarx
          Jun 16 at 21:37





          Deleting from an array works the same way. delete foo[5] will just zero out the storage used by foo[5], regardless of whether foo is a mapping or an array.

          – smarx
          Jun 16 at 21:37

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Ethereum Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fethereum.stackexchange.com%2fquestions%2f71917%2fmapping-with-iterating-uint-as-identifier-multiple-transactions-in-the-same-bl%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?