var db = require('../../config/initializers/sequelize');
var Sequelize = require("sequelize");

var RippleAddress = db.define('ripple_address', {
  id: { 
		type: Sequelize.INTEGER, 
		primaryKey: true,
		autoIncrement: true,
	},
  user_id: { type: Sequelize.INTEGER, notNull: true },
  managed: { type: Sequelize.BOOLEAN, notNull: true, default: false },
  address: { type: Sequelize.STRING, notNull: true },
  secret: { type: Sequelize.STRING },
  tag: { type: Sequelize.STRING },
  type: { type: Sequelize.STRING },
  previous_transaction_hash: { type: Sequelize.STRING }
}, {
  classMethods: {
    createHosted: function(user, fn){
      console.log('create hosted called');
      RippleAddress.find({ where: { type: 'hot' }}).complete(function(err, address) {
        console.log('hot wallet', address);
        if (address) {
          var hotWallet = address; 
          RippleAddress.create({
            type: 'hosted',
            managed: true,
            user_id: user.id,
            tag: user.id,
            address: hotWallet.address
          }).complete(function(err, address){
            console.log(err);
            console.log('new ripple address', address);
            fn(err, address);
          });
        } else { fn(err, null) }
      });
    }
  }
});

module.exports = RippleAddress;

@@ -599,84 +599,1436 @@
     
-createHosted: function(user, fn)%7B%0A      console.log('create hosted called');
+getHot: function(fn)%7B%0A      RippleAddress.find(%7B where: %7B type: 'hot' %7D%7D).complete(fn);%0A    %7D,%0A    getCold: function(fn)%7B%0A      RippleAddress.find(%7B where: %7B type: 'cold' %7D%7D).complete(fn);%0A    %7D,%0A    createHot: function(adminId, hotWallet, fn) %7B%0A      RippleAddress.create(%7B%0A        managed: true,%0A        user_id: adminId,%0A        type: 'hot',%0A        address: hotWallet.address,%0A        secret: hotWallet.secret%0A      %7D).complete(fn)%0A    %7D,%0A    createCold: function(fn) %7B%0A      RippleAddress.create(%7B%0A        managed: true,%0A        user_id: admin.id,%0A        type: 'cold',%0A        address: hotWallet.address,%0A        secret: hotWallet.secret%0A      %7D).complete(fn)%0A    %7D,%0A    setHot: function(adminId, hotWallet, fn) %7B%0A      var Klass = this;%0A      RippleAddress.getHot(function(err, address)%7B%0A        if (address) %7B%0A          address.destroy().success(function()%7B%0A            Klass.createHot(adminId, hotWallet, fn);%0A          %7D);%0A        %7D else %7B  %0A          Klass.createHot(adminId, hotWallet, fn);%0A        %7D%0A      %7D);%0A    %7D,%0A    setCold: function(adminId, coldWallet, fn) %7B%0A      var Klass = this;%0A      RippleAddress.getCold(function(err, address)%7B%0A        if (address) %7B%0A          address.destroy().success(function()%7B%0A            Klass.createCold(adminId, hotWallet, fn);%0A          %7D);%0A       %7D else %7B  %0A          Klass.createCold(adminId, hotWallet, fn);%0A        %7D%0A      %7D);%0A    %7D,%0A    createHosted: function(user, fn)%7B
 %0A   
@@ -2114,52 +2114,8 @@
 ) %7B%0A
-        console.log('hot wallet', address);%0A
     
@@ -2352,16 +2352,16 @@
 address%0A
+
         
@@ -2402,94 +2402,8 @@
 s)%7B%0A
-            console.log(err);%0A            console.log('new ripple address', address);%0A
     

Add RippleAddress methods for get/create hot/cold wallets.