awesome-solidity-patterns
awesome-solidity-patterns copied to clipboard
TODO
https://github.com/OpenZeppelin/openzeppelin-solidity/tree/master/contracts
https://github.com/0xProject/0x-monorepo
https://ethereum.stackexchange.com/questions/32354/mapping-to-contract
You're bringing the whole bytecode of MyContract into MappingExample. The code for MyContract isn't shown, but let's say it's near the gasLimit because it's a complex beast. MappingExample will be that big plus additional bytecode for its own function. Multiple layers of this style lead to contracts that are too large to be deployed. This is what happens when you say MyContract c. You could just as well say MyContractInterface c and it would be smaller.
explain linking
https://ethereum.stackexchange.com/questions/17558/what-does-deploy-link-exactly-do-in-truffle
how to issue a token contract and then access it from other areas of codebase.
https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/trading/FillOrder.sol#L104
https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/reporting/Universe.sol#L49:27
Delegate pattern:
- Controller: register of all contracts
- IControlled - inheritance gives access to singleton controller instance throughout code
- Delegator responsible for forwarding calls to the contract registered in the controller. Looking up contract address from controller, delegatecall'ing the contract, and then returning the data (asm)
-
Delegator _delegator = new Delegator(_controller, "ReputationToken");
will forward calls to the contract registered by the name "ReputationToken" - registration occurs in the deployment process
-
IReputationToken _reputationToken = IReputationToken(_delegator);
the interface provides the ABI typings to interact with the delegated contract -
_reputationToken.initialize(_universe);
initialise is a generic pattern to inject the controller instance
contract ReputationTokenFactory {
function createReputationToken(IController _controller, IUniverse _universe) public returns (IReputationToken) {
Delegator _delegator = new Delegator(_controller, "ReputationToken");
IReputationToken _reputationToken = IReputationToken(_delegator);
_reputationToken.initialize(_universe);
return _reputationToken;
}
}
https://sourcegraph.com/github.com/AugurProject/augur-core@master/-/blob/source/contracts/factories/ReputationTokenFactory.sol#L11:60