Skip to content

Commit

Permalink
server: added different codec for blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
vhurryharry committed Aug 25, 2020
1 parent 3a5ca78 commit 0738aa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions server/app/com/xsn/explorer/models/persisted/BlockHeader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ object BlockHeader {
"nonce" -> obj.nonce,
"bits" -> obj.bits,
"filter" -> filterMaybe,
"difficulty" -> obj.difficulty
)
}

val blockWrites: Writes[BlockHeader] = (obj: BlockHeader) => {
Json.obj(
"hash" -> obj.hash,
"previousBlockhash" -> obj.previousBlockhash,
"nextBlockhash" -> obj.nextBlockhash,
"merkleRoot" -> obj.merkleRoot,
"height" -> obj.height,
"time" -> obj.time,
"difficulty" -> obj.difficulty,
"transactions" -> obj.transactions
)
Expand Down
2 changes: 1 addition & 1 deletion server/app/controllers/BlocksController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BlocksController @Inject()(
}

def getBlocks(lastSeenHash: Option[String], limit: Int, orderingCondition: String) = public { _ =>
implicit val codec: Writes[BlockHeader] = BlockHeader.partialWrites
implicit val codec: Writes[BlockHeader] = BlockHeader.blockWrites
blockService
.getBlocks(Limit(limit), lastSeenHash, orderingCondition)
.toFutureOr
Expand Down

0 comments on commit 0738aa1

Please sign in to comment.