Skip to content

Commit

Permalink
chore: minor changes to client and server logic (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks authored Aug 31, 2023
1 parent 2f54e75 commit 7bcb611
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SPENDING_KEY=""
SPENDING_KEY=""
WALLET_SERVER_HOST="walletserver.ironfish.network:50051"
2 changes: 1 addition & 1 deletion example/src/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AccountsManager } from "./utils/AccountsManager";
import { BlockCache } from "./utils/BlockCache";

const client = new LightStreamerClient(
"localhost:50051",
process.env["WALLET_SERVER_HOST"] ?? "localhost:50051",
credentials.createInsecure(),
);

Expand Down
4 changes: 2 additions & 2 deletions example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from "dotenv";
import { Client } from "./Client/Client";

config();

import { Client } from "./Client/Client";

async function main() {
const client = new Client();
await client.start();
Expand Down
23 changes: 20 additions & 3 deletions src/services/LightStreamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,39 @@ class LightStreamer implements LightStreamerServer {

public getBlockRange: handleServerStreamingCall<BlockRange, LightBlock> =
async (call) => {
if (!call.request.start?.sequence || !call.request.end?.sequence) {
if (
(!call.request.start?.sequence && call.request.start?.sequence !== 0) ||
(!call.request.end?.sequence && call.request.end?.sequence !== 0)
) {
call.emit("error", {
code: status.INVALID_ARGUMENT,
details: "Must provide sequence for start and end",
});
call.end();
return;
}
if (call.request.start.sequence >= call.request.end.sequence) {

if (call.request.start.sequence > call.request.end.sequence) {
call.emit("error", {
code: status.INVALID_ARGUMENT,
details: "End sequence must be greater than start sequence",
details:
"End sequence must be greater than or equal to start sequence",
});
call.end();
return;
}

const requested_block_amount =
call.request.end.sequence - call.request.start.sequence;
if (
process.env["BLOCK_RANGE_MAX"] &&
requested_block_amount > Number(process.env["BLOCK_RANGE_MAX"])
) {
call.emit("error", {
code: status.INVALID_ARGUMENT,
details: `Maximum block range exceeded for server, requested: ${requested_block_amount}, allowed: ${process.env["BLOCK_RANGE_MAX"]}}`,
});
}
try {
for (
let i = call.request.start.sequence;
Expand Down
2 changes: 1 addition & 1 deletion test/server.test.slow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe("getBlock", () => {
});
});
expect(promise).rejects.toThrow(
"INVALID_ARGUMENT: End sequence must be greater than start sequence",
"INVALID_ARGUMENT: End sequence must be greater than or equal to start sequence",
);
});

Expand Down

0 comments on commit 7bcb611

Please sign in to comment.