sc/deposit.js
function getBalanceOfDepositContract(conn, depositAddress, roundIndex, cb){
    var conn = conn || db;
    if(!validationUtils.isNonemptyString(depositAddress))
        return cb("param depositAddress is null or empty string");
    if(!validationUtils.isValidAddress(depositAddress))
        return cb("param depositAddress is not a valid address");
    if(!validationUtils.isPositiveInteger(roundIndex))
        return cb("param roundIndex is not a positive integer");
    if(roundIndex === 1)
        return cb(null, 0);
    //WHERE src_unit=? AND src_message_index=? AND src_output_index=? \n\
    round.getMaxMciByRoundIndex(conn, roundIndex-1, function(lastRoundMaxMci){
        var sumBanlance = 0;
        conn.query("SELECT src_unit, src_message_index, src_output_index AS count \n\
            FROM inputs JOIN units USING(unit) \n\
            WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index>? AND address=?", 
        [lastRoundMaxMci, depositAddress], 
        function(rowsInputs) {
            conn.query("SELECT unit, is_spent, amount, message_index, output_index \n\
                FROM outputs JOIN units USING(unit) \n\
                WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index<=? AND address=?", 
            [lastRoundMaxMci, depositAddress], 
            function(rowsOutputs) {
                if (rowsOutputs.length === 0)
                    return cb(null, 0);
                for (var i=0; i<rowsOutputs.length; i++) {
                    if(rowsOutputs[i].is_spent === 0) {
                        sumBanlance += rowsOutputs[i].amount;
                    }
                    else {
                        if(rowsInputs.length > 0) {
                            for (var j=0; j<rowsInputs.length; j++) {
                                if(rowsInputs[j].src_unit === rowsOutputs[i].unit && rowsInputs[j].src_message_index === rowsOutputs[i].message_index && rowsInputs[j].src_output_index === rowsOutputs[i].output_index ){
                                    sumBanlance += rowsOutputs[i].amount;
                                }
                            }
                        }                        
                    }
                }
                cb(null, sumBanlance);
            });
        });
    });
}
function getBalanceOfDepositContract(conn, depositAddress, roundIndex, cb){
    var conn = conn || db;
    if(!validationUtils.isNonemptyString(depositAddress))
        return cb("param depositAddress is null or empty string");
    if(!validationUtils.isValidAddress(depositAddress))
        return cb("param depositAddress is not a valid address");
    if(!validationUtils.isPositiveInteger(roundIndex))
        return cb("param roundIndex is not a positive integer");
    if(roundIndex === 1)
        return cb(null, 0);
    //WHERE src_unit=? AND src_message_index=? AND src_output_index=? \n\
    round.getMaxMciByRoundIndex(conn, roundIndex-1, function(lastRoundMaxMci){
        var sumBanlance = 0;
        conn.query("SELECT src_unit, src_message_index, src_output_index AS count \n\
            FROM inputs JOIN units USING(unit) \n\
            WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index>? AND address=?", 
        [lastRoundMaxMci, depositAddress], 
        function(rowsInputs) {
            conn.query("SELECT unit, is_spent, amount, message_index, output_index \n\
                FROM outputs JOIN units USING(unit) \n\
                WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index<=? AND address=?", 
            [lastRoundMaxMci, depositAddress], 
            function(rowsOutputs) {
                if (rowsOutputs.length === 0)
                    return cb(null, 0);
                for (var i=0; i<rowsOutputs.length; i++) {
                    if(rowsOutputs[i].is_spent === 0) {
                        sumBanlance += rowsOutputs[i].amount;
                    }
                    else {
                        if(rowsInputs.length > 0) {
                            for (var j=0; j<rowsInputs.length; j++) {
                                if(rowsInputs[j].src_unit === rowsOutputs[i].unit && rowsInputs[j].src_message_index === rowsOutputs[i].message_index && rowsInputs[j].src_output_index === rowsOutputs[i].output_index ){
                                    sumBanlance += rowsOutputs[i].amount;
                                }
                            }
                        }                        
                    }
                }
                cb(null, sumBanlance);
            });
        });
    });
}
function getBalanceOfDepositContract ( conn , depositAddress , roundIndex , cb ) { var conn = conn || db ; if ( ! validationUtils . isNonemptyString ( depositAddress ) ) return cb ( "param depositAddress is null or empty string" ) ; if ( ! validationUtils . isValidAddress ( depositAddress ) ) return cb ( "param depositAddress is not a valid address" ) ; if ( ! validationUtils . isPositiveInteger ( roundIndex ) ) return cb ( "param roundIndex is not a positive integer" ) ; if ( roundIndex === 1 ) return cb ( null , 0 ) ; //WHERE src_unit=? AND src_message_index=? AND src_output_index=? \n\ round . getMaxMciByRoundIndex ( conn , roundIndex - 1 , function ( lastRoundMaxMci ) { var sumBanlance = 0 ; conn . query ( "SELECT src_unit, src_message_index, src_output_index AS count \n\
            FROM inputs JOIN units USING(unit) \n\
            WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index>? AND address=?" , [ lastRoundMaxMci , depositAddress ] , function ( rowsInputs ) { conn . query ( "SELECT unit, is_spent, amount, message_index, output_index \n\
                FROM outputs JOIN units USING(unit) \n\
                WHERE asset IS NULL AND sequence='good' AND is_stable=1 AND main_chain_index<=? AND address=?" , [ lastRoundMaxMci , depositAddress ] , function ( rowsOutputs ) { if ( rowsOutputs . length === 0 ) return cb ( null , 0 ) ; for ( var i = 0 ; i < rowsOutputs . length ; i ++ ) { if ( rowsOutputs [ i ] . is_spent === 0 ) { sumBanlance += rowsOutputs [ i ] . amount ; } else { if ( rowsInputs . length > 0 ) { for ( var j = 0 ; j < rowsInputs . length ; j ++ ) { if ( rowsInputs [ j ] . src_unit === rowsOutputs [ i ] . unit && rowsInputs [ j ] . src_message_index === rowsOutputs [ i ] . message_index && rowsInputs [ j ] . src_output_index === rowsOutputs [ i ] . output_index ) { sumBanlance += rowsOutputs [ i ] . amount ; } } } } } cb ( null , sumBanlance ) ; } ) ; } ) ; } ) ; }
Returns deposit address stable balance, Before the roundIndex

@param	{obj}	    conn      if conn is null, use db query, otherwise use conn.
@param   {String}    depositAddress
@param   {String}    roundIndex
@param   {function}	cb( err, balance ) callback function
If address is invalid, then returns err "invalid address".
If address is not a deposit, then returns err "address is not a deposit".
If can not find the address, then returns err "address not found".
@return {"base":{"stable":{Integer},"pending":{Integer}}} balance
Returns deposit address stable balance Before the roundIndex