antododo / tictactoeTuto

2 stars 1 forks source link

Issue with multiple calls to the contract #22

Closed dabana closed 6 years ago

dabana commented 6 years ago

An event is created in the contract to log to the blockchain: 1) Winner address 2) Loser address 3) a game index 4) the bet ammount

An array containing the players address, playerAddresses, has been created for this purpose. But the React app seams to be calling its SendWinner() multiple times in a row. This creates an opcode error in the VM because the extra calls to the contract function ClaimBet() cause an indexing of an empty array (playerAddresses is empty when the game is finished and the bet is claimed by the winner).

It is a React related issues I have problems solving.

AkaashMukherjee commented 6 years ago

an opcode error?

AkaashMukherjee commented 6 years ago

I get:

Warning: Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount.

dabana commented 6 years ago

Oui ça c'est un warning parce qu'on change le state du React component dans le render(). Ça cause pas de problème, mais après il est supposé y avoir une autre erreur VM invalid op code

dabana commented 6 years ago

Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: invalid opcode

dabana commented 6 years ago

Je pense que je sais c'est quoi le problème. C'Est que le remet pas les boolean de mon mapping a false dans ClaimBet().

Mais ça regle pas les calls multiples à SendWinner() mais c'est peut-être pas grave

dabana commented 6 years ago

Ah ah! c'est le require qui envoie l'erreur. Bien sur!

https://medium.com/blockchannel/the-use-of-revert-assert-and-require-in-solidity-and-the-new-revert-opcode-in-the-evm-1a3a7990e06e

If you look up either of those opcodes in the yellow paper, you won’t find them. This is why you see the invalid opcode error, because there’s no specification for how a client should handle them.

dabana commented 6 years ago

Okai je n'ai plus l'erreur quand je commente la ligne require(isPlayer[msg.sender]); ET la ligne delete playerAddresses; dans le contract.

dabana commented 6 years ago

Mais tout ça viens du call multiple a SendWinner() je crois