(function (env) {
    "use strict";
    env.ddg_spice_bitcoin_transaction = function(api_result) {

        if (!api_result || api_result.status !== 200) {
            return Spice.failed('bitcoin_transaction');
        }

        var transaction = api_result.data;

        var formatDate = function(d) {
            var year = d.getFullYear();
            var month = d.getMonth() + 1;
            var day = d.getDay();
            var hours = d.getHours();
            var minutes = d.getMinutes();
            var seconds = d.getSeconds();

            return year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds; 
        };

        var formatBtc = function(amount) {
            return (amount / 100000000.0)+" BTC"
        };
        
        Spice.add({
            id: "bitcoin_transaction",
            name: "Bitcoin Transaction",
            data: {
                record_data: {
                    "Hash": transaction.hash,
                    "Date Time": formatDate(new Date(transaction.created_at)),
                    "Confirmations": transaction.confirmations,
                    "Size": (transaction.size/1024.0).toFixed(2)+" KB",
                    "Total Input": (transaction.inputs_value / 100000000.0)+" BTC",
                    "Total Output": (transaction.outputs_value / 100000000.0)+" BTC",
                    "Coinbase": transaction.is_coinbase ? 'Yes' : 'No',
                    "Fee": formatBtc(transaction.fee),
                    "BTC Transacted": (transaction.transacted_value / 100000000.0)+" BTC"
                }
            },
            meta: {
                sourceName: "Biteasy",
                sourceUrl: "https://www.biteasy.com/blockchain/transactions/" + transaction.hash
            },
            templates: {
                group: 'base',
                options: {
                    content: 'record',
                    moreAt: true,
                    rowHighlight: true
                }
            }
        });
    };
}(this));
@@ -33,243 +33,9 @@
 t%22;%0A
-    env.ddg_spice_bitcoin_transaction = function(api_result) %7B%0A%0A        if (!api_result %7C%7C api_result.status !== 200) %7B%0A            return Spice.failed('bitcoin_transaction');%0A        %7D%0A%0A        var transaction = api_result.data;%0A%0A    
+%0A
     
@@ -69,28 +69,24 @@
 ) %7B%0A        
-  
-  
 var year = d
@@ -97,28 +97,24 @@
 FullYear();%0A
-    
         var 
@@ -143,28 +143,24 @@
  1;%0A        
-  
-  
 var day = d.
@@ -165,28 +165,24 @@
 d.getDay();%0A
-    
         var 
@@ -207,28 +207,24 @@
 ();%0A        
- 
-   
 var minutes 
@@ -237,28 +237,24 @@
 tMinutes();%0A
-    
         var 
@@ -284,28 +284,24 @@
 );%0A%0A        
- 
-   
 return year+
@@ -354,20 +354,16 @@
 conds; %0A
-    
     %7D;%0A%0A
@@ -362,28 +362,24 @@
     %7D;%0A%0A    
- 
-   
 var formatBt
@@ -397,28 +397,24 @@
 n(amount) %7B%0A
-    
         retu
@@ -445,26 +445,254 @@
 )+%22 BTC%22
-%0A        %7D
+;%0A    %7D;%0A%0A    env.ddg_spice_bitcoin_transaction = function(api_result) %7B%0A%0A        if (!api_result %7C%7C api_result.status !== 200) %7B%0A            return Spice.failed('bitcoin_transaction');%0A        %7D%0A%0A        var transaction = api_result.data
 ;%0A      

Move functions outside env block