Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new fields to big_map_contents table #970

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions conseil-api/src/main/resources/metadata/tezos.babylonnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@
display-order: 3
visible: true
}
block_level {
display-priority: 0
display-order: 4
display-name: "Block Level"
data-type: "int"
visible: true
}
timestamp {
display-priority: 0
display-order: 5
data-format: "YYYY MMM DD, HH:mm"
visible: true
}
cycle {
display-priority: 0
display-order: 6
visible: true
}
period {
display-priority: 0
display-order: 7
visible: true
}
}
}
originated_account_maps {
Expand Down
23 changes: 23 additions & 0 deletions conseil-api/src/main/resources/metadata/tezos.carthagenet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,29 @@
display-order: 3
visible: true
}
block_level {
display-priority: 0
display-order: 4
display-name: "Block Level"
data-type: "int"
visible: true
}
timestamp {
display-priority: 0
display-order: 5
data-format: "YYYY MMM DD, HH:mm"
visible: true
}
cycle {
display-priority: 0
display-order: 6
visible: true
}
period {
display-priority: 0
display-order: 7
visible: true
}
}
}
originated_account_maps {
Expand Down
23 changes: 23 additions & 0 deletions conseil-api/src/main/resources/metadata/tezos.delphinet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,29 @@
display-order: 3
visible: true
}
block_level {
display-priority: 0
display-order: 4
display-name: "Block Level"
data-type: "int"
visible: true
}
timestamp {
display-priority: 0
display-order: 5
data-format: "YYYY MMM DD, HH:mm"
visible: true
}
cycle {
display-priority: 0
display-order: 6
visible: true
}
period {
display-priority: 0
display-order: 7
visible: true
}
}
}
originated_account_maps {
Expand Down
23 changes: 23 additions & 0 deletions conseil-api/src/main/resources/metadata/tezos.edonet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,29 @@
display-order: 3
visible: true
}
block_level {
display-priority: 0
display-order: 4
display-name: "Block Level"
data-type: "int"
visible: true
}
timestamp {
display-priority: 0
display-order: 5
data-format: "YYYY MMM DD, HH:mm"
visible: true
}
cycle {
display-priority: 0
display-order: 6
visible: true
}
period {
display-priority: 0
display-order: 7
visible: true
}
}
}
originated_account_maps {
Expand Down
23 changes: 23 additions & 0 deletions conseil-api/src/main/resources/metadata/tezos.mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,29 @@
display-order: 3
visible: true
}
block_level {
display-priority: 0
display-order: 4
display-name: "Block Level"
data-type: "int"
visible: true
}
timestamp {
display-priority: 0
display-order: 5
data-format: "YYYY MMM DD, HH:mm"
visible: true
}
cycle {
display-priority: 0
display-order: 6
visible: true
}
period {
display-priority: 0
display-order: 7
visible: true
}
}
}
originated_account_maps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ class GenericPlatformDiscoveryOperationsTest
KeyType.NonKey,
"big_map_contents"
),
Attribute("value", "Value", DataType.String, None, KeyType.NonKey, "big_map_contents")
Attribute("value", "Value", DataType.String, None, KeyType.NonKey, "big_map_contents"),
Attribute("block_level", "Block level", DataType.LargeInt, None, KeyType.NonKey, "big_map_contents"),
Attribute("timestamp", "Timestamp", DataType.DateTime, None, KeyType.NonKey, "big_map_contents"),
Attribute("cycle", "Cycle", DataType.Int, None, KeyType.NonKey, "big_map_contents"),
Attribute("period", "Period", DataType.Int, None, KeyType.NonKey, "big_map_contents")
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1268,8 +1268,14 @@ trait Tables {
/** Index over (blockHash) (database name fki_fk_block_hash) */
val index3 = index("fki_fk_block_hash", blockHash)

/** Index over (cycle) (database name ix_cycle) */
val index4 = index("ix_cycle", cycle)

/** Index over (delegate,priority) (database name ix_delegate_priority) */
val index4 = index("ix_delegate_priority", (delegate, priority))
val index5 = index("ix_delegate_priority", (delegate, priority))

/** Index over (delegate,priority,cycle) (database name ix_delegate_priority_cycle) */
val index6 = index("ix_delegate_priority_cycle", (delegate, priority, cycle))
}

