-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(client): migrate to json-rpc #81
Conversation
function checkRes<T, R>( | ||
res: GenericResponse<T>, | ||
selector?: (r: T) => R | undefined | ||
res: AxiosResponse<JsonRPCResponse<T>>, | ||
selector: (r: JsonRPCResponse<T>) => R | undefined | ||
): GenericResponse<R> { | ||
if (res.status != 200 || !res.data) { | ||
throw new Error( | ||
JSON.stringify(res.data) || | ||
|
||
switch (res.status) { | ||
case 200: | ||
break; | ||
case 401: | ||
throw new Error(JSON.stringify(res.data) || 'Unauthorized.'); | ||
case 404: | ||
throw new Error(JSON.stringify(res.data) || 'Not found.'); | ||
case 500: | ||
throw new Error(JSON.stringify(res.data) || 'Internal server error.'); | ||
default: | ||
throw new Error( | ||
JSON.stringify(res.data) || | ||
'An unknown error has occurred. Please check your network connection.' | ||
); | ||
); | ||
} | ||
|
||
if (!res.data) { | ||
throw new Error(`failed to parse response: ${res}`); | ||
} | ||
|
||
if (res.data.error) { | ||
const data = res.data.error.data ? `, data: ${JSON.stringify(res.data.error.data)}` : ''; | ||
throw new Error(`JSON RPC call error: code: ${res.data.error.code}, message: ${res.data.error.message}` + data); | ||
} | ||
|
||
if (res.data.jsonrpc !== '2.0') { | ||
throw new Error(JSON.stringify(res.data) || 'Invalid JSON RPC response.'); | ||
} | ||
|
||
if (!selector) { | ||
return { status: res.status, data: undefined }; | ||
if (!res.data.result) { | ||
throw new Error(JSON.stringify(res.data) || 'No result in JSON RPC response.'); | ||
} | ||
|
||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jchappelow, do you mind taking a look at this checkRes
function? I tried to model similar to how you showed me here.
src/builders/payload_builder.ts
Outdated
// @ts-ignore - DO NOT MERGE WITHOUT RESOLVING - Jon is looking into why fee is unmarshalled to an integer. | ||
fee: Number(newTx.body.fee), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure the resolution is simple, but need to make sure this is as expected: kwilteam/kwil-db#713
The client.ts now uses kwil-db's JSONRPC endpoints (instead of REST). BREAKING CHANGE: Kwil-JS now relies on kwil-db's JSONRPC endpoints (available in kwil-db v0.8+). From this commit on, you should only use Kwil-JS with kwil-db v0.8+.
change CI to use kwil-db json RPC endpoints
Changed KGW APIs to use JSON RPC.
9d36fd2
to
58b4309
Compare
let msg = ''; | ||
msg += `${domain} wants you to sign in with your account:\n`; | ||
msg += `\n`; | ||
if (authParam.statement !== '') { | ||
msg += `${authParam.statement}\n`; | ||
} | ||
msg += '\n'; | ||
msg += `URI: ${target.href}\n`; | ||
// @Yaiba: Should I trust the URI provided by KGW or should I use the domain / create my own? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yaiba, can you advise on this? Should I trust the URI provided by KGW or should I create my own?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have checked that the domain matches, KGW will always return domain + /rpc/v1
, we can trust returned URI.
Fixed a minor bug that cleared all cookies on an individual logout for a multi-user session in NodeKwil. Now, kwil-js appropriately manages all cookies for different sessions.
Added `EncodableDatabase` type, which is to be used before RLP-encoding a schema. It allows `rlp:nil` fields to be an empty array.
Should we merge this? I have this branch tested kwilteam/kwil-db#746 in CI https://github.com/kwilteam/kwil-db/actions/runs/9161574685/job/25186730490 and passed |
Just a sec, scanning through the main handler |
Yeah, lgtm. Fire when ready @KwilLuke |
The client.ts now uses kwil-db's JSONRPC endpoints (instead of REST).
BREAKING CHANGE: Kwil-JS now relies on kwil-db's JSONRPC endpoints (available in kwil-db v0.8+). From this commit on, you should only use Kwil-JS with kwil-db v0.8+.