1 2
import Accounts from '../services/accounts'
2 2
import { create as createLogger } from '../common/log'
3 2
import ILDCP = require('ilp-protocol-ildcp')
4 2
const log = createLogger('ildcp-host')
5
import reduct = require('reduct')
6

7 2
export default class IldcpHostController {
8
  protected accounts: Accounts
9

10
  constructor (deps: reduct.Injector) {
11 2
    this.accounts = deps(Accounts)
12
  }
13

14
  async handle (data: Buffer, sourceAccount: string) {
15 2
    const clientAddress = this.accounts.getChildAddress(sourceAccount)
16 2
    const info = this.accounts.getInfo(sourceAccount)
17 2
    log.trace('responding to ILDCP config request. clientAddress=%s', clientAddress)
18

19 2
    return ILDCP.serve({
20
      requestPacket: data,
21 2
      handler: () => Promise.resolve({
22
        clientAddress,
23
        assetScale: info.assetScale,
24
        assetCode: info.assetCode
25
      }),
26
      serverAddress: this.accounts.getOwnAddress()
27
    })
28
  }
29
}

Read our documentation on viewing source code .

Loading