0

Am getting the following error for the below code. Any insights greatly appreciated. Not quite sure what is causing this as I have ample other User Defined Types throughout the application which have not caused this behaviour.

Let me know if any more information is needed to be able to offer guidance/suggestions.

    [error] /Users/dan_mi_sun/projects/openblockchain/src/main/scala/org/dyne/danielsan/openblockchain/data/model/GenericVinModel.scala:35: type mismatch;
    [error]  found   : org.dyne.danielsan.openblockchain.data.model.VinsModel
    [error]  required: com.websudos.phantom.CassandraTable[org.dyne.danielsan.openblockchain.data.model.VinsModel,org.dyne.danielsan.openblockchain.data.entity.Vin]
    [error] Note: org.dyne.danielsan.openblockchain.data.model.ConcreteVinsModel <: org.dyne.danielsan.openblockchain.data.model.VinsModel (and org.dyne.danielsan.openblockchain.data.model.VinsModel <: com.websudos.phantom.CassandraTable[org.dyne.danielsan.openblockchain.data.model.ConcreteVinsModel,org.dyne.danielsan.openblockchain.data.entity.Vin]), but class CassandraTable is invariant in type T.
    [error] You may wish to define T as +T instead. (SLS 4.5)
    [error]   object scriptsig extends JsonListColumn[VinsModel, Vin, ScriptSig](this) {
    [error]                                                                      ^
    [error] one error found

import com.websudos.phantom.CassandraTable
import com.websudos.phantom.dsl._
import org.json4s._
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.write

import scala.concurrent.Future

case class ScriptSig(asm: String,
                     hex: String)

case class Vin(txid: String,
               vout: Int,
               scriptSig: List[ScriptSig],
               sequence: Int)

sealed class VinsModel extends CassandraTable[ConcreteVinsModel, Vin] {

  implicit val formats = Serialization.formats(NoTypeHints)

  override def fromRow(row: Row): Vin = {
    Vin(
      txid(row),
      vout(row),
      scriptSig(row),
      sequence(row)
    )
  }

  object txid extends StringColumn(this)

  object vout extends IntColumn(this)

  object scriptSig extends JsonListColumn[VinsModel, Vin, ScriptSig](this) {
    override def fromJson(obj: String): ScriptSig = {
      parse(obj).extract[ScriptSig]
    }

    override def toJson(obj: ScriptSig): String = {
      write(obj)
    }

  }

  object sequence extends IntColumn(this)
}

abstract class ConcreteVinsModel  extends VinsModel  with RootConnector {

  override val tableName = "vins"

  def insertNew(v: Vin): Future[ResultSet] = insertNewVin(v).future()

  def insertNewVin(v: Vin) = {
    insert
      .value(_.txid, v.txid)
      .value(_.vout, v.vout)
      .value(_.scriptSig, v.scriptSig)
      .value(_.sequence, v.sequence)
  }
}
dan-mi-sun
  • 551
  • 2
  • 4
  • 18
  • 1
    What JSON lib are you using? please share your imports – Rhys Bradbury May 20 '16 at 14:42
  • In more recent versions of phantom you no longer need to provide 3 arguments to the `JsonListColumn`, one should be enough. Even if that's not true, what you are missing is that you need to put `ConcreteVinsModel` inside `JsonListColumn` – flavian May 31 '16 at 12:56

1 Answers1

0

This line:

object scriptSig extends JsonListColumn[VinsModel, Vin, ScriptSig](this)

should be

object scriptSig extends JsonListColumn[ConcreteVinsModel, Vin, ScriptSig](this)
flavian
  • 28,161
  • 11
  • 65
  • 105