Skip to content

Commit

Permalink
editorconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
  • Loading branch information
pcaversaccio committed May 15, 2022
1 parent 890e94d commit 51455a2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = false

[*.sol]
indent_size = 4
82 changes: 41 additions & 41 deletions contracts/DeployBytecode.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ pragma solidity 0.8.13;
error Failed(address emitter);

contract DeployBytecode {
/**
* @dev Event that is emitted when a contract is successfully created.
* @param newContract The address of the new contract.
*/
event ContractCreation(address newContract);
/**
* @dev Event that is emitted when a contract is successfully created.
* @param newContract The address of the new contract.
*/
event ContractCreation(address newContract);

/**
* @dev The function `deployBytecode` deploys a new contract via calling
* the `CREATE` opcode and using the creation bytecode as input.
* @param bytecode The creation bytecode.
*/
function deployBytecode(bytes memory bytecode)
public
returns (address newContract)
{
// solhint-disable-next-line no-inline-assembly
assembly {
/** @dev `CREATE` opcode
*
* Stack input
* ------------
* value: value in wei to send to the new account.
* offset: byte offset in the memory in bytes, the instructions of the new account.
* size: byte size to copy (size of the instructions).
*
* Stack output
* ------------
* address: the address of the deployed contract.
*
* How are bytes stored in Solidity:
* In memory the `bytes` is stored by having first the length of the `bytes` and then the data,
* this results in the following schema: `<32-bytes length><data>` at the location where bytecode points to.
*
* Now if we want to use the data with `CREATE`, we first point to the start of the raw data, which is after the length.
* Therefore, we add 32 (the space required for the length) to the location stored in the bytecode variable.
* This is the first parameter. For the second parameter, we read the length from memory using `mload`.
* As the length is the first 32 bytes at the location of `bytecode`, we can read the length by calling `mload(bytecode)`.
*/
newContract := create(0, add(bytecode, 0x20), mload(bytecode))
/**
* @dev The function `deployBytecode` deploys a new contract via calling
* the `CREATE` opcode and using the creation bytecode as input.
* @param bytecode The creation bytecode.
*/
function deployBytecode(bytes memory bytecode)
public
returns (address newContract)
{
// solhint-disable-next-line no-inline-assembly
assembly {
/** @dev `CREATE` opcode
*
* Stack input
* ------------
* value: value in wei to send to the new account.
* offset: byte offset in the memory in bytes, the instructions of the new account.
* size: byte size to copy (size of the instructions).
*
* Stack output
* ------------
* address: the address of the deployed contract.
*
* How are bytes stored in Solidity:
* In memory the `bytes` is stored by having first the length of the `bytes` and then the data,
* this results in the following schema: `<32-bytes length><data>` at the location where bytecode points to.
*
* Now if we want to use the data with `CREATE`, we first point to the start of the raw data, which is after the length.
* Therefore, we add 32 (the space required for the length) to the location stored in the bytecode variable.
* This is the first parameter. For the second parameter, we read the length from memory using `mload`.
* As the length is the first 32 bytes at the location of `bytecode`, we can read the length by calling `mload(bytecode)`.
*/
newContract := create(0, add(bytecode, 0x20), mload(bytecode))
}
if (newContract == address(0)) revert Failed(address(this));
emit ContractCreation(newContract);
}
if (newContract == address(0)) revert Failed(address(this));
emit ContractCreation(newContract);
}
}
24 changes: 12 additions & 12 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
pragma solidity >=0.4.22 <0.9.0;

contract Migrations {
address public owner = msg.sender;
uint256 public last_completed_migration;
address public owner = msg.sender;
uint256 public last_completed_migration;

modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}
modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}

function setCompleted(uint256 completed) public restricted {
last_completed_migration = completed;
}
function setCompleted(uint256 completed) public restricted {
last_completed_migration = completed;
}
}

0 comments on commit 51455a2

Please sign in to comment.