renamed contracts::lib -> contracts::utils
This commit is contained in:
@@ -22,10 +22,10 @@
|
||||
"src/mixins/MNonFungibleToken.sol",
|
||||
"src/ERC1155Mintable.sol",
|
||||
"src/MixinNonFungibleToken.sol",
|
||||
"src/lib/SafeMath.sol",
|
||||
"src/lib/Address.sol",
|
||||
"src/interfaces/IERC1155Mintable.sol",
|
||||
"src/interfaces/IERC1155Receiver.sol",
|
||||
"src/interfaces/IERC1155.sol"
|
||||
"src/interfaces/IERC1155.sol",
|
||||
"src/utils/SafeMath.sol",
|
||||
"src/utils/Address.sol"
|
||||
]
|
||||
}
|
||||
|
@@ -18,8 +18,8 @@
|
||||
|
||||
pragma solidity ^0.5.3;
|
||||
|
||||
import "./lib/SafeMath.sol";
|
||||
import "./lib/Address.sol";
|
||||
import "./utils/SafeMath.sol";
|
||||
import "./utils/Address.sol";
|
||||
import "./interfaces/IERC1155.sol";
|
||||
import "./interfaces/IERC1155Receiver.sol";
|
||||
import "./MixinNonFungibleToken.sol";
|
||||
|
@@ -1,6 +1,6 @@
|
||||
pragma solidity ^0.5.3;
|
||||
|
||||
import "./lib/SafeMath.sol";
|
||||
import "./utils/SafeMath.sol";
|
||||
import "./ERC1155.sol";
|
||||
import "./interfaces/IERC1155Mintable.sol";
|
||||
|
||||
|
29
contracts/erc1155/contracts/src/utils/Address.sol
Normal file
29
contracts/erc1155/contracts/src/utils/Address.sol
Normal file
@@ -0,0 +1,29 @@
|
||||
pragma solidity ^0.5.3;
|
||||
|
||||
|
||||
/**
|
||||
* Utility library of inline functions on addresses
|
||||
*/
|
||||
library Address {
|
||||
|
||||
/**
|
||||
* Returns whether the target address is a contract
|
||||
* @dev This function will return false if invoked during the constructor of a contract,
|
||||
* as the code is not actually created until after the constructor finishes.
|
||||
* @param account address of the account to check
|
||||
* @return whether the target address is a contract
|
||||
*/
|
||||
function isContract(address account) internal view returns (bool) {
|
||||
uint256 size;
|
||||
// XXX Currently there is no better way to check if there is a contract in an address
|
||||
// than to check the size of the code at that address.
|
||||
// See https://ethereum.stackexchange.com/a/14016/36603
|
||||
// for more details about how this works.
|
||||
// TODO Check this again before the Serenity release, because all addresses will be
|
||||
// contracts then.
|
||||
// solium-disable-next-line security/no-inline-assembly
|
||||
assembly { size := extcodesize(account) }
|
||||
return size > 0;
|
||||
}
|
||||
|
||||
}
|
87
contracts/erc1155/contracts/src/utils/SafeMath.sol
Normal file
87
contracts/erc1155/contracts/src/utils/SafeMath.sol
Normal file
@@ -0,0 +1,87 @@
|
||||
pragma solidity ^0.5.3;
|
||||
|
||||
|
||||
contract SafeMath {
|
||||
|
||||
function safeMul(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
if (a == 0) {
|
||||
return 0;
|
||||
}
|
||||
uint256 c = a * b;
|
||||
require(
|
||||
c / a == b,
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeDiv(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
uint256 c = a / b;
|
||||
return c;
|
||||
}
|
||||
|
||||
function safeSub(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
require(
|
||||
b <= a,
|
||||
"UINT256_UNDERFLOW"
|
||||
);
|
||||
return a - b;
|
||||
}
|
||||
|
||||
function safeAdd(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
uint256 c = a + b;
|
||||
require(
|
||||
c >= a,
|
||||
"UINT256_OVERFLOW"
|
||||
);
|
||||
return c;
|
||||
}
|
||||
|
||||
function max64(uint64 a, uint64 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min64(uint64 a, uint64 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
function max256(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
function min256(uint256 a, uint256 b)
|
||||
internal
|
||||
pure
|
||||
returns (uint256)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user