Skip to content

Commit

Permalink
Code review rework
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Oct 26, 2023
1 parent f2b1a99 commit 866603e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions node/pkg/query/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,12 @@ func (ecd *EthCallWithFinalityQueryRequest) UnmarshalFromReader(reader *bytes.Re

finalityLen := uint32(0)
if err := binary.Read(reader, binary.BigEndian, &finalityLen); err != nil {
return fmt.Errorf("failed to read following finality len: %w", err)
return fmt.Errorf("failed to read finality len: %w", err)
}

finality := make([]byte, finalityLen)
if n, err := reader.Read(finality[:]); err != nil || n != int(finalityLen) {
return fmt.Errorf("failed to read following block id hint [%d]: %w", n, err)
return fmt.Errorf("failed to read finality [%d]: %w", n, err)
}
ecd.Finality = string(finality[:])

Expand Down
2 changes: 1 addition & 1 deletion node/pkg/query/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (perChainResponse *PerChainQueryResponse) UnmarshalFromReader(reader *bytes
case EthCallWithFinalityQueryRequestType:
r := EthCallWithFinalityQueryResponse{}
if err := r.UnmarshalFromReader(reader); err != nil {
return fmt.Errorf("failed to unmarshal eth call by timestamp response: %w", err)
return fmt.Errorf("failed to unmarshal eth call with finality response: %w", err)
}
perChainResponse.Response = &r
default:
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/watchers/evm/ccq.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ func (w *Watcher) ccqHandleEthCallWithFinalityQueryRequest(logger *zap.Logger, c
}

if blockNumber > latestBlockNum {
logger.Info("requested block for eth_call_with_finality is not yet finalized",
logger.Info("requested block for eth_call_with_finality has not yet reached the requested finality",
zap.String("finality", req.Finality),
zap.Uint64("requestedBlockNumber", blockNumber),
zap.Uint64("latestBlockNumber", latestBlockNum),
Expand Down
6 changes: 4 additions & 2 deletions sdk/js-query/src/query/ethCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ export class EthCallQueryRequest implements ChainSpecificQuery {
}

export function parseBlockId(blockId: BlockTag): string {
if (blockId == "") {
if (!blockId || blockId === "") {
throw new Error(`block tag is required`);
}

if (typeof blockId === "number") {
if (blockId < 0) {
throw new Error(`block tag must be positive`);
}
blockId = `0x${blockId.toString(16)}`;
} else if (isValidHexString(blockId)) {
if (!blockId.startsWith("0x")) {
blockId = `0x${blockId}`;
}
blockId = blockId;
} else {
throw new Error(`Invalid block tag: ${blockId}`);
}
Expand Down
6 changes: 4 additions & 2 deletions sdk/js-query/src/query/ethCallByTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ export class EthCallByTimestampQueryRequest implements ChainSpecificQuery {

function parseBlockHint(blockHint: BlockTag): string {
// Block hints are not required.
if (blockHint != "") {
if (blockHint !== "") {
if (typeof blockHint === "number") {
if (blockHint < 0) {
throw new Error(`block tag must be positive`);
}
blockHint = `0x${blockHint.toString(16)}`;
} else if (isValidHexString(blockHint)) {
if (!blockHint.startsWith("0x")) {
blockHint = `0x${blockHint}`;
}
blockHint = blockHint;
} else {
throw new Error(`Invalid block tag: ${blockHint}`);
}
Expand Down

0 comments on commit 866603e

Please sign in to comment.