Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make js look great again #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions 01_channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ Participants commit a specific state between them to a blockchain to start a cha

All users have payment channels with everyone else by default with `insurance=0 ondelta=0 offdelta=0` and no payments can happen, so we don't use the term "open a channel". To start paying through a channel Alice must send a tx onchain that deposits `insurance` into the channel with Bank. Since all tx in Fair are batched, this code will create a new deposit.

`batch.push('depositTo', asset, [amountToDeposit, giveTo, withPartner, invoice])`
```js
batch.push('depositTo', asset, [amountToDeposit, giveTo, withPartner, invoice])`
```

Let's say asset=1 (FRD), amountToDeposit=$6, giveTo=user id 5, withPartner=user id 7 and `invoice` is empty (this field exists for paying large purchases with direct onchain settlement).

Expand All @@ -26,7 +28,7 @@ For simplicity we want to have deterministic channel where two users can have on

Let's say 5 happened to have lower pubkey and is left one. How do we deposit to 5@7? This is actual code:

```
```js
ins.insurance += amount
if (compared == -1) ins.ondelta += amount
```
Expand Down Expand Up @@ -59,7 +61,7 @@ Alright, now the ondelta is 6, insurance is 6 and offdelta is still 0.

This function is used to define what parts of balance are insured/uninsured for you and counterparty.

```
```js
resolveChannel = (insurance, delta, is_left = true) => {
var parts = {
// left user promises only with negative delta, scenario 3
Expand Down Expand Up @@ -116,7 +118,7 @@ resolveChannel = (insurance, delta, is_left = true) => {

In order to make our first payment, we must figure out the common canonical representation of a state channel. We don't need to bother to use actual onchain tx like they do in Lightning, we also don't want to send always changing balance of the counterparty like in Raiden. All we care about is offdelta.

```
```js
var state = [
map('disputeWith'),
[
Expand Down Expand Up @@ -147,7 +149,7 @@ Now both parties know that there's collateral/insurance locked between them onch

Internally all payments are expressed in flush_channel and update_channel files. Flush channel finds all pending transitions and applies them on the state, then send the request of following format:

```
```js
me.envelope(
map('update'), // denotes that it is an update message
asset, // asset id we are operating with
Expand Down
2 changes: 1 addition & 1 deletion 03_rebalance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ If Alice or Bob are unresponsive or gone offline, the bank can start a dispute o

Now bank has accumulated $1600 in withdrawals, $1550 in deposits, and broadcasts a single batched onchain tx which roughly looks like:

```
```js
[
"batch",
nonce...
Expand Down
6 changes: 4 additions & 2 deletions 05_consensus.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ Now let's try to build the specification around that.

Each round we deterministically decide who proposes a new block. That's pretty easy: we take Unix timestamp, divide by blocktime:

`epoch = Math.floor(timestamp() / blocktime)`
```js
epoch = Math.floor(timestamp() / blocktime)

`current_validator = epoch % validators.length`
current_validator = epoch % validators.length
```

This validator must broadcast to everyone else signed block built from tx taken from their mempool, receive signatures back, and as soon as they receive 2/3+ of sigs they can broadcast to all users valid and final block, prepended with commitments from other validators:

Expand Down
10 changes: 5 additions & 5 deletions 09_receive_and_pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You can modify the port Fair daemon occupies on your server. Pass `-pXXXX` to th

Put something like this helper in util libs:

```
```js
FairRPC = (params, cb) => {
http.get('http://127.0.0.1:8002/rpc?auth_code=AUTH_CODE&'+params, (res) => {
let rawData = '';
Expand All @@ -45,15 +45,15 @@ For someone to pay they need destination address, an amount and optional invoice

You can read your own address at bootstrap or have it hardcoded

```
```js
FairRPC('method=getinfo', (r)=>{
console.log('My address', r.address)
})
```

Once you have an address, you can make a button "Pay with Fair" or simply show the address having onclick action. This action should open user's local Fair wallet with all the values prefilled:

```
```js
var fs_origin = 'http://127.0.0.1:8001'
deposit.onclick = function(){
fs_w = window.open(fs_origin+'#wallet?invoice='+id+"&address=${address}&amount=10&asset=1")
Expand Down Expand Up @@ -83,7 +83,7 @@ The user's wallet makes a postMessage event to the opener to notify your app's a

The app that integrates Fair should set up a periodic pulling request to the daemon e.g. every 1 second:

```
```js
FairRPC('method=receivedAndFailed', (r)=>{
if (!r.receivedAndFailed) return
for (obj of r.receivedAndFailed) {
Expand Down Expand Up @@ -131,7 +131,7 @@ Then make a request to your local Fair daemon with **following parameters carefu
- `params[invoice]` - set the same invoice you would use to receive assets from this user, so if the payment fails it will be credited back according to this invoice.
- `params[asset]` - id of asset to operate in. 1 for FRD, 2 for FRB and so on.

```
```js
FairRPC('method=send&params[address]=ADDRESS&params[asset]=1&params[amount]=200&params[invoice]=INVOICE', (r)=>{
// sent
})
Expand Down
36 changes: 18 additions & 18 deletions 10_genesis.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ It's recommended to use Prettier, you can add it to Sublime Text (don't forget t

Perfect way to run new code against old blockchain:

```
rm -rf fair
id=fair
f=Fair-1.tar.gz
mkdir $id && cd $id && curl https://fairlayer.com/$f -o $f
tar -xzf $f && rm $f
ln -s ~/work/fair/node_modules
ln -s ~/work/fair/wallet/node_modules wallet/node_modules
rm -rf ./src
cp -r ~/work/fair/src src
node fair -p8001
```sh
$ rm -rf fair
$ id=fair
$ f=Fair-1.tar.gz
$ mkdir $id && cd $id && curl https://fairlayer.com/$f -o $f
$ tar -xzf $f && rm $f
$ ln -s ~/work/fair/node_modules
$ ln -s ~/work/fair/wallet/node_modules wallet/node_modules
$ rm -rf ./src
$ cp -r ~/work/fair/src src
$ node fair -p8001
```

## Reading the codebase
Expand All @@ -59,33 +59,33 @@ Start with `/src/fair.js`.

## Deploy FL

```
./deploy
```sh
$ ./deploy
```

Ensure https://fairlayer.com/ opens.

#### Troubleshooting

```sh
./l
# prints FL logs
$ ./l
```

## Reconfigure caddy

```
vi Caddyfile
caddy -service restart
```sh
$ vi Caddyfile
$ caddy -service restart
```

Ensure https://fairlayer.com/ opens.

#### Troubleshooting

```sh
journalctl --boot -u Caddy.service
# prints Caddy logs
$ journalctl --boot -u Caddy.service
```

# [2. Step by step](/11_step_by_step.md) / [Home](/README.md)