|
|
@ -4,7 +4,7 @@ import java.sql.Connection |
|
|
|
import javax.inject.Inject |
|
|
|
|
|
|
|
import anorm._ |
|
|
|
import com.alexitc.playsonify.models.{Count, FieldOrdering, PaginatedQuery} |
|
|
|
import com.alexitc.playsonify.models._ |
|
|
|
import com.xsn.explorer.data.anorm.interpreters.FieldOrderingSQLInterpreter |
|
|
|
import com.xsn.explorer.data.anorm.parsers.BlockParsers._ |
|
|
|
import com.xsn.explorer.models.fields.BlockField |
|
|
@ -138,26 +138,14 @@ class BlockPostgresDAO @Inject() (fieldOrderingSQLInterpreter: FieldOrderingSQLI |
|
|
|
} |
|
|
|
|
|
|
|
def getLatestBlock(implicit conn: Connection): Option[Block] = { |
|
|
|
SQL( |
|
|
|
""" |
|
|
|
|SELECT blockhash, previous_blockhash, next_blockhash, tpos_contract, merkle_root, size, |
|
|
|
| height, version, time, median_time, nonce, bits, chainwork, difficulty |
|
|
|
|FROM blocks |
|
|
|
|ORDER BY height DESC |
|
|
|
|LIMIT 1 |
|
|
|
""".stripMargin |
|
|
|
).as(parseBlock.singleOpt).flatten |
|
|
|
val query = PaginatedQuery(Offset(0), Limit(1)) |
|
|
|
val ordering = FieldOrdering(BlockField.Height, OrderingCondition.DescendingOrder) |
|
|
|
getBy(query, ordering).headOption |
|
|
|
} |
|
|
|
|
|
|
|
def getFirstBlock(implicit conn: Connection): Option[Block] = { |
|
|
|
SQL( |
|
|
|
""" |
|
|
|
|SELECT blockhash, previous_blockhash, next_blockhash, tpos_contract, merkle_root, size, |
|
|
|
| height, version, time, median_time, nonce, bits, chainwork, difficulty |
|
|
|
|FROM blocks |
|
|
|
|ORDER BY height |
|
|
|
|LIMIT 1 |
|
|
|
""".stripMargin |
|
|
|
).as(parseBlock.singleOpt).flatten |
|
|
|
val query = PaginatedQuery(Offset(0), Limit(1)) |
|
|
|
val ordering = FieldOrdering(BlockField.Height, OrderingCondition.AscendingOrder) |
|
|
|
getBy(query, ordering).headOption |
|
|
|
} |
|
|
|
} |
|
|
|