janken-solidity – 詹肯坚固性区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,janken-solidity – 詹肯坚固性区块链毕设代写 是一篇很好的国外资料

janken-solidity

janken-solidity - 詹肯坚固性 janken-solidity - 詹肯坚固性

operation flow

create a game by Player1(the host)

Generate a secret in a cryptographically secure way and hash it with your chosen hand. You need to remember the secret to prove correctness later. Also, need to send ether with that transaction as a deposit.

createGame(hostEncryptedHand, { value: web3.utils.toWei('1'), from: host })

how to generate encrypted hand

// chose your hand in Rock: 1, Paper: 2, Scissors: 3 const hand = 1; // this `secret` is necessary for a step that reveals your hand so you need to make a note. const secret = web3.utils.soliditySha3({ type: 'bytes32', value: crypto.randomBytes(32).toString('hex') }); const encryptedHand = web3.utils.soliditySha3({ type: 'uint', value: hand }, { type: 'bytes32', value: secret });

join the game by Player2(the opponent)

Commit the hand in the same way as the host. The transaction requires you to send the same amount of ether as host’s deposit.

joinGame(gameId, opponentEncryptedHand, { value: web3.utils.toWei('1'), from: opponent })

note

You can join a game only if deadlineToJoin is not past.

reveal the hand you commited before

Reveal the not encrypted hand by sending it together with the secret used for encryption before.

revealHand(gameId, hostHand, hostSecret, { from: host }) revealHand(gameId, opponentHand, opponentSecret, { from: opponent })

note

If you don’t reveal your hand by the time of deadlineToReveal, you will lose your all deposit.

withdraw funds deposited by the two (if you win!)

withdraw(gameId, { from: opponent })

rescue the deposit (optional)

There are two situations in which you can execute resuce(). The first situation is when you are a host of a game that no one has joined by deadlineToJoin. The second one is when you reveal a hand but your opponent doesn’t reveal by deadlineToReveal. deadlineToJoin and deadlineToReveal are set a term of a day in default.

rescue(gameId, { from: host })

See run.js for more details.

run through in your console

npx truffle develop  truffle(develop)> migrate --reset truffle(develop)> exec scripts/run.js Using network 'develop'.  host =>   handInt: 1,   encryptedHand: 0xf307279d3fe9b98cbf0514a3de81e4e2c7465ea4c3893527ec105629e31f4959,   secret: 0xbf5631c9938a1638afad2e1ba2439fe8b7e7d6410957a05c1b60ed8536373203 gameId =>  1 opponent =>   handInt: 2,   encryptedHand: 0x9b9d9d35bfd420b9c7e860583927b1773583caca81c75b0326d48ea2ecd66cd9,   secret: 0x740ce4b15f0ed6433d4d981f33ba2b3bff4d32f2b9cb3eb277b005bed19519fc result =>     beforeBalance: 98995848940000000000,     afterBalance: 100995330380000000000,     delta: 1999481440000000000,     fee: 518560000000000,     deltaWithoutFee: 1998962880000000000

compile and run on remix

Go to https://remix.ethereum.org, and copy and paste Jankein.sol in Remix. You need to do one thing to compile and run on Remix, fix import statement about SafeMath.sol like below diffs.

-import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

Deployment may fail. Raise the amount of Gas Limit on Remix and try again.

run tests

./test.sh

janken solidity

操作流程

由玩家1(主机)创建游戏

如何生成加密手

由玩家2(对手)加入游戏

注意

展示您之前提交的手牌

注意

提取两人存入的资金(如果您赢了!)

拯救沉淀(可选)

在控制台中运行

<janken-solidity><janken-solidity>janken-solidity - 詹肯坚固性

以加密安全的方式生成一个秘密,并用您选择的手散列它。你需要记住这个秘密,以后才能证明它的正确性。另外,需要将该交易作为定金发送给ether。

以与主机相同的方式提交手部。交易要求您发送与主机押金相同数量的乙醚。

只有当加入的死线未超过时,才能加入游戏。

将未加密的手与之前用于加密的密钥一起发送,以显示未加密的手。

如果您在截止日期前不露出手,您将失去所有押金。

有两种情况可以执行resuce()。第一种情况是,当你是一个游戏的主人,没有人加入到死线加入。第二种情况是当你露出一只手,而你的对手却没有用致命一击来展示。deadlineToJoin和deadlineToReveal默认设置为一天的期限。

