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

Add improved local options with preflight #185

Merged
merged 35 commits into from
Apr 11, 2023
Merged

Add improved local options with preflight #185

merged 35 commits into from
Apr 11, 2023

Conversation

ggobugi27
Copy link
Contributor

@ggobugi27 ggobugi27 commented Mar 6, 2023

Reason:

kadena-io/chainweb-node#1585

  • Adds function to implement the new feature in chainweb, /local with preflight and signatureVerification

Changes made (preferably with images/screenshots):

chainweb-node-client

  • local defaults to preflight=true, signatureVerification=true
    -local and send only accepts fully signed commands.
  • moved createSendRequest , createPollRequest , createListenRequest from kadena.js

kadena.js

  • prepareExecCommand , prepareContCommand, createCommand results changed from ICommand to IUnsignedCommand

types

  • removed {sig: undefined} option in ICommand
  • added IUnsignedCommand

pactjs

  • added isSignedCommand function which checks if signature is present
  • added ensureSignedCommand function which checks if signature is present and return the command in ICommand type, throws error if signature is not present.

Check off the following:

  • [V ] I have reviewed my changes and run the appropriate tests.
  • [ V] I have have run rush change to add the appropriate change logs.
  • [V ] I have added/edited docs.
  • I have added tutorials.
  • I have double checked and DEFINITELY added docs.

import type { ICommand, SignatureWithHash } from '@kadena/types';

import type { IUnsignedCommand, SignCommand } from '@kadena/types';
import { createSendRequest } from 'kadena.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this import not be something along the lines of @kadena/client ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadena/client 's send uses the send in chainweb-node-client, and has it's own send function from the command builder.

@ggobugi27 ggobugi27 requested a review from alber70g March 10, 2023 11:54
@ggobugi27 ggobugi27 changed the title [WIP] Add improved local options with preflight Add improved local options with preflight Mar 10, 2023
Copy link
Member

@alber70g alber70g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a preliminary, but I wanted to get you started

Comment on lines 447 to 461
export interface ILocalCommandResultWithPreflight {
reqKey: IBase64Url;
/* eslint-disable-next-line @rushstack/no-new-null*/
txId: number | null;
result: IPactResultSuccess | IPactResultError;
gas: number;
/* eslint-disable-next-line @rushstack/no-new-null*/
logs: string | null;
/* eslint-disable-next-line @rushstack/no-new-null*/
continuation: IPactExec | null;
/* eslint-disable-next-line @rushstack/no-new-null*/
metaData: IChainwebResponseMetaData | null;
events?: Array<IPactEvent>;
preflightWarnings?: Array<string>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to have a intersection type between ILocalCommandResult and the separate Preflight part, instead of duplicating across two interfaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per our discussion, because the preflight result only includes another field, preflightWarnings, this type will be used as the LocalResultWithPreflight , and LocalResultWithoutPreflight will be

Omit<
  LocalResultWithPreflight,
  'preflightWarnings'
>;```

@alber70g alber70g self-requested a review March 17, 2023 12:59
Copy link
Member

@alber70g alber70g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

@Randynamic
Copy link
Contributor

@all-contributors please add @ggobugi27 for code

@allcontributors
Copy link
Contributor

@Randynamic

I've put up a pull request to add @ggobugi27! 🎉

Copy link
Member

@alber70g alber70g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments

Comment on lines 164 to 167
export type LocalResultWithoutPreflight = Omit<
LocalResultWithPreflight,
'preflightWarnings'
>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default for a local call, with or without preflight? I'd rather have one that doesn't have a specifier on preflight. So LocalResult and either LocalPreflightResult or LocalResultWithoutPreflight.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default will be with preflight. I'll change the naming.

Comment on lines 289 to 303
export interface ILocalCommandResultWithPreflight {
reqKey: IBase64Url;
/* eslint-disable-next-line @rushstack/no-new-null*/
txId: number | null;
result: IPactResultSuccess | IPactResultError;
gas: number;
/* eslint-disable-next-line @rushstack/no-new-null*/
logs: string | null;
/* eslint-disable-next-line @rushstack/no-new-null*/
continuation: IPactExec | null;
/* eslint-disable-next-line @rushstack/no-new-null*/
metaData: IChainwebResponseMetaData | null;
events?: Array<IPactEvent>;
preflightWarnings?: Array<string>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see on line 228 the following interface:

export interface IPreflightResult {
  preflightResult: ICommandResult;
  preflightWarnings: [];
}

Should ILocalCommandResultWithPreflight also have preflightResult? Or is this what the API returns and not what is used in downstream code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is interface for the parsed commandResult, where preflightResult is spread into the object.

Comment on lines 17 to 19
test('/spv returns SPV proof', async () => {
const actual: string | Response = await spv(testSPVRequest, '');
const actual: string | Response = await spv(testSPVRequest, testURL);
const expected: SPVResponse = testSPVProof;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make an issue to convert all tests to describe+it?

@ggobugi27 ggobugi27 merged commit 46a356e into master Apr 11, 2023
@ggobugi27 ggobugi27 deleted the feat/local branch April 11, 2023 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants