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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form