From 00149965ed9bf3a8f417d13dc4e62cad8c26e000 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Fri, 16 Mar 2018 19:32:33 -0600 Subject: [PATCH] server: Add TransactionLogic --- .../services/logic/TransactionLogic.scala | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 server/app/com/xsn/explorer/services/logic/TransactionLogic.scala 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)) + } +}