/** Collection-like TableQuery object for table BakingRights */
Expand Down Expand Up @@ -1472,35 +1478,63 @@ trait Tables {
* @param key Database column key SqlType(varchar)
* @param keyHash Database column key_hash SqlType(varchar), Default(None)
* @param operationGroupId Database column operation_group_id SqlType(varchar), Default(None)
* @param value Database column value SqlType(varchar), Default(None) */
* @param value Database column value SqlType(varchar), Default(None)
* @param blockLevel Database column block_level SqlType(int8), Default(None)
* @param timestamp Database column timestamp SqlType(timestamp), Default(None)
* @param cycle Database column cycle SqlType(int4), Default(None)
* @param period Database column period SqlType(int4), Default(None) */
case class BigMapContentsRow(
bigMapId: scala.math.BigDecimal,
key: String,
keyHash: Option[String] = None,
operationGroupId: Option[String] = None,
value: Option[String] = None
value: Option[String] = None,
blockLevel: Option[Long] = None,
timestamp: Option[java.sql.Timestamp] = None,
cycle: Option[Int] = None,
period: Option[Int] = None
)

/** GetResult implicit for fetching BigMapContentsRow objects using plain SQL queries */
implicit def GetResultBigMapContentsRow(
implicit e0: GR[scala.math.BigDecimal],
e1: GR[String],
e2: GR[Option[String]]
e2: GR[Option[String]],
e3: GR[Option[Long]],
e4: GR[Option[java.sql.Timestamp]],
e5: GR[Option[Int]]
): GR[BigMapContentsRow] = GR { prs =>
import prs._
BigMapContentsRow.tupled((<<[scala.math.BigDecimal], <<[String], <<?[String], <<?[String], <<?[String]))
BigMapContentsRow.tupled(
(
<<[scala.math.BigDecimal],
<<[String],
<<?[String],
<<?[String],
<<?[String],
<<?[Long],
<<?[java.sql.Timestamp],
<<?[Int],
<<?[Int]
)
)
}

/** Table description of table big_map_contents. Objects of this class serve as prototypes for rows in queries. */
class BigMapContents(_tableTag: Tag)
extends profile.api.Table[BigMapContentsRow](_tableTag, Some("tezos"), "big_map_contents") {
def * = (bigMapId, key, keyHash, operationGroupId, value) <> (BigMapContentsRow.tupled, BigMapContentsRow.unapply)
def * =
(bigMapId, key, keyHash, operationGroupId, value, blockLevel, timestamp, cycle, period) <> (BigMapContentsRow.tupled, BigMapContentsRow.unapply)

/** Maps whole row to an option. Useful for outer joins. */
def ? =
((Rep.Some(bigMapId), Rep.Some(key), keyHash, operationGroupId, value)).shaped.<>({ r =>
import r._; _1.map(_ => BigMapContentsRow.tupled((_1.get, _2.get, _3, _4, _5)))
}, (_: Any) => throw new Exception("Inserting into ? projection not supported."))
((Rep.Some(bigMapId), Rep.Some(key), keyHash, operationGroupId, value, blockLevel, timestamp, cycle, period)).shaped
.<>(
{ r =>
import r._; _1.map(_ => BigMapContentsRow.tupled((_1.get, _2.get, _3, _4, _5, _6, _7, _8, _9)))
},
(_: Any) => throw new Exception("Inserting into ? projection not supported.")
)

/** Database column big_map_id SqlType(numeric) */
val bigMapId: Rep[scala.math.BigDecimal] = column[scala.math.BigDecimal]("big_map_id")
Expand All @@ -1517,6 +1551,18 @@ trait Tables {
/** Database column value SqlType(varchar), Default(None) */
val value: Rep[Option[String]] = column[Option[String]]("value", O.Default(None))

/** Database column block_level SqlType(int8), Default(None) */
val blockLevel: Rep[Option[Long]] = column[Option[Long]]("block_level", O.Default(None))

/** Database column timestamp SqlType(timestamp), Default(None) */
val timestamp: Rep[Option[java.sql.Timestamp]] = column[Option[java.sql.Timestamp]]("timestamp", O.Default(None))

/** Database column cycle SqlType(int4), Default(None) */
val cycle: Rep[Option[Int]] = column[Option[Int]]("cycle", O.Default(None))

/** Database column period SqlType(int4), Default(None) */
val period: Rep[Option[Int]] = column[Option[Int]]("period", O.Default(None))

/** Primary key of BigMapContents (database name big_map_contents_pkey) */
val pk = primaryKey("big_map_contents_pkey", (bigMapId, key))
}
Expand Down Expand Up @@ -1959,8 +2005,11 @@ trait Tables {
/** Index over (blockHash) (database name fki_fk_block_hash2) */
val index3 = index("fki_fk_block_hash2", blockHash)

/** Index over (delegate,blockLevel) (database name ix_delegate_block_level) */
val index4 = index("ix_delegate_block_level", (delegate, blockLevel))

/** Index over (delegate,slot) (database name ix_delegate_slot) */
val index4 = index("ix_delegate_slot", (delegate, slot))
val index5 = index("ix_delegate_slot", (delegate, slot))
}

/** Collection-like TableQuery object for table EndorsingRights */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package tech.cryptonomic.conseil.indexer.tezos.bigmaps

import java.sql.Timestamp

import cats.implicits._
import tech.cryptonomic.conseil.common.io.Logging.ConseilLogSupport
import tech.cryptonomic.conseil.common.tezos.Tables
Expand All @@ -16,7 +18,8 @@ import scribe._
object BigMapsConversions extends ConseilLogSupport {

// Simplify understanding in parts of the code
case class BlockBigMapDiff(get: (TezosBlockHash, Option[OperationHash], Contract.BigMapDiff)) extends AnyVal
case class BlockBigMapDiff(get: BlockTagged[(TezosBlockHash, Option[OperationHash], Contract.BigMapDiff)])
extends AnyVal
case class BlockContractIdsBigMapDiff(get: (TezosBlockHash, List[ContractId], Contract.BigMapDiff)) extends AnyVal

//input to collect token data to convert
Expand All @@ -37,20 +40,20 @@ object BigMapsConversions extends ConseilLogSupport {
implicit lazy val _: Logger = logger

def convert(from: BlockBigMapDiff) = from.get match {
case (_, _, BigMapAlloc(_, Decimal(id), key_type, value_type)) =>
case BlockTagged(ref, (_, _, BigMapAlloc(_, Decimal(id), key_type, value_type))) =>
Some(
Tables.BigMapsRow(
bigMapId = id,
keyType = Some(toMichelsonScript[MichelsonExpression](key_type.expression)),
valueType = Some(toMichelsonScript[MichelsonExpression](value_type.expression))
)
)
case (hash, _, BigMapAlloc(_, InvalidDecimal(json), _, _)) =>
case BlockTagged(ref, (hash, _, BigMapAlloc(_, InvalidDecimal(json), _, _))) =>
logger.warn(
s"Big Map Allocations: A big_map_diff allocation hasn't been converted to a BigMap on db, because the map id '$json' is not a valid number. The block containing the Origination operation is ${hash.value}"
)
None
case (_, opHash, diffAction) =>
case BlockTagged(ref, (_, opHash, diffAction)) =>
logger.warn(
s"Big Map Allocations: A big_map_diff result will be ignored by the allocation conversion to BigMap on db, because the diff action is not supported: $diffAction for operation $opHash"
)
Expand All @@ -71,22 +74,26 @@ object BigMapsConversions extends ConseilLogSupport {
implicit lazy val _: Logger = logger

def convert(from: BlockBigMapDiff) = from.get match {
case (_, opGroupHash, BigMapUpdate(_, key, keyHash, Decimal(id), value)) =>
case BlockTagged(ref, (_, opGroupHash, BigMapUpdate(_, key, keyHash, Decimal(id), value))) =>
Some(
Tables.BigMapContentsRow(
bigMapId = id,
key = toMichelsonScript[MichelsonInstruction](key.expression), //we're using instructions to represent data values
keyHash = Some(keyHash.value),
operationGroupId = opGroupHash.map(_.value),
value = value.map(it => toMichelsonScript[MichelsonInstruction](it.expression)) //we're using instructions to represent data values
value = value.map(it => toMichelsonScript[MichelsonInstruction](it.expression)), //we're using instructions to represent data values
blockLevel = Some(ref.level),
timestamp = ref.timestamp.map(Timestamp.from),
cycle = ref.cycle,
period = ref.period
)
)
case (hash, _, BigMapUpdate(_, _, _, InvalidDecimal(json), _)) =>
case BlockTagged(ref, (hash, _, BigMapUpdate(_, _, _, InvalidDecimal(json), _))) =>
logger.warn(
s"Big Map Updates: A big_map_diff update hasn't been converted to a BigMapContent on db, because the map id '$json' is not a valid number. The block containing the Transation operation is ${hash.value}"
)
None
case (_, opHash, diffAction) =>
case BlockTagged(ref, (_, opHash, diffAction)) =>
logger.warn(
s"Big Map Updates: A big_map_diff result will be ignored by the update conversion to BigMapContent on db, because the diff action is not supported: $diffAction for operation $opHash"
)
Expand Down
Loading