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

Javascript console that exposes Filecoin API #2492

Merged
merged 87 commits into from
Feb 22, 2023
Merged

Conversation

elmattic
Copy link
Contributor

@elmattic elmattic commented Feb 1, 2023

Summary of changes

Changes introduced in this pull request:

  • Add builtin Javascript console for interacting with the Filecoin JSON-RPC API

Run it with:

$ ./target/release/forest-cli --token $TOKEN attach                                            
Welcome to the Forest Javascript console!

To exit, press ctrl-d or type :quit
> showWallet()
Address                                         Balance
f12k7gkx5buk4rwe53zjb6ma5q47jetj3ual73rfq       10000 attoFIL
f1a4uu6j4kdtpfuzbqeaitlqgsdxbsbysayl32bzi       99999998974003915915 attoFIL
f1bfl2qqwnnbkkx44cvmvs4rvtsp6nrnksetrkzma       99999999197203014528 attoFIL
f1edwx7zalu54vvoytpuviurt6bypdsqux3ta4dxa       0 attoFIL
f1elanep3pvyahdelqqtyxsst2j6bxks4sdl7be3q       0 attoFIL
f1fzb3vu2iwu3efrctucm337dfinj6dgicz7e7qgy       0 attoFIL
f1gb4gte4e42wclh6jgtf4tdqvfyf3gcjv4vox2ia       6000036789 attoFIL
f1gundv7oc7bo6tevxccqpwginlgki7yqk4na2tyi       30000 attoFIL
f1hyge7fhoyifmhxjzzj37s7eowqeibsjh7auptea       20000 attoFIL
f1jxa25q6fawbhloee462kyvwjhfolxj7rkh26t3q       0 attoFIL
f1l5kiz7hmrbs7blm23sn6clyweoyqpyzc5anqvfi       0 attoFIL
f1ngj547fvvm4tryw4zwu37uqfure6rgm46b5cj6a       7486950930 attoFIL
f1wteveg4sxbtbo3tgz4dgk5owq6epd6fvk5m654y       100080 attoFIL

> showSyncStatus()
sync status:
Stage:  complete
Height: 281967

You can also use custom modules and exec flag, ie:

$ ./target/release/forest-cli --token $TOKEN attach --jspath .. --exec "const Math = require('calc.js'); console.log(Math.add(39,3));"
Loading: ../calc.js
42

where calc.js:

module.exports = {
    add: function (a, b) {
      return a + b;
    },
    multiply: function (a, b) {
      return a * b;
    },
};

Reference issue to close (if applicable)

Closes

Other information and links

Inspired by: https://geth.ethereum.org/docs/interacting-with-geth/javascript-console

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@elmattic elmattic marked this pull request as ready for review February 7, 2023 15:58
@elmattic elmattic requested a review from lemmih as a code owner February 7, 2023 15:58
@elmattic
Copy link
Contributor Author

@LesnyRumcajs looks good for you now?

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
documentation/developer_documentation/CLI.md Outdated Show resolved Hide resolved
documentation/src/js_console.md Outdated Show resolved Hide resolved
documentation/src/js_console.md Outdated Show resolved Hide resolved
documentation/src/js_console.md Outdated Show resolved Hide resolved
documentation/src/js_console.md Outdated Show resolved Hide resolved
Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Can't test it now because calibnet is down on our side, but I have faith it works. :)

Copy link
Contributor

@lemmih lemmih left a comment

Choose a reason for hiding this comment

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

Faith!

@elmattic elmattic merged commit ff0c825 into main Feb 22, 2023
@elmattic elmattic deleted the elmattic/js-console branch February 22, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

4 participants