aboutsummaryrefslogtreecommitdiffstats
path: root/compose.yml.sample
blob: c29d1654833573eec185743c63692e1d117d0027 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
version: '3.6'
services:
  app:
    image: asoltys/coinos-server
    container_name: app
    depends_on:
      - db
      - bc
      - cl
    command: "bun run dev"
    environment:
      NODE_OPTIONS: "--import ./hooks.js"
      NODE_ENV: development
      URL: http://localhost:5173
    ports:
      - '3119:3119'
    volumes:
      - .aws/:/root/.aws
      - ./:/home/bun/app
      - ./logs:/logs
      - ./data/bitcoin/bitcoin.conf:/bitcoin.conf
    restart: always
  bc:
    image: asoltys/bitcoin
    container_name: bc
    ports:
      - '18443:18443'
    volumes:
      - ./data/bitcoin:/home/bitcoin/.bitcoin
    restart: always
  lq:
    image: asoltys/liquid:23.x
    container_name: lq
    volumes:
      - ./data/liquid:/home/elements/.elements
    restart: always
    ports:
      - 7043:7040
  cl:
    image: asoltys/cln
    container_name: cl
    environment:
      LIGHTNINGD_NETWORK: regtest
    volumes:
      - ./data/lightning:/root/.lightning
    restart: always
  clb:
    image: elementsproject/lightningd:v23.11.1-amd64
    container_name: clb
    environment:
      LIGHTNINGD_NETWORK: regtest
    volumes:
      - ./data/lightningb:/root/.lightning
    restart: always
  clc:
    image: elementsproject/lightningd:v23.11.1-amd64
    container_name: clc
    environment:
      LIGHTNINGD_NETWORK: regtest
    volumes:
      - ./data/lightningc:/root/.lightning
    restart: always
  db:
    image: eqalpha/keydb:alpine_x86_64_v6.3.4
    container_name: db
    ports:
      - '6379:6379'
    volumes:
      - ./data/db:/data
      - ./data/db/keydb.conf:/etc/keydb/keydb.conf
    restart: always
  archive:
    image: eqalpha/keydb:alpine_x86_64_v6.3.4
    container_name: archive
    ports:
      - '6380:6379'
    volumes:
      - ./data/archive:/data
    restart: always
  nostr:
    container_name: nostr
    image: asoltys/nostr-rs-relay
    restart: always
    user: 100:100
    volumes:
      - "./data/nostr/data:/usr/src/app/db" 
      - "./data/nostr/config.toml:/usr/src/app/config.toml" 
    ports:
      - '8082:8080'
  mint:
    image: asoltys/nutshell
    container_name: mint
    ports:
      - "3338:3338"
    environment:
      - MINT_CLNREST_URL=http://cl:3010
      - MINT_CLNREST_RUNE=lC9j5Z8-x7uN3oPqEGbpcNk2yknxQ4h5To5Z2Dp8ONE9Mg==
      - MINT_BACKEND_BOLT11_SAT=CLNRestWallet
      # - MINT_BACKEND_BOLT11_SAT=FakeWallet
      - MINT_LISTEN_HOST=0.0.0.0
      - MINT_LISTEN_PORT=3338
      - MINT_PRIVATE_KEY=TEST_PRIVATE_KEY
      - MINT_CLNREST_COINOS_URL=http://app:3119
      - MINT_CLNREST_COINOS_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjYTM0YWU4LTdiMTItNDU4OS04ODMyLTUyMTNjOWVhMjc5NyIsImlhdCI6MTcyNDA0NjI3OH0.bdX1YLnpgqpjmjrkCdIdDbdmZUdViNSVrAJ0OX3ByPo
    command: ["poetry", "run", "mint"]
    volumes:
      - "/home/adam/nutshell:/app"
      - "./data/mint:/app/data/mint"
  mintb:
    image: asoltys/nutshell
    container_name: mintb
    ports:
      - "3339:3338"
    environment:
      - MINT_CLNREST_URL=http://clb:3010
      - MINT_CLNREST_RUNE=kTyXJ6yJwESVezCl4yB4z0zGMjXi11qggnKRQ4nnc2Y9MA==
      - MINT_BACKEND_BOLT11_SAT=CLNRestWallet
      # - MINT_BACKEND_BOLT11_SAT=FakeWallet
      - MINT_LISTEN_HOST=0.0.0.0
      - MINT_LISTEN_PORT=3338
      - MINT_PRIVATE_KEY=TEST_PRIVATE_KEYB
      - MINT_CLNREST_COINOS_URL=http://app:3119
      - MINT_CLNREST_COINOS_JWT=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjYTM0YWU4LTdiMTItNDU4OS04ODMyLTUyMTNjOWVhMjc5NyIsImlhdCI6MTcyNDA0NjI3OH0.bdX1YLnpgqpjmjrkCdIdDbdmZUdViNSVrAJ0OX3ByPo
    command: ["poetry", "run", "mint"]
    volumes:
      - "/home/adam/nutshell:/app"
      - "./data/mint:/app/data/mint"
* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
#= require js/jquery-1.8.2.min.js
#= require js/moment.min.js
#= require js/qrcode.js
#= require js/bootstrap.min.js
#= require js/2.5.3-crypto-sha256.js
#= require js/jsbn.js
#= require js/jsbn2.js
#= require js/bitcoinjs-min.js
#= require js/bitcoinjs-min-1.0.2.js
#= require js/sha512.js
#= require js/modsqrt.js
#= require js/rfc1751.js
#= require js/bip32.js

EXCHANGE_FAIL = "Error fetching exchange rate"
SOCKET_FAIL = "Error connecting to payment server"
ADDRESS_FAIL = "Invalid address"

g = exports ? this

$(->
  $.ajax(
    url: $('#user').val() + '.json', 
    dataType: 'json',
    success: (data) ->
      g.user = data
      setup()
  )

  $('#tip button').click(->
    value = $(this).html().slice(0, -1)
    $(this).siblings().css('font-weight','normal').removeClass('active')
    $(this).css('font-weight','bold')
    g.tip = 1 + (parseFloat(value)/100)
    updateTotal()
  )

  $('#amount').keyup(updateTotal)
  $('#amount').focus(->
    $('#received').hide()
    $('#payment').fadeIn('slow')
    $(this).val('')
    updateTotal()
  )

  $('#received').click(-> window.location = "/#{g.user.username}/report")
)

setup = ->
  g.errors = []
  g.amount_requested = 0
  g.tip = 1
  g.user.address or= ''
  g.user.commission or= 0
  g.user.currency or= 'CAD'
  g.user.symbol or= 'quadrigacx'
  g.user.unit or= 'BTC'

  if g.user.title 
    $('#title').html("<a href='/#{g.user.username}/edit'>#{g.user.title}</a>").show()

  if g.user.logo
    $('#logo').attr('src', g.user.logo).show()

  getAddress()

  $('#symbol').html(g.user.currency)
  $('#currency').html(g.user.currency)
  $('#unit').html(g.user.unit)
  $('#received').hide()
  $('#tip button').first().click()

  fetchExchangeRate()
  listen()

fetchExchangeRate = ->
  $.ajax(
    url: "ticker?currency=#{g.user.currency}&symbol=#{g.user.symbol}&type=bid",
    success: (exchange) -> 
      if exchange?
        clear(EXCHANGE_FAIL)
      else
        fail(EXCHANGE_FAIL)
        return

      g.exchange = (exchange - exchange * g.user.commission * 0.01).toFixed(2)
      $('#exchange').html(g.exchange)
      updateTotal()

      unless g.setupComplete
        $('#amount').focus()
        g.setupComplete = true

    error: -> fail(EXCHANGE_FAIL)
  )
  setTimeout(fetchExchangeRate, 900000)

updateTotal = ->
  precision = 9 - multiplier().toString().length
  amount = parseFloat($('#amount').val() * g.tip)
  total = (amount * multiplier() / g.exchange).toFixed(precision)
  g.amount_requested = (amount / g.exchange).toFixed(8)

  unless $.isNumeric(total)
    total = ''

  $('#total').html(total.toString())
  $('#qr').html('')
  new QRCode('qr', text: "bitcoin:#{g.user.address}?amount=#{g.amount_requested.toString()}", width: 320, height: 320)

