lib/transactions.js
/**
 * Energy to Coins transaction
 * @param {org.decentralized.energy.network.EnergyToCoins} UpdateValues 
 * @transaction
 */
Energy to Coins transaction
@param {org.decentralized.energy.network.EnergyToCoins} UpdateValues
@transaction
Energy to Coins transaction @param { org . decentralized . energy . network . EnergyToCoins } UpdateValues @transaction
function EnergyToCoins(UpdateValues) {
    var coinsChange = (UpdateValues.energyRate * UpdateValues.energyValue);
    UpdateValues.coinsInc.value = UpdateValues.coinsInc.value + coinsChange;
    UpdateValues.coinsDec.value = UpdateValues.coinsDec.value - coinsChange;
    UpdateValues.energyInc.value = UpdateValues.energyInc.value + UpdateValues.energyValue;
    UpdateValues.energyDec.value = UpdateValues.energyDec.value - UpdateValues.energyValue;
    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.Energy')
            .then(function (assetRegistry) {
                return assetRegistry.updateAll([UpdateValues.energyInc,UpdateValues.energyDec]);
            });            
        });        
}
function EnergyToCoins ( UpdateValues ) { var coinsChange = ( UpdateValues . energyRate * UpdateValues . energyValue ) ; UpdateValues . coinsInc . value = UpdateValues . coinsInc . value + coinsChange ; UpdateValues . coinsDec . value = UpdateValues . coinsDec . value - coinsChange ; UpdateValues . energyInc . value = UpdateValues . energyInc . value + UpdateValues . energyValue ; UpdateValues . energyDec . value = UpdateValues . energyDec . value - UpdateValues . energyValue ; 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.Energy' ) . then ( function ( assetRegistry ) { return assetRegistry . updateAll ( [ UpdateValues . energyInc , UpdateValues . energyDec ] ) ; } ) ; } ) ; }
Energy to Coins transaction
 @param {org.decentralized.energy.network.EnergyToCoins} UpdateValues
 @transaction
Energy to Coins transaction @param { org . decentralized . energy . network . EnergyToCoins } UpdateValues @transaction
//determine change in coins value from the rate //update values of the assets //get asset registry for Coins and Energy, and update on the ledger