Skip to content

Instantly share code, notes, and snippets.

@yemel
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yemel/aab130cd501327e438ec to your computer and use it in GitHub Desktop.
Save yemel/aab130cd501327e438ec to your computer and use it in GitHub Desktop.
Copay 2.0

Goal

The main goal of this refactor is to define a proper separation between the frontend and the backend of the application. Although Copay is a 100% client side application, a clean separation of the core functionalities is needed to later offer different endpoints, eg. web interface, npm command line interface or just a library that runs both on server and browser.

Layers of application

Three layers are proposed for the application:

  1. UI Interface: AngularJS | CLI
  2. Wallet Models and Services
  3. Backing Services: P2P Networking | Blockchain | Storage

UI Interface

Every interface shold have their own user repository/package and use the core copay npm package as dependency, e.g. copay-ui, copay-cli, copay-api. Below the most important services for the AngularJS interface are described:

  1. Notification Service: Handles the notifications and flash messages.
  2. Video Service: Responsable of managing WebRTC video features.
  3. Settings Service: Responsable for storing the settings and configuring the wallet.
  4. Session Service: Exposes core functionalities of the wallet current wallet.

Wallet Models and Services

Contains the core functionality of copay, organized in diferente models and services exposing features with a comprehensive error handling. Some services extends EventEmmiter class providing a way to UI to listen for changes. Below some of this models/services and its functionalities are described:

  1. Wallet
  • List all
  • Open
  • Create
  • Join
  • Import
  • Export
  • Delete
  • Close
  1. Address
  • Create
  • List all
  • Events: NEW_ADDRESS
  1. Balance
  • Total balance
  • Available to spend
  • Balance for address
  • Events: UPDATE
  1. Proposal
  • Create
  • List all
  • List pending
  • Sign
  • Reject
  • Broadcast
  • Events: NEW
  1. Transaction
  • List all
  • Update status
  • Broadcast
  • Events: NEW
  1. P2P Service
  • List members
  • Get connections
  • Events: JOIN_RING, CONNECT, DISCONNECT
  1. Logging Service
  • Log
  • Export

TO-DO: Review the proposed models and document list of possible errors.

Note: All this services can be implemented using a Factory Pattern, to create an instance associated to the current wallet.

Backing Services

This services are essentials for the correct operation of Copay, however their implementation should be easily changable. The copay core must offer default implementations but pluggable backing services should be supported.

  1. P2P Networking: Handles connection between peers and sync of data. (PeerJS, Permanent Mesages Queues, etc.)
  2. Blockchain: Connects to a trusted node and gets information about the blockchain. (Insight, Blockchain.info, Bitcoind)
  3. Storage: Medium used for storing the encripted wallet. (Localstorage, mongodb, leveldb)

Conclusions

The proposed architecture improves testing and code organization, also allows copay functionalities to be used by servers, custom signing services and third parties who wants to integrate their services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment