Skip to content

Instantly share code, notes, and snippets.

@emschwartz
Created May 18, 2018 04:04
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save emschwartz/cc3f3ae6d219efb49a730ebfadb00b64 to your computer and use it in GitHub Desktop.
STREAM Server Snippet
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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment