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

Blockfrost Block by number/hash api Response Format Mismatch #405

Merged
merged 2 commits into from
Nov 26, 2024
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
33 changes: 33 additions & 0 deletions api-tests/block.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###
### Get block by block number
GET {{base_url}}/api/v1/blocks/2925862

> {%
client.test("Get block by block number", function() {
client.assert(response.status === 200, "Response status is not 200");
client.assert(response.body.height === 2925862, "Block number is wrong" + response.body.height)
client.assert(response.body.hash === "1b57a2298737589695f7ec88da9e5b1af8f9f4479e7bd03367c10e165d5cc4bc", "Block hash is wrong" + response.body.hash)
client.assert(response.body.op_cert_counter === "6", "Expected 6 as string")
client.assert(response.body.next_block === "7d50f0dbc258ffeee329fbd61e10ccdc83d65068cb9d99e2a663c07b3a7f15fd", "Mismatch next block")
client.assert(response.body.confirmations > 1, "Confirmations should be greater than 1")
client.assert(response.body.output === "19511865", "Output mismatch")
client.assert(response.body.fees === "488135", "Fees mismatch")
});
%}


### Get block by block hash
GET {{base_url}}/api/v1/blocks/1b57a2298737589695f7ec88da9e5b1af8f9f4479e7bd03367c10e165d5cc4bc

> {%
client.test("Get block by block number", function() {
client.assert(response.status === 200, "Response status is not 200");
client.assert(response.body.height === 2925862, "Block number is wrong" + response.body.height)
client.assert(response.body.hash === "1b57a2298737589695f7ec88da9e5b1af8f9f4479e7bd03367c10e165d5cc4bc", "Block hash is wrong" + response.body.hash)
client.assert(response.body.op_cert_counter === "6", "Expected 6 as string")
client.assert(response.body.next_block === "7d50f0dbc258ffeee329fbd61e10ccdc83d65068cb9d99e2a663c07b3a7f15fd", "Mismatch next block")
client.assert(response.body.confirmations > 1, "Confirmations should be greater than 1")
client.assert(response.body.output === "19511865", "Output mismatch")
client.assert(response.body.fees === "488135", "Fees mismatch")
});
%}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[libraries]
yaci = "com.bloxbean.cardano:yaci:0.3.3"
yaci = "com.bloxbean.cardano:yaci:0.3.4"
cardano-client-lib = "com.bloxbean.cardano:cardano-client-lib:0.6.2"
cardano-client-backend = "com.bloxbean.cardano:cardano-client-backend:0.6.2"
cardano-client-backend-ogmios = "com.bloxbean.cardano:cardano-client-backend-ogmios:0.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,31 @@ public class BlockController {
@GetMapping("{numberOrHash}")
@Operation(summary = "Block Information by Number or Hash", description = "Get block information by number or hash.")
public ResponseEntity<BlockDto> getBlockByNumber(@PathVariable String numberOrHash) {
BlockDto blockDto;
if (NumberUtils.isParsable(numberOrHash)) {
return blockService.getBlockByNumber(Long.parseLong(numberOrHash))
.map(block -> ResponseEntity.ok(dtoMapper.toBlockDto(block)))
.orElse(ResponseEntity.notFound().build());
blockDto = blockService.getBlockByNumber(Long.parseLong(numberOrHash))
.map(block -> dtoMapper.toBlockDto(block)).orElse(null);
} else {
return blockService.getBlockByHash(numberOrHash)
.map(block -> ResponseEntity.ok(dtoMapper.toBlockDto(block)))
.orElse(ResponseEntity.notFound().build());
blockDto = blockService.getBlockByHash(numberOrHash)
.map(block -> dtoMapper.toBlockDto(block)).orElse(null);
}

if (blockDto == null) {
return ResponseEntity.notFound().build();
}

var confirmation = blockService.getLatestBlock()
.map(latestBlock -> latestBlock.getNumber() - blockDto.getNumber())
.orElse(0L);

var nextBlockHash = blockService.getBlockByNumber(blockDto.getNumber() + 1)
.map(block -> block.getHash())
.orElse(null);

blockDto.setNextBlock(nextBlockHash);
blockDto.setConfirmations(confirmation);

return ResponseEntity.ok(blockDto);
}

@GetMapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.*;

import java.math.BigInteger;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -29,16 +29,19 @@ public class BlockDto {
private String slotLeader;
private long size;
private int txCount;
@JsonSerialize(using = ToStringSerializer.class)
private BigInteger output;
@JsonSerialize(using = ToStringSerializer.class)
private BigInteger fees;
private String blockVrf;
private String opCert;
@JsonSerialize(using = ToStringSerializer.class)
private Integer opCertCounter;
private Integer opCertKesPeriod;
private String opCertSigma;
private String previousBlock;
// private String nextBlock; //TODO
// private long confirmations; //TODO
private String nextBlock;
private long confirmations;

private String issuerVkey;
private Vrf nonceVrf;
Expand Down