var RippleTransaction = require('../app/models/ripple_transaction');
var RippleAddress = require('../app/models/ripple_address');
var request = require('request');
var hotWallet = null;
var nconf = require('../config/nconf.js');
var rippleRest = nconf.get('RIPPLE_REST_API');

function popCreatedRippleTransaction() {
  RippleTransaction.find({ where: [
    "transaction_state IS NULL"
  ]}).complete(function(err, transaction){
    if (transaction) {
      var payment = {
        src_address: hotWallet.address,
        dst_address: transaction.to_address,
        dst_amount: {
          currency: transaction.to_currency,
          value: transaction.to_amount,
          issuer: transaction.to_issuer
        },
        secret: hotWallet.secret
      };

      var params = {
        url: rippleRest+'/api/v1/addresses/'+hotWallet.address+'/payments',
        form: payment,
        json: true
      };

      request.post(params, function(err,resp,body){
        if ((!err) && (body.success)) {
          transaction.transaction_state = 'submitted';
          transaction.transaction_hash = body.confirmation_token;
        } else {
          transaction.transaction_state = body.error;
        }
        transaction.save().complete(function(err, transaction){
          setTimeout(popCreatedRippleTransaction, 1000);
        });
      });
    } else {
      setTimeout(popCreatedRippleTransaction, 1000);
    }
  });
}

function getHotWallet(fn) {
  RippleAddress.find({ where: { type: 'hot' }}).complete(fn);
}

getHotWallet(function(err, wallet) {
  hotWallet = wallet;
  popCreatedRippleTransaction();
});


@@ -1,134 +1,4 @@
-var RippleTransaction = require('../app/models/ripple_transaction');%0Avar RippleAddress = require('../app/models/ripple_address');%0A
 var 
@@ -31,30 +31,8 @@
 ');%0A
-var hotWallet = null;%0A
 var 
@@ -163,127 +163,119 @@
 ) %7B%0A
+%0A
   
-RippleTransaction.find(%7B where: %5B%0A    %22transaction_state IS NULL%22%0A  %5D%7D).complete(function(err, transaction)%7B%0A    if (
+adapter.getQueuedRippleTransactions(function(err, transactions) %7B%0A    if (!err) %7B%0A      for (transaction in 
 tran
@@ -281,16 +281,17 @@
 nsaction
+s
 ) %7B%0A    
@@ -288,24 +288,26 @@
 ns) %7B%0A      
+  
 var payment 
@@ -306,24 +306,26 @@
 payment = %7B%0A
+  
         src_
@@ -356,24 +356,26 @@
 ss,%0A        
+ 
+ 
 dst_address:
@@ -403,24 +403,26 @@
 ss,%0A        
+  
 dst_amount: 
@@ -433,16 +433,18 @@
         
+ 
+ 
 currency
@@ -480,16 +480,18 @@
         
+  
 value: t
@@ -508,24 +508,26 @@
 .to_amount,%0A
+  
           is
@@ -566,11 +566,15 @@
     
+  
 %7D,%0A
+  
     
@@ -604,28 +604,64 @@
 ecret%0A      
+ 
+ 
 %7D;%0A
-%0A
+      %7D%0A      if (transaction) %7B%0A  
       var pa
@@ -665,24 +665,26 @@
  params = %7B%0A
+  
         url:
@@ -755,16 +755,18 @@
         
+ 
+ 
 form: pa
@@ -780,16 +780,18 @@
         
+  
 json: tr
@@ -803,12 +803,16 @@
     
+ 
+ 
 %7D;%0A%0A
+  
     
@@ -871,62 +871,80 @@
     
-if ((!err) && (body.success)) %7B%0A          transaction.
+  adapter.updateRippleTransaction(%7B id: transaction.id %7D, %7B%0A            
 tran
@@ -956,18 +956,17 @@
 on_state
- =
+:
  'submit
@@ -969,17 +969,17 @@
 bmitted'
-;
+,
 %0A       
@@ -977,36 +977,26 @@
 ,%0A          
-transaction.
+  
 transaction_
@@ -999,18 +999,17 @@
 ion_hash
- =
+:
  body.co
@@ -1028,127 +1028,22 @@
 oken
-;%0A        %7D else %7B%0A          transaction.transaction_state = body.error;%0A        %7D%0A        transaction.save().complete(
+%0A          %7D, 
 func
@@ -1064,16 +1064,17 @@
 saction)
+ 
 %7B%0A      
@@ -1073,24 +1073,26 @@
 %7B%0A          
+  
 setTimeout(p
@@ -1130,28 +1130,32 @@
 0);%0A        
+  
 %7D);%0A
+  
       %7D);%0A  
@@ -1156,16 +1156,18 @@
 %7D);%0A    
+  
 %7D else %7B
@@ -1167,16 +1167,18 @@
  else %7B%0A
+  
       se
@@ -1218,24 +1218,32 @@
 ion, 1000);%0A
+      %7D%0A
     %7D%0A  %7D);%0A
@@ -1242,16 +1242,22 @@
 %7D%0A  %7D);%0A
+  %7D);%0A
 %7D%0A%0Afunct
@@ -1285,62 +1285,28 @@
 %7B%0A  
-RippleAddress.find(%7B where: %7B type: 'hot' %7D%7D).comp
+adapter.getHotWal
 let
-e
 (fn)

Remove models from outgoing payment worker.