diff --git a/server/app/com/xsn/explorer/services/logic/TransactionLogic.scala b/server/app/com/xsn/explorer/services/logic/TransactionLogic.scala new file mode 100644 index 0000000..2ed93d6 --- /dev/null +++ b/server/app/com/xsn/explorer/services/logic/TransactionLogic.scala @@ -0,0 +1,24 @@ +package com.xsn.explorer.services.logic + +import com.alexitc.playsonify.core.ApplicationResult +import com.alexitc.playsonify.models.ApplicationError +import com.xsn.explorer.models.{Address, Transaction, TransactionVIN, TransactionVOUT} +import org.scalactic.{One, Or} + +class TransactionLogic { + + def getAddress(vout: TransactionVOUT, error: ApplicationError): ApplicationResult[Address] = { + val maybe = vout.address + Or.from(maybe, One(error)) + } + + def getVIN(tx: Transaction, error: ApplicationError): ApplicationResult[TransactionVIN] = { + val maybe = tx.vin + Or.from(maybe, One(error)) + } + + def getVOUT(vin: TransactionVIN, previousTX: Transaction, error: ApplicationError): ApplicationResult[TransactionVOUT] = { + val maybe = previousTX.vout.find(_.n == vin.voutIndex) + Or.from(maybe, One(error)) + } +}