Instantly share code, notes, and snippets.

Embed
What would you like to do?
var express = require('express');
var fs = require('fs');
var app = express();
// generate a wallet. The smart-wallet manages this wallet, and the user can only control it via the smart-wallet.
// The wallet is bound to the rules of the 'resilience network'. It will automatically send dividends based on the rate that the user has set.
var RippleWallet = require('ripple-wallet')
var wallet = RippleWallet.generate();
// generate a key for the owner of this smart-wallet
var ResilienceKey = require('resilience-key-generator')
var res_key = ResilienceKey.generate();
// return the key to the process that booted up the smart-contract
// ...
// set dividendRate
var dividendRate = "" // import value from the process that booted up the smart-wallet
// container for dividendPathways
var dividendPathways = []
// subscribe to transactions for this wallet
var WebSocket = require('ws')
var websocket = new WebSocket('wss://s1.ripple.com')
var subscribeCommand = '{"command":"subscribe","id":0,"accounts":["'+wallet.address+'"]}'
websocket.on('open', function(){
console.log('Connected to the Ripple payment network')
websocket.send(subscribeCommand)
})
websocket.on('message', function(data){
console.log('message', data)
// do this stuff, https://github.com/p2p-safety-net-co-op-dividend-scheme/server/blob/master/connect_transaction.js
// the smart-wallet will perform a somewhat complex algorithm, and communicate with other smart-wallets within the 'resilience network',
// and distribute dividends based on some somewhat complex rules
// for more info, read about my swarm-redistribution algorithm on http://resilience.world
})
// connect to Ripple
var RippleRestClient = require("ripple-rest-client").Client;
var client = new RippleRestClient({
api: 'http://api.ripple.com',
account: wallet.address,
secret: wallet.secret
});
// provide some control to the user who has the smart-wallet's key (not the key to the wallet - the wallet can only be known by the contract - the contract's wallet is controlled by another key)
app.post('/sendpayment/', function (req, res) {
//first, verify cryptographic signature to gain access to the smart-wallet
if(req.body.resilience_secret_key === res_key){
//then send payment
client.sendPayment({
recipient: req.body.destination,
amount: req.body.amount,
currency: req.body.currency,
issuer: wallet.address
}, function(err, response){
console.log('payment submitted');
res.send(response);
});
}
});
app.post('/editDividendRate/', function (req, res) {
dividendRate = req.body.dividendRate
});
// define more:
// ...
// ...
app.get('/', function(req, res) {
// let the user check stuff
//res.send()
});
app.listen(process.env.PORT || 8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment