0.3.150 • Published 4 years ago

simple.swap.core v0.3.150

Weekly downloads
8
License
ISC
Repository
github
Last release
4 years ago

simple swap core

Simplest usage:

//const swap = require('simple.swap.core')
const swap = require('./../src/index')

const {
  on: { onFinish },
  room: { ready },
  orders: { request, subscribe },
  swap: { onStep, start },
} = swap.helpers

const { wallet, auth, room, orders } = swap.setup

const doSwap = async order => {
  console.log('new order', order.id)
  if (order.buyAmount > 10) {
    const swap = await request(order)

    console.log('starting swap', swap.flow._flowName, swap.id)

    start(swap)

    await onFinish(swap)

    console.log('finished swap', swap.id)
  }
}

(async () => {
  const info = await wallet.getBalance()
  console.log('balance:', info)

  await ready(room)
  console.log('info:', wallet.view())

  orders.on('new orders', orders => orders.map(doSwap))
  orders.on('new order', doSwap)
})()

Examples

Go to src/ directory, then:

npm i

Go to examples/ directory, then:

npm i
cp .env.example .env
npm start

In the .env:

  • ROOT_DIR is where the credentials are stored. If omitted, . will be used
  • ACCOUNT or SERVER_ID is the name of the account directory inside $ROOT_DIR:

    $ROOT_DIR/.storage/$ACCOUNT $ROOT_DIR/.ipfs/$ACCOUNT

    Will be generated if not given.

  • NETWORK is one of the mainnet, testnet. Default = testnet

  • OFFSET is better to be omitted!

    this variable should be consistent between different scripts if you wish to access the same IPFS peer id. By default OFFSET is a process.argv[1], which is usually the name of the script you run: node bot.js => bot.js, so if you launching the same file, it will match.

0.3.150

4 years ago

0.3.145

4 years ago

0.3.144

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.141

4 years ago

0.3.143

4 years ago

0.3.142

4 years ago

0.3.14

4 years ago

0.3.12

4 years ago

0.3.11

5 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.5-7

5 years ago

0.3.5-6

5 years ago

0.3.5-5

5 years ago

0.3.5-4

5 years ago

0.3.5-3

5 years ago

0.3.5-2

5 years ago

0.3.5-1

5 years ago

0.3.5

5 years ago

0.3.4-8

5 years ago

0.3.4-7

5 years ago

0.3.4-6

5 years ago

0.3.4-5

5 years ago

0.3.4-4

5 years ago

0.3.4-3

5 years ago

0.3.4-2

5 years ago

0.3.4-1

5 years ago

0.3.4

5 years ago

0.3.3-1

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.1-rc31

5 years ago

0.3.1-rc30

5 years ago

0.3.1-rc29

5 years ago

0.3.1-rc28

5 years ago

0.3.1-rc27

5 years ago

0.3.1-rc26

5 years ago

0.3.1-rc25

5 years ago

0.3.1-rc24

5 years ago

0.3.1-rc23

5 years ago

0.3.1-rc22

5 years ago

0.3.1-rc21

5 years ago

0.3.0-rc20

5 years ago

0.3.0-rc19

5 years ago

0.3.0-rc18

5 years ago

0.3.0-rc17

5 years ago

0.3.0-rc16

5 years ago

0.3.0-rc15

5 years ago

0.3.0-rc14

5 years ago

0.3.0-rc13

5 years ago

0.3.0-rc12

5 years ago

0.3.0-rc11

5 years ago

0.3.0-rc10

5 years ago

0.3.0-rc9

5 years ago

0.3.0-rc8

5 years ago

0.3.0-rc7

5 years ago

0.3.0-rc6

5 years ago

0.3.0-rc5

5 years ago

0.3.0-rc4

5 years ago

0.3.0-rc3

5 years ago

0.3.0-rc2

5 years ago

0.3.0-rc1

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago