-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.js
More file actions
32 lines (28 loc) · 1.08 KB
/
example.js
File metadata and controls
32 lines (28 loc) · 1.08 KB
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
const { PaymentServer, createSocket } = require('.')
const IlpPluginBtp = require('ilp-plugin-btp')
const crypto = require('crypto')
async function run () {
const receiverPlugin = new IlpPluginBtp({ server: `btp+wss://:${crypto.randomBytes(16).toString('hex')}@amundsen.ilpdemo.org:1810` })
const server = new PaymentServer({
plugin: receiverPlugin,
secret: crypto.randomBytes(32)
})
await server.connect()
const receiverSocket = server.createSocket({
enableRefunds: true
})
receiverSocket.setMaxBalance(4000)
const senderPlugin = new IlpPluginBtp({ server: `btp+wss://:${crypto.randomBytes(16).toString('hex')}@amundsen.ilpdemo.org:1810` })
const senderSocket = await createSocket({
plugin: senderPlugin,
destinationAccount: receiverSocket.destinationAccount,
sharedSecret: receiverSocket.sharedSecret
})
senderSocket.setMinAndMaxBalance(-5000)
senderSocket.on('chunk', () => {
if (senderSocket.balance === '-4000' && senderSocket.minBalance !== '0') {
senderSocket.setMinAndMaxBalance(0)
}
})
}
run().catch(err => console.log(err))