Giter Club home page Giter Club logo

smart-contract-patterns's Introduction

Smart-Contract Patterns

Writing good software has never been an easy task, however the introduction of common design patterns by the gang of four (Gamma, Helm, Johnson, Vlissides) in their seminal book 'Design Patterns' in 1995, went a long way to creating a language of patterns, an essential method of describing solutions to common problems.

This is a library of smart-contract patterns written in Solidity. Writing smart-contracts has been proven to be difficult, exemplified by TheDAO in recent events. It is my intention that this repository will serve the community by collating the most useful smart-contract patterns for public benefit.

Patterns

The patterns are logically divided into four groupings. Lifetime is a group of patterns that control the construction and destruction of smart-contracts. Maintenance is a group of patterns that provide mechanisms for live contracts. Ownership is a group of patterns that control access to smart-contract. And finally Security is a group of patterns that seek to mitigate security related matters.

Lifetime

auto_deprecation - Provides a mechanism for automatic expiration of a contract interface after some period of time has elapsed. lifetime/auto_deprecation.sol

mortal - Provides a method for the creator of a contract to destroy it. lifetime/mortal.sol

Maintenance

relay - Provides a method for the creator of a contract to update it to a newer version without invalidating the address. maintenance/relay.sol

data_segregation - Segregates a contract and its data so as to avoid costly data migrations. maintenance/data_segregation.sol

Ownership

owner - Limits access to certain functions to only the owner of the contract. ownership/owner.sol

Security

circuit_breaker - The circuit breaker pattern allows the owner to disable or enable a contract by a runtime toggle. security/circuit_breaker.sol

rejector - The rejector pattern automatically rejects all ether sent to it. security/rejector.sol

speed_bump - The speed bump pattern limits how often a function can be called to deliberately slow down certain functions. security/speed_bump.sol

Contributions

Contributions are welcome. Please use the issue tracker to submit requests or report issues.

If you would like to submit a pattern to the library, please first submit a proposal via the issue tracker.

License

The code contained within this repository is licensed and distributed under the Apache 2.0 license. It is my intention to invite derivative works, as well as encourage commercial use without obligation.

LICENSE

smart-contract-patterns's People

Contributors

cjgdev avatar

Watchers

j03 k1ng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.