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

Block helper functions for successful function calls #60

Closed
wants to merge 2 commits into from

Conversation

gabehamilton
Copy link

@gabehamilton gabehamilton commented Apr 30, 2024

See Feature Request near/queryapi#366

  • successfulFunctionCalls
  • socialOperations
    This is more specific than other methods in the class. However, this specificity helps users. In future we could add additional "more specific" helper methods for fungible tokens and NFTs.

Should we add Wrapper types for all Action Operations? see near/queryapi#409

Copy link

changeset-bot bot commented Apr 30, 2024

🦋 Changeset detected

Latest commit: afe3407

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@near-lake/framework Patch
@near-lake/primitives Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gabehamilton gabehamilton force-pushed the block-helpers-function-calls branch 2 times, most recently from 62c28a7 to 196a92e Compare April 30, 2024 22:02
@gabehamilton gabehamilton linked an issue Apr 30, 2024 that may be closed by this pull request
.map((exeuctionOutcomeWithReceipt) => Action.fromReceiptView(exeuctionOutcomeWithReceipt.receipt))
.filter((executionOutcomeWithReceipt) =>
Action.isActionReceipt(executionOutcomeWithReceipt.receipt) &&
(!successfulOnly || (executionOutcomeWithReceipt.executionOutcome.outcome.status as {SuccessValue: any}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This assertion doesn't actually check if the action was only successful - it only checks if status exists, which it does for both successful/failure. as is just a type cast, and won't affect the outcome of this.

We need to check for the existence of status.SuccessValue, and perhaps status.SuccessReceiptId too, instead.

Copy link
Author

@gabehamilton gabehamilton Jun 18, 2024

Choose a reason for hiding this comment

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

@pkudinov hopefully your function is better than mine here.

packages/near-lake-primitives/src/types/block.ts Outdated Show resolved Hide resolved
.filter((functionCallOperation) => functionCallOperation && (!method || functionCallOperation?.methodName === method))
.map((functionCallOperation) => ({
...functionCallOperation,
args: this.base64decode(functionCallOperation.args),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
args: this.base64decode(functionCallOperation.args),
decoded_args: this.base64decode(functionCallOperation.args)

It may be better to expose this as decoded_args, as well as the raw args. base64decode will silently fail, so having both allows developers to use the raw args if decoded_args is undefined.

Comment on lines +179 to +182
console.error(
'Error parsing base64 JSON - skipping data',
error
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't really like the idea of libraries logging things, because they can't be suppressed.

Let's just return undefined explicitly here, without the log.

Comment on lines +218 to +230
if (
!functionCall ||
!functionCall.args ||
!functionCall.args.data ||
!Object.keys(functionCall.args.data) ||
!Object.keys(functionCall.args.data)[0]
) {
console.error(
"Set operation did not have arg data in expected format"
);
return;
}
const accountId = Object.keys(functionCall.args.data)[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (
!functionCall ||
!functionCall.args ||
!functionCall.args.data ||
!Object.keys(functionCall.args.data) ||
!Object.keys(functionCall.args.data)[0]
) {
console.error(
"Set operation did not have arg data in expected format"
);
return;
}
const accountId = Object.keys(functionCall.args.data)[0];
const accountId = Object.keys(functionCall.args.data ?? {})[0];
if (!accountId) {
return false;
}

I believe this is the same?

Same comment around logging, can we please remove? Also we should be returning false here and below?

* @param contract Defaults to 'social.near', pass in a different contract if needed
* @param method Defaults to 'set', pass in a different method if needed
*/
socialOperations(operation: string, contract: string = "social.near", method: string = "set") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a return type here please?

@@ -75,4 +75,24 @@ describe("Block", () => {
);
expect(authorToPostId).toMatchSnapshot();
});

it("parses successful function calls", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test for actions(successfulOnly) too please?

@@ -167,7 +169,7 @@ class DeleteAccount {
export type Operation =
| 'CreateAccount'
| DeployContract
| FunctionCall
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this incorrect? Is this a breaking change?

Copy link
Author

@gabehamilton gabehamilton Jun 18, 2024

Choose a reason for hiding this comment

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

@pkudinov This file is where I ran into the Operations types not matching the data. I only changed FunctionCall but they should probably all be corrected.

@morgsmccauley
Copy link
Collaborator

Should we close now that #61 is merged?

@gabehamilton
Copy link
Author

Yes, closing, #61 looks great. I do think more helper functions in either near-lake or queryapi would still be useful, extracting: SocialDB operations, NFTs, FTs, DAO proposals. Hiding all the error handling so that indexers can be just a few lines will make for great demos and onboarding.

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.

Social operations context helper functions
2 participants