Skip to content

How FairCoins work in OCP

Xavi Paniello edited this page Apr 10, 2017 · 1 revision

Note: some of this will not make much sense to you if you do not understand the OCP models. You can read about them here: https://github.com/FreedomCoop/valuenetwork/wiki/Core

FairCoin Wallet and Addresses:

  • OCP has one wallet for all addresses.
  • Each EconomicAgent (such as a Freedom Coop worker) in OCP may have their own FairCoin address, all in that same wallet.
    • When a user is created for an EconomicAgent by a FreedomCoop administrator, a FairCoin address request is created which will be processed by the cron job explained below.
    • FreedomCoop administrators can also request FairCoin addresses for other agents like projects which do not have login user ids. Project coordinators can manage these addresses.

FairCoin connections to OCP models:

FairCoins:

FairCoins are a Unit of value in OCP.

FairCoin Addresses:

A FairCoin address is represented by an OCP EconomicResource that is owned by an OCP EconomicAgent. The ResourceType is FairCoin Address. The Unit of value is FairCoin. You can see them listed here: https://ocp.freedomcoop.eu/accounting/resource-type/26/

FairCoin Transactions:

  • FairCoin transactions are wrapped in OCP EconomicEvents.
  • A Freedom Coop agent with a FairCoin address can create OCP EconomicEvents to send FairCoins to any other FairCoin address.
    • These events will be processed by the cron job explained below to create and broadcast FairCoin transactions.
  • Each FairCoin address resource will have a history of all of the events that have happened to it through OCP. Each event will show its current FairCoin transaction status, and if the transaction has been broadcast, will also present a link to the transaction on the Chain.

Connecting to the FairChain:

This took a lot of trial and error, and several moving parts.

electrum-fair

You can see how this is installed and configured in Xavi's install doc.

OCP FairCoin app

Located in https://github.com/FreedomCoop/valuenetwork/tree/master/faircoin_nrp (called "nrp" because OCP was forked from a system called NRP and had not been renamed yet when this code was first created.)

  • daemon. A daemon in the system that comunicates with electrum-fair client through rpc socket and listen to commands from ocp.
  • elecrum_fair_nrp sends commands to the daemon.
  • faircoin_utils bridge between OCP and electrum_fair_nrp.

Cronjob

I was not able to call the daemon directly from the OCP Django code to create FairCoin addresses or transactions. Django just hung; the calls never returned. However, I was able to do both of those from a separate background process, which is run from a cronjob.

So when FairCoin addresses and transactions are needed, OCP creates "request" objects in the database. These request objects are picked up by the send_faircoin_requests command, which is called from the cronjob.

The command calls process_faircoin_requests, which finds the unsatisfied faircoin address and transaction requests, and then calls electrum_fair_nrp, which calls the daemon, which calls functions in electrum-fair, to get the work done.

That's a lot of moving parts. They evolved piecemeal, one part at a time, until we got things to work. Might be able to simplify if somebody rethought everything.