solana-program-library/stake-pool/js
Lieu Zheng Hong 346075743e
stake-pool: Stake pool deserializer (#1656)
* first commit

* add schema for stakepool accounts

* got imports working

* add typescript support

* fix schema

* Change to use PublicKey type

* change to camelCase instead

* add type annotations to typescript classes

* add readme

* Add prettier linting

* add instructions to run

* add test section

* prettier clean up schema.ts

* convert index.js to index.ts

* actually use decode method available in Assignable

* rename stakepoolaccount so i can have a wrapper class

* add new class StakePool and change return type of getStakePoolAccounts

* remove extraneous .js files

* update schema to incorporate jon's comments

* remove unnecessary comments

* add helper functions to get individual accounts; cleaned up code

* add Fee, change denominator/numerator to BN

* Add enums so we can check what type an accountType is

* Remove name and ticker in StakePool class

* fix borshjs import

* change outdir to dist/ folder

* Edit package.json

* add toBuffer for schema.PublicKey

* add exports and default exports to index.ts

* fix trailing comma on tsconfig.json

* get mocha test harness working with ts-node, ts-mocha, esm

* fix borsh import

* clean up imports

* add working test script

* remove unneeded borshjs import

* add unit tests for both decodes (WIP)

* no need to console.log in testOnDevnet since we now have a test suite

* Add tests for ValidatorListAccount.decode

* add schema.decode.StakePoolAccount test

* Finish up

* reduce dependencies in package.json

* Add lint command to package.json

* Lint with prettier

* Update README.md with new commands

* Write explanatory comments in index.js

* Small linting change

* feat: introduce new borshjs deserializeUnchecked import

* lint: npm lint

* refactor: upgrade web3js version

* refactor: refactor type names

* refactor: npm run lint

* refactor: improve tsconfig.json

* feat: add declaration and declarationMap to tsconfig.json

* feat: allow getStakePoolAccounts to more robustly handle errors

* Update stake-pool/js/.gitignore

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* Update stake-pool/js/package.json

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* Update stake-pool/js/package.json

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* Update stake-pool/js/package.json

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* Update stake-pool/js/package.json

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* refactor: modify `constructStakePoolSchema` to mutate in place

* lint: remove webpack.config.js

* lint: npm run lint

* lint: add comments above index.ts

* lint: lowercase schema

* feat: add full deserialization test

* Update stake-pool/js/package.json

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>

* refactor: remove try-catch block in getStakePoolAccounts

* lint: lint

* refactor: use web3js pubkey

* refactor: move integration tests to separate file

* refactor: change test.js to do encode-decode loop

Co-authored-by: Jon Cinque <jon.cinque@gmail.com>
2021-06-23 14:18:45 +02:00
..
src stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
.gitignore stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
.prettierrc.yaml stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
README.md stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
package-lock.json stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
package.json stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00
tsconfig.json stake-pool: Stake pool deserializer (#1656) 2021-06-23 14:18:45 +02:00

README.md

TypeScript bindings for stake-pool program

For use with both node.js and in-browser.

Installation

npm install

Build and run

In the js folder:

npm run compile
npm run lint
node dist/index.js

Test

npm run compile
npm test

Sample output:

> stake-pool-js@0.0.1 test
> ./node_modules/mocha/bin/mocha -p ./dist


  schema.decode
    StakePoolAccount
      ✓ should successfully decode StakePoolAccount account data
    ValidatorListAccount
      ✓ should successfully decode ValidatorListAccount account data
      ✓ should successfully decode ValidatorListAccount with nonempty ValidatorInfo

  index.ts/PrettyPrintPubkey
    ✓ should successfully pretty print a pubkey


  4 passing (610ms)