0

I'm thinking I could make a kind of contract that can make serial story on blockchain(using solidity and Remix). So I want to know the way how to detect whether "someone already added a story to previous one or not" in real time at the place like Remix.

[my delusion]

1, function getPreviousStory() : returns previous story

2, function getState() : returns bool (will be false when someone is executing addStory() function and the transaction still not mined. will be true when anyone isn't executing addStory and not generating transaction)

3, function addStory(string story) : fire a Write event and send a new story if getState() returns true now. If getState() returns false, addStory() failes to avoid deprecated.

1

I get the impression you're trying to solve for serialization of potentially concurrent events. You don't need to do that as long as your transactions finish completely. That is to say, they should leave the contract in a complete state.

The mining process will order your transactions for you. One transaction will be selected to be first, and it will execute completely. Then, later, the next will execute using the state from the first.

There is no case where there could be another thread executing addStory(). It may help to think of the EVM as single-threaded processor using mining to queue the transactions in a specific order.

Hope it helps.

  • Thank you for your advise! I could study EVM as single threaded processor! But even so, deprecation will happen, like "first story..." "second story..." "second story..." "second story...". I'm wondering if there is a way to prevent deprecation like "If other one is generating "second story" now, other people can't generate "second story "transaction" (without loss of gas). – shshsh12 May 27 '18 at 14:04
  • sorry, not "deprecation", I mean "duplication". – shshsh12 May 27 '18 at 15:11
  • Sure. One way would be to generalize a nextStory () function (if feasible), so they don't need to know their position. Another is to have them send index information and then check for duplicates, rejecting claims on slots that are taken. – Rob Hitchens - B9lab May 27 '18 at 18:20

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.