Skip to content

Instantly share code, notes, and snippets.

@justmoon
Last active May 23, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save justmoon/e07ed137c98d8272231d6e549a876e56 to your computer and use it in GitHub Desktop.
Save justmoon/e07ed137c98d8272231d6e549a876e56 to your computer and use it in GitHub Desktop.
SPP Example
// P2P payment
import { Client } from 'spp'
const client = new Client({
account: 'https://red.ilpdemo.org/accounts/alice',
auth: {
password: 'secret'
}
})
setInterval(() => {
client.send({
destination: 'bob@blue.ilpdemo.org',
sourceAmount: '0.01',
memo: 'Still love you!',
onQuote: (quote) => {
console.log('Received a quote; recipient will receive ' + quote.destinationAmount)
}
}).then((payment) => {
console.log('Payment was ' + payment.result ? 'successful' : 'not successful')
console.log('')
})
}, 1500)
// P2P payment
import { Server } from 'spp'
import http from 'http'
const server = new Server({
account: 'https://blue.ilpdemo.org/accounts/bob',
auth: {
password: 'secret'
},
httpServer: http.createServer(3000),
conditionSecret: 'hardtoguess'
})
client.acceptPeerPayments()
client.on('incoming', (payment) => {
console.log('Received ' + payment.amount + ' bucks!')
console.log(payment.sender + ' says: ' + payment.memo)
})
// Paying an invoice
import { Client } from 'spp'
const client = new Client({
username: 'alice@red.ilpdemo.org',
password: 'secret'
})
client.send({
destination: '213@amazon.com',
maxSourceAmount: '110'
})
// Receiving invoice payments
import { Server } from 'spp'
const client = new Client({
username: 'bob@blue.ilpdemo.org',
password: 'secret'
})
client.acceptInvoicePayment(async function (receiverId) {
const invoice = await db.getInvoice(receiverId)
if (invoice.paid)
return {
amount: invoice.amount
}
})
client.on('incoming', (payment) => {
console.log('Received ' + payment.amount + ' bucks!')
console.log(payment.sender + ' says: ' + payment.memo)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment