Exemple #1
0
 data.users.create(userOpts, function(err, user) {
   if (err) { sqlTransaction.rollback(); fn(err, null); return; }
   var addressOpts = { 
     user_id: user.id,
     address: opts.ripple_address,
     managed: false,
     type: 'independent'
   };  
   data.rippleAddresses.create(addressOpts, function(err, ripple_address) {
   if (err) { sqlTransaction.rollback(); fn(err, null); return; }
     data.externalAccounts.create({ name: 'default', user_id: user.id }, function(err, account){
       if (err) { fn(err, null); return; }
       var addressOpts = { 
         user_id: user.id,
         address: config.get('COLD_WALLET'),
         managed: true,
         type: 'hosted',
         tag: account.id
       };  
       data.rippleAddresses.create(addressOpts, function(err, hosted_address) {
         if (err) { sqlTransaction.rollback(); fn(err, null); return; }
         var response = user.toJSON();
         response.ripple_address = ripple_address;
         response.external_account = account;
         response.hosted_address = hosted_address;
         sqlTransaction.commit();
         fn(err, response);
       }); 
     }); 
   }); 
 }); 
function setHotWallet(address, secret, fn) {
  var rippleAddress = address;

  function saveHotWallet(address) {
    var key = 'HOT_WALLET';
    config.set(key, {
      address: address.address,
      secret: secret,
      id: address.id
    });
    config.save(function (){
      var hot_wallet = config.get(key);
      fn(null, hot_wallet);
    });
  }
  data.rippleAddresses.read({ address: rippleAddress }, function(err, address) {
    if (err) {
      data.rippleAddresses.create({
        type: 'hot',
        managed: true,
        address: rippleAddress
      }, function(err, address) {
        saveHotWallet(address);
      });
    } else {
      saveHotWallet(address);
    }
  });
}
 data.rippleAddresses.read({ address: rippleAddress }, function(err, address) {
   if (err) {
     data.rippleAddresses.create({
       type: 'hot',
       managed: true,
       address: rippleAddress
     }, function(err, address) {
       saveHotWallet(address);
     });
   } else {
     saveHotWallet(address);
   }
 });
function setHotWallet(address, secret){
  gateway.rippleAddresses.setHotWallet(address, secret, console.log);
}