aboutsummaryrefslogtreecommitdiffstats
path: root/docs/solidity-by-example.rst
diff options
context:
space:
mode:
authorJoão Vítor <joaovmferreira@gmail.com>2018-06-12 07:14:17 +0800
committerGitHub <noreply@github.com>2018-06-12 07:14:17 +0800
commit6ec61e283c598be5ee4bb9124366f2631912ff00 (patch)
treedb726bbb36c8c00abdcb6e813b5737327d460485 /docs/solidity-by-example.rst
parent48e6bb51fb39736cf0d95f7860682fb44528ca60 (diff)
downloaddexon-solidity-6ec61e283c598be5ee4bb9124366f2631912ff00.tar.gz
dexon-solidity-6ec61e283c598be5ee4bb9124366f2631912ff00.tar.zst
dexon-solidity-6ec61e283c598be5ee4bb9124366f2631912ff00.zip
update code version
Diffstat (limited to 'docs/solidity-by-example.rst')
-rw-r--r--docs/solidity-by-example.rst15
1 files changed, 7 insertions, 8 deletions
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index aa084483..e55b11b1 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -795,7 +795,7 @@ The full contract
::
- pragma solidity ^0.4.20;
+ pragma solidity ^0.4.24;
contract ReceiverPays {
address owner = msg.sender;
@@ -809,7 +809,7 @@ The full contract
usedNonces[nonce] = true;
// this recreates the message that was signed on the client
- bytes32 message = prefixed(keccak256(msg.sender, amount, nonce, this));
+ bytes32 message = prefixed(keccak256(abi.encodePacked(msg.sender, amount, nonce, this)));
require(recoverSigner(message, signature) == owner);
@@ -862,12 +862,11 @@ The full contract
/// builds a prefixed hash to mimic the behavior of eth_sign.
function prefixed(bytes32 hash) internal pure returns (bytes32) {
- return keccak256("\x19Ethereum Signed Message:\n32", hash);
+ return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
}
-
Writing a Simple Payment Channel
================================
@@ -999,14 +998,14 @@ The full contract
::
- pragma solidity ^0.4.20;
+ pragma solidity ^0.4.24;
contract SimplePaymentChannel {
address public sender; // The account sending payments.
address public recipient; // The account receiving the payments.
uint256 public expiration; // Timeout in case the recipient never closes.
- function SimplePaymentChannel(address _recipient, uint256 duration)
+ constructor (address _recipient, uint256 duration)
public
payable
{
@@ -1020,7 +1019,7 @@ The full contract
view
returns (bool)
{
- bytes32 message = prefixed(keccak256(this, amount));
+ bytes32 message = prefixed(keccak256(abi.encodePacked(this, amount)));
// check that the signature is from the payment sender
return recoverSigner(message, signature) == sender;
@@ -1098,7 +1097,7 @@ The full contract
/// builds a prefixed hash to mimic the behavior of eth_sign.
function prefixed(bytes32 hash) internal pure returns (bytes32) {
- return keccak256("\x19Ethereum Signed Message:\n32", hash);
+ return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
}
}