ssb-mutual v0.1.0
ssb-mutual
Mutual credit community currency system for the secure-scuttlebutt network.
Schema
var schemas = require('ssb-mutual/schemas')type: mutual/credit
Credit another account with an amount of currency, and debit the same from the author's account.
{
type: "mutual/credit",
account: Link,
amount: number|string,
currency: string,
memo: string?,
}- account: feed id or
mutual/accountmsg id for the account to receive the credit. - amount: amount of currency to transfer. may be a number in decimal string format, or a number if this does not lose precision. may be negative.
- currency: currency type to transfer. may be a three-letter currency code, or a msg id or blob id, or some other string.
- memo: memo text for the transaction
var value = schemas.credit(account, amount, currency, memo)
sbot.publish(value, cb)debit
A debit is represented with the same message type as a credit (mutual/credit), but with a negative amount. There is a helper method in the schemas module:
var value = schemas.debit(account, amount, currency, memo)
sbot.publish(value, cb)type: mutual/account
An account, whose id may be used in the account property of a mutual/credit message instead of a feed id.
{
type: "mutual/account",
name: string?,
description: string?,
}- name: name of the account.
- description: text describing the account
When rendering an account, prefer taking the name and description from about messages targeting the account, if there are any.
var value = schemas.account(name, description)
sbot.publish(value, cb)API
var Mutual = require('ssb-mutual')
var mutual = Mutual.init(sbot, config)
mutual.getAccountBalances(account, cb)getAccountBalance: async
Get an account's balance for a currency
getAccountBalance({account, currency}, cb)
cb(err, amount)getAccountBalances: async
Get an account's balances for all currencies
getAccountBalances(account, cb)
cb(err, {<currency>: amount, ...})- account (Ref): account to get a balances for
- currency (string): currency id
- amount (string): balance the account has for that curency
getCurrencyBalances: async
Get balances of all accounts for a currency
getCurrencyBalances(currency, cb)
cb(err, {<account>: amount, ...})- currency (string): currency to get account balances for
- account (Ref): account holding a balance with this currency
- amount (string): balance the account has for this curency
streamAccountHistory: source
Get transactions to/from an account.
streamAccountHistory({account, currency, counterparty})- account (Id): id of account to get transactions to/from
- currency (string, optional): filter transactions by currency
- counterparty (Id, optional): filter transactions by other account
{
id: MsgId,
timestamp: number,
counterparty: Id,
currency: string,
amount: string,
originated: boolean,
memo: string,
private: boolean,
}- id: id of the
mutual/creditmessage - timestamp: publish time of the message
- counterparty: the other entity in the transaction
- currency: currency of the transaction
- amount: change in account's balance
- originated: whether
accountpublished this transaction (true), or didcounterparty(false). iffalse,amountis the negative of the original transaction amount. - memo: memo text for the transaction
- private: whether the transaction was in a private message (
true), or was public (false)
streamTransactions: source
streamTransactions({currency})- currency (string, optional): filter transactions by currency
{
id: MsgId,
timestamp: number,
author: FeedId,
counterparty: Id,
currency: string,
amount: string,
memo: string,
private: boolean,
}- id: id of the
mutual/creditmessage - timestamp: publish time of the message
- author: creator of the transaction
- counterparty: the other entity in the transaction
- currency: currency of the transaction
- amount: amount transfered from author to counterparty
- memo: memo text for the transaction
- private: whether the transaction was in a private message, or public
close: async
close the API and its sbot client
close([err], [cb])- err error to pass upstream, if any
References
- Intro discussion thread
- http://wiki.p2pfoundation.net/Mutual_Credit
- http://appropriate-economics.org/materials/mutualcreditmanual.html
- https://github.com/matslats/groupaccounting/wiki/Functional-Requirements
License
Copyright (c) 2017 @cel
Usage of the works is permitted provided that this instrument is retained with the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
9 years ago