参见运行.js更多细节。

转到https://remix.ethereum.org,并复制粘贴太阳报混音。您需要做一件事来编译和运行在混音上,修复import语句about安全数学.sol就像下面的差异。

部署可能失败。提高混合气的用量限制,然后再试一次。

janken solidity

操作流程

由玩家1(主机)创建游戏

如何生成加密手

由玩家2(对手)加入游戏

注意

展示您之前提交的手牌

注意

提取两人存入的资金(如果您赢了!)

拯救沉淀(可选)

在控制台中运行

操作流程

由玩家1(主机)创建游戏

以加密安全的方式生成一个秘密,并用您选择的手散列它。你需要记住这个秘密,以后才能证明它的正确性。另外,需要将该交易作为定金发送给ether。

createGame(hostEncryptedHand, { value: web3.utils.toWei('1'), from: host })

如何生成加密手

由玩家2(对手)加入游戏

注意

展示您之前提交的手牌

注意

提取两人存入的资金(如果您赢了!)

拯救沉淀(可选)

在控制台中运行

// chose your hand in Rock: 1, Paper: 2, Scissors: 3 const hand = 1; // this `secret` is necessary for a step that reveals your hand so you need to make a note. const secret = web3.utils.soliditySha3({ type: 'bytes32', value: crypto.randomBytes(32).toString('hex') }); const encryptedHand = web3.utils.soliditySha3({ type: 'uint', value: hand }, { type: 'bytes32', value: secret });

由玩家2(对手)加入游戏

以与主机相同的方式提交手部。交易要求您发送与主机押金相同数量的乙醚。

joinGame(gameId, opponentEncryptedHand, { value: web3.utils.toWei('1'), from: opponent })

注意

展示您之前提交的手牌

注意

提取两人存入的资金(如果您赢了!)

拯救沉淀(可选)

在控制台中运行

只有当加入的死线未超过时,才能加入游戏。

展示您之前提交的手牌

将未加密的手与之前用于加密的密钥一起发送,以显示未加密的手。

revealHand(gameId, hostHand, hostSecret, { from: host }) revealHand(gameId, opponentHand, opponentSecret, { from: opponent })

注意

如果您在截止日期前不露出手,您将失去所有押金。

提取两人存入的资金(如果您赢了!)

withdraw(gameId, { from: opponent })

拯救沉淀(可选)

有两种情况可以执行resuce()。第一种情况是,当你是一个游戏的主人,没有人加入到死线加入。第二种情况是当你露出一只手,而你的对手却没有用致命一击来展示。deadlineToJoin和deadlineToReveal默认设置为一天的期限。

rescue(gameId, { from: host })

参见运行.js更多细节。

在控制台中运行

npx truffle develop  truffle(develop)> migrate --reset truffle(develop)> exec scripts/run.js Using network 'develop'.  host =>   handInt: 1,   encryptedHand: 0xf307279d3fe9b98cbf0514a3de81e4e2c7465ea4c3893527ec105629e31f4959,   secret: 0xbf5631c9938a1638afad2e1ba2439fe8b7e7d6410957a05c1b60ed8536373203 gameId =>  1 opponent =>   handInt: 2,   encryptedHand: 0x9b9d9d35bfd420b9c7e860583927b1773583caca81c75b0326d48ea2ecd66cd9,   secret: 0x740ce4b15f0ed6433d4d981f33ba2b3bff4d32f2b9cb3eb277b005bed19519fc result =>     beforeBalance: 98995848940000000000,     afterBalance: 100995330380000000000,     delta: 1999481440000000000,     fee: 518560000000000,     deltaWithoutFee: 1998962880000000000

compile and run on remix

转到https://remix.ethereum.org,并复制粘贴太阳报混音。您需要做一件事来编译和运行在混音上,修复import语句about安全数学.sol就像下面的差异。

-import "openzeppelin-solidity/contracts/math/SafeMath.sol"; +import "github.com/OpenZeppelin/openzeppelin-solidity/contracts/math/SafeMath.sol";

部署可能失败。提高混合气的用量限制,然后再试一次。

run tests

./test.sh

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/16628.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » janken-solidity – 詹肯坚固性区块链毕设代写

提供最优质的资源集合

立即查看 了解详情