Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 3460757

Browse files
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 <[email protected]> * Update stake-pool/js/package.json Co-authored-by: Jon Cinque <[email protected]> * Update stake-pool/js/package.json Co-authored-by: Jon Cinque <[email protected]> * Update stake-pool/js/package.json Co-authored-by: Jon Cinque <[email protected]> * Update stake-pool/js/package.json Co-authored-by: Jon Cinque <[email protected]> * 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 <[email protected]> * 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 <[email protected]>
1 parent d10db8d commit 3460757

File tree

10 files changed

+4365
-0
lines changed

10 files changed

+4365
-0
lines changed

stake-pool/js/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

stake-pool/js/.prettierrc.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
arrowParens: "avoid"
2+
bracketSpacing: false
3+
jsxBracketSameLine: false
4+
semi: true
5+
singleQuote: true
6+
tabWidth: 2
7+
trailingComma: "all"

stake-pool/js/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# TypeScript bindings for stake-pool program
2+
3+
For use with both node.js and in-browser.
4+
5+
## Installation
6+
7+
```
8+
npm install
9+
```
10+
11+
## Build and run
12+
13+
In the `js` folder:
14+
15+
```
16+
npm run compile
17+
npm run lint
18+
node dist/index.js
19+
```
20+
21+
## Test
22+
23+
```
24+
npm run compile
25+
npm test
26+
```
27+
28+
Sample output:
29+
30+
```
31+
32+
> ./node_modules/mocha/bin/mocha -p ./dist
33+
34+
35+
schema.decode
36+
StakePoolAccount
37+
✓ should successfully decode StakePoolAccount account data
38+
ValidatorListAccount
39+
✓ should successfully decode ValidatorListAccount account data
40+
✓ should successfully decode ValidatorListAccount with nonempty ValidatorInfo
41+
42+
index.ts/PrettyPrintPubkey
43+
✓ should successfully pretty print a pubkey
44+
45+
46+
4 passing (610ms)
47+
```

0 commit comments

Comments
 (0)