listen = ->
  setTimeout(listen, 10000)

  unless g.blockchain and g.blockchain.readyState is 1
    g.blockchain = new WebSocket("wss://ws.blockchain.info/inv")

    g.blockchain.onopen = -> 
      $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal')
      g.blockchain.send('{"op":"addr_sub", "addr":"' + g.user.address + '"}')
    
    g.blockchain.onerror =  ->
      $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
      g.blockchain = null
      fail(SOCKET_FAIL)

    g.blockchain.onclose = ->
      $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
      g.blockchain = null
      fail(SOCKET_FAIL)

    g.blockchain.onmessage = (e) ->
      results = eval('(' + e.data + ')')
      amount = 0
      txid = results.x.hash

      return if txid == g.last
      g.last = txid
      
      $.each(results.x.out, (i, v) ->
        if (v.addr == g.user.address) 
          amount += v.value / 100000000
      )

      logTransaction(txid, amount)

  unless g.btcd and g.btcd.readyState is 1
    g.btcd = new WebSocket("wss://coinos.io/ws")

    g.btcd.onopen = -> 
      $('#connection').fadeIn().removeClass('glyphicon-exclamation-sign').addClass('glyphicon-signal')
      msg = JSON.stringify { jsonrpc: "1.0", id: "coinos", method: 'notifyreceived', params: [[g.user.address]] }
      g.btcd.send(msg)
    
    g.btcd.onerror =  ->
      $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
      g.btcd = null

    g.btcd.onclose = ->
      $('#connection').addClass('glyphicon-exclamation-sign').removeClass('glyphicon-signal')
      g.btcd = null

    g.btcd.onmessage = (e) ->
      data = JSON.parse(e.data)
      amount = 0

      if data.result
        txid = data.result.txid
        return if txid == g.last
        g.last = txid

        for output in data.result.vout
          if g.user.address in output.scriptPubKey.addresses
            amount += parseFloat(output.value)

        logTransaction(txid, amount)

      if data.method and data.method is 'recvtx' and data.params.length is 1
        msg = JSON.stringify { jsonrpc: "1.0", id: "coinos", method: 'decoderawtransaction', params: [data.params[0]] }
        g.btcd.send(msg)

logTransaction = (txid, amount) ->
  if $('#received').is(":hidden") and amount >= g.amount_requested
    $('#amount').blur()
    $('#payment').hide()
    $('#received').fadeIn('slow')
    $('#chaching')[0].play()
    g.user.index++

    $.post("/#{g.user.username}/transactions",
      txid: txid,
      address: g.user.address,
      date: moment().format("YYYY-MM-DD HH:mm:ss"),
      received: amount,
      exchange: g.exchange
    )

    getAddress()

getAddress = ->
  try
    bitcoin.Address.fromBase58Check(g.user.pubkey)
    g.user.address = g.user.pubkey
  catch
    try
      bip32 = new BIP32(g.user.pubkey)
      i = g.user.index
      result = bip32.derive("m/0/#{i}")
      hash160 = result.eckey.pubKeyHash
      g.user.address = (new Bitcoin.Address(hash160)).toString()
    catch
      fail(ADDRESS_FAIL)

  s = """
    <a href='/#{g.user.username}/report'>#{g.user.address}</a> 
    <a href='http://blockchain.info/address/#{g.user.address}' target='_blank'>
      <img src='/assets/img/blockchain.png' />
    </a>
  """
  $('#address').html(s)

fail = (msg) ->
  g.errors.push(msg)
  g.errors = g.errors.uniq()
  $('#error').show().html(g.errors.toString())
  
clear = (msg) ->
  i = g.errors.indexOf(msg)
  g.errors.splice(i, 1) if i >= 0
  if (g.errors.length > 0)
    $('#error').show().html(g.errors.toString())
  else
    $('#error').hide()
    $('#calculator').fadeIn('slow')

Array::uniq = ->
  output = {}
  output[@[key]] = @[key] for key in [0...@length]
  value for key, value of output

multiplier = ->
  switch g.user.unit
    when 'BTC' then 1
    when 'mBTC' then 1000
    when 'µBTC' then 1000000
    when 'bits' then 1000000
    when 'satoshis' then 100000000