S
ingle responsibility principleO
pen / closed principleL
iskov substitution principle ( Barbara Liskov substitution principle )I
nterface segregation principleD
ependency inversion principleBonusCrowdsale
and TokensCappedCrowdsale
smart contracts in the repository, which were designed to handle such aspects of our sales as the processing of participants' bonuses depending on the time and amount of investment, as well as to control the total number of tokens sold. We received a rather laudable review of the smart contract security auditor for our code:“Excellent work on reusing existing OpenZeppelin library contracts! Additional contracts look very thoughtfully designed and look like a good extension of this framework "(" Great work reusing the existing OpenZeppelin libraries! The additional contracts are very thoughtfully designed, and Zeppelin Solutions. The full conclusion can be found on the link .
super
keyword. Perhaps the following example will additionally help to understand how the linearization of C3 multiple inheritance works: contract A { } contract B { } contract C is A, B { } // C(A,B) = ABC contract D is C, A { } // D(C(A,B),A) = D(ABC,A) = ABCAD !!! Error !!! contract E is A, C { } // E(A,C(A,B)) = E(A,ABC) = ABCE
A
cannot redefine C
, because C
redefines B
, which in turn redefines A
: TypeError: Linearization of inheritance graph impossible contract D is C, A { } ^ — — — — — — — — — — ^ Compiliation failed. See above.
W
, and its parent contract Z
becomes the successor of the contract Y
(which is the successor of X
), instead of directly inheriting from X
: contract X {} contract Y is X {} // Y(X) = XY contract Z is X {} // Z(X) = XZ contract W is Y, Z {} // W(Y(X),Z(X)) = W(XY, XZ) = XYZW
Ownable
contract — you just need to follow it and add onlyAnyOwner
and onlyManyOwners
to the necessary functions: contract SimplestMultiWallet is Multiownable { bool avoidReentrancy = false; function () payable { } function transferTo(address to, uint256 amount) onlyManyOwners { require(!avoidReentrancy); avoidReentrancy = true; to.transfer(amount); avoidReentrancy = false; } }
transferTo
method of the smart contract will be called only after all the wallet owners call it with the same arguments. You will not believe it, but this is the complete code of the simplest multi-signature wallet for the Ether currency. Additionally, you can implement support for any tokens compatible with the ERC20 specification, this is the following method: function transferTokens(address token, address to, uint256 amount) onlyManyOwners { require(!avoidReentrancy); avoidReentrancy = true; ERC20(token).transfer(to, amount); avoidReentrancy = false; }
transfer
method.Source: https://habr.com/ru/post/342100/
All Articles