lib/transactions.js
/**
 * Resident to bank transaction
 * @param {org.decentralized.energy.network.CashToCoins} UpdateValues
 * @transaction
 */
Resident to bank transaction
@param {org.decentralized.energy.network.CashToCoins} UpdateValues
@transaction
Resident to bank transaction @param { org . decentralized . energy . network . CashToCoins } UpdateValues @transaction
function CashToCoins(UpdateValues) {
    var coinsChange = (UpdateValues.cashRate * UpdateValues.cashValue);
    UpdateValues.coinsInc.value = UpdateValues.coinsInc.value + coinsChange;
    UpdateValues.coinsDec.value = UpdateValues.coinsDec.value - coinsChange;
    UpdateValues.cashInc.value = UpdateValues.cashInc.value + UpdateValues.cashValue;
    UpdateValues.cashDec.value = UpdateValues.cashDec.value - UpdateValues.cashValue;
    return getAssetRegistry('org.decentralized.energy.network.Coins')
        .then(function (assetRegistry) {
            return assetRegistry.updateAll([UpdateValues.coinsInc,UpdateValues.coinsDec]);
        })                
        .then(function () {
            return  getAssetRegistry('org.decentralized.energy.network.Cash')
            .then(function (assetRegistry) {
                return assetRegistry.updateAll([UpdateValues.cashInc,UpdateValues.cashDec]);
            });            
        });     
}
function CashToCoins ( UpdateValues ) { var coinsChange = ( UpdateValues . cashRate * UpdateValues . cashValue ) ; UpdateValues . coinsInc . value = UpdateValues . coinsInc . value + coinsChange ; UpdateValues . coinsDec . value = UpdateValues . coinsDec . value - coinsChange ; UpdateValues . cashInc . value = UpdateValues . cashInc . value + UpdateValues . cashValue ; UpdateValues . cashDec . value = UpdateValues . cashDec . value - UpdateValues . cashValue ; return getAssetRegistry ( 'org.decentralized.energy.network.Coins' ) . then ( function ( assetRegistry ) { return assetRegistry . updateAll ( [ UpdateValues . coinsInc , UpdateValues . coinsDec ] ) ; } ) . then ( function ( ) { return getAssetRegistry ( 'org.decentralized.energy.network.Cash' ) . then ( function ( assetRegistry ) { return assetRegistry . updateAll ( [ UpdateValues . cashInc , UpdateValues . cashDec ] ) ; } ) ; } ) ; }
Resident to bank transaction
 @param {org.decentralized.energy.network.CashToCoins} UpdateValues
 @transaction
Resident to bank transaction @param { org . decentralized . energy . network . CashToCoins } UpdateValues @transaction
//determine change in coins value from the rate //update values of the assets //get asset registry for Coins and Cash, and update the ledger