add getBalance, clear input from memory

This commit is contained in:
DieMyst 2019-03-15 15:41:14 +03:00
parent a8d0da3879
commit fb090f3c82
3 changed files with 9 additions and 5 deletions

View File

@ -67,6 +67,9 @@ export class GameManager {
} }
getBalance(playerId: u64): Response { getBalance(playerId: u64): Response {
return new GetBalanceResponse(1); if (!this.playerBalance.has(playerId)) {
return new ErrorResponse("There is no player with id: " + playerId.toString());
}
return new GetBalanceResponse(this.playerBalance.get(playerId));
} }
} }

View File

@ -16,10 +16,9 @@ export function handler(requestBytes: Uint8Array): string {
} else if (request instanceof GetBalanceRequest) { } else if (request instanceof GetBalanceRequest) {
return gameManager.getBalance(request.playerId).serialize(); return gameManager.getBalance(request.playerId).serialize();
} else if (request instanceof UnknownRequest) { } else if (request instanceof UnknownRequest) {
return new ErrorResponse("").serialize(); return new ErrorResponse("There is no such type of request.").serialize();
} else { } else {
unreachable();
}
return ""; return "";
}
} }

View File

@ -35,5 +35,7 @@ export function invoke(ptr: i32, size: i32): i32 {
store<u8>(strAddr + i, b); store<u8>(strAddr + i, b);
} }
memory.free(ptr);
return addr; return addr;
} }