Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const IlpStream = require('ilp-protocol-stream')
- const createPlugin = require('ilp-plugin')
- const serverPlugin = createPlugin()
- const server = await IlpStream.createServer({
- plugin: serverPlugin
- })
- server.on('connection', (connection) => {
- console.log('server got connection')
- connection.on('stream', (stream) => {
- console.log(`server got a new stream: ${stream.id}`)
- // Set the maximum amount of money this stream can receive
- stream.setReceiveMax(10000)
- // Handle incoming money
- stream.on('money', (amount) => {
- console.log(`server stream ${stream.id} got incoming payment for: ${amount}`)
- })
- // Handle incoming data
- stream.on('data', (chunk) => {
- console.log(`server stream ${stream.id} got data: ${chunk.toString('utf8')}`)
- })
- })
- })
- // These would need to be passed from the server to the client using
- // some encrypted communication channel (not provided by STREAM)
- const { destinationAccount, sharedSecret } = server.generateAddressAndSecret()
- console.log(`server generated ILP address (${destinationAccount}) and shared secret (${sharedSecret.toString('hex')}) for client`)
Add Comment
Please, Sign In to add comment