Last active
May 23, 2016 17:09
-
-
Save justmoon/e07ed137c98d8272231d6e549a876e56 to your computer and use it in GitHub Desktop.
SPP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// P2P payment | |
import { Client } from 'spp' | |
const client = new Client({ | |
account: 'https://red.ilpdemo.org/accounts/alice', | |
auth: { | |
password: 'secret' | |
} | |
}) | |
setInterval(() => { | |
client.send({ | |
destination: '[email protected]', | |
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Paying an invoice | |
import { Client } from 'spp' | |
const client = new Client({ | |
username: '[email protected]', | |
password: 'secret' | |
}) | |
client.send({ | |
destination: '[email protected]', | |
maxSourceAmount: '110' | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Receiving invoice payments | |
import { Server } from 'spp' | |
const client = new Client({ | |
username: '[email protected]', | |
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