├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── release.yml │ ├── test.yml │ └── typedoc.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── examples └── sdk-events-example │ ├── CHANGELOG.md │ ├── README.md │ ├── babel.config.js │ ├── package-lock.json │ ├── package.json │ ├── public │ └── index.html │ ├── src │ ├── App.vue │ ├── main.ts │ └── shims-vue.d.ts │ ├── tsconfig.json │ ├── vue.config.js │ └── webpack.config.js ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── ext-taquito │ ├── .cspell.json │ ├── .editorconfig │ ├── .eslintrc.js │ ├── .gitignore │ ├── .prettierignore │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.ts │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── tzktReadProvider.ts │ ├── tests │ │ ├── data │ │ │ └── contractScript.ts │ │ └── methods.test.ts │ ├── tsconfig.json │ └── tsconfig.module.json ├── sdk-api │ ├── .cspell.json │ ├── .editorconfig │ ├── .eslintrc.js │ ├── .github │ │ ├── CONTRIBUTING.md │ │ ├── ISSUE_TEMPLATE.md │ │ └── PULL_REQUEST_TEMPLATE.md │ ├── .gitignore │ ├── .prettierignore │ ├── .vscode │ │ ├── extensions.json │ │ ├── launch.json │ │ └── settings.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── jest.config.ts │ ├── oazapfts.config.ts │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── index.ts │ │ ├── queryParamParsers.ts │ │ └── types │ │ │ └── example.d.ts │ ├── tests │ │ └── request-url.test.ts │ ├── tsconfig.json │ └── tsconfig.module.json └── sdk-events │ ├── .cspell.json │ ├── .editorconfig │ ├── .eslintrc.js │ ├── .gitignore │ ├── .prettierignore │ ├── CHANGELOG.md │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── client.ts │ ├── index.ts │ └── types.ts │ ├── tsconfig.json │ └── tsconfig.module.json └── typedoc.js /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Example Contributing Guidelines 2 | 3 | This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | - **Summary** 8 | 9 | - **Other information** (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | - **What is the current behavior?** (You can also link to an open issue here) 4 | 5 | - **What is the new behavior (if this is a feature change)?** 6 | 7 | - **Other information**: 8 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | on: 3 | push: 4 | tags: 5 | - 'v*.*.*' 6 | 7 | jobs: 8 | release: 9 | name: Publish packages to npmjs 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node-version: [16] 14 | steps: 15 | - name: Git Checkout 16 | uses: actions/checkout@master 17 | 18 | - name: Setup Node.js ${{ matrix.node-version }} 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | 23 | - name: Install dependencies 24 | run: npm install --no-package-lock 25 | 26 | - name: Bootstrap lerna 27 | run: npm run bootstrap 28 | 29 | - name: Build packages 30 | run: npx lerna run build 31 | 32 | - name: Setup npm 33 | run: npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_AUTH_TOKEN }}" 34 | 35 | - name: Publish to npmjs 36 | run: npx lerna publish from-package --yes --registry https://registry.npmjs.org/ --loglevel debug --no-git-tag-version --no-push --no-verify-access 37 | 38 | - name: Setup npm 39 | run: npm set "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" 40 | 41 | - name: Publish to github packages 42 | run: npx lerna publish from-package --yes --registry https://npm.pkg.github.com/ --loglevel debug --no-git-tag-version --no-push --no-verify-access 43 | 44 | - name: Build github release 45 | uses: "marvinpinto/action-automatic-releases@latest" 46 | with: 47 | repo_token: "${{ secrets.GITHUB_TOKEN }}" 48 | prerelease: false -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | pull_request: 4 | 5 | jobs: 6 | release: 7 | name: Run linter and tests 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | node-version: [16] 12 | steps: 13 | - name: Git Checkout 14 | uses: actions/checkout@master 15 | 16 | - name: Setup Node.js ${{ matrix.node-version }} 17 | uses: actions/setup-node@v2 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | 21 | - name: Install dependencies 22 | run: npm install 23 | 24 | - name: Bootstrap lerna 25 | run: npm run bootstrap 26 | 27 | - name: Run tests 28 | run: npx lerna run test -------------------------------------------------------------------------------- /.github/workflows/typedoc.yml: -------------------------------------------------------------------------------- 1 | name: Typedoc 2 | on: 3 | push: 4 | branches: 5 | - main 6 | 7 | jobs: 8 | release: 9 | name: Generate TS docs and publish to ghp 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | node-version: [16] 14 | steps: 15 | - name: Git Checkout 16 | uses: actions/checkout@master 17 | 18 | - name: Setup Node.js ${{ matrix.node-version }} 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: ${{ matrix.node-version }} 22 | 23 | - name: Install dependencies 24 | run: npm install 25 | 26 | - name: Bootstrap lerna 27 | run: npm run bootstrap 28 | 29 | - name: Build packages 30 | run: npx lerna run build 31 | 32 | - name: Generate docs 33 | run: npx typedoc 34 | 35 | - name: Deploy to GH Pages 36 | uses: peaceiris/actions-gh-pages@v3 37 | with: 38 | github_token: ${{ secrets.GITHUB_TOKEN }} 39 | publish_dir: ./build/typedoc 40 | cname: sdk.tzkt.io 41 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | node_modules 3 | *.log 4 | yarn.lock 5 | .DS_Store 6 | swagger.json 7 | *.tsbuildinfo 8 | build/ 9 | dist/ -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ### [2.2.1](https://github.com/tzkt/api-sdk-ts/compare/v2.2.0...v2.2.1) (2023-09-20) 7 | 8 | **Note:** Version bump only for package root 9 | 10 | 11 | 12 | 13 | 14 | 15 | ## [2.2.0](https://github.com/tzkt/api-sdk-ts/compare/v2.1.0...v2.2.0) (2023-03-11) 16 | 17 | 18 | ### Features 19 | 20 | * **sdk-api:** update to latest API version ([81fa339](https://github.com/tzkt/api-sdk-ts/commit/81fa339d8c6d00b49ab546714ad24b2bed1dcaca)) 21 | 22 | 23 | 24 | ## [2.1.0](https://github.com/tzkt/api-sdk-ts/compare/v2.0.0...v2.1.0) (2022-12-14) 25 | 26 | 27 | ### Features 28 | 29 | * **sdk-api:** update oazaptfs & add nonNullableRequiredParamExtension ([4e7de0f](https://github.com/tzkt/api-sdk-ts/commit/4e7de0f03bc54560cb71c2eb93d67f0646ae1406)) 30 | 31 | 32 | ### Bug Fixes 33 | 34 | * **ext-taquito:** types issues & getEntrypoints ([b892a8e](https://github.com/tzkt/api-sdk-ts/commit/b892a8edfc76c9782bc830a041324201be339232)) 35 | * **sdk-event:** types issues ([a93a52c](https://github.com/tzkt/api-sdk-ts/commit/a93a52c10ae9a23df9c2817b48a30a96926fcac1)) 36 | 37 | 38 | 39 | ## [2.0.0](https://github.com/tzkt/api-sdk-ts/compare/v1.0.2...v2.0.0) (2022-12-14) 40 | 41 | **Note:** Version bump only for package root 42 | 43 | 44 | 45 | 46 | 47 | ### [1.0.2](https://github.com/tzkt/api-sdk-ts/compare/v1.0.1...v1.0.2) (2022-12-09) 48 | 49 | **Note:** Version bump only for package root 50 | 51 | 52 | 53 | 54 | 55 | ### [1.0.1](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.1) (2022-10-27) 56 | 57 | **Note:** Version bump only for package root 58 | 59 | 60 | 61 | 62 | 63 | ## [1.0.0](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.0) (2022-09-13) 64 | 65 | **Note:** Version bump only for package root 66 | 67 | 68 | 69 | 70 | 71 | ## [0.3.0](https://github.com/tzkt/api-sdk-ts/compare/v0.2.0...v0.3.0) (2022-08-25) 72 | 73 | **Note:** Version bump only for package root 74 | 75 | 76 | 77 | 78 | 79 | ## [0.3.0](https://github.com/tzkt/api-sdk-ts/compare/v0.2.0...v0.3.0) (2022-08-25) 80 | 81 | ### Features 82 | 83 | * Latest TzKT version supported: TORU operations 84 | * `anyof.*.*.eq`, `anyof.*.*.in`, and `anyof.*.*.null` selectors 85 | 86 | ## [0.2.0](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.2.0) (2022-04-30) 87 | 88 | 89 | ### Features 90 | 91 | * update readme ([#7](https://github.com/tzkt/api-sdk-ts/issues/7)) ([31b1d90](https://github.com/tzkt/api-sdk-ts/commit/31b1d90baa7f1926f8d1541ac64faebc4eafce97)) 92 | 93 | 94 | ### Bug Fixes 95 | 96 | * distribute src for sourcemaps ([#9](https://github.com/tzkt/api-sdk-ts/issues/9)) ([d135489](https://github.com/tzkt/api-sdk-ts/commit/d135489ac53b92bf57af2709c026eb5e1c52eb35)) 97 | * **queryParamParsers:** allow for empty `jsonPath` ([3112820](https://github.com/tzkt/api-sdk-ts/commit/31128205047d6daddcb6af716d7a1c5683140f54)) 98 | * **readme:** branch name ([e5d4049](https://github.com/tzkt/api-sdk-ts/commit/e5d4049eac97d6372d5c0cef29e74db3af77b337)) 99 | 100 | 101 | 102 | ### [0.1.3](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.1.3) (2022-04-21) 103 | 104 | **Note:** Version bump only for package root 105 | 106 | 107 | 108 | 109 | 110 | ### [0.1.2](https://github.com/tzkt/api-sdk-ts/compare/v0.1.1...v0.1.2) (2022-04-21) 111 | 112 | 113 | ### Bug Fixes 114 | 115 | * **readme:** use local lerna package for scripts ([ca0da3d](https://github.com/tzkt/api-sdk-ts/commit/ca0da3dd39e8f16bf7621b5b92231767a599e38a)) 116 | 117 | 118 | 119 | ### [0.1.1](https://github.com/tzkt/api-sdk-ts/compare/v0.1.0...v0.1.1) (2022-04-21) 120 | 121 | **Note:** Version bump only for package root 122 | 123 | 124 | 125 | 126 | 127 | ## [0.1.0](https://github.com/tzkt/api-sdk-ts/compare/v0.0.10...v0.1.0) (2022-04-21) 128 | 129 | 130 | ### Features 131 | 132 | * **app:** add sync-swagger npm script ([2b5be1c](https://github.com/tzkt/api-sdk-ts/commit/2b5be1c959d1dbc6a512710c77468c86e4193af4)) 133 | * **deps:** install necessary deps ([1955124](https://github.com/tzkt/api-sdk-ts/commit/1955124f5ca99be25666cbbfb128387f60b3f041)) 134 | * **lerna:** add conventionalcommits changelog preset ([be8f45f](https://github.com/tzkt/api-sdk-ts/commit/be8f45fa12ebbc75661e968f41ccaa4dc5efd358)) 135 | * **lerna:** generate changelog by default ([cec6706](https://github.com/tzkt/api-sdk-ts/commit/cec6706a7fbfa9710fdaa38cb23fdf5fe1bd62f1)) 136 | * **lerna:** init ([8e10a35](https://github.com/tzkt/api-sdk-ts/commit/8e10a358a8b0b7727e6c6afec92ab5d51c615ba9)) 137 | * **lerna:** update release commit message ([431b7af](https://github.com/tzkt/api-sdk-ts/commit/431b7af2818d7f38d64f5e6d51198f899faec4b1)) 138 | * **package:** add generate script ([e0b27c3](https://github.com/tzkt/api-sdk-ts/commit/e0b27c3af3a244d80662f3ab943d112d682d31bb)) 139 | * **package:** add generator config ([e5e04ec](https://github.com/tzkt/api-sdk-ts/commit/e5e04ec9f7ae2a121001da9abd7a325d55d2efe4)) 140 | * **package:** add npmrc config and update package ([485813e](https://github.com/tzkt/api-sdk-ts/commit/485813e18bcc054ae61ccc6ce4898cd3ba6c42be)) 141 | * **package:** add query parameters parsers ([df86356](https://github.com/tzkt/api-sdk-ts/commit/df863565e6be9914d557d3b6c0202843156777fe)) 142 | * **package:** add source swagger file ([2d737a9](https://github.com/tzkt/api-sdk-ts/commit/2d737a94673c2eace56bf7ebcaedde37b42bcba8)) 143 | * **package:** generate api sdk ([b00d3b6](https://github.com/tzkt/api-sdk-ts/commit/b00d3b69b7c15bf70b119933580d3c46e82459de)) 144 | * **package:** udpate engines field, make strict ([f665a3e](https://github.com/tzkt/api-sdk-ts/commit/f665a3ef8d841a1fd0dfa86f68165b5668bf7dad)) 145 | 146 | 147 | ### Bug Fixes 148 | 149 | * **deps:** use remote @tzkt/oazapfts dep ([ffb7537](https://github.com/tzkt/api-sdk-ts/commit/ffb7537d19d87ddece87eda0947945c6641cd917)) 150 | * **lerna:** bump starting version to match api-sdk-ts ([bcf45b2](https://github.com/tzkt/api-sdk-ts/commit/bcf45b22aaf7fdde07f44311163bf53d6d0e6521)) 151 | * **lerna:** change changelog preset ([13b41ce](https://github.com/tzkt/api-sdk-ts/commit/13b41ce65159f2f829dba20f51053a9b7fbaaa97)) 152 | * **lerna:** explicit publish registry ([6eb3918](https://github.com/tzkt/api-sdk-ts/commit/6eb3918df282543bd61f3f9fb087e7aada4af462)) 153 | * **lerna:** remove files moved to packages ([8ed955a](https://github.com/tzkt/api-sdk-ts/commit/8ed955a8250ea1783a884d32499d79aecbca3f49)) 154 | * **lerna:** update changelog to match new format ([183d56c](https://github.com/tzkt/api-sdk-ts/commit/183d56ca579b355e994d12b2800caefcfbde815f)) 155 | * **package.json:** remove publish script ([926a836](https://github.com/tzkt/api-sdk-ts/commit/926a836a9c136ea54b463b189883d7522058cb3e)) 156 | * **package:** explicit public access ([05c3795](https://github.com/tzkt/api-sdk-ts/commit/05c37955cbfef1502bfe7fd50db7c7cf4d340565)) 157 | * **package:** proper publish registry ([ef44609](https://github.com/tzkt/api-sdk-ts/commit/ef446093fd260a4461b8a8b47dc1be8dac79450b)) 158 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 mv-go 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TzKt API SDK written in Typescript 2 | 3 | [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/) 4 | 5 | A collection of packages simplifying working with TzKT APIs. 6 | 7 | Please note, this is a monorepository. Documentation for packages provided by it may be found in readme files in respective project folders. 8 | 9 | ## Install 10 | 11 | Installing any package from this repository for use in you project is as simple as running 12 | 13 | ```bash 14 | npm i @tzkt/ 15 | ``` 16 | 17 | | Name | Description | NPM | 18 | |----------------------------------------------------| -------------------------------- | -------------------------------------------------------------- | 19 | | [@tzkt/sdk-api](packages/sdk-api/README.md) | Wrappers for TzKT API endpoints written in TS | [![npm version](https://badge.fury.io/js/%40tzkt%2Fsdk-api.svg)](https://badge.fury.io/js/%40tzkt%2Fsdk-api) | 20 | | [@tzkt/sdk-events](packages/sdk-events/README.md) | Subscription manager for TzKT events | [![npm version](https://badge.fury.io/js/%40tzkt%2Fsdk-events.svg)](https://badge.fury.io/js/%40tzkt%2Fsdk-events) | 21 | | [@tzkt/ext-taquito](packages/ext-taquito/README.md) | TzKT taquito extension | [![npm version](https://badge.fury.io/js/%40tzkt%2Fext-taquito.svg)](https://badge.fury.io/js/%40tzkt%2Fext-taquito) | 22 | ## Contributing and publishing 23 | 24 | This repository and packages inside of it are managed by Lerna. The preferred package manager is npm. That said - you will need at least `node > 14` and `npm > 6` to proceed. 25 | 26 | ### Development and update 27 | 28 | Documentation on development and updating of packages may be found in the respective folders. Below are some bootstrapping commands that you first need to run in the root of this repository. 29 | 30 | Install dependencies (this will install Lerna and any shared dependencies). 31 | 32 | ```bash 33 | npm install 34 | ``` 35 | 36 | Bootstrap it all together - installs local dependencies and ties it all up. Under the hood it uses `lerna bootstrap` with strict hoisting flags passed to it. 37 | 38 | ```bash 39 | npm run bootstrap 40 | ``` 41 | 42 | ### Build and publish 43 | 44 | After you're done with making your changes, you will need to build packages in this repo and then publish. 45 | 46 | ```bash 47 | npm run build 48 | npm run publish 49 | ``` 50 | -------------------------------------------------------------------------------- /examples/sdk-events-example/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ### [2.2.1](https://github.com/tzkt/api-sdk-ts/compare/v2.2.0...v2.2.1) (2023-09-20) 7 | 8 | **Note:** Version bump only for package @tzkt/sdk-events-example 9 | 10 | 11 | 12 | 13 | 14 | 15 | ## [2.2.0](https://github.com/tzkt/api-sdk-ts/compare/v2.1.0...v2.2.0) (2023-03-11) 16 | 17 | **Note:** Version bump only for package @tzkt/sdk-events-example 18 | 19 | 20 | 21 | 22 | 23 | ## [2.1.0](https://github.com/tzkt/api-sdk-ts/compare/v2.0.0...v2.1.0) (2022-12-14) 24 | 25 | **Note:** Version bump only for package @tzkt/sdk-events-example 26 | 27 | 28 | 29 | 30 | 31 | ## [2.0.0](https://github.com/tzkt/api-sdk-ts/compare/v1.0.2...v2.0.0) (2022-12-14) 32 | 33 | **Note:** Version bump only for package @tzkt/sdk-events-example 34 | 35 | 36 | 37 | 38 | 39 | ### [1.0.1](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.1) (2022-10-27) 40 | 41 | **Note:** Version bump only for package @tzkt/sdk-events-example 42 | 43 | 44 | 45 | 46 | 47 | ## [1.0.0](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.0) (2022-09-13) 48 | 49 | **Note:** Version bump only for package @tzkt/sdk-events-example 50 | 51 | 52 | 53 | 54 | 55 | ## [0.3.0](https://github.com/tzkt/api-sdk-ts/compare/v0.2.0...v0.3.0) (2022-08-25) 56 | 57 | **Note:** Version bump only for package @tzkt/sdk-events-example 58 | 59 | 60 | 61 | 62 | 63 | ## [0.2.0](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.2.0) (2022-04-30) 64 | 65 | **Note:** Version bump only for package @tzkt/sdk-events-example 66 | -------------------------------------------------------------------------------- /examples/sdk-events-example/README.md: -------------------------------------------------------------------------------- 1 | # Demo: Tezos token transfers subscription 2 | 3 | ## Install 4 | ``` 5 | npm run install 6 | ``` 7 | 8 | ## Run 9 | ``` 10 | npm run serve 11 | ``` 12 | -------------------------------------------------------------------------------- /examples/sdk-events-example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /examples/sdk-events-example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tzkt/sdk-events-example", 3 | "version": "2.2.1", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve --open" 7 | }, 8 | "dependencies": { 9 | "@tzkt/sdk-events": "^2.2.1", 10 | "@vue/composition-api": "^1.0.0-rc.12", 11 | "acorn": "^8.7.1", 12 | "buefy": "^0.9.8", 13 | "bulma": "^0.9.3", 14 | "core-js": "^3.6.5", 15 | "vue": "~2.6.14", 16 | "webpack": "^5.0.0" 17 | }, 18 | "devDependencies": { 19 | "@babel/eslint-parser": "^7.17.0", 20 | "@babel/plugin-proposal-class-properties": "^7.16.7", 21 | "@typescript-eslint/eslint-plugin": "^5.46.1", 22 | "@typescript-eslint/parser": "^5.46.1", 23 | "@vue/cli": "^5.0.8", 24 | "@vue/cli-plugin-babel": "~5.0.8", 25 | "@vue/cli-plugin-eslint": "~5.0.8", 26 | "@vue/cli-plugin-typescript": "~5.0.8", 27 | "@vue/cli-service": "~5.0.8", 28 | "@vue/eslint-config-typescript": "^10.0.0", 29 | "babel-loader": "^8.2.5", 30 | "eslint": "^7.10.0", 31 | "eslint-plugin-vue": "^8.0.1", 32 | "typedoc": "^0.23.22", 33 | "typescript": "^4.9.4", 34 | "vue-template-compiler": "~2.6.14" 35 | }, 36 | "peerDependencies": { 37 | "css-loader": "3.6.0" 38 | }, 39 | "eslintConfig": { 40 | "root": true, 41 | "env": { 42 | "node": true 43 | }, 44 | "extends": [ 45 | "plugin:vue/essential", 46 | "eslint:recommended", 47 | "@vue/typescript" 48 | ], 49 | "parserOptions": { 50 | "parser": "@typescript-eslint/parser" 51 | } 52 | }, 53 | "browserslist": [ 54 | "> 1%", 55 | "last 2 versions", 56 | "not dead" 57 | ] 58 | } 59 | -------------------------------------------------------------------------------- /examples/sdk-events-example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= htmlWebpackPlugin.options.title %> 8 | 9 | 10 | 13 |
14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/sdk-events-example/src/App.vue: -------------------------------------------------------------------------------- 1 | 83 | 84 | 135 | -------------------------------------------------------------------------------- /examples/sdk-events-example/src/main.ts: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueCompositionApi from '@vue/composition-api' 3 | import App from './App.vue' 4 | import Buefy from 'buefy' 5 | import 'buefy/dist/buefy.css' 6 | 7 | Vue.use(VueCompositionApi); 8 | Vue.use(Buefy); 9 | 10 | /*eslint no-unexpected-multiline: "off"*/ 11 | (async () => { 12 | return new Vue({ 13 | render: h => h(App) 14 | }).$mount('#app'); 15 | })(); 16 | -------------------------------------------------------------------------------- /examples/sdk-events-example/src/shims-vue.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.vue' { 2 | import Vue from 'vue' 3 | export default Vue 4 | } 5 | -------------------------------------------------------------------------------- /examples/sdk-events-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "esnext", 4 | "module": "esnext", 5 | "strict": true, 6 | "jsx": "preserve", 7 | "importHelpers": true, 8 | "moduleResolution": "node16", 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "sourceMap": true, 14 | "baseUrl": ".", 15 | "types": ["webpack-env"], 16 | "paths": { 17 | "@/*": ["src/*"] 18 | }, 19 | "lib": ["esnext", "dom", "dom.iterable", "scripthost"] 20 | }, 21 | "include": [ 22 | "src/**/*.ts", 23 | "src/**/*.tsx", 24 | "src/**/*.vue", 25 | "tests/**/*.ts", 26 | "tests/**/*.tsx" 27 | ], 28 | "exclude": ["node_modules"] 29 | } 30 | -------------------------------------------------------------------------------- /examples/sdk-events-example/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | chainWebpack: config => { 3 | config.module 4 | .rule('js') 5 | .use('babel-loader') 6 | .loader('babel-loader') 7 | .end() 8 | } 9 | } -------------------------------------------------------------------------------- /examples/sdk-events-example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { VueLoaderPlugin } = require("vue-loader"); 2 | const path = require("path"); 3 | 4 | module.exports = { 5 | entry: { 6 | main: "./src/main.js", 7 | }, 8 | output: { 9 | path: path.resolve(__dirname, "dist"), 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.js$/, 15 | exclude: /node_modules/, 16 | use: { 17 | loader: "babel-loader", 18 | }, 19 | }, 20 | { 21 | test: /\.vue$/, 22 | loader: "vue-loader", 23 | }, 24 | ], 25 | }, 26 | plugins: [ 27 | new VueLoaderPlugin(), 28 | ], 29 | resolve: { 30 | alias: { 31 | vue$: "vue/dist/vue.runtime.esm.js", 32 | }, 33 | extensions: ["*", ".js", ".vue", ".json"], 34 | }, 35 | }; -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*", 4 | "examples/*" 5 | ], 6 | "version": "2.2.1", 7 | "conventionalCommits": true, 8 | "changelogPreset": "conventionalcommits", 9 | "command": { 10 | "version": { 11 | "message": "chore(release): %v" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "root", 3 | "private": true, 4 | "devDependencies": { 5 | "@knodes/typedoc-plugin-pages": "^0.23.1", 6 | "conventional-changelog-conventionalcommits": "^4.6.3", 7 | "lerna": "^4.0.0", 8 | "typedoc": "^0.23.22", 9 | "typescript": "^4.9.4" 10 | }, 11 | "scripts": { 12 | "bootstrap": "lerna bootstrap --hoist --strict", 13 | "build": "lerna run build", 14 | "publish": "lerna version", 15 | "typedoc": "typedoc" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /packages/ext-taquito/.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", 4 | "language": "en", 5 | "words": [ 6 | "annots", 7 | "taquito", 8 | "anyof", 9 | "Atomex", 10 | "nocheck", 11 | "bigmap", 12 | "bignumber", 13 | "entypoints", 14 | "entypoint", 15 | "bigmaps", 16 | "bitauth", 17 | "bitjson", 18 | "ticketer", 19 | "rollups", 20 | "Tezos", 21 | "cimg", 22 | "circleci", 23 | "codecov", 24 | "codegen", 25 | "commitlint", 26 | "datetime", 27 | "Delegators", 28 | "dependabot", 29 | "editorconfig", 30 | "entrypoint", 31 | "entrypoints", 32 | "esnext", 33 | "execa", 34 | "exponentiate", 35 | "globby", 36 | "libauth", 37 | "micheline", 38 | "mkdir", 39 | "oazapfts", 40 | "OBJKT", 41 | "openapi", 42 | "originations", 43 | "preendorsement", 44 | "preendorsements", 45 | "preendorsing", 46 | "prettierignore", 47 | "sandboxed", 48 | "supermajority", 49 | "transpiled", 50 | "typedoc", 51 | "tzips", 52 | "tzkt", 53 | "untracked", 54 | "upvoted", 55 | "upvotes" 56 | ], 57 | "flagWords": [], 58 | "ignorePaths": [ 59 | "package.json", 60 | "package-lock.json", 61 | "yarn.lock", 62 | "tsconfig.json", 63 | "node_modules/**", 64 | "swagger.json" 65 | ], 66 | "ignoreRegExpList": [ 67 | "(tz|KT)[1-9A-HJ-NP-Za-km-z]{34}", 68 | "o[1-9A-HJ-NP-Za-km-z]{50}" 69 | ] 70 | } 71 | -------------------------------------------------------------------------------- /packages/ext-taquito/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | max_line_length = 80 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | max_line_length = 0 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /packages/ext-taquito/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line no-undef 2 | module.exports = { 3 | "root": true, 4 | "parser": "@typescript-eslint/parser", 5 | "parserOptions": { 6 | "project": "./tsconfig.json", 7 | // eslint-disable-next-line no-undef 8 | "tsconfigRootDir": __dirname, 9 | }, 10 | "env": { "es6": true }, 11 | "ignorePatterns": ["node_modules", "build", "coverage"], 12 | "plugins": ["import", "eslint-comments", "functional"], 13 | "extends": [ 14 | "eslint:recommended", 15 | "plugin:eslint-comments/recommended", 16 | "plugin:@typescript-eslint/recommended", 17 | "plugin:import/typescript", 18 | // "plugin:functional/lite", 19 | "prettier", 20 | "prettier/@typescript-eslint" 21 | ], 22 | "globals": { "BigInt": true, "console": true, "WebAssembly": true }, 23 | "rules": { 24 | "@typescript-eslint/explicit-module-boundary-types": "off", 25 | "eslint-comments/disable-enable-pair": [ 26 | "error", 27 | { "allowWholeFile": true } 28 | ], 29 | "eslint-comments/no-unused-disable": "error", 30 | "import/order": [ 31 | "error", 32 | { "newlines-between": "always", "alphabetize": { "order": "asc" } } 33 | ], 34 | "sort-imports": [ 35 | "error", 36 | { "ignoreDeclarationSort": true, "ignoreCase": true } 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/ext-taquito/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .nyc_output 3 | build 4 | node_modules 5 | test 6 | src/**.js 7 | coverage 8 | *.log 9 | yarn.lock 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /packages/ext-taquito/.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json -------------------------------------------------------------------------------- /packages/ext-taquito/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [2.2.0](https://github.com/tzkt/api-sdk-ts/compare/v2.1.0...v2.2.0) (2023-03-11) 7 | 8 | **Note:** Version bump only for package @tzkt/ext-taquito 9 | 10 | 11 | 12 | 13 | 14 | ## [2.1.0](https://github.com/tzkt/api-sdk-ts/compare/v2.0.0...v2.1.0) (2022-12-14) 15 | 16 | 17 | ### Bug Fixes 18 | 19 | * **ext-taquito:** types issues & getEntrypoints ([b892a8e](https://github.com/tzkt/api-sdk-ts/commit/b892a8edfc76c9782bc830a041324201be339232)) 20 | 21 | 22 | 23 | ## [2.0.0](https://github.com/tzkt/api-sdk-ts/compare/v1.0.2...v2.0.0) (2022-12-14) 24 | 25 | **Note:** Version bump only for package @tzkt/ext-taquito 26 | 27 | 28 | 29 | 30 | 31 | ### [1.0.2](https://github.com/tzkt/api-sdk-ts/compare/v1.0.1...v1.0.2) (2022-12-09) 32 | 33 | **Note:** Version bump only for package @tzkt/ext-taquito 34 | 35 | 36 | 37 | 38 | 39 | ### [1.0.1](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.1) (2022-10-27) 40 | 41 | **Note:** Version bump only for package @tzkt/ext-taquito 42 | -------------------------------------------------------------------------------- /packages/ext-taquito/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 mv-go 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/ext-taquito/README.md: -------------------------------------------------------------------------------- 1 | # TzKT taquito extension 2 | Extension that will reduce the load on the main node and speed up interaction with data 3 | 4 | ## Install 5 | 6 | ```bash 7 | npm i @tzkt/ext-taquito 8 | ``` 9 | 10 | ## Use 11 | 12 | ### Basic config 13 | 14 | Simplest example of integrating and using an extension with basic settings. 15 | 16 | ```js 17 | import { TezosToolkit } from '@taquito/taquito'; 18 | import { TzktExtension } from '@tzkt/ext-taquito'; 19 | 20 | const Tezos = new TezosToolkit('https://rpc.tzkt.io/mainnet'); 21 | Tezos.addExtension(new TzktExtension()); 22 | 23 | const balance = await Tezos.tz.getBalance('tz1WMrppYADANWkNus4vs8xqKztacLETnKmT') 24 | ``` 25 | 26 | ### Change api endpoint 27 | 28 | You may override base URL used by the package in the following manner. This may come useful should you want to make requests to a test network or to your custom server. 29 | 30 | ```js 31 | Tezos.addExtension(new TzktExtension({url: 'https://api.tzkt.io'})); 32 | ``` 33 | -------------------------------------------------------------------------------- /packages/ext-taquito/jest.config.ts: -------------------------------------------------------------------------------- 1 | import { Config } from "@jest/types"; 2 | 3 | const config: Config.InitialOptions = { 4 | verbose: true, 5 | preset: "ts-jest", 6 | rootDir: "./", 7 | restoreMocks: true, 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /packages/ext-taquito/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tzkt/ext-taquito", 3 | "version": "2.2.0", 4 | "description": "TzKt taquito extension", 5 | "main": "build/main/index.js", 6 | "types": "build/main/index.d.ts", 7 | "typings": "build/main/index.d.ts", 8 | "module": "build/module/index.js", 9 | "repository": "git://github.com/tzkt/api-sdk-ts.git", 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "license": "MIT", 14 | "keywords": [], 15 | "scripts": { 16 | "build": "run-p build:*", 17 | "build:main": "tsc -p tsconfig.json", 18 | "build:module": "tsc -p tsconfig.module.json", 19 | "fix": "run-s fix:*", 20 | "fix:prettier": "prettier \"src/**/*.ts\" --write", 21 | "fix:lint": "eslint src --ext .ts --fix", 22 | "test": "run-s build test:*", 23 | "test:lint": "eslint src --ext .ts", 24 | "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"", 25 | "test:extension": "jest", 26 | "test:extension:watch": "jest --watch", 27 | "check-cli": "run-s test diff-integration-tests check-integration-tests", 28 | "check-integration-tests": "run-s check-integration-test:*", 29 | "diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'", 30 | "watch:build": "tsc -p tsconfig.json -w", 31 | "watch:test": "nyc --silent ava --watch", 32 | "cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html", 33 | "cov:html": "nyc report --reporter=html", 34 | "cov:lcov": "nyc report --reporter=lcov", 35 | "cov:send": "run-s cov:lcov && codecov", 36 | "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", 37 | "doc": "run-s doc:html && open-cli build/docs/index.html", 38 | "doc:html": "typedoc src/ --exclude **/*.spec.ts --out build/docs", 39 | "doc:json": "typedoc src/ --exclude **/*.spec.ts --json build/docs/typedoc.json", 40 | "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs", 41 | "reset-hard": "git clean -dfx && git reset --hard && npm i", 42 | "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish" 43 | }, 44 | "engines": { 45 | "node": ">=14", 46 | "npm": ">=6" 47 | }, 48 | "engineStrict": true, 49 | "devDependencies": { 50 | "@ava/typescript": "^1.1.1", 51 | "@istanbuljs/nyc-config-typescript": "^1.0.1", 52 | "@types/jest": "^29.0.0", 53 | "@types/lodash": "^4.14.178", 54 | "@types/node": "^16.0.0", 55 | "@typescript-eslint/eslint-plugin": "^5.46.1", 56 | "@typescript-eslint/parser": "^5.46.1", 57 | "ava": "^3.12.1", 58 | "codecov": "^3.5.0", 59 | "cspell": "^4.1.0", 60 | "cz-conventional-changelog": "^3.3.0", 61 | "eslint": "^7.10.0", 62 | "eslint-config-prettier": "^6.11.0", 63 | "eslint-plugin-eslint-comments": "^3.2.0", 64 | "eslint-plugin-functional": "^3.0.2", 65 | "eslint-plugin-import": "^2.22.0", 66 | "gh-pages": "^3.1.0", 67 | "jest": "^29.0.0", 68 | "lodash": "^4.17.21", 69 | "npm-run-all": "^4.1.5", 70 | "nyc": "^15.1.0", 71 | "open-cli": "^6.0.1", 72 | "openapi-types": "^10.0.0", 73 | "prettier": "^2.1.1", 74 | "standard-version": "^9.0.0", 75 | "ts-jest": "^29.1.1", 76 | "ts-node-dev": "^2.0.0", 77 | "typedoc": "^0.23.22", 78 | "typescript": "^4.9.4" 79 | }, 80 | "files": [ 81 | "build/main", 82 | "build/module", 83 | "!**/*.spec.*", 84 | "!**/*.json", 85 | "CHANGELOG.md", 86 | "LICENSE", 87 | "README.md", 88 | "src" 89 | ], 90 | "ava": { 91 | "failFast": true, 92 | "timeout": "60s", 93 | "typescript": { 94 | "rewritePaths": { 95 | "src/": "build/main/" 96 | } 97 | }, 98 | "files": [ 99 | "!build/module/**" 100 | ] 101 | }, 102 | "config": { 103 | "commitizen": { 104 | "path": "cz-conventional-changelog" 105 | } 106 | }, 107 | "prettier": { 108 | "singleQuote": true 109 | }, 110 | "nyc": { 111 | "extends": "@istanbuljs/nyc-config-typescript", 112 | "exclude": [ 113 | "**/*.spec.js" 114 | ] 115 | }, 116 | "dependencies": { 117 | "@taquito/taquito": "^15.0.1", 118 | "@tzkt/sdk-api": "^2.2.0", 119 | "cross-fetch": "^3.1.5" 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /packages/ext-taquito/src/index.ts: -------------------------------------------------------------------------------- 1 | import { Context, Extension } from '@taquito/taquito'; 2 | import * as api from '@tzkt/sdk-api'; 3 | 4 | import { TzktReadProvider } from './tzktReadProvider'; 5 | 6 | class TzktExtension implements Extension { 7 | constructor({ url }: { url?: string } = {}) { 8 | if (url) { 9 | api.defaults.baseUrl = url; 10 | api.servers.server1 = url; 11 | } 12 | } 13 | 14 | configureContext(context: Context): void { 15 | const readProvider = new TzktReadProvider(context.readProvider); 16 | Object.assign(context, { readProvider }); 17 | } 18 | } 19 | 20 | export { TzktExtension }; 21 | -------------------------------------------------------------------------------- /packages/ext-taquito/src/tzktReadProvider.ts: -------------------------------------------------------------------------------- 1 | import 'cross-fetch/polyfill'; 2 | import { 3 | BlockResponse, 4 | EntrypointsResponse, 5 | MichelsonV1Expression, 6 | SaplingDiffResponse, 7 | ScriptedContracts, 8 | } from '@taquito/rpc'; 9 | import { 10 | BigMapQuery, 11 | BlockIdentifier, 12 | SaplingStateQuery, 13 | TzReadProvider, 14 | } from '@taquito/taquito'; 15 | import { 16 | accountsGetBalance, 17 | accountsGetBalanceAtLevel, 18 | accountsGetByAddress, 19 | accountsGetCounter, 20 | bigMapsGetKey, 21 | bigMapsGetKey2, 22 | Block, 23 | blocksGet, 24 | blocksGetByHash, 25 | blocksGetByLevel, 26 | blocksGetCount, 27 | contractsGetCode, 28 | contractsGetEntrypoints, 29 | contractsGetRawStorage, 30 | Entrypoint, 31 | headGet, 32 | Protocol, 33 | protocolsGetByCycle, 34 | protocolsGetCurrent, 35 | } from '@tzkt/sdk-api'; 36 | import { BigNumber } from 'bignumber.js'; 37 | 38 | export class TzktReadProvider implements TzReadProvider { 39 | constructor(private readProvider: TzReadProvider) {} 40 | 41 | private readonly liveBlocksLimit = 120; 42 | 43 | private async _getBlockLevel(block: BlockIdentifier): Promise { 44 | if (typeof block === 'number') { 45 | return block; 46 | } 47 | 48 | if (this._blockIdIsHead(block)) { 49 | return blocksGetCount(); 50 | } 51 | 52 | if (String(block).includes('head~')) { 53 | const n = Number(String(block).split('head~')[1]); 54 | const count = await blocksGetCount(); 55 | 56 | return Number(count) - n; 57 | } 58 | 59 | const { level } = await blocksGetByHash(block); 60 | return level || 0; 61 | } 62 | 63 | private _blockIdIsHash(block: BlockIdentifier) { 64 | return String(block)[0] === 'B'; 65 | } 66 | 67 | private _blockIdIsHead(block: BlockIdentifier) { 68 | return typeof block !== 'number' && (!block || block === 'head'); 69 | } 70 | 71 | async getScript( 72 | address: string, 73 | block: BlockIdentifier 74 | ): Promise { 75 | let filter; 76 | 77 | if (!this._blockIdIsHead(block)) { 78 | const blockLevel = await this._getBlockLevel(block); 79 | filter = { level: blockLevel }; 80 | } 81 | 82 | const [codeBlob, storage] = await Promise.all([ 83 | contractsGetCode(address, filter), 84 | contractsGetRawStorage(address, filter) as MichelsonV1Expression, 85 | ]); 86 | 87 | const codeText = await codeBlob.text(); 88 | const code = JSON.parse(codeText) as MichelsonV1Expression[]; 89 | 90 | return { 91 | code, 92 | storage, 93 | }; 94 | } 95 | 96 | async getBalance( 97 | address: string, 98 | block: BlockIdentifier 99 | ): Promise { 100 | if (this._blockIdIsHead(block)) { 101 | const balance = await accountsGetBalance(address); 102 | return new BigNumber(balance); 103 | } 104 | 105 | const blockLevel = await this._getBlockLevel(block); 106 | const balance = await accountsGetBalanceAtLevel(address, blockLevel); 107 | return new BigNumber(balance); 108 | } 109 | 110 | async getDelegate( 111 | address: string, 112 | block: BlockIdentifier 113 | ): Promise { 114 | if (!this._blockIdIsHead(block)) { 115 | return this.readProvider.getDelegate(address, block); 116 | } 117 | 118 | const account = await accountsGetByAddress(address); 119 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 120 | // @ts-ignore 121 | return account?.delegate?.address; 122 | } 123 | 124 | async getNextProtocol(block: BlockIdentifier): Promise { 125 | if (!this._blockIdIsHead(block)) { 126 | return this.readProvider.getNextProtocol(block); 127 | } 128 | 129 | const protocol = await protocolsGetCurrent(); 130 | return protocol?.hash || ''; 131 | } 132 | 133 | async getProtocolConstants(block: BlockIdentifier): Promise<{ 134 | time_between_blocks?: BigNumber[] | undefined; 135 | minimal_block_delay?: BigNumber | undefined; 136 | hard_gas_limit_per_operation: BigNumber; 137 | hard_gas_limit_per_block: BigNumber; 138 | hard_storage_limit_per_operation: BigNumber; 139 | cost_per_byte: BigNumber; 140 | }> { 141 | let protocol: Protocol; 142 | 143 | if (!this._blockIdIsHead(block)) { 144 | const blockLevel = await this._getBlockLevel(block); 145 | const { cycle } = await blocksGetByLevel(blockLevel); 146 | 147 | protocol = await protocolsGetByCycle(cycle || 0); 148 | } else { 149 | protocol = await protocolsGetCurrent(); 150 | } 151 | 152 | return { 153 | time_between_blocks: 154 | [new BigNumber(protocol?.constants?.timeBetweenBlocks || 0)] || 155 | undefined, 156 | minimal_block_delay: new BigNumber(0), 157 | hard_gas_limit_per_operation: new BigNumber( 158 | protocol?.constants?.hardOperationGasLimit || 0 159 | ), 160 | hard_gas_limit_per_block: new BigNumber( 161 | protocol?.constants?.hardBlockGasLimit || 0 162 | ), 163 | hard_storage_limit_per_operation: new BigNumber( 164 | protocol?.constants?.hardOperationStorageLimit || 0 165 | ), 166 | cost_per_byte: new BigNumber(protocol?.constants?.byteCost || 0), 167 | }; 168 | } 169 | 170 | async getStorage( 171 | contract: string, 172 | block: BlockIdentifier 173 | ): Promise { 174 | if (this._blockIdIsHead(block)) { 175 | return contractsGetRawStorage(contract) as MichelsonV1Expression; 176 | } 177 | 178 | const blockLevel = await this._getBlockLevel(block); 179 | return contractsGetRawStorage(contract, { 180 | level: blockLevel, 181 | }) as MichelsonV1Expression; 182 | } 183 | 184 | async getBlockHash(block: BlockIdentifier): Promise { 185 | if (this._blockIdIsHash(block)) { 186 | return String(block); 187 | } 188 | 189 | if (this._blockIdIsHead(block)) { 190 | const blocks = await blocksGet({ 191 | sort: { desc: 'level' }, 192 | select: { fields: ['hash'] }, 193 | limit: 1, 194 | }); 195 | 196 | return String(blocks[0]); 197 | } 198 | 199 | const blockLevel = await this._getBlockLevel(block); 200 | const { hash } = await blocksGetByLevel(blockLevel); 201 | 202 | return hash as string; 203 | } 204 | 205 | async getBlockLevel(block: BlockIdentifier): Promise { 206 | return this._getBlockLevel(block); 207 | } 208 | 209 | async getCounter(pkh: string): Promise { 210 | const counter = await accountsGetCounter(pkh); 211 | return String(counter); 212 | } 213 | 214 | async getBlockTimestamp(block: BlockIdentifier): Promise { 215 | if (this._blockIdIsHash(block)) { 216 | const { timestamp } = await blocksGetByHash(block as string); 217 | return timestamp as string; 218 | } 219 | 220 | if (this._blockIdIsHead(block)) { 221 | const blocks = await blocksGet({ 222 | sort: { desc: 'level' }, 223 | select: { fields: ['timestamp'] }, 224 | limit: 1, 225 | }); 226 | return String(blocks[0]); 227 | } 228 | 229 | const blockLevel = await this._getBlockLevel(block); 230 | const { timestamp } = await blocksGetByLevel(blockLevel); 231 | return timestamp || ''; 232 | } 233 | 234 | async getBigMapValue( 235 | bigMapQuery: BigMapQuery, 236 | block: BlockIdentifier 237 | ): Promise { 238 | if (!this._blockIdIsHead(block)) { 239 | const { value } = await bigMapsGetKey( 240 | Number(bigMapQuery.id), 241 | bigMapQuery.expr, 242 | { micheline: 'Raw' } 243 | ); 244 | return value; 245 | } 246 | 247 | const blockLevel = await this._getBlockLevel(block); 248 | 249 | const { value } = await bigMapsGetKey2( 250 | Number(bigMapQuery.id), 251 | blockLevel, 252 | bigMapQuery.expr, 253 | { micheline: 'Raw' } 254 | ); 255 | return value; 256 | } 257 | 258 | getSaplingDiffById( 259 | saplingStateQuery: SaplingStateQuery, 260 | block: BlockIdentifier 261 | ): Promise { 262 | return this.readProvider.getSaplingDiffById(saplingStateQuery, block); 263 | } 264 | 265 | getSaplingDiffByContract( 266 | contractAddress: string, 267 | block: BlockIdentifier 268 | ): Promise { 269 | return this.readProvider.getSaplingDiffByContract(contractAddress, block); 270 | } 271 | 272 | async getEntrypoints(contract: string): Promise { 273 | const response = await contractsGetEntrypoints(contract, { 274 | json: false, 275 | micheline: true, 276 | all: true, 277 | }); 278 | 279 | const entrypoints = response.map((entrypoint: Entrypoint) => { 280 | return [entrypoint.name, entrypoint.michelineParameters]; 281 | }); 282 | 283 | return { 284 | entrypoints: Object.fromEntries(entrypoints), 285 | }; 286 | } 287 | 288 | async getChainId(): Promise { 289 | const { chainId } = await headGet(); 290 | 291 | return chainId || ''; 292 | } 293 | 294 | async isAccountRevealed( 295 | publicKeyHash: string, 296 | block: BlockIdentifier 297 | ): Promise { 298 | if (this._blockIdIsHead(block)) { 299 | const account = await accountsGetByAddress(publicKeyHash); 300 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment 301 | // @ts-ignore 302 | return account.revealed as boolean; 303 | } 304 | 305 | return this.readProvider.isAccountRevealed(publicKeyHash, block); 306 | } 307 | 308 | getBlock(block: BlockIdentifier): Promise { 309 | return this.readProvider.getBlock(block); 310 | } 311 | 312 | async getLiveBlocks(block: BlockIdentifier): Promise { 313 | let filters = {}; 314 | 315 | if (this._blockIdIsHash(block)) { 316 | return [String(block)]; 317 | } 318 | 319 | if (!this._blockIdIsHead(block)) { 320 | filters = { 321 | level: { 322 | le: await this._getBlockLevel(block), 323 | }, 324 | }; 325 | } 326 | 327 | const liveBlocks = await blocksGet({ 328 | sort: { 329 | desc: 'level', 330 | }, 331 | limit: this.liveBlocksLimit, 332 | select: { fields: ['hash,timestamp'] }, // FIXME: https://github.com/tzkt/api-sdk-ts/issues/24 333 | ...filters, 334 | }); 335 | 336 | return liveBlocks.map((d: Block) => d?.hash || ''); 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /packages/ext-taquito/tests/data/contractScript.ts: -------------------------------------------------------------------------------- 1 | export const contractScript = { 2 | code: [ 3 | { 4 | prim: "parameter", 5 | args: [ 6 | { 7 | prim: "or", 8 | args: [ 9 | { 10 | prim: "or", 11 | args: [ 12 | { 13 | prim: "pair", 14 | args: [ 15 | { 16 | prim: "address", 17 | annots: [ 18 | "%participant" 19 | ] 20 | }, 21 | { 22 | prim: "pair", 23 | args: [ 24 | { 25 | prim: "pair", 26 | args: [ 27 | { 28 | prim: "bytes", 29 | annots: [ 30 | "%hashed_secret" 31 | ] 32 | }, 33 | { 34 | prim: "timestamp", 35 | annots: [ 36 | "%refund_time" 37 | ] 38 | } 39 | ] 40 | }, 41 | { 42 | prim: "mutez", 43 | annots: [ 44 | "%payoff" 45 | ] 46 | } 47 | ], 48 | annots: [ 49 | "%settings" 50 | ] 51 | } 52 | ], 53 | annots: [ 54 | ":initiate", 55 | "%initiate" 56 | ] 57 | }, 58 | { 59 | prim: "bytes", 60 | annots: [ 61 | ":hashed_secret", 62 | "%add" 63 | ] 64 | } 65 | ], 66 | annots: [ 67 | "%fund" 68 | ] 69 | }, 70 | { 71 | prim: "or", 72 | args: [ 73 | { 74 | prim: "bytes", 75 | annots: [ 76 | ":secret", 77 | "%redeem" 78 | ] 79 | }, 80 | { 81 | prim: "bytes", 82 | annots: [ 83 | ":hashed_secret", 84 | "%refund" 85 | ] 86 | } 87 | ], 88 | annots: [ 89 | "%withdraw" 90 | ] 91 | } 92 | ] 93 | } 94 | ] 95 | }, 96 | { 97 | prim: "storage", 98 | args: [ 99 | { 100 | prim: "pair", 101 | args: [ 102 | { 103 | prim: "big_map", 104 | args: [ 105 | { 106 | prim: "bytes" 107 | }, 108 | { 109 | prim: "pair", 110 | args: [ 111 | { 112 | prim: "pair", 113 | args: [ 114 | { 115 | prim: "address", 116 | annots: [ 117 | "%initiator" 118 | ] 119 | }, 120 | { 121 | prim: "address", 122 | annots: [ 123 | "%participant" 124 | ] 125 | } 126 | ], 127 | annots: [ 128 | "%recipients" 129 | ] 130 | }, 131 | { 132 | prim: "pair", 133 | args: [ 134 | { 135 | prim: "pair", 136 | args: [ 137 | { 138 | prim: "mutez", 139 | annots: [ 140 | "%amount" 141 | ] 142 | }, 143 | { 144 | prim: "timestamp", 145 | annots: [ 146 | "%refund_time" 147 | ] 148 | } 149 | ] 150 | }, 151 | { 152 | prim: "mutez", 153 | annots: [ 154 | "%payoff" 155 | ] 156 | } 157 | ], 158 | annots: [ 159 | "%settings" 160 | ] 161 | } 162 | ] 163 | } 164 | ] 165 | }, 166 | { 167 | prim: "unit" 168 | } 169 | ] 170 | } 171 | ] 172 | }, 173 | { 174 | prim: "code", 175 | args: [ 176 | [ 177 | { 178 | prim: "NIL", 179 | args: [ 180 | { 181 | prim: "operation" 182 | } 183 | ], 184 | annots: [ 185 | "@operations" 186 | ] 187 | }, 188 | { 189 | prim: "SWAP" 190 | }, 191 | [ 192 | [ 193 | { 194 | prim: "DUP" 195 | }, 196 | { 197 | prim: "CAR", 198 | annots: [ 199 | "@%" 200 | ] 201 | }, 202 | { 203 | prim: "DIP", 204 | args: [ 205 | [ 206 | { 207 | prim: "CDR" 208 | } 209 | ] 210 | ] 211 | } 212 | ], 213 | { 214 | prim: "DIP", 215 | args: [ 216 | [ 217 | [ 218 | { 219 | prim: "DUP" 220 | }, 221 | { 222 | prim: "CAR", 223 | annots: [ 224 | "@%" 225 | ] 226 | }, 227 | { 228 | prim: "DIP", 229 | args: [ 230 | [ 231 | { 232 | prim: "CDR", 233 | annots: [ 234 | "@%" 235 | ] 236 | } 237 | ] 238 | ] 239 | } 240 | ] 241 | ] 242 | ] 243 | } 244 | ], 245 | { 246 | prim: "DIP", 247 | args: [ 248 | [ 249 | { 250 | prim: "DUP" 251 | } 252 | ] 253 | ] 254 | }, 255 | { 256 | prim: "IF_LEFT", 257 | args: [ 258 | [ 259 | { 260 | prim: "IF_LEFT", 261 | args: [ 262 | [ 263 | [ 264 | [ 265 | { 266 | prim: "DUP" 267 | }, 268 | { 269 | prim: "CAR", 270 | annots: [ 271 | "@%" 272 | ] 273 | }, 274 | { 275 | prim: "DIP", 276 | args: [ 277 | [ 278 | { 279 | prim: "CDR", 280 | annots: [ 281 | "@%" 282 | ] 283 | } 284 | ] 285 | ] 286 | } 287 | ] 288 | ], 289 | { 290 | prim: "DUP" 291 | }, 292 | { 293 | prim: "CONTRACT", 294 | args: [ 295 | { 296 | prim: "unit" 297 | } 298 | ], 299 | annots: [ 300 | "@participant" 301 | ] 302 | }, 303 | [ 304 | { 305 | prim: "IF_NONE", 306 | args: [ 307 | [ 308 | [ 309 | { 310 | prim: "UNIT" 311 | }, 312 | { 313 | prim: "FAILWITH" 314 | } 315 | ] 316 | ], 317 | [] 318 | ] 319 | } 320 | ], 321 | { 322 | prim: "DROP" 323 | }, 324 | { 325 | prim: "SWAP" 326 | }, 327 | [ 328 | [ 329 | { 330 | prim: "DUP" 331 | }, 332 | { 333 | prim: "CAR" 334 | }, 335 | { 336 | prim: "DIP", 337 | args: [ 338 | [ 339 | { 340 | prim: "CDR", 341 | annots: [ 342 | "@%" 343 | ] 344 | } 345 | ] 346 | ] 347 | } 348 | ], 349 | [ 350 | { 351 | prim: "DUP" 352 | }, 353 | { 354 | prim: "CAR", 355 | annots: [ 356 | "@%" 357 | ] 358 | }, 359 | { 360 | prim: "DIP", 361 | args: [ 362 | [ 363 | { 364 | prim: "CDR", 365 | annots: [ 366 | "@%" 367 | ] 368 | } 369 | ] 370 | ] 371 | } 372 | ] 373 | ], 374 | { 375 | prim: "DUP" 376 | }, 377 | { 378 | prim: "SIZE" 379 | }, 380 | { 381 | prim: "PUSH", 382 | args: [ 383 | { 384 | prim: "nat" 385 | }, 386 | { 387 | int: "32" 388 | } 389 | ] 390 | }, 391 | [ 392 | [ 393 | { 394 | prim: "COMPARE" 395 | }, 396 | { 397 | prim: "EQ" 398 | } 399 | ], 400 | { 401 | prim: "IF", 402 | args: [ 403 | [], 404 | [ 405 | [ 406 | { 407 | prim: "UNIT" 408 | }, 409 | { 410 | prim: "FAILWITH" 411 | } 412 | ] 413 | ] 414 | ] 415 | } 416 | ], 417 | { 418 | prim: "DIP", 419 | args: [ 420 | [ 421 | { 422 | prim: "DIP", 423 | args: [ 424 | [ 425 | { 426 | prim: "DUP" 427 | } 428 | ] 429 | ] 430 | }, 431 | { 432 | prim: "SWAP" 433 | }, 434 | { 435 | prim: "AMOUNT", 436 | annots: [ 437 | "@amount" 438 | ] 439 | }, 440 | { 441 | prim: "SUB" 442 | }, 443 | { 444 | prim: "SENDER" 445 | }, 446 | { 447 | prim: "DUP" 448 | }, 449 | { 450 | prim: "CONTRACT", 451 | args: [ 452 | { 453 | prim: "unit" 454 | } 455 | ], 456 | annots: [ 457 | "@initiator" 458 | ] 459 | }, 460 | [ 461 | { 462 | prim: "IF_NONE", 463 | args: [ 464 | [ 465 | [ 466 | { 467 | prim: "UNIT" 468 | }, 469 | { 470 | prim: "FAILWITH" 471 | } 472 | ] 473 | ], 474 | [] 475 | ] 476 | } 477 | ], 478 | { 479 | prim: "DROP" 480 | }, 481 | { 482 | prim: "DIP", 483 | args: [ 484 | [ 485 | [ 486 | { 487 | prim: "PAIR" 488 | }, 489 | { 490 | prim: "PAIR" 491 | } 492 | ], 493 | { 494 | prim: "SWAP" 495 | } 496 | ] 497 | ] 498 | }, 499 | [ 500 | { 501 | prim: "PAIR" 502 | }, 503 | { 504 | prim: "PAIR" 505 | } 506 | ], 507 | { 508 | prim: "SOME", 509 | annots: [ 510 | "@xcat" 511 | ] 512 | }, 513 | { 514 | prim: "SWAP" 515 | } 516 | ] 517 | ] 518 | }, 519 | { 520 | prim: "DUP" 521 | }, 522 | { 523 | prim: "DIP", 524 | args: [ 525 | [ 526 | { 527 | prim: "MEM" 528 | }, 529 | { 530 | prim: "NOT" 531 | }, 532 | [ 533 | { 534 | prim: "IF", 535 | args: [ 536 | [], 537 | [ 538 | [ 539 | { 540 | prim: "UNIT" 541 | }, 542 | { 543 | prim: "FAILWITH" 544 | } 545 | ] 546 | ] 547 | ] 548 | } 549 | ] 550 | ] 551 | ] 552 | } 553 | ], 554 | [ 555 | { 556 | prim: "DUP" 557 | }, 558 | { 559 | prim: "DIP", 560 | args: [ 561 | [ 562 | { 563 | prim: "GET" 564 | }, 565 | [ 566 | { 567 | prim: "IF_NONE", 568 | args: [ 569 | [ 570 | [ 571 | { 572 | prim: "UNIT" 573 | }, 574 | { 575 | prim: "FAILWITH" 576 | } 577 | ] 578 | ], 579 | [] 580 | ] 581 | } 582 | ], 583 | [ 584 | [ 585 | { 586 | prim: "DUP" 587 | }, 588 | { 589 | prim: "CAR", 590 | annots: [ 591 | "@%" 592 | ] 593 | }, 594 | { 595 | prim: "DIP", 596 | args: [ 597 | [ 598 | { 599 | prim: "CDR", 600 | annots: [ 601 | "@%" 602 | ] 603 | } 604 | ] 605 | ] 606 | } 607 | ] 608 | ], 609 | { 610 | prim: "DIP", 611 | args: [ 612 | [ 613 | [ 614 | [ 615 | { 616 | prim: "DUP" 617 | }, 618 | { 619 | prim: "CAR" 620 | }, 621 | { 622 | prim: "DIP", 623 | args: [ 624 | [ 625 | { 626 | prim: "CDR", 627 | annots: [ 628 | "@%" 629 | ] 630 | } 631 | ] 632 | ] 633 | } 634 | ], 635 | [ 636 | { 637 | prim: "DUP" 638 | }, 639 | { 640 | prim: "CAR", 641 | annots: [ 642 | "@%" 643 | ] 644 | }, 645 | { 646 | prim: "DIP", 647 | args: [ 648 | [ 649 | { 650 | prim: "CDR", 651 | annots: [ 652 | "@%" 653 | ] 654 | } 655 | ] 656 | ] 657 | } 658 | ] 659 | ], 660 | { 661 | prim: "SWAP" 662 | }, 663 | { 664 | prim: "DUP" 665 | }, 666 | { 667 | prim: "NOW" 668 | }, 669 | [ 670 | [ 671 | { 672 | prim: "COMPARE" 673 | }, 674 | { 675 | prim: "LT" 676 | } 677 | ], 678 | { 679 | prim: "IF", 680 | args: [ 681 | [], 682 | [ 683 | [ 684 | { 685 | prim: "UNIT" 686 | }, 687 | { 688 | prim: "FAILWITH" 689 | } 690 | ] 691 | ] 692 | ] 693 | } 694 | ], 695 | { 696 | prim: "SWAP" 697 | }, 698 | { 699 | prim: "AMOUNT", 700 | annots: [ 701 | "@amount" 702 | ] 703 | }, 704 | { 705 | prim: "ADD" 706 | } 707 | ] 708 | ] 709 | }, 710 | [ 711 | { 712 | prim: "DIP", 713 | args: [ 714 | [ 715 | { 716 | prim: "PAIR" 717 | } 718 | ] 719 | ] 720 | }, 721 | { 722 | prim: "DIP", 723 | args: [ 724 | [ 725 | { 726 | prim: "PAIR" 727 | } 728 | ] 729 | ] 730 | }, 731 | { 732 | prim: "PAIR" 733 | } 734 | ], 735 | { 736 | prim: "SOME", 737 | annots: [ 738 | "@xcat" 739 | ] 740 | } 741 | ] 742 | ] 743 | } 744 | ] 745 | ] 746 | }, 747 | { 748 | prim: "UPDATE" 749 | }, 750 | { 751 | prim: "PAIR", 752 | annots: [ 753 | "@new_storage" 754 | ] 755 | }, 756 | { 757 | prim: "SWAP" 758 | }, 759 | { 760 | prim: "PAIR" 761 | } 762 | ], 763 | [ 764 | { 765 | prim: "IF_LEFT", 766 | args: [ 767 | [ 768 | { 769 | prim: "DUP" 770 | }, 771 | { 772 | prim: "SIZE" 773 | }, 774 | { 775 | prim: "PUSH", 776 | args: [ 777 | { 778 | prim: "nat" 779 | }, 780 | { 781 | int: "32" 782 | } 783 | ] 784 | }, 785 | [ 786 | [ 787 | { 788 | prim: "COMPARE" 789 | }, 790 | { 791 | prim: "EQ" 792 | } 793 | ], 794 | { 795 | prim: "IF", 796 | args: [ 797 | [], 798 | [ 799 | [ 800 | { 801 | prim: "UNIT" 802 | }, 803 | { 804 | prim: "FAILWITH" 805 | } 806 | ] 807 | ] 808 | ] 809 | } 810 | ], 811 | { 812 | prim: "SHA256" 813 | }, 814 | { 815 | prim: "SHA256", 816 | annots: [ 817 | "@hash" 818 | ] 819 | }, 820 | { 821 | prim: "DUP" 822 | }, 823 | { 824 | prim: "DIP", 825 | args: [ 826 | [ 827 | { 828 | prim: "SWAP" 829 | } 830 | ] 831 | ] 832 | }, 833 | [ 834 | { 835 | prim: "DIP", 836 | args: [ 837 | [ 838 | { 839 | prim: "DIP", 840 | args: [ 841 | [ 842 | { 843 | prim: "GET" 844 | }, 845 | [ 846 | { 847 | prim: "IF_NONE", 848 | args: [ 849 | [ 850 | [ 851 | { 852 | prim: "UNIT" 853 | }, 854 | { 855 | prim: "FAILWITH" 856 | } 857 | ] 858 | ], 859 | [] 860 | ] 861 | } 862 | ], 863 | { 864 | prim: "DUP" 865 | }, 866 | [ 867 | [ 868 | { 869 | prim: "DUP" 870 | }, 871 | { 872 | prim: "CAR", 873 | annots: [ 874 | "@%" 875 | ] 876 | }, 877 | { 878 | prim: "DIP", 879 | args: [ 880 | [ 881 | { 882 | prim: "CDR", 883 | annots: [ 884 | "@%" 885 | ] 886 | } 887 | ] 888 | ] 889 | } 890 | ] 891 | ], 892 | { 893 | prim: "CDR", 894 | annots: [ 895 | "@%" 896 | ] 897 | }, 898 | { 899 | prim: "CONTRACT", 900 | args: [ 901 | { 902 | prim: "unit" 903 | } 904 | ], 905 | annots: [ 906 | "@participant" 907 | ] 908 | }, 909 | [ 910 | { 911 | prim: "IF_NONE", 912 | args: [ 913 | [ 914 | [ 915 | { 916 | prim: "UNIT" 917 | }, 918 | { 919 | prim: "FAILWITH" 920 | } 921 | ] 922 | ], 923 | [] 924 | ] 925 | } 926 | ], 927 | { 928 | prim: "SWAP" 929 | }, 930 | [ 931 | { 932 | prim: "CAR" 933 | }, 934 | { 935 | prim: "CAR", 936 | annots: [ 937 | "@%" 938 | ] 939 | } 940 | ], 941 | [ 942 | { 943 | prim: "DIP", 944 | args: [ 945 | [ 946 | { 947 | prim: "DIP", 948 | args: [ 949 | [ 950 | { 951 | prim: "SENDER" 952 | }, 953 | { 954 | prim: "CONTRACT", 955 | args: [ 956 | { 957 | prim: "unit" 958 | } 959 | ], 960 | annots: [ 961 | "@sender" 962 | ] 963 | }, 964 | [ 965 | { 966 | prim: "IF_NONE", 967 | args: [ 968 | [ 969 | [ 970 | { 971 | prim: "UNIT" 972 | }, 973 | { 974 | prim: "FAILWITH" 975 | } 976 | ] 977 | ], 978 | [] 979 | ] 980 | } 981 | ], 982 | { 983 | prim: "SWAP" 984 | }, 985 | { 986 | prim: "CDR", 987 | annots: [ 988 | "@%" 989 | ] 990 | }, 991 | [ 992 | [ 993 | { 994 | prim: "DUP" 995 | }, 996 | { 997 | prim: "CAR" 998 | }, 999 | { 1000 | prim: "DIP", 1001 | args: [ 1002 | [ 1003 | { 1004 | prim: "CDR", 1005 | annots: [ 1006 | "@%" 1007 | ] 1008 | } 1009 | ] 1010 | ] 1011 | } 1012 | ], 1013 | [ 1014 | { 1015 | prim: "DUP" 1016 | }, 1017 | { 1018 | prim: "CAR", 1019 | annots: [ 1020 | "@%" 1021 | ] 1022 | }, 1023 | { 1024 | prim: "DIP", 1025 | args: [ 1026 | [ 1027 | { 1028 | prim: "CDR", 1029 | annots: [ 1030 | "@%" 1031 | ] 1032 | } 1033 | ] 1034 | ] 1035 | } 1036 | ] 1037 | ], 1038 | { 1039 | prim: "DROP" 1040 | }, 1041 | { 1042 | prim: "NOW" 1043 | }, 1044 | [ 1045 | [ 1046 | { 1047 | prim: "COMPARE" 1048 | }, 1049 | { 1050 | prim: "LT" 1051 | } 1052 | ], 1053 | { 1054 | prim: "IF", 1055 | args: [ 1056 | [], 1057 | [ 1058 | [ 1059 | { 1060 | prim: "UNIT" 1061 | }, 1062 | { 1063 | prim: "FAILWITH" 1064 | } 1065 | ] 1066 | ] 1067 | ] 1068 | } 1069 | ], 1070 | { 1071 | prim: "DUP" 1072 | }, 1073 | { 1074 | prim: "PUSH", 1075 | args: [ 1076 | { 1077 | prim: "mutez" 1078 | }, 1079 | { 1080 | int: "0" 1081 | } 1082 | ] 1083 | }, 1084 | [ 1085 | { 1086 | prim: "COMPARE" 1087 | }, 1088 | { 1089 | prim: "LT" 1090 | }, 1091 | { 1092 | prim: "IF", 1093 | args: [ 1094 | [ 1095 | { 1096 | prim: "UNIT" 1097 | }, 1098 | { 1099 | prim: "TRANSFER_TOKENS" 1100 | }, 1101 | { 1102 | prim: "DIP", 1103 | args: [ 1104 | [ 1105 | { 1106 | prim: "SWAP" 1107 | } 1108 | ] 1109 | ] 1110 | }, 1111 | { 1112 | prim: "CONS" 1113 | } 1114 | ], 1115 | [ 1116 | { 1117 | prim: "DROP" 1118 | }, 1119 | { 1120 | prim: "DROP" 1121 | }, 1122 | { 1123 | prim: "SWAP" 1124 | } 1125 | ] 1126 | ] 1127 | } 1128 | ] 1129 | ] 1130 | ] 1131 | } 1132 | ] 1133 | ] 1134 | } 1135 | ], 1136 | { 1137 | prim: "UNIT" 1138 | }, 1139 | { 1140 | prim: "TRANSFER_TOKENS" 1141 | } 1142 | ] 1143 | ] 1144 | } 1145 | ] 1146 | ] 1147 | } 1148 | ] 1149 | ], 1150 | [ 1151 | { 1152 | prim: "DUP" 1153 | }, 1154 | { 1155 | prim: "DIP", 1156 | args: [ 1157 | [ 1158 | { 1159 | prim: "GET" 1160 | }, 1161 | [ 1162 | { 1163 | prim: "IF_NONE", 1164 | args: [ 1165 | [ 1166 | [ 1167 | { 1168 | prim: "UNIT" 1169 | }, 1170 | { 1171 | prim: "FAILWITH" 1172 | } 1173 | ] 1174 | ], 1175 | [] 1176 | ] 1177 | } 1178 | ], 1179 | { 1180 | prim: "DUP" 1181 | }, 1182 | [ 1183 | { 1184 | prim: "CAR" 1185 | }, 1186 | { 1187 | prim: "CAR", 1188 | annots: [ 1189 | "@%" 1190 | ] 1191 | } 1192 | ], 1193 | { 1194 | prim: "CONTRACT", 1195 | args: [ 1196 | { 1197 | prim: "unit" 1198 | } 1199 | ], 1200 | annots: [ 1201 | "@initiator" 1202 | ] 1203 | }, 1204 | [ 1205 | { 1206 | prim: "IF_NONE", 1207 | args: [ 1208 | [ 1209 | [ 1210 | { 1211 | prim: "UNIT" 1212 | }, 1213 | { 1214 | prim: "FAILWITH" 1215 | } 1216 | ] 1217 | ], 1218 | [] 1219 | ] 1220 | } 1221 | ], 1222 | { 1223 | prim: "SWAP" 1224 | }, 1225 | { 1226 | prim: "CDR" 1227 | }, 1228 | [ 1229 | [ 1230 | { 1231 | prim: "DUP" 1232 | }, 1233 | { 1234 | prim: "CAR" 1235 | }, 1236 | { 1237 | prim: "DIP", 1238 | args: [ 1239 | [ 1240 | { 1241 | prim: "CDR", 1242 | annots: [ 1243 | "@%" 1244 | ] 1245 | } 1246 | ] 1247 | ] 1248 | } 1249 | ], 1250 | [ 1251 | { 1252 | prim: "DUP" 1253 | }, 1254 | { 1255 | prim: "CAR", 1256 | annots: [ 1257 | "@%" 1258 | ] 1259 | }, 1260 | { 1261 | prim: "DIP", 1262 | args: [ 1263 | [ 1264 | { 1265 | prim: "CDR", 1266 | annots: [ 1267 | "@%" 1268 | ] 1269 | } 1270 | ] 1271 | ] 1272 | } 1273 | ] 1274 | ], 1275 | { 1276 | prim: "SWAP" 1277 | }, 1278 | { 1279 | prim: "NOW" 1280 | }, 1281 | [ 1282 | [ 1283 | { 1284 | prim: "COMPARE" 1285 | }, 1286 | { 1287 | prim: "GE" 1288 | } 1289 | ], 1290 | { 1291 | prim: "IF", 1292 | args: [ 1293 | [], 1294 | [ 1295 | [ 1296 | { 1297 | prim: "UNIT" 1298 | }, 1299 | { 1300 | prim: "FAILWITH" 1301 | } 1302 | ] 1303 | ] 1304 | ] 1305 | } 1306 | ], 1307 | { 1308 | prim: "ADD" 1309 | }, 1310 | { 1311 | prim: "UNIT" 1312 | }, 1313 | { 1314 | prim: "TRANSFER_TOKENS" 1315 | }, 1316 | { 1317 | prim: "SWAP" 1318 | }, 1319 | [ 1320 | { 1321 | prim: "DIP", 1322 | args: [ 1323 | [ 1324 | { 1325 | prim: "DIP", 1326 | args: [ 1327 | [ 1328 | { 1329 | prim: "SWAP" 1330 | } 1331 | ] 1332 | ] 1333 | } 1334 | ] 1335 | ] 1336 | } 1337 | ] 1338 | ] 1339 | ] 1340 | } 1341 | ] 1342 | ] 1343 | }, 1344 | { 1345 | prim: "NONE", 1346 | args: [ 1347 | { 1348 | prim: "pair", 1349 | args: [ 1350 | { 1351 | prim: "pair", 1352 | args: [ 1353 | { 1354 | prim: "address" 1355 | }, 1356 | { 1357 | prim: "address" 1358 | } 1359 | ] 1360 | }, 1361 | { 1362 | prim: "pair", 1363 | args: [ 1364 | { 1365 | prim: "pair", 1366 | args: [ 1367 | { 1368 | prim: "mutez" 1369 | }, 1370 | { 1371 | prim: "timestamp" 1372 | } 1373 | ] 1374 | }, 1375 | { 1376 | prim: "mutez" 1377 | } 1378 | ] 1379 | } 1380 | ] 1381 | } 1382 | ], 1383 | annots: [ 1384 | "@none" 1385 | ] 1386 | }, 1387 | { 1388 | prim: "SWAP" 1389 | }, 1390 | { 1391 | prim: "UPDATE", 1392 | annots: [ 1393 | "@cleared_map" 1394 | ] 1395 | }, 1396 | { 1397 | prim: "SWAP" 1398 | }, 1399 | { 1400 | prim: "DIP", 1401 | args: [ 1402 | [ 1403 | { 1404 | prim: "SWAP" 1405 | }, 1406 | { 1407 | prim: "DIP", 1408 | args: [ 1409 | [ 1410 | { 1411 | prim: "PAIR" 1412 | } 1413 | ] 1414 | ] 1415 | } 1416 | ] 1417 | ] 1418 | }, 1419 | { 1420 | prim: "CONS" 1421 | }, 1422 | { 1423 | prim: "PAIR" 1424 | } 1425 | ] 1426 | ] 1427 | } 1428 | ] 1429 | ] 1430 | } 1431 | ], 1432 | storage: { 1433 | prim: "Pair", 1434 | args: [ 1435 | { 1436 | int: "4" 1437 | }, 1438 | { 1439 | prim: "Unit" 1440 | } 1441 | ] 1442 | } 1443 | } 1444 | -------------------------------------------------------------------------------- /packages/ext-taquito/tests/methods.test.ts: -------------------------------------------------------------------------------- 1 | import {TzktExtension} from '../src'; 2 | import {TezosToolkit} from '@taquito/taquito'; 3 | import {TzktReadProvider} from "../src/tzktReadProvider"; 4 | // const request = require("supertest"); 5 | 6 | describe("request", () => { 7 | const Tezos = new TezosToolkit('https://rpc.tzkt.io/mainnet'); 8 | const extension = new TzktReadProvider(Tezos as any); 9 | Tezos.addExtension(new TzktExtension()); 10 | 11 | test('Get Balance should equal 7554173199759', async () => { 12 | const result = await extension.getBalance('tz1iG3vqiT95KKSqNQuYnQEXNQk5gXQepM1r',2664043 ); 13 | expect(result.toNumber()).toEqual(7542493683789); 14 | }); 15 | 16 | test('Get Delegate should equal tz1irJKkXS2DBWkU1NnmFQx1c1L7pbGg4yhk', async () => { 17 | const result = await Tezos.tz.getDelegate('tz1iG3vqiT95KKSqNQuYnQEXNQk5gXQepM1r'); 18 | expect(result).toEqual('tz1irJKkXS2DBWkU1NnmFQx1c1L7pbGg4yhk'); 19 | }); 20 | 21 | // TODO: update next time there's protocol upgrade 22 | test('Get Next protocol should equal PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf', async () => { 23 | const result = await extension.getNextProtocol('head'); 24 | expect(result).toEqual('PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf'); 25 | }); 26 | 27 | 28 | test('Get Protocol Constants .hardBlockGasLimit should equal 5200000', async () => { 29 | const result = await extension.getProtocolConstants(2703631); 30 | 31 | expect({ 32 | hard_gas_limit_per_block: result.hard_gas_limit_per_block.toNumber(), 33 | hard_storage_limit_per_operation: result.hard_storage_limit_per_operation.toNumber(), 34 | cost_per_byte: result.cost_per_byte.toNumber() 35 | }).toEqual({ 36 | hard_gas_limit_per_block: 5200000, 37 | hard_storage_limit_per_operation: 60000, 38 | cost_per_byte: 250 39 | }); 40 | }); 41 | 42 | test('Get Storage should to return valid data', async () => { 43 | const result = await Tezos.rpc.getStorage('KT1Qej1k8WxPvBLUjGVtFXStgzQtcx3itSk5') 44 | // @ts-ignore 45 | expect(result.prim).toEqual('Pair') 46 | }); 47 | 48 | test('Get Script should to return valid data', async () => { 49 | const result = await Tezos.rpc.getScript('KT1Qej1k8WxPvBLUjGVtFXStgzQtcx3itSk5') 50 | expect(result).toHaveProperty('storage') 51 | }); 52 | 53 | test('Get entryPoints protocol should return valid data', async () => { 54 | const result = await extension.getEntrypoints('KT1Qej1k8WxPvBLUjGVtFXStgzQtcx3itSk5'); 55 | expect(result.entrypoints).toHaveProperty('withdrawProfit'); 56 | }); 57 | 58 | 59 | test('getBlockHash should equal BMHZJm9ome4S7jTAs4ibeDH88rUrvsEm3RLe43Rrr9Xx4QwADP3', async () => { 60 | const result = await extension.getBlockHash(2664043) 61 | expect(result).toEqual('BMHZJm9ome4S7jTAs4ibeDH88rUrvsEm3RLe43Rrr9Xx4QwADP3') 62 | }); 63 | 64 | test('getBlockLevel should equal 2664043', async () => { 65 | const result = await extension.getBlockLevel('BMHZJm9ome4S7jTAs4ibeDH88rUrvsEm3RLe43Rrr9Xx4QwADP3') 66 | expect(result).toEqual(2664043) 67 | }); 68 | 69 | test('getCounter should equal 3829', async () => { 70 | const result = await extension.getCounter('tz1Nx7hmKnagtzPyWDEba4naJb37Jn6RaP6E') 71 | expect(Number(result)).toEqual(3829) 72 | }); 73 | 74 | test('getBlockTimestamp should equal 2022-08-29T12:06:59Z', async () => { 75 | const result = await extension.getBlockTimestamp(2664043) 76 | expect(result).toEqual('2022-08-29T12:06:59Z') 77 | }); 78 | 79 | 80 | test('getBigMapValue should to return valida data', async () => { 81 | const result = await extension.getBigMapValue({ 82 | id: '4', 83 | expr: 'exprvS1VCPqQXtksURt9uuKPhvmBCbQuXXvHa1LkjundxjaFQBcrQk' 84 | }, 2664043) 85 | // @ts-ignore 86 | expect(result.prim).toEqual('Pair') 87 | }); 88 | 89 | test('getChainId should equal NetXdQprcVkpaWU', async () => { 90 | const result = await Tezos.rpc.getChainId() 91 | expect(result).toEqual('NetXdQprcVkpaWU') 92 | }); 93 | 94 | test('isAccountRevealed should equal true', async () => { 95 | const result = await extension.isAccountRevealed('tz1iG3vqiT95KKSqNQuYnQEXNQk5gXQepM1r', 'head') 96 | expect(result).toEqual(true) 97 | }); 98 | 99 | test('getLiveBlocks length should toBeTruthy', async () => { 100 | const result = await extension.getLiveBlocks(2664043) 101 | console.log(result) 102 | expect( 103 | result.includes('BKjSBdD5pUyDTgv8o5FBTD1wBE7R2cwLptcPDBSVoWKtDzRKCf2') && 104 | result.includes('BMeHqAgX5pfqWuthAzBMMZhw3KqDPMctsa29Tner8iqJ3jMHR79') 105 | ).toBeTruthy(); 106 | 107 | }); 108 | }) 109 | -------------------------------------------------------------------------------- /packages/ext-taquito/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es2017", 5 | "outDir": "build/main", 6 | "rootDir": "src", 7 | "moduleResolution": "node16", 8 | "module": "commonjs", 9 | "declaration": true, 10 | "inlineSourceMap": true, 11 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 12 | "resolveJsonModule": true /* Include modules imported with .json extension. */, 13 | 14 | "strict": true /* Enable all strict type-checking options. */, 15 | 16 | /* Strict Type-Checking Options */ 17 | // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, 18 | // "strictNullChecks": true /* Enable strict null checks. */, 19 | // "strictFunctionTypes": true /* Enable strict checking of function types. */, 20 | // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, 21 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, 22 | // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, 23 | 24 | /* Additional Checks */ 25 | "noUnusedLocals": true /* Report errors on unused locals. */, 26 | "noUnusedParameters": true /* Report errors on unused parameters. */, 27 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, 28 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, 29 | "skipLibCheck": true, 30 | /* Debugging Options */ 31 | "traceResolution": false /* Report module resolution log messages. */, 32 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */, 33 | "listFiles": false /* Print names of files part of the compilation. */, 34 | "pretty": true /* Stylize errors and messages using color and context. */, 35 | 36 | /* Experimental Options */ 37 | // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, 38 | // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, 39 | 40 | "lib": ["es2017", "dom"], 41 | "types": ["node", "jest"], 42 | "typeRoots": [ 43 | "../../node_modules/@types", 44 | "src/types", 45 | "node_modules/@types" 46 | ] 47 | }, 48 | "include": ["src/**/*.ts", ".eslintrc.js"], 49 | "exclude": ["node_modules/**", "jest.config.ts"], 50 | "compileOnSave": false 51 | } 52 | -------------------------------------------------------------------------------- /packages/ext-taquito/tsconfig.module.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "compilerOptions": { 4 | "target": "esnext", 5 | "outDir": "build/module", 6 | "module": "esnext", 7 | "types": ["node", "jest"] 8 | }, 9 | "exclude": [ 10 | "node_modules/**" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/sdk-api/.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", 4 | "language": "en", 5 | "words": [ 6 | "annots", 7 | "anyof", 8 | "Atomex", 9 | "bigmap", 10 | "bigmaps", 11 | "bitauth", 12 | "bitjson", 13 | "ticketer", 14 | "rollups", 15 | "cimg", 16 | "circleci", 17 | "codecov", 18 | "codegen", 19 | "commitlint", 20 | "datetime", 21 | "Delegators", 22 | "dependabot", 23 | "editorconfig", 24 | "entrypoint", 25 | "entrypoints", 26 | "esnext", 27 | "execa", 28 | "exponentiate", 29 | "globby", 30 | "libauth", 31 | "micheline", 32 | "mkdir", 33 | "oazapfts", 34 | "OBJKT", 35 | "openapi", 36 | "originations", 37 | "preendorsement", 38 | "preendorsements", 39 | "preendorsing", 40 | "prettierignore", 41 | "sandboxed", 42 | "supermajority", 43 | "transpiled", 44 | "typedoc", 45 | "tzips", 46 | "tzkt", 47 | "untracked", 48 | "upvoted", 49 | "upvotes" 50 | ], 51 | "flagWords": [], 52 | "ignorePaths": [ 53 | "package.json", 54 | "package-lock.json", 55 | "yarn.lock", 56 | "tsconfig.json", 57 | "node_modules/**", 58 | "swagger.json" 59 | ], 60 | "ignoreRegExpList": [ 61 | "(tz|KT)[1-9A-HJ-NP-Za-km-z]{34}", 62 | "o[1-9A-HJ-NP-Za-km-z]{50}" 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /packages/sdk-api/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | max_line_length = 80 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | max_line_length = 0 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /packages/sdk-api/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "project": "./tsconfig.json", 6 | // eslint-disable-next-line no-undef 7 | "tsconfigRootDir": __dirname, 8 | }, 9 | "env": { "es6": true }, 10 | "ignorePatterns": ["node_modules", "build", "coverage", "tests"], 11 | "plugins": ["import", "eslint-comments", "functional"], 12 | "extends": [ 13 | "eslint:recommended", 14 | "plugin:eslint-comments/recommended", 15 | "plugin:@typescript-eslint/recommended", 16 | "plugin:import/typescript", 17 | // "plugin:functional/lite", 18 | "prettier", 19 | "prettier/@typescript-eslint" 20 | ], 21 | "globals": { "BigInt": true, "console": true, "WebAssembly": true }, 22 | "rules": { 23 | "@typescript-eslint/explicit-module-boundary-types": "off", 24 | "eslint-comments/disable-enable-pair": [ 25 | "error", 26 | { "allowWholeFile": true } 27 | ], 28 | "eslint-comments/no-unused-disable": "error", 29 | "import/order": [ 30 | "error", 31 | { "newlines-between": "always", "alphabetize": { "order": "asc" } } 32 | ], 33 | "sort-imports": [ 34 | "error", 35 | { "ignoreDeclarationSort": true, "ignoreCase": true } 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/sdk-api/.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Example Contributing Guidelines 2 | 3 | This is an example of GitHub's contributing guidelines file. Check out GitHub's [CONTRIBUTING.md help center article](https://help.github.com/articles/setting-guidelines-for-repository-contributors/) for more information. 4 | -------------------------------------------------------------------------------- /packages/sdk-api/.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **I'm submitting a ...** 2 | [ ] bug report 3 | [ ] feature request 4 | [ ] question about the decisions made in the repository 5 | [ ] question about how to use this project 6 | 7 | - **Summary** 8 | 9 | - **Other information** (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.) 10 | -------------------------------------------------------------------------------- /packages/sdk-api/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | - **What kind of change does this PR introduce?** (Bug fix, feature, docs update, ...) 2 | 3 | - **What is the current behavior?** (You can also link to an open issue here) 4 | 5 | - **What is the new behavior (if this is a feature change)?** 6 | 7 | - **Other information**: 8 | -------------------------------------------------------------------------------- /packages/sdk-api/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .nyc_output 3 | build 4 | node_modules 5 | test 6 | src/**.js 7 | coverage 8 | *.log 9 | yarn.lock 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /packages/sdk-api/.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json -------------------------------------------------------------------------------- /packages/sdk-api/.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "dbaeumer.vscode-eslint", 4 | "esbenp.prettier-vscode", 5 | "eamodio.gitlens", 6 | "streetsidesoftware.code-spell-checker", 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /packages/sdk-api/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | // To debug, make sure a *.spec.ts file is active in the editor, then run a configuration 5 | { 6 | "type": "node", 7 | "request": "launch", 8 | "name": "Debug Active Spec", 9 | "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", 10 | "runtimeArgs": ["debug", "--break", "--serial", "${file}"], 11 | "port": 9229, 12 | "outputCapture": "std", 13 | "skipFiles": ["/**/*.js"], 14 | "preLaunchTask": "npm: build" 15 | // "smartStep": true 16 | }, 17 | { 18 | // Use this one if you're already running `yarn watch` 19 | "type": "node", 20 | "request": "launch", 21 | "name": "Debug Active Spec (no build)", 22 | "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", 23 | "runtimeArgs": ["debug", "--break", "--serial", "${file}"], 24 | "port": 9229, 25 | "outputCapture": "std", 26 | "skipFiles": ["/**/*.js"] 27 | // "smartStep": true 28 | }] 29 | } 30 | -------------------------------------------------------------------------------- /packages/sdk-api/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.userWords": [], // only use words from .cspell.json 3 | "cSpell.enabled": true, 4 | "editor.formatOnSave": true, 5 | "typescript.tsdk": "node_modules/typescript/lib", 6 | "typescript.enablePromptUseWorkspaceTsdk": true 7 | } 8 | -------------------------------------------------------------------------------- /packages/sdk-api/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [2.2.0](https://github.com/tzkt/api-sdk-ts/compare/v2.1.0...v2.2.0) (2023-03-11) 7 | 8 | 9 | ### Features 10 | 11 | * **sdk-api:** update to latest API version ([81fa339](https://github.com/tzkt/api-sdk-ts/commit/81fa339d8c6d00b49ab546714ad24b2bed1dcaca)) 12 | 13 | 14 | 15 | ## [2.1.0](https://github.com/tzkt/api-sdk-ts/compare/v2.0.0...v2.1.0) (2022-12-14) 16 | 17 | 18 | ### Features 19 | 20 | * **sdk-api:** update oazaptfs & add nonNullableRequiredParamExtension ([4e7de0f](https://github.com/tzkt/api-sdk-ts/commit/4e7de0f03bc54560cb71c2eb93d67f0646ae1406)) 21 | 22 | 23 | 24 | ## [2.0.0](https://github.com/tzkt/api-sdk-ts/compare/v1.0.2...v2.0.0) (2022-12-14) 25 | 26 | **Note:** Version bump only for package @tzkt/sdk-api 27 | 28 | 29 | 30 | 31 | 32 | ### [1.0.1](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.1) (2022-10-27) 33 | 34 | **Note:** Version bump only for package @tzkt/sdk-api 35 | 36 | 37 | 38 | 39 | 40 | ## [1.0.0](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.0) (2022-09-13) 41 | 42 | **Note:** Version bump only for package @tzkt/sdk-api 43 | 44 | 45 | 46 | 47 | 48 | ## [0.3.0](https://github.com/tzkt/api-sdk-ts/compare/v0.2.0...v0.3.0) (2022-08-25) 49 | 50 | **Note:** Version bump only for package @tzkt/sdk-api 51 | 52 | 53 | 54 | 55 | 56 | ## [0.2.0](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.2.0) (2022-04-30) 57 | 58 | 59 | ### Features 60 | 61 | * update readme ([#7](https://github.com/tzkt/api-sdk-ts/issues/7)) ([31b1d90](https://github.com/tzkt/api-sdk-ts/commit/31b1d90baa7f1926f8d1541ac64faebc4eafce97)) 62 | 63 | 64 | ### Bug Fixes 65 | 66 | * distribute src for sourcemaps ([#9](https://github.com/tzkt/api-sdk-ts/issues/9)) ([d135489](https://github.com/tzkt/api-sdk-ts/commit/d135489ac53b92bf57af2709c026eb5e1c52eb35)) 67 | * **queryParamParsers:** allow for empty `jsonPath` ([3112820](https://github.com/tzkt/api-sdk-ts/commit/31128205047d6daddcb6af716d7a1c5683140f54)) 68 | 69 | 70 | 71 | ### [0.1.3](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.1.3) (2022-04-21) 72 | 73 | **Note:** Version bump only for package @tzkt/sdk-api 74 | 75 | 76 | 77 | 78 | 79 | ### [0.1.2](https://github.com/tzkt/api-sdk-ts/compare/v0.1.1...v0.1.2) (2022-04-21) 80 | 81 | **Note:** Version bump only for package @tzkt/sdk-api 82 | 83 | 84 | 85 | 86 | 87 | ### [0.1.1](https://github.com/tzkt/api-sdk-ts/compare/v0.1.0...v0.1.1) (2022-04-21) 88 | 89 | **Note:** Version bump only for package @tzkt/sdk-api 90 | 91 | 92 | 93 | 94 | 95 | ## [0.1.0](https://github.com/tzkt/api-sdk-ts/compare/v0.0.10...v0.1.0) (2022-04-21) 96 | 97 | 98 | ### Features 99 | 100 | * **app:** add sync-swagger npm script ([2b5be1c](https://github.com/tzkt/api-sdk-ts/commit/2b5be1c959d1dbc6a512710c77468c86e4193af4)) 101 | * **deps:** install necessary deps ([1955124](https://github.com/tzkt/api-sdk-ts/commit/1955124f5ca99be25666cbbfb128387f60b3f041)) 102 | * **package:** add generate script ([e0b27c3](https://github.com/tzkt/api-sdk-ts/commit/e0b27c3af3a244d80662f3ab943d112d682d31bb)) 103 | * **package:** add generator config ([e5e04ec](https://github.com/tzkt/api-sdk-ts/commit/e5e04ec9f7ae2a121001da9abd7a325d55d2efe4)) 104 | * **package:** add npmrc config and update package ([485813e](https://github.com/tzkt/api-sdk-ts/commit/485813e18bcc054ae61ccc6ce4898cd3ba6c42be)) 105 | * **package:** add query parameters parsers ([df86356](https://github.com/tzkt/api-sdk-ts/commit/df863565e6be9914d557d3b6c0202843156777fe)) 106 | * **package:** add source swagger file ([2d737a9](https://github.com/tzkt/api-sdk-ts/commit/2d737a94673c2eace56bf7ebcaedde37b42bcba8)) 107 | * **package:** generate api sdk ([b00d3b6](https://github.com/tzkt/api-sdk-ts/commit/b00d3b69b7c15bf70b119933580d3c46e82459de)) 108 | * **package:** udpate engines field, make strict ([f665a3e](https://github.com/tzkt/api-sdk-ts/commit/f665a3ef8d841a1fd0dfa86f68165b5668bf7dad)) 109 | 110 | 111 | ### Bug Fixes 112 | 113 | * **deps:** use remote @tzkt/oazapfts dep ([ffb7537](https://github.com/tzkt/api-sdk-ts/commit/ffb7537d19d87ddece87eda0947945c6641cd917)) 114 | * **lerna:** update changelog to match new format ([183d56c](https://github.com/tzkt/api-sdk-ts/commit/183d56ca579b355e994d12b2800caefcfbde815f)) 115 | * **package.json:** remove publish script ([926a836](https://github.com/tzkt/api-sdk-ts/commit/926a836a9c136ea54b463b189883d7522058cb3e)) 116 | * **package:** explicit public access ([05c3795](https://github.com/tzkt/api-sdk-ts/commit/05c37955cbfef1502bfe7fd50db7c7cf4d340565)) 117 | * **package:** proper publish registry ([ef44609](https://github.com/tzkt/api-sdk-ts/commit/ef446093fd260a4461b8a8b47dc1be8dac79450b)) 118 | 119 | 120 | 121 | ### [0.0.10](https://github.com/tzkt/api-sdk-ts/compare/v0.0.9...v0.0.10) (2022-04-14) 122 | 123 | 124 | ### Features 125 | 126 | * **app:** add sync-swagger npm script ([5f28a95](https://github.com/tzkt/api-sdk-ts/commit/5f28a95585edb29464810a61289ba1b0c00a4504)) 127 | 128 | ### [0.0.9](https://github.com/tzkt/api-sdk-ts/compare/v0.0.8...v0.0.9) (2022-02-20) 129 | 130 | ### [0.0.8](https://github.com/tzkt/api-sdk-ts/compare/v0.0.7...v0.0.8) (2022-02-20) 131 | 132 | ### [0.0.7](https://github.com/tzkt/api-sdk-ts/compare/v0.0.5...v0.0.7) (2022-02-18) 133 | 134 | 135 | ### Bug Fixes 136 | 137 | * **deps:** use remote @tzkt/oazapfts dep ([c29797e](https://github.com/tzkt/api-sdk-ts/commit/c29797e7112e3c8680f28f630a7cd868a5f42159)) 138 | 139 | ### 0.0.5 (2022-02-18) 140 | 141 | 142 | ### Features 143 | 144 | * **deps:** install necessary deps ([653dc2a](https://github.com/tzkt/api-sdk-ts/commit/653dc2aa6c69b93308d5a2811f7f03b6e96af72d)) 145 | * **package:** add generate script ([43e233e](https://github.com/tzkt/api-sdk-ts/commit/43e233e760c7c7fc98e57437aca899d65fb40a49)) 146 | * **package:** add generator config ([c871943](https://github.com/tzkt/api-sdk-ts/commit/c8719438ef615b6b7af6ac10efb3dad4af5a7c03)) 147 | * **package:** add npmrc config and update package ([45ce436](https://github.com/tzkt/api-sdk-ts/commit/45ce4366c2d5137057d13624e74576be0c4b76d9)) 148 | * **package:** add query parameters parsers ([f719070](https://github.com/tzkt/api-sdk-ts/commit/f719070ca9f9bbacaa68ae8ec6a241a4d066b2ea)) 149 | * **package:** add source swagger file ([21659c2](https://github.com/tzkt/api-sdk-ts/commit/21659c2faf9d6bbd8b6ad8034ad2f94a50656683)) 150 | * **package:** generate api sdk ([3c5f6b2](https://github.com/tzkt/api-sdk-ts/commit/3c5f6b2ac00465dd79ac8612cc70c0f15d43a7e6)) 151 | * **package:** udpate engines field, make strict ([00cd9ed](https://github.com/tzkt/api-sdk-ts/commit/00cd9ed5a4017f6231ae04421258fb179cbe7c43)) 152 | -------------------------------------------------------------------------------- /packages/sdk-api/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 mv-go 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/sdk-api/README.md: -------------------------------------------------------------------------------- 1 | # TzKT API SDK 2 | 3 | Auto-generated from OpenApi spec using [@tzkt/oazapfts](https://github.com/tzkt/oazapfts). 4 | Supports most of the TzKT features including deep filtering and deep sorting. 5 | 6 | ## Install 7 | 8 | ```bash 9 | npm i @tzkt/sdk-api 10 | ``` 11 | 12 | ## Use 13 | 14 | ### Simplest request 15 | 16 | Simplest example of getting double baking operations, accused of being such by a certain address. 17 | 18 | ```ts 19 | import { operationsGetDoubleBaking } from '@tzkt/sdk-api' 20 | 21 | await operationsGetDoubleBaking( 22 | { 23 | quote: 'Btc', 24 | accuser: { 25 | in: ['tz3VEZ4k6a4Wx42iyev6i2aVAptTRLEAivNN'] 26 | } 27 | } 28 | ) 29 | ``` 30 | 31 | ### Overriding base API URL 32 | 33 | You may override base URL used by the package in the following manner. This may come useful should you want to make requests to a test network or to your custom server. 34 | 35 | ```ts 36 | import * as api from "@tzkt/sdk-api"; 37 | 38 | api.defaults.baseUrl = "https://api.ithacanet.tzkt.io/"; 39 | ``` 40 | 41 | In case you need to override request headers, this is also possible. 42 | 43 | ```ts 44 | import * as api from "@tzkt/sdk-api"; 45 | 46 | api.defaults.headers = { 47 | access_token: "secret", 48 | }; 49 | ``` 50 | 51 | Please refer to the [original documentation](https://github.com/cellular/oazapfts#overriding-the-defaults) for more details on how to configure defaults. 52 | 53 | ## More involved examples 54 | 55 | ### [Access BigMaps](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/) 56 | 57 | Please refer to an article on [BigMaps indexing](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#full-fledged-bigmaps) for a more detailed explanation on what these requests allow you to achieve. 58 | 59 | #### Accessing [BigMap by Ptr](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#access-bigmaps) 60 | 61 | ```ts 62 | import { bigMapsGetBigMapById } from '@tzkt/sdk-api' 63 | 64 | const bigMapPtr = 543 65 | 66 | await bigMapsGetBigMapById(bigMapPtr) 67 | ``` 68 | 69 | #### Accessing [BigMap by the path in the contract storage](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#example-2) 70 | 71 | ```ts 72 | import { contractsGetBigMapByName } from '@tzkt/sdk-api' 73 | 74 | const contractAddress = 'KT1TtaMcoSx5cZrvaVBWsFoeZ1L15cxo5AEy' 75 | const pathToBigMap = 'ledger' 76 | 77 | await contractsGetBigMapByName( 78 | contractAddress, 79 | pathToBigMap 80 | ) 81 | ``` 82 | 83 | #### Accessing [BigMap keys](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#get-all-bigmap-keys) 84 | 85 | ```ts 86 | import { bigMapsGetKeys } from '@tzkt/sdk-api' 87 | 88 | const bigMapId = 511 89 | const limit = 10 90 | 91 | await bigMapsGetKeys( 92 | bigMapId, 93 | { limit } 94 | ) 95 | ``` 96 | 97 | #### Accessing [All owners of NFT with non-zero balance](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#how-to-get-current-owners-with-balance-0-of-that-nft) 98 | 99 | ```ts 100 | import { bigMapsGetKeys } from '@tzkt/sdk-api' 101 | 102 | const bigMapId = 511 103 | const key = { 104 | value: 154, 105 | path: 'nat' 106 | } 107 | const minValue = 0 108 | 109 | await bigMapsGetKeys( 110 | bigMapId, 111 | { 112 | key: { 113 | eq: { 114 | jsonValue: `${key.value}`, 115 | jsonPath: key.path 116 | } 117 | }, 118 | value: { 119 | gt: { 120 | jsonValue: `${minValue}` 121 | } 122 | } 123 | } 124 | ) 125 | ``` 126 | 127 | #### Accessing [all updates of all BigMaps of a specific contract](https://baking-bad.org/blog/2021/04/28/tzkt-v15-released-with-bigmaps-and-florence-support/#bigmap-updates) 128 | 129 | ```ts 130 | import { bigMapsGetBigMapUpdates } from '@tzkt/sdk-api' 131 | 132 | const contract = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV' 133 | await bigMapsGetBigMapUpdates({ 134 | contract: { 135 | eq: contract 136 | } 137 | }) 138 | ``` 139 | 140 | ### [Accessing Tokens API](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/) 141 | 142 | Please refer to an article on [Tokens indexing](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/) for a more detailed explanation on what these requests allow you to achieve. 143 | 144 | #### Accessing [tokens transfers with deep fields selection](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/#deep-selecting) 145 | 146 | ```ts 147 | import { tokensGetTokenTransfers } from '@tzkt/sdk-api' 148 | 149 | const tokenId = 778919 150 | const limit = 2 151 | const sort = 'id' 152 | const fields = [ 153 | 'from.address', 154 | 'to.address', 155 | 'amount', 156 | 'token.metadata.symbol', 157 | 'token.metadata.decimals' 158 | ] 159 | 160 | await tokensGetTokenTransfers({ 161 | tokenId: { 162 | eq: tokenId 163 | }, 164 | sort: { 165 | desc: sort 166 | }, 167 | limit, 168 | select: { 169 | fields 170 | } 171 | }) 172 | ``` 173 | 174 | #### Accessing [FA1.2 tokens with the largest number of holders](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/#examples-of-the-v1-tokens-endpoint-usage) 175 | 176 | ```ts 177 | import { tokensGetTokens } from '@tzkt/sdk-api' 178 | 179 | const standard = 'fa1.2' 180 | const sort = 'holdersCount' 181 | const limit = 10 182 | 183 | const r = await tokensGetTokens({ 184 | standard: { 185 | eq: standard 186 | }, 187 | sort: { 188 | desc: sort 189 | }, 190 | limit 191 | }) 192 | ``` 193 | 194 | #### Accessing [all account's NFTs](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/#examples-of-the-v1-tokens-balances-endpoint-usage) 195 | 196 | ```ts 197 | import { tokensGetTokenBalances } from '@tzkt/sdk-api' 198 | 199 | const account = 'tz1SLgrDBpFWjGCnCwyNpCpQC1v8v2N8M2Ks' 200 | const minBalance = 0 201 | const symbol = 'OBJKT' 202 | const limit = 10 203 | 204 | const r = await tokensGetTokenBalances({ 205 | account: { 206 | eq: account 207 | }, 208 | balance: { 209 | ne: `${minBalance}` 210 | }, 211 | tokenMetadata: { 212 | eq: { 213 | jsonPath: 'symbol', 214 | jsonValue: symbol 215 | } 216 | }, 217 | limit 218 | }) 219 | ``` 220 | 221 | #### Accessing [whale transfers of a token](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/#examples-of-the-v1-tokens-transfers-endpoint-usage) 222 | 223 | ```ts 224 | import { tokensGetTokenTransfers } from '@tzkt/sdk-api' 225 | 226 | const tokenId = 85 227 | const minAmount = '100000000000000000000000' 228 | const sort = 'id' 229 | const limit = 10 230 | 231 | const r = await tokensGetTokenTransfers({ 232 | tokenId: { 233 | eq: tokenId 234 | }, 235 | amount: { 236 | gt: minAmount 237 | }, 238 | sort: { 239 | desc: sort 240 | }, 241 | limit 242 | }) 243 | ``` 244 | 245 | #### Accessing ["mints" of a token](https://baking-bad.org/blog/2022/01/11/tzkt-v17-with-generic-token-indexing-released/#examples-of-the-v1-tokens-transfers-endpoint-usage) 246 | 247 | ```ts 248 | import { tokensGetTokenTransfers } from '@tzkt/sdk-api' 249 | 250 | const tokenId = 85 251 | const sort = 'id' 252 | const limit = 10 253 | 254 | const r = await tokensGetTokenTransfers({ 255 | tokenId: { 256 | eq: tokenId 257 | }, 258 | from: { 259 | null: true 260 | }, 261 | sort: { 262 | desc: sort 263 | }, 264 | limit 265 | }) 266 | ``` 267 | 268 | ### [Accessing Transactions](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 269 | 270 | Please refer to an article on [Transactions querying](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) for a more detailed explanation on what these requests allow you to achieve. 271 | 272 | #### Accessing [incoming transfers for the account](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 273 | 274 | ```ts 275 | import { operationsGetTransactions } from '@tzkt/sdk-api' 276 | 277 | const target = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV' 278 | const parameter = { 279 | path: 'to', 280 | value: 'tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a' 281 | } 282 | 283 | const r = await operationsGetTransactions({ 284 | target: { 285 | eq: target 286 | }, 287 | parameter: { 288 | eq: { 289 | jsonPath: parameter.path, 290 | jsonValue: parameter.value 291 | } 292 | } 293 | }) 294 | ``` 295 | 296 | #### Accessing [Dexter XTZ to USDtz trades with specified amount](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 297 | 298 | ```ts 299 | import { operationsGetTransactions } from '@tzkt/sdk-api' 300 | 301 | const target = 'KT1K9gCRgaLRFKTErYt1wVxA3Frb9FjasjTV' 302 | const parameter = { 303 | path: 'to', 304 | value: 'tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a' 305 | } 306 | 307 | const r = await operationsGetTransactions({ 308 | target: { 309 | eq: target 310 | }, 311 | parameter: { 312 | eq: { 313 | jsonPath: parameter.path, 314 | jsonValue: parameter.value 315 | } 316 | } 317 | }) 318 | ``` 319 | 320 | #### Accessing [Atomex atomic swaps with specified refund time](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 321 | 322 | ```ts 323 | import { operationsGetTransactions } from '@tzkt/sdk-api' 324 | 325 | const target = 'KT1VG2WtYdSWz5E7chTeAdDPZNy2MpP8pTfL' 326 | const filterField = 'settings.refund_time' 327 | const timeFrame = '2021-02-*' 328 | 329 | const r = await operationsGetTransactions({ 330 | target: { 331 | eq: target 332 | }, 333 | parameter: { 334 | as: { 335 | jsonPath: filterField, 336 | jsonValue: timeFrame 337 | } 338 | } 339 | }) 340 | ``` 341 | 342 | #### Accessing [Dexter wXTZ/XTZ trades](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 343 | 344 | ```ts 345 | import { operationsGetTransactions } from '@tzkt/sdk-api' 346 | 347 | const target = 'KT1D56HQfMmwdopmFLTwNHFJSs6Dsg2didFo' 348 | const entrypoints = ['xtzToToken', 'tokenToXtz', 'tokenToToken'] 349 | 350 | const r = await operationsGetTransactions({ 351 | target: { 352 | eq: target 353 | }, 354 | entrypoint: { 355 | in: entrypoints 356 | } 357 | }) 358 | ``` 359 | 360 | #### Accessing [operations with tzBTC related to a specific account](https://baking-bad.org/blog/2021/03/03/tzkt-v14-released-with-improved-smart-contract-data-and-websocket-api/#filter-transactions-by-parameter-like-a-boss) 361 | 362 | ```ts 363 | import { operationsGetTransactions } from '@tzkt/sdk-api' 364 | 365 | const target = 'KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn' 366 | const entrypoints = ['mint', 'transfer', 'burn'] 367 | const parameter = '*tz1aKTCbAUuea2RV9kxqRVRg3HT7f1RKnp6a*' 368 | 369 | const r = await operationsGetTransactions({ 370 | target: { 371 | eq: target 372 | }, 373 | entrypoint: { 374 | in: entrypoints 375 | }, 376 | parameter: { 377 | as: { 378 | jsonValue: parameter 379 | } 380 | } 381 | }) 382 | ``` 383 | 384 | ## With node.js or a custom fetch library 385 | 386 | Please refer to the [documentation](https://github.com/cellular/oazapfts#overriding-the-defaults) of the original codegen library. 387 | 388 | ## Update & publish 389 | 390 | This package is managed by Lerna. All publishing and dep management should be done using it. Only regeneration of APIs is kept local (for now). 391 | 392 | ### Inside this package 393 | 394 | - Get the latest swagger file 395 | - Use it to re-generate APIs 396 | - Fix linting and prettify 397 | 398 | ```bash 399 | npm run sync-swagger 400 | npm run generate 401 | npm run fix 402 | ``` 403 | 404 | ### Building and publishing 405 | 406 | You may build this package for local testing with simple `npm run build`. For publishing and deploying to production all builds should be done via Lerna. 407 | 408 | After you've committed your changes and ready to publish, please follow [Build and publish](/README.md#build-and-publish) instructions in the root of this repository. 409 | -------------------------------------------------------------------------------- /packages/sdk-api/jest.config.ts: -------------------------------------------------------------------------------- 1 | import { Config } from "@jest/types"; 2 | 3 | const config: Config.InitialOptions = { 4 | verbose: true, 5 | preset: "ts-jest", 6 | rootDir: "./", 7 | restoreMocks: true, 8 | }; 9 | 10 | export default config; 11 | -------------------------------------------------------------------------------- /packages/sdk-api/oazapfts.config.ts: -------------------------------------------------------------------------------- 1 | import { 2 | OazapftsExtensions, 3 | ParameterParserExtension, 4 | QueryStringParserExtension, 5 | ReponseTypeExtension, 6 | SchemaParserExtension, 7 | } from "@tzkt/oazapfts/lib/codegen/extensions"; 8 | import * as _ from "lodash"; 9 | import { OpenAPIV3 } from "openapi-types"; 10 | import {factory, TypeElement, UnionTypeNode} from "typescript"; 11 | 12 | const tzktExtensionKey = "x-tzkt-extension"; 13 | 14 | type TzktExtended = T & { 15 | [tzktExtensionKey]: string; 16 | }; 17 | 18 | const hasOwnProp = , K extends PropertyKey>( 19 | p: O, 20 | k: K 21 | ): p is O & Record => { 22 | return Object.prototype.hasOwnProperty.call(p, k); 23 | }; 24 | 25 | const isTzktExtended =

>(p: P): p is P & TzktExtended

=> { 26 | if (!hasOwnProp(p, tzktExtensionKey)) return false; 27 | 28 | return typeof p[tzktExtensionKey] === "string"; 29 | }; 30 | 31 | const anyofParameterExtension: ParameterParserExtension = (p, helpers) => { 32 | if (!isTzktExtended(p)) return; 33 | 34 | const extension = p[tzktExtensionKey]; 35 | if (extension !== "anyof-parameter") return; 36 | 37 | // getSchemaFromContent() 38 | 39 | if (!hasOwnProp(p, "x-tzkt-anyof-parameter")) return; 40 | 41 | const rawAnyof = p["x-tzkt-anyof-parameter"]; 42 | if (typeof rawAnyof !== "string") return; 43 | 44 | const types = rawAnyof 45 | .split(",") 46 | .map((t) => factory.createLiteralTypeNode(factory.createStringLiteral(t))); 47 | 48 | const valNode = helpers.createPropertySignature({ 49 | name: "value", 50 | questionToken: true, 51 | type: factory.createUnionTypeNode([ 52 | helpers.keywordType.string, 53 | helpers.keywordType.null, 54 | ]), 55 | }); 56 | 57 | const eqNode = helpers.createPropertySignature({ 58 | name: "eq", 59 | questionToken: true, 60 | type: helpers.keywordType.string, 61 | }); 62 | 63 | const nullNode = helpers.createPropertySignature({ 64 | name: "null", 65 | questionToken: true, 66 | type: helpers.keywordType.boolean, 67 | }); 68 | 69 | const inNode = helpers.createPropertySignature({ 70 | name: "in", 71 | questionToken: true, 72 | type: factory.createArrayTypeNode(helpers.keywordType.string) , 73 | }); 74 | 75 | const pathNode = helpers.createPropertySignature({ 76 | name: "fields", 77 | questionToken: true, 78 | type: factory.createArrayTypeNode(factory.createUnionTypeNode(types)), 79 | }); 80 | 81 | return factory.createTypeLiteralNode([ 82 | valNode, 83 | pathNode, 84 | inNode, 85 | nullNode, 86 | eqNode, 87 | ]); 88 | }; 89 | 90 | /** 91 | * If parameter is required and nullable at the same time makes it non-nullable 92 | */ 93 | const nonNullableRequiredParamExtension: ParameterParserExtension = (parameter, helpers, ctx) => { 94 | if (helpers.isNullable(parameter.schema) && parameter.required) { 95 | return ctx.getBaseTypeFromSchema(parameter.schema) 96 | }; 97 | return undefined; 98 | } 99 | 100 | const jsonParameterExtension: SchemaParserExtension = (schema, name, helpers) => { 101 | if (!schema || helpers.isReference(schema) || !isTzktExtended(schema)) return; 102 | 103 | const extension = schema["x-tzkt-extension"]; 104 | if (extension !== "json-parameter") return; 105 | 106 | /** 107 | * This is a bodge to filter out method parameters that have 'json-parameter' 108 | * in 'x-tzkt-extension' field. Such method parameters should not be 109 | * extended, but rather their properties should be (and are) processed by 110 | * this extension. 111 | * TODO!: remove 'json-parameter' from top-level parameter description 112 | */ 113 | if (hasOwnProp(schema, "properties")) return; 114 | 115 | const valNode = helpers.createPropertySignature({ 116 | name: "jsonValue", 117 | questionToken: false, 118 | type: helpers.defaultSchemaTypeParser(schema), 119 | }); 120 | 121 | const pathNode = helpers.createPropertySignature({ 122 | name: "jsonPath", 123 | questionToken: true, 124 | type: helpers.keywordType.string, 125 | }); 126 | 127 | return factory.createTypeLiteralNode([valNode, pathNode]); 128 | }; 129 | 130 | const queryParameterExtension: SchemaParserExtension = (schema, name, helpers) => { 131 | if (!schema || helpers.isReference(schema) || !isTzktExtended(schema)) return; 132 | 133 | const extension = schema["x-tzkt-extension"]; 134 | if (extension !== "query-parameter") return; 135 | 136 | const props = schema.properties; 137 | if (!props) { 138 | console.error("Unexpected schema structure", schema); 139 | throw new Error(`Expected properties list in query-parameter schema.`); 140 | } 141 | 142 | type SpecifiedQueryParameter = TzktExtended & { 143 | "x-tzkt-query-parameter": string; 144 | }; 145 | 146 | const isSpecified = ( 147 | schema: TzktExtended 148 | ): schema is SpecifiedQueryParameter => { 149 | return typeof (schema as any)["x-tzkt-query-parameter"] === "string"; 150 | }; 151 | 152 | let specifiedType: UnionTypeNode | undefined = undefined; 153 | 154 | if (isSpecified(schema)) { 155 | const types = schema["x-tzkt-query-parameter"].split(","); 156 | specifiedType = factory.createUnionTypeNode( 157 | types.map((t) => 158 | factory.createLiteralTypeNode(factory.createStringLiteral(t)) 159 | ) 160 | ); 161 | } 162 | 163 | const getPropType = ( 164 | p: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject, 165 | specifiedType?: UnionTypeNode 166 | ) => { 167 | if (helpers.isReference(p)) { 168 | const m = "Unexpected reference in schema property"; 169 | console.error(m, p); 170 | throw new Error(m); 171 | } 172 | 173 | if ("items" in p) { 174 | if (specifiedType) return factory.createArrayTypeNode(specifiedType); 175 | 176 | const parsedType = helpers.defaultSchemaTypeParser(p.items); 177 | return factory.createArrayTypeNode(parsedType); 178 | } 179 | 180 | return specifiedType ?? helpers.defaultSchemaTypeParser(p); 181 | }; 182 | 183 | const { required } = schema; 184 | const members: TypeElement[] = Object.entries(props).map( 185 | ([name, prop]) => { 186 | const isRequired = required?.includes(name); 187 | return helpers.createPropertySignature({ 188 | questionToken: !isRequired, 189 | name, 190 | type: getPropType(prop, specifiedType), 191 | }); 192 | } 193 | ); 194 | 195 | return factory.createTypeLiteralNode(members); 196 | }; 197 | 198 | const tzktQueryStringExtension: QueryStringParserExtension = (p) => { 199 | if (isTzktExtended(p)) return _.camelCase(p[tzktExtensionKey]); 200 | }; 201 | 202 | const tzktQueryStringQueryParameterExtension: QueryStringParserExtension = ( 203 | p, 204 | helpers, 205 | ) => { 206 | const schema = p.schema; 207 | if (helpers.isReference(schema)) return; 208 | 209 | const oneOfs = schema?.oneOf; 210 | if (!oneOfs) return; 211 | 212 | if ( 213 | oneOfs.some((oneOf) => { 214 | if (!helpers.isReference(oneOf)) return false; 215 | 216 | const schema = helpers.defaultSchemaResolver(oneOf); 217 | if (!isTzktExtended(schema)) return false; 218 | 219 | if (schema[tzktExtensionKey] !== "query-parameter") return false; 220 | 221 | return true; 222 | }) 223 | ) 224 | return "queryParameter"; 225 | }; 226 | 227 | const extensions: OazapftsExtensions = { 228 | schemaParserExtensions: [ 229 | jsonParameterExtension, 230 | queryParameterExtension, 231 | ], 232 | parameterParserExtensions: [ 233 | anyofParameterExtension, 234 | nonNullableRequiredParamExtension 235 | ], 236 | queryStringParserExtensions: [ 237 | tzktQueryStringExtension, 238 | tzktQueryStringQueryParameterExtension, 239 | ], 240 | }; 241 | 242 | export default extensions; 243 | -------------------------------------------------------------------------------- /packages/sdk-api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tzkt/sdk-api", 3 | "version": "2.2.0", 4 | "description": "TzKt API SDK written in Typescript", 5 | "main": "build/main/index.js", 6 | "types": "build/main/index.d.ts", 7 | "typings": "build/main/index.d.ts", 8 | "module": "build/module/index.js", 9 | "repository": "git://github.com/tzkt/api-sdk-ts.git", 10 | "publishConfig": { 11 | "access": "public" 12 | }, 13 | "license": "MIT", 14 | "keywords": [], 15 | "scripts": { 16 | "build": "run-p build:main build:module", 17 | "build:main": "tsc -p tsconfig.json", 18 | "build:module": "tsc -p tsconfig.module.json", 19 | "build:api": "run-s sync-swagger generate fix", 20 | "build:full": "run-s build:api build", 21 | "fix": "run-s fix:*", 22 | "fix:prettier": "prettier \"src/**/*.ts\" --write", 23 | "fix:lint": "eslint src --ext .ts --fix", 24 | "test": "run-s build test:*", 25 | "test:lint": "eslint src --ext .ts", 26 | "test:prettier": "prettier \"src/**/*.ts\" --list-different", 27 | "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"", 28 | "test:api": "jest", 29 | "test:api:watch": "jest --watch", 30 | "check-cli": "run-s test diff-integration-tests check-integration-tests", 31 | "check-integration-tests": "run-s check-integration-test:*", 32 | "diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'", 33 | "watch:build": "tsc -p tsconfig.json -w", 34 | "watch:test": "nyc --silent ava --watch", 35 | "cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html", 36 | "cov:html": "nyc report --reporter=html", 37 | "cov:lcov": "nyc report --reporter=lcov", 38 | "cov:send": "run-s cov:lcov && codecov", 39 | "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", 40 | "doc": "run-s doc:html && open-cli build/docs/index.html", 41 | "doc:html": "typedoc src/ --exclude **/*.spec.ts --out build/docs", 42 | "doc:json": "typedoc src/ --exclude **/*.spec.ts --json build/docs/typedoc.json", 43 | "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs", 44 | "reset-hard": "git clean -dfx && git reset --hard && npm i", 45 | "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish", 46 | "generate": "node --experimental-vm-modules node_modules/.bin/oazapfts --optimistic swagger.json src/index.ts", 47 | "sync-swagger": "curl -O https://api.tzkt.io/v1/swagger.json -k" 48 | }, 49 | "engines": { 50 | "node": ">=14", 51 | "npm": ">=6" 52 | }, 53 | "engineStrict": true, 54 | "dependencies": { 55 | "@tzkt/oazapfts": "^4.5.2" 56 | }, 57 | "devDependencies": { 58 | "@ava/typescript": "^1.1.1", 59 | "@istanbuljs/nyc-config-typescript": "^1.0.1", 60 | "@types/jest": "^29.0.0", 61 | "@types/lodash": "^4.14.178", 62 | "@types/node": "^16.0.0", 63 | "@typescript-eslint/eslint-plugin": "^5.46.1", 64 | "@typescript-eslint/parser": "^5.46.1", 65 | "ava": "^3.12.1", 66 | "codecov": "^3.5.0", 67 | "cspell": "^4.1.0", 68 | "cz-conventional-changelog": "^3.3.0", 69 | "eslint": "^7.10.0", 70 | "eslint-config-prettier": "^6.11.0", 71 | "eslint-plugin-eslint-comments": "^3.2.0", 72 | "eslint-plugin-functional": "^3.0.2", 73 | "eslint-plugin-import": "^2.22.0", 74 | "gh-pages": "^3.1.0", 75 | "jest": "^29.0.0", 76 | "lodash": "^4.17.21", 77 | "npm-run-all": "^4.1.5", 78 | "nyc": "^15.1.0", 79 | "open-cli": "^6.0.1", 80 | "openapi-types": "^10.0.0", 81 | "prettier": "^2.1.1", 82 | "standard-version": "^9.0.0", 83 | "ts-jest": "^29.1.1", 84 | "ts-node-dev": "^2.0.0", 85 | "typedoc": "^0.23.22", 86 | "typescript": "^4.9.4" 87 | }, 88 | "files": [ 89 | "build/main", 90 | "build/module", 91 | "!**/*.spec.*", 92 | "!**/*.json", 93 | "CHANGELOG.md", 94 | "LICENSE", 95 | "README.md", 96 | "src" 97 | ], 98 | "ava": { 99 | "failFast": true, 100 | "timeout": "60s", 101 | "typescript": { 102 | "rewritePaths": { 103 | "src/": "build/main/" 104 | } 105 | }, 106 | "files": [ 107 | "!build/module/**" 108 | ] 109 | }, 110 | "config": { 111 | "commitizen": { 112 | "path": "cz-conventional-changelog" 113 | } 114 | }, 115 | "prettier": { 116 | "singleQuote": true 117 | }, 118 | "nyc": { 119 | "extends": "@istanbuljs/nyc-config-typescript", 120 | "exclude": [ 121 | "**/*.spec.js" 122 | ] 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /packages/sdk-api/src/queryParamParsers.ts: -------------------------------------------------------------------------------- 1 | import type { QueryParamParser } from '@tzkt/oazapfts/codegen/extensions'; 2 | 3 | const jsonParameter: QueryParamParser = (paramName, p?) => { 4 | if (!p) return {}; 5 | 6 | const mainParamsObj: Record = {}; 7 | 8 | Object.entries(p).forEach(([k, v]) => { 9 | if (!(v instanceof Object)) { 10 | throw new Error( 11 | `Expected ${paramName} value to be object, received ${typeof v}` 12 | ); 13 | } 14 | 15 | const { jsonPath, jsonValue } = v; 16 | if (jsonValue === undefined || jsonValue === null) 17 | throw new Error( 18 | `Expected jsonValue in ${paramName} -> ${k}, found: ${jsonValue}` 19 | ); 20 | 21 | // k is top eq, ne, in, etc. 22 | const parameterPathParts = [paramName, jsonPath, k]; 23 | 24 | const parameterPath = parameterPathParts 25 | .filter((p) => p !== undefined) 26 | .join('.'); 27 | mainParamsObj[parameterPath] = jsonValue; 28 | }); 29 | 30 | return mainParamsObj; 31 | }; 32 | 33 | const anyofParameter: QueryParamParser = (paramName, p) => { 34 | if (!p) return {}; 35 | 36 | const { fields } = p; 37 | 38 | const validateFields = (fields: unknown): fields is string[] => { 39 | if (!Array.isArray(fields)) { 40 | throw new Error( 41 | `Expected ${paramName} fields to be Array. Received ${typeof fields}.` 42 | ); 43 | } 44 | 45 | fields.forEach((f) => { 46 | if (typeof f === 'string') return; 47 | throw new Error( 48 | `Expected ${paramName} fields to be strings. Received ${typeof f}` 49 | ); 50 | }); 51 | 52 | return true; 53 | }; 54 | 55 | // never really returns but oh well 56 | if (!validateFields(fields)) return {}; 57 | 58 | const mainParamsObj: Record = {}; 59 | 60 | const anyof = fields.join('.'); 61 | 62 | if (p.value) { 63 | const prefixedKey = `${paramName}.${anyof}`; 64 | mainParamsObj[prefixedKey] = p.value; 65 | } 66 | 67 | for (const param of ['in', 'eq', 'null']) { 68 | if (p[param]) { 69 | const prefixedKey = `${paramName}.${anyof}.${param}`; 70 | mainParamsObj[prefixedKey] = Array.isArray(p[param]) 71 | ? p[param].join(',') 72 | : p[param]; 73 | return mainParamsObj; 74 | } 75 | } 76 | 77 | return mainParamsObj; 78 | }; 79 | 80 | const queryParameter: QueryParamParser = (paramName, p) => { 81 | if (!p) return {}; 82 | 83 | const mainParamsObj: Record = {}; 84 | 85 | Object.entries(p).forEach(([k, v]) => { 86 | const key = `${paramName}.${k}`; 87 | mainParamsObj[key] = v; 88 | }); 89 | 90 | return mainParamsObj; 91 | }; 92 | 93 | const parsers: Record = { 94 | jsonParameter, 95 | queryParameter, 96 | anyofParameter, 97 | }; 98 | 99 | export default parsers; 100 | -------------------------------------------------------------------------------- /packages/sdk-api/src/types/example.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * If you import a dependency which does not include its own type definitions, 3 | * TypeScript will try to find a definition for it by following the `typeRoots` 4 | * compiler option in tsconfig.json. For this project, we've configured it to 5 | * fall back to this folder if nothing is found in node_modules/@types. 6 | * 7 | * Often, you can install the DefinitelyTyped 8 | * (https://github.com/DefinitelyTyped/DefinitelyTyped) type definition for the 9 | * dependency in question. However, if no one has yet contributed definitions 10 | * for the package, you may want to declare your own. (If you're using the 11 | * `noImplicitAny` compiler options, you'll be required to declare it.) 12 | * 13 | * This is an example type definition which allows import from `module-name`, 14 | * e.g.: 15 | * ```ts 16 | * import something from 'module-name'; 17 | * something(); 18 | * ``` 19 | */ 20 | declare module 'module-name' { 21 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 22 | const whatever: any; 23 | export = whatever; 24 | } 25 | -------------------------------------------------------------------------------- /packages/sdk-api/tests/request-url.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | blocksGet, 3 | operationsGetTransactions, 4 | tokensGetTokenTransfers, 5 | } from '../src'; 6 | 7 | const getBlocksRequestUrl = async (method: any, params: any) => { 8 | let requestUrl = ''; 9 | 10 | const fetchMock = (url: string) => { 11 | requestUrl = url; 12 | return { 13 | ok: true, 14 | status: 200, 15 | text: '', 16 | headers: { 17 | get: () => undefined, 18 | }, 19 | }; 20 | }; 21 | 22 | const res = await method(params, { 23 | fetch: fetchMock as any, 24 | }); 25 | 26 | expect(res).toEqual(undefined); 27 | 28 | return requestUrl; 29 | }; 30 | 31 | describe('request', () => { 32 | test('blocksGet any on in', async () => { 33 | const checkUrl = 34 | 'https://api.tzkt.io/v1/blocks?limit=50&anyof.producer.proposer.in=tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K,tz3bTdwZinP8U1JmSweNzVKhmwafqWmFWRfk&level.lt=1000000'; 35 | 36 | const url = await getBlocksRequestUrl(blocksGet, { 37 | anyof: { 38 | in: [ 39 | 'tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K', 40 | 'tz3bTdwZinP8U1JmSweNzVKhmwafqWmFWRfk', 41 | ], 42 | fields: ['producer', 'proposer'], 43 | }, 44 | level: { 45 | lt: 1000000, 46 | }, 47 | limit: 50, 48 | }); 49 | 50 | expect(decodeURIComponent(url)).toEqual(checkUrl); 51 | }); 52 | 53 | test('tokensGetTokenTransfers null', async () => { 54 | const checkUrl = 55 | 'https://api.tzkt.io/v1/tokens/transfers?limit=50&level.lt=1000000&anyof.from.to.null=true'; 56 | 57 | const url = await getBlocksRequestUrl(tokensGetTokenTransfers, { 58 | anyof: { 59 | null: true, 60 | fields: ['from', 'to'], 61 | }, 62 | limit: 50, 63 | level: { 64 | lt: 1000000, 65 | }, 66 | }); 67 | 68 | expect(decodeURIComponent(url)).toEqual(checkUrl); 69 | }); 70 | 71 | test('blocksGet eq', async () => { 72 | const checkUrl = 73 | 'https://api.tzkt.io/v1/blocks?limit=50&anyof.proposer.producer=tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K&level.lt=1000000'; 74 | 75 | const url = await getBlocksRequestUrl(blocksGet, { 76 | anyof: { 77 | value: 'tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K', 78 | fields: ['proposer', 'producer'], 79 | }, 80 | limit: 50, 81 | level: { 82 | lt: 1000000, 83 | }, 84 | }); 85 | 86 | expect(decodeURIComponent(url)).toEqual(checkUrl); 87 | }); 88 | 89 | test('operationsGetTransactions eq', async () => { 90 | const checkUrl = 91 | 'https://api.tzkt.io/v1/operations/transactions?limit=50&anyof.sender.target.eq=tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K&level.lt=1000000'; 92 | 93 | const url = await getBlocksRequestUrl(operationsGetTransactions, { 94 | anyof: { 95 | eq: 'tz3WMqdzXqRWXwyvj5Hp2H7QEepaUuS7vd9K', 96 | fields: ['sender', 'target'], 97 | }, 98 | limit: 50, 99 | level: { 100 | lt: 1000000, 101 | }, 102 | }); 103 | 104 | expect(decodeURIComponent(url)).toEqual(checkUrl); 105 | }); 106 | }); 107 | -------------------------------------------------------------------------------- /packages/sdk-api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es2017", 5 | "outDir": "build/main", 6 | "rootDir": "src", 7 | "moduleResolution": "node16", 8 | "module": "commonjs", 9 | "declaration": true, 10 | "inlineSourceMap": true, 11 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 12 | "resolveJsonModule": true /* Include modules imported with .json extension. */, 13 | 14 | "strict": true /* Enable all strict type-checking options. */, 15 | 16 | /* Strict Type-Checking Options */ 17 | // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, 18 | // "strictNullChecks": true /* Enable strict null checks. */, 19 | // "strictFunctionTypes": true /* Enable strict checking of function types. */, 20 | // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, 21 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, 22 | // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, 23 | 24 | /* Additional Checks */ 25 | "noUnusedLocals": true /* Report errors on unused locals. */, 26 | "noUnusedParameters": true /* Report errors on unused parameters. */, 27 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, 28 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, 29 | "skipLibCheck": true, 30 | /* Debugging Options */ 31 | "traceResolution": false /* Report module resolution log messages. */, 32 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */, 33 | "listFiles": false /* Print names of files part of the compilation. */, 34 | "pretty": true /* Stylize errors and messages using color and context. */, 35 | 36 | /* Experimental Options */ 37 | // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, 38 | // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, 39 | 40 | "lib": ["es2017", "dom"], 41 | "types": ["node", "jest"], 42 | "typeRoots": [ 43 | "../../node_modules/@types", 44 | "src/types", 45 | "node_modules/@types" 46 | ] 47 | }, 48 | "include": ["src/**/*.ts", ".eslintrc.js"], 49 | "exclude": ["node_modules/**", "jest.config.ts"], 50 | "compileOnSave": false 51 | } 52 | -------------------------------------------------------------------------------- /packages/sdk-api/tsconfig.module.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "compilerOptions": { 4 | "target": "esnext", 5 | "outDir": "build/module", 6 | "module": "esnext" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /packages/sdk-events/.cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json", 4 | "language": "en", 5 | "words": [ 6 | "annots", 7 | "anyof", 8 | "Atomex", 9 | "bigmap", 10 | "bigmaps", 11 | "bitauth", 12 | "bitjson", 13 | "cimg", 14 | "circleci", 15 | "codecov", 16 | "codegen", 17 | "commitlint", 18 | "datetime", 19 | "Delegators", 20 | "dependabot", 21 | "editorconfig", 22 | "entrypoint", 23 | "entrypoints", 24 | "esnext", 25 | "execa", 26 | "exponentiate", 27 | "globby", 28 | "libauth", 29 | "micheline", 30 | "mkdir", 31 | "oazapfts", 32 | "OBJKT", 33 | "openapi", 34 | "originations", 35 | "preendorsement", 36 | "preendorsements", 37 | "preendorsing", 38 | "prettierignore", 39 | "sandboxed", 40 | "supermajority", 41 | "transpiled", 42 | "typedoc", 43 | "tzips", 44 | "tzkt", 45 | "untracked", 46 | "upvoted", 47 | "upvotes", 48 | "signalr", 49 | "tezos", 50 | "onreconnecting", 51 | "onreconnected", 52 | "BIGMAPTAG" 53 | ], 54 | "flagWords": [], 55 | "ignorePaths": [ 56 | "package.json", 57 | "package-lock.json", 58 | "yarn.lock", 59 | "tsconfig.json", 60 | "node_modules/**", 61 | "swagger.json" 62 | ], 63 | "ignoreRegExpList": [ 64 | "(tz|KT)[1-9A-HJ-NP-Za-km-z]{34}", 65 | "o[1-9A-HJ-NP-Za-km-z]{50}" 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /packages/sdk-events/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | max_line_length = 80 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | max_line_length = 0 15 | trim_trailing_whitespace = false 16 | -------------------------------------------------------------------------------- /packages/sdk-events/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "project": "./tsconfig.json", 6 | // eslint-disable-next-line no-undef 7 | "tsconfigRootDir": __dirname, 8 | }, 9 | "env": { "es6": true }, 10 | "ignorePatterns": ["node_modules", "build", "coverage"], 11 | "plugins": ["import", "eslint-comments", "functional"], 12 | "extends": [ 13 | "eslint:recommended", 14 | "plugin:eslint-comments/recommended", 15 | "plugin:@typescript-eslint/recommended", 16 | "plugin:import/typescript", 17 | // "plugin:functional/lite", 18 | "prettier", 19 | "prettier/@typescript-eslint" 20 | ], 21 | "globals": { "BigInt": true, "console": true, "WebAssembly": true }, 22 | "rules": { 23 | "@typescript-eslint/explicit-module-boundary-types": "off", 24 | "eslint-comments/disable-enable-pair": [ 25 | "error", 26 | { "allowWholeFile": true } 27 | ], 28 | "eslint-comments/no-unused-disable": "error", 29 | "import/order": [ 30 | "error", 31 | { "newlines-between": "always", "alphabetize": { "order": "asc" } } 32 | ], 33 | "sort-imports": [ 34 | "error", 35 | { "ignoreDeclarationSort": true, "ignoreCase": true } 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/sdk-events/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | .nyc_output 3 | build 4 | node_modules 5 | test 6 | src/**.js 7 | coverage 8 | *.log 9 | yarn.lock 10 | .DS_Store 11 | -------------------------------------------------------------------------------- /packages/sdk-events/.prettierignore: -------------------------------------------------------------------------------- 1 | # package.json is formatted by package managers, so we ignore it here 2 | package.json -------------------------------------------------------------------------------- /packages/sdk-events/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ### [2.2.1](https://github.com/tzkt/api-sdk-ts/compare/v2.2.0...v2.2.1) (2023-09-20) 7 | 8 | **Note:** Version bump only for package @tzkt/sdk-events 9 | 10 | 11 | 12 | 13 | 14 | 15 | ## [2.2.0](https://github.com/tzkt/api-sdk-ts/compare/v2.1.0...v2.2.0) (2023-03-11) 16 | 17 | **Note:** Version bump only for package @tzkt/sdk-events 18 | 19 | 20 | 21 | 22 | 23 | ## [2.1.0](https://github.com/tzkt/api-sdk-ts/compare/v2.0.0...v2.1.0) (2022-12-14) 24 | 25 | 26 | ### Bug Fixes 27 | 28 | * **sdk-event:** types issues ([a93a52c](https://github.com/tzkt/api-sdk-ts/commit/a93a52c10ae9a23df9c2817b48a30a96926fcac1)) 29 | 30 | 31 | 32 | ## [2.0.0](https://github.com/tzkt/api-sdk-ts/compare/v1.0.2...v2.0.0) (2022-12-14) 33 | 34 | **Note:** Version bump only for package @tzkt/sdk-events 35 | 36 | 37 | 38 | 39 | 40 | ### [1.0.1](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.1) (2022-10-27) 41 | 42 | **Note:** Version bump only for package @tzkt/sdk-events 43 | 44 | 45 | 46 | 47 | 48 | ## [1.0.0](https://github.com/tzkt/api-sdk-ts/compare/v0.3.0...v1.0.0) (2022-09-13) 49 | 50 | **Note:** Version bump only for package @tzkt/sdk-events 51 | 52 | 53 | 54 | 55 | 56 | ## [0.3.0](https://github.com/tzkt/api-sdk-ts/compare/v0.2.0...v0.3.0) (2022-08-25) 57 | 58 | **Note:** Version bump only for package @tzkt/sdk-events 59 | 60 | 61 | 62 | 63 | 64 | ## [0.2.0](https://github.com/tzkt/api-sdk-ts/compare/v0.1.2...v0.2.0) (2022-04-30) 65 | 66 | **Note:** Version bump only for package @tzkt/sdk-events 67 | -------------------------------------------------------------------------------- /packages/sdk-events/README.md: -------------------------------------------------------------------------------- 1 | # TzKT Events SDK 2 | 3 | Fully typed client for working with TzKT subscriptions API. 4 | A thin wrapper on top of SignalR converting subscriptions to observables. 5 | 6 | ## Install 7 | 8 | ```bash 9 | npm i @tzkt/sdk-events 10 | ``` 11 | 12 | ## Use 13 | 14 | Create an instance of events service specifying TzKT events endpoint. 15 | ```js 16 | import { EventsService } from "@tzkt/sdk-events"; 17 | 18 | const events = new EventsService({ url: "https://api.tzkt.io/v1/events", reconnect: true }); 19 | ``` 20 | 21 | Connection is not initiated until the first request (lazy connection): 22 | ```js 23 | const sub = events.operations({ types: [ 'origination' ] }) 24 | .subscribe({ next: console.log }); 25 | ``` 26 | 27 | Events service implements subscription router internally (on TzKT your subscriptions are aggregated) hence you can always "unsubscribe" from new updates (however it does not change anything on the TzKT side, just stops firing your observer): 28 | ```js 29 | sub.unsubscribe(); 30 | ``` 31 | 32 | By default events service will infinitely try to reconnect in case of drop, you can monitor current state by subscribing to status updates: 33 | ```js 34 | events.status() 35 | .subscribe({ next: console.log }); 36 | ``` 37 | 38 | In case you need to terminate the connection you can do that (note that event service will start again in case you send a subscription request afterwards): 39 | ```js 40 | await events.stop(); 41 | ``` 42 | 43 | ## Examples 44 | 45 | Check out the [demo app](https://github.com/tzkt/api-sdk-ts/tree/main/examples/sdk-events-example). -------------------------------------------------------------------------------- /packages/sdk-events/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@tzkt/sdk-events", 3 | "version": "2.2.1", 4 | "description": "Fully typed client for TzKT subscription API", 5 | "main": "build/main/index.js", 6 | "types": "build/main/index.d.ts", 7 | "typings": "build/main/index.d.ts", 8 | "module": "build/module/index.js", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/tzkt/api-sdk-ts.git" 12 | }, 13 | "author": "Michael Zaikin ", 14 | "license": "MIT", 15 | "scripts": { 16 | "build": "run-p build:*", 17 | "build:main": "tsc -p tsconfig.json", 18 | "build:module": "tsc -p tsconfig.module.json", 19 | "fix": "run-s fix:*", 20 | "fix:prettier": "prettier \"src/**/*.ts\" --write", 21 | "fix:lint": "eslint src --ext .ts --fix", 22 | "test": "run-s build test:*", 23 | "test:lint": "eslint src --ext .ts", 24 | "test:prettier": "prettier \"src/**/*.ts\" --list-different", 25 | "test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"", 26 | "check-cli": "run-s test diff-integration-tests check-integration-tests", 27 | "check-integration-tests": "run-s check-integration-test:*", 28 | "diff-integration-tests": "mkdir -p diff && rm -rf diff/test && cp -r test diff/test && rm -rf diff/test/test-*/.git && cd diff && git init --quiet && git add -A && git commit --quiet --no-verify --allow-empty -m 'WIP' && echo '\\n\\nCommitted most recent integration test output in the \"diff\" directory. Review the changes with \"cd diff && git diff HEAD\" or your preferred git diff viewer.'", 29 | "watch:build": "tsc -p tsconfig.json -w", 30 | "watch:test": "nyc --silent ava --watch", 31 | "cov": "run-s build test:unit cov:html cov:lcov && open-cli coverage/index.html", 32 | "cov:html": "nyc report --reporter=html", 33 | "cov:lcov": "nyc report --reporter=lcov", 34 | "cov:send": "run-s cov:lcov && codecov", 35 | "cov:check": "nyc report && nyc check-coverage --lines 100 --functions 100 --branches 100", 36 | "doc": "run-s doc:html && open-cli build/docs/index.html", 37 | "doc:html": "typedoc src/ --exclude **/*.spec.ts --out build/docs", 38 | "doc:json": "typedoc src/ --exclude **/*.spec.ts --json build/docs/typedoc.json", 39 | "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs", 40 | "reset-hard": "git clean -dfx && git reset --hard && npm i", 41 | "prepare-release": "run-s reset-hard test cov:check doc:html version doc:publish" 42 | }, 43 | "engines": { 44 | "node": ">=14", 45 | "npm": ">=6" 46 | }, 47 | "engineStrict": true, 48 | "devDependencies": { 49 | "@ava/typescript": "^1.1.1", 50 | "@istanbuljs/nyc-config-typescript": "^1.0.1", 51 | "@types/jest": "^29.0.0", 52 | "@types/lodash": "^4.14.178", 53 | "@types/node": "^16.0.0", 54 | "@types/ws": "^7.4.5", 55 | "@types/zen-observable": "^0.8.3", 56 | "@typescript-eslint/eslint-plugin": "^5.46.1", 57 | "@typescript-eslint/parser": "^5.46.1", 58 | "ava": "^3.12.1", 59 | "codecov": "^3.5.0", 60 | "cspell": "^4.1.0", 61 | "cz-conventional-changelog": "^3.3.0", 62 | "eslint": "^7.10.0", 63 | "eslint-config-prettier": "^6.11.0", 64 | "eslint-plugin-eslint-comments": "^3.2.0", 65 | "eslint-plugin-functional": "^3.0.2", 66 | "eslint-plugin-import": "^2.22.0", 67 | "gh-pages": "^3.1.0", 68 | "jest": "^29.0.0", 69 | "lodash": "^4.17.21", 70 | "npm-run-all": "^4.1.5", 71 | "nyc": "^15.1.0", 72 | "open-cli": "^6.0.1", 73 | "openapi-types": "^10.0.0", 74 | "prettier": "^2.1.1", 75 | "standard-version": "^9.0.0", 76 | "ts-jest": "^29.1.1", 77 | "ts-node-dev": "^2.0.0", 78 | "typescript": "^4.9.4" 79 | }, 80 | "dependencies": { 81 | "@microsoft/signalr": "^7.0.11", 82 | "@tzkt/sdk-api": "^2.2.0", 83 | "zen-observable": "^0.8.15" 84 | }, 85 | "ava": { 86 | "failFast": true, 87 | "timeout": "60s", 88 | "typescript": { 89 | "rewritePaths": { 90 | "src/": "build/main/" 91 | } 92 | }, 93 | "files": [ 94 | "!build/module/**" 95 | ] 96 | }, 97 | "config": { 98 | "commitizen": { 99 | "path": "cz-conventional-changelog" 100 | } 101 | }, 102 | "prettier": { 103 | "singleQuote": true 104 | }, 105 | "nyc": { 106 | "extends": "@istanbuljs/nyc-config-typescript", 107 | "exclude": [ 108 | "**/*.spec.js" 109 | ] 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /packages/sdk-events/src/client.ts: -------------------------------------------------------------------------------- 1 | import * as signalR from '@microsoft/signalr'; 2 | import { 3 | Account, 4 | ActivationOperation, 5 | BakingOperation, 6 | BallotOperation, 7 | BigMapUpdate, 8 | Block, 9 | DelegationOperation, 10 | DoubleBakingOperation, 11 | DoubleEndorsingOperation, 12 | DoublePreendorsingOperation, 13 | EndorsementOperation, 14 | EndorsingRewardOperation, 15 | MigrationOperation, 16 | NonceRevelationOperation, 17 | OriginationOperation, 18 | PreendorsementOperation, 19 | ProposalOperation, 20 | RegisterConstantOperation, 21 | RevealOperation, 22 | RevelationPenaltyOperation, 23 | SetDepositsLimitOperation, 24 | State, 25 | TokenTransfer, 26 | TransactionOperation, 27 | } from '@tzkt/sdk-api'; 28 | import Observable from 'zen-observable'; 29 | 30 | import { 31 | AccountSubscriptionParameters, 32 | BigMapSubscriptionParameters, 33 | CHANNEL, 34 | channelToMethod, 35 | Event, 36 | EventsConfig, 37 | EventType, 38 | Message, 39 | METHOD, 40 | OperationKind, 41 | OperationSubscriptionParameters, 42 | ResponseTypes, 43 | SubscriptionParameters, 44 | TezosOperation, 45 | TokenTransferSubscriptionParameters, 46 | } from './types'; 47 | 48 | export type StatusObservable = Observable; 49 | export type EventObservable = Observable; 50 | export type AccountObservable = Observable>; 51 | export type StateObservable = Observable>; 52 | export type BlockObservable = Observable>; 53 | export type OperationObservable = Observable< 54 | SubscriptionMessage 55 | >; 56 | export type BigMapObservable = Observable>; 57 | export type TokenTransferObservable = Observable< 58 | SubscriptionMessage 59 | >; 60 | export type ZenSubscription = ZenObservable.Subscription; 61 | 62 | export class EventsService { 63 | private connection: signalR.HubConnection; 64 | private subscriptions: Set>; 65 | private networkEvents: Observable; 66 | private statusChanges: Observable; 67 | private eventObservers: Set>; 68 | private statusObservers: Set< 69 | ZenObservable.Observer 70 | >; 71 | 72 | constructor({ url, reconnect = true }: EventsConfig) { 73 | this.subscriptions = new Set>(); 74 | this.eventObservers = new Set>(); 75 | this.statusObservers = new Set< 76 | ZenObservable.Observer 77 | >(); 78 | 79 | let builder = new signalR.HubConnectionBuilder() 80 | .configureLogging(signalR.LogLevel.Error) 81 | .withUrl(url); 82 | 83 | if (reconnect) { 84 | builder = builder.withAutomaticReconnect({ 85 | nextRetryDelayInMilliseconds: (ctx) => { 86 | // TODO: better policy 87 | return ctx.elapsedMilliseconds < 10000 ? 1000 : 5000; 88 | }, 89 | }); 90 | } 91 | 92 | this.connection = builder.build(); 93 | 94 | this.connection.on(CHANNEL.HEAD, (msg) => 95 | this.onMessage(CHANNEL.HEAD, msg) 96 | ); 97 | this.connection.on(CHANNEL.ACCOUNT, (msg) => 98 | this.onMessage(CHANNEL.ACCOUNT, msg) 99 | ); 100 | this.connection.on(CHANNEL.BLOCKS, (msg) => 101 | this.onMessage(CHANNEL.BLOCKS, msg) 102 | ); 103 | this.connection.on(CHANNEL.OPERATIONS, (msg) => 104 | this.onMessage(CHANNEL.OPERATIONS, msg) 105 | ); 106 | this.connection.on(CHANNEL.BIGMAPS, (msg) => 107 | this.onMessage(CHANNEL.BIGMAPS, msg) 108 | ); 109 | this.connection.on(CHANNEL.TRANSFERS, (msg) => 110 | this.onMessage(CHANNEL.TRANSFERS, msg) 111 | ); 112 | 113 | this.connection.onclose(() => 114 | this.onStatusChanged(signalR.HubConnectionState.Disconnected) 115 | ); 116 | this.connection.onreconnecting(() => 117 | this.onStatusChanged(signalR.HubConnectionState.Reconnecting) 118 | ); 119 | 120 | if (reconnect) { 121 | this.connection.onreconnected(async () => { 122 | this.onStatusChanged(signalR.HubConnectionState.Connected); 123 | this.subscriptions.forEach(async (sub) => await this.invoke(sub), this); 124 | }); 125 | } else { 126 | this.connection.onreconnected(() => 127 | this.onStatusChanged(signalR.HubConnectionState.Connected) 128 | ); 129 | } 130 | 131 | this.networkEvents = new Observable((observer) => { 132 | this.eventObservers.add(observer); 133 | return () => { 134 | this.eventObservers.delete(observer); 135 | }; 136 | }); 137 | 138 | this.statusChanges = new Observable( 139 | (observer) => { 140 | this.statusObservers.add(observer); 141 | return () => { 142 | this.statusObservers.delete(observer); 143 | }; 144 | } 145 | ); 146 | } 147 | 148 | public async start(): Promise { 149 | switch (this.connection.state) { 150 | case signalR.HubConnectionState.Disconnected: { 151 | this.onStatusChanged(signalR.HubConnectionState.Connecting); 152 | await this.connection.start(); 153 | this.onStatusChanged(signalR.HubConnectionState.Connected); 154 | break; 155 | } 156 | case signalR.HubConnectionState.Connected: 157 | break; 158 | default: 159 | throw new Error( 160 | `Intermediate connection hub state: ${this.connection.state}` 161 | ); 162 | } 163 | } 164 | 165 | public async stop() { 166 | switch (this.connection.state) { 167 | case signalR.HubConnectionState.Disconnected: 168 | break; 169 | case signalR.HubConnectionState.Connected: { 170 | this.onStatusChanged(signalR.HubConnectionState.Disconnecting); 171 | await this.connection.stop(); 172 | this.subscriptions.forEach((sub) => { 173 | if (sub.observer.complete) { 174 | sub.observer.complete(); 175 | } 176 | }, this); 177 | this.subscriptions.clear(); 178 | break; 179 | } 180 | default: 181 | throw new Error( 182 | `Intermediate connection hub state: ${this.connection.state}` 183 | ); 184 | } 185 | } 186 | 187 | private async invoke(sub: Subscription) { 188 | if (sub.params) { 189 | const args = sub.params as any; 190 | // Fix inconsistencies in the subscription interface 191 | if (sub.method == METHOD.OPERATIONS) { 192 | const params = sub.params as OperationSubscriptionParameters; 193 | if (params.types && params.types.length > 0) { 194 | args.types = params.types.join(','); 195 | } 196 | } 197 | return await this.connection.invoke(sub.method, args); 198 | } 199 | return await this.connection.invoke(sub.method); 200 | } 201 | 202 | /** 203 | * Subscribe to connection status changes 204 | */ 205 | public status(): StatusObservable { 206 | return this.statusChanges; 207 | } 208 | 209 | /** 210 | * Subscribe to raw TzKT events (init, rollback message types) 211 | */ 212 | public events(): EventObservable { 213 | return this.networkEvents; 214 | } 215 | 216 | /* 217 | * head 218 | */ 219 | public head(): StateObservable { 220 | return new Observable>((observer) => { 221 | return this.createSubscription(CHANNEL.HEAD, observer); 222 | }); 223 | } 224 | 225 | /* 226 | * account 227 | */ 228 | public account(params: AccountSubscriptionParameters): AccountObservable { 229 | return new Observable>((observer) => { 230 | return this.createSubscription( 231 | CHANNEL.ACCOUNT, 232 | observer, 233 | params 234 | ); 235 | }); 236 | } 237 | 238 | /* 239 | * blocks 240 | */ 241 | public blocks(): BlockObservable { 242 | return new Observable>((observer) => { 243 | return this.createSubscription(CHANNEL.BLOCKS, observer); 244 | }); 245 | } 246 | 247 | /* 248 | * operations 249 | */ 250 | public operations( 251 | params: OperationSubscriptionParameters 252 | ): OperationObservable { 253 | return new Observable>((observer) => { 254 | return this.createSubscription( 255 | CHANNEL.OPERATIONS, 256 | observer, 257 | params 258 | ); 259 | }); 260 | } 261 | 262 | /* 263 | * bigmaps 264 | */ 265 | public bigmaps(params: BigMapSubscriptionParameters): BigMapObservable { 266 | return new Observable>((observer) => { 267 | return this.createSubscription( 268 | CHANNEL.BIGMAPS, 269 | observer, 270 | params 271 | ); 272 | }); 273 | } 274 | 275 | /* 276 | * transfers 277 | */ 278 | public transfers( 279 | params: TokenTransferSubscriptionParameters 280 | ): TokenTransferObservable { 281 | return new Observable>((observer) => { 282 | return this.createSubscription( 283 | CHANNEL.TRANSFERS, 284 | observer, 285 | params 286 | ); 287 | }); 288 | } 289 | 290 | private createSubscription( 291 | channel: CHANNEL, 292 | observer: ZenObservable.Observer>, 293 | params?: SubscriptionParameters 294 | ): () => void { 295 | const subscription = new Subscription(channel, observer, params); 296 | this.subscriptions.add(subscription); 297 | 298 | this.start() 299 | .then(() => this.invoke(subscription)) 300 | .catch((error) => { 301 | throw new Error(error); 302 | }); 303 | 304 | return () => { 305 | this.subscriptions.delete(subscription); 306 | if (subscription.observer.complete) { 307 | subscription.observer.complete(); 308 | } 309 | }; 310 | } 311 | 312 | private handle(channel: CHANNEL, item: ResponseTypes, state: number) { 313 | this.subscriptions.forEach((sub) => { 314 | if (sub.observer.next && sub.match(channel, item)) { 315 | sub.observer.next({ 316 | data: item, 317 | state: state, 318 | }); 319 | } 320 | }); 321 | } 322 | 323 | private onMessage(channel: CHANNEL, message: Message) { 324 | switch (message.type) { 325 | case EventType.Init: 326 | return this.onEvent(message); 327 | case EventType.Reorg: 328 | return this.onEvent(message); 329 | case EventType.Data: { 330 | switch (channel) { 331 | case CHANNEL.HEAD: 332 | return this.handle(channel, message.data as State, message.state); 333 | case CHANNEL.ACCOUNT: 334 | return this.handle(channel, message.data as Account, message.state); 335 | default: { 336 | const items = message.data as Array< 337 | Block | TezosOperation | BigMapUpdate | TokenTransfer 338 | >; 339 | return items.forEach( 340 | (item) => this.handle(channel, item, message.state), 341 | this 342 | ); 343 | } 344 | } 345 | } 346 | } 347 | } 348 | 349 | private onEvent(event: Event) { 350 | this.eventObservers.forEach((o) => { 351 | if (o.next) { 352 | o.next(event); 353 | } 354 | }); 355 | } 356 | 357 | private onStatusChanged(status: signalR.HubConnectionState) { 358 | this.statusObservers.forEach((o) => { 359 | if (o.next) { 360 | o.next(status); 361 | } 362 | }); 363 | } 364 | } 365 | 366 | export interface SubscriptionMessage { 367 | data: Type; 368 | state: number; 369 | } 370 | 371 | class Subscription { 372 | method: string; 373 | 374 | constructor( 375 | private channel: CHANNEL, 376 | public observer: ZenObservable.Observer>, 377 | public params?: SubscriptionParameters 378 | ) { 379 | this.method = channelToMethod(channel); 380 | } 381 | 382 | public match(channel: CHANNEL, item: ResponseTypes): boolean { 383 | if (this.channel !== channel) { 384 | return false; 385 | } 386 | if (this.params) { 387 | switch (channel) { 388 | case CHANNEL.ACCOUNT: 389 | return this.matchAccount( 390 | item as Account, 391 | this.params as AccountSubscriptionParameters 392 | ); 393 | case CHANNEL.OPERATIONS: 394 | return this.matchOperation( 395 | item as TezosOperation, 396 | this.params as OperationSubscriptionParameters 397 | ); 398 | case CHANNEL.BIGMAPS: 399 | return this.matchBigMapUpdate( 400 | item as BigMapUpdate, 401 | this.params as BigMapSubscriptionParameters 402 | ); 403 | case CHANNEL.TRANSFERS: 404 | return this.matchTokenTransfer( 405 | item as TokenTransfer, 406 | this.params as TokenTransferSubscriptionParameters 407 | ); 408 | } 409 | } 410 | return true; 411 | } 412 | 413 | private matchAccount( 414 | _account: Account, 415 | _params: AccountSubscriptionParameters 416 | ): boolean { 417 | // TODO: Account model either not generated correctly or not valid in the openapi spec 418 | return true; 419 | } 420 | 421 | private matchOperation( 422 | operation: TezosOperation, 423 | params: OperationSubscriptionParameters 424 | ): boolean { 425 | if ( 426 | params.types && 427 | !params.types.includes(operation.type as OperationKind) 428 | ) { 429 | return false; 430 | } 431 | if (params.address) { 432 | switch (operation.type) { 433 | case 'endorsement': 434 | return ( 435 | (operation as EndorsementOperation).delegate?.address === 436 | params.address 437 | ); 438 | case 'preendorsement': 439 | return ( 440 | (operation as PreendorsementOperation).delegate?.address === 441 | params.address 442 | ); 443 | case 'ballot': 444 | return ( 445 | (operation as BallotOperation).delegate?.address === params.address 446 | ); 447 | case 'proposal': 448 | return ( 449 | (operation as ProposalOperation).delegate?.address === 450 | params.address 451 | ); 452 | case 'activation': 453 | return ( 454 | (operation as ActivationOperation).account?.address === 455 | params.address 456 | ); 457 | case 'double_baking': { 458 | const op = operation as DoubleBakingOperation; 459 | return ( 460 | op.offender?.address === params.address || 461 | op.accuser?.address === params.address 462 | ); 463 | } 464 | case 'double_endorsing': { 465 | const op = operation as DoubleEndorsingOperation; 466 | return ( 467 | op.offender?.address === params.address || 468 | op.accuser?.address === params.address 469 | ); 470 | } 471 | case 'double_preendorsing': { 472 | const op = operation as DoublePreendorsingOperation; 473 | return ( 474 | op.offender?.address === params.address || 475 | op.accuser?.address === params.address 476 | ); 477 | } 478 | case 'nonce_revelation': { 479 | const op = operation as NonceRevelationOperation; 480 | return ( 481 | op.baker?.address === params.address || 482 | op.sender?.address === params.address 483 | ); 484 | } 485 | case 'delegation': 486 | return ( 487 | (operation as DelegationOperation).sender?.address === 488 | params.address 489 | ); 490 | case 'origination': { 491 | const op = operation as OriginationOperation; 492 | return ( 493 | op.sender?.address === params.address || 494 | op.originatedContract?.address === params.address 495 | ); 496 | } 497 | case 'transaction': { 498 | const op = operation as TransactionOperation; 499 | return ( 500 | op.sender?.address === params.address || 501 | op.target?.address === params.address 502 | ); 503 | } 504 | case 'reveal': 505 | return ( 506 | (operation as RevealOperation).sender?.address === params.address 507 | ); 508 | case 'register_constant': 509 | return ( 510 | (operation as RegisterConstantOperation).sender?.address === 511 | params.address 512 | ); 513 | case 'set_deposits_limit': 514 | return ( 515 | (operation as SetDepositsLimitOperation).sender?.address === 516 | params.address 517 | ); 518 | case 'migration': 519 | return ( 520 | (operation as MigrationOperation).account?.address === 521 | params.address 522 | ); 523 | case 'revelation_penalty': 524 | return ( 525 | (operation as RevelationPenaltyOperation).baker?.address === 526 | params.address 527 | ); 528 | case 'baking': { 529 | const op = operation as BakingOperation; 530 | return ( 531 | op.proposer?.address === params.address || 532 | op.producer?.address === params.address 533 | ); 534 | } 535 | case 'endorsing_reward': 536 | return ( 537 | (operation as EndorsingRewardOperation).baker?.address === 538 | params.address 539 | ); 540 | } 541 | } 542 | return true; 543 | } 544 | 545 | private matchBigMapUpdate( 546 | update: BigMapUpdate, 547 | params: BigMapSubscriptionParameters 548 | ): boolean { 549 | if (params.contract) { 550 | if (params.contract !== update.contract) { 551 | return false; 552 | } 553 | } 554 | if (params.ptr) { 555 | if (params.ptr !== update.bigmap) { 556 | return false; 557 | } 558 | } 559 | if (params.path) { 560 | if (!update.path?.startsWith(params.path)) { 561 | return false; 562 | } 563 | } 564 | // TODO: filter by tags 565 | return true; 566 | } 567 | 568 | private matchTokenTransfer( 569 | transfer: TokenTransfer, 570 | params: TokenTransferSubscriptionParameters 571 | ): boolean { 572 | if (params.account) { 573 | if (params.account !== transfer.from && params.account !== transfer.to) { 574 | return false; 575 | } 576 | } 577 | if (params.contract) { 578 | if (params.contract !== transfer.token?.contract) { 579 | return false; 580 | } 581 | } 582 | if (params.tokenId) { 583 | if (params.tokenId !== transfer.token?.tokenId) { 584 | return false; 585 | } 586 | } 587 | return true; 588 | } 589 | } 590 | -------------------------------------------------------------------------------- /packages/sdk-events/src/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | EventsService, 3 | SubscriptionMessage, 4 | StateObservable, 5 | BlockObservable, 6 | OperationObservable, 7 | BigMapObservable, 8 | TokenTransferObservable, 9 | StatusObservable, 10 | EventObservable, 11 | ZenSubscription as Subscription, 12 | } from './client'; 13 | export { 14 | EventsConfig, 15 | TezosOperation, 16 | OperationKind, 17 | OperationSubscriptionParameters, 18 | BigMapSubscriptionParameters, 19 | TokenTransferSubscriptionParameters, 20 | BigMapTag, 21 | Event, 22 | EventType, 23 | } from './types'; 24 | export { 25 | Account, 26 | Block, 27 | BigMapUpdate, 28 | TokenTransfer, 29 | ActivationOperation, 30 | BallotOperation, 31 | DelegationOperation, 32 | DoubleBakingOperation, 33 | DoubleEndorsingOperation, 34 | EndorsementOperation, 35 | NonceRevelationOperation, 36 | OriginationOperation, 37 | ProposalOperation, 38 | RevealOperation, 39 | TransactionOperation, 40 | RegisterConstantOperation, 41 | PreendorsementOperation, 42 | DoublePreendorsingOperation, 43 | RevelationPenaltyOperation, 44 | SetDepositsLimitOperation, 45 | MigrationOperation, 46 | EndorsingRewardOperation, 47 | BakingOperation, 48 | } from '@tzkt/sdk-api'; 49 | -------------------------------------------------------------------------------- /packages/sdk-events/src/types.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Account, 3 | ActivationOperation, 4 | BakingOperation, 5 | BallotOperation, 6 | BigMapUpdate, 7 | Block, 8 | DelegationOperation, 9 | DoubleBakingOperation, 10 | DoubleEndorsingOperation, 11 | DoublePreendorsingOperation, 12 | EndorsementOperation, 13 | EndorsingRewardOperation, 14 | MigrationOperation, 15 | NonceRevelationOperation, 16 | OriginationOperation, 17 | PreendorsementOperation, 18 | ProposalOperation, 19 | RegisterConstantOperation, 20 | RevealOperation, 21 | RevelationPenaltyOperation, 22 | SetDepositsLimitOperation, 23 | State, 24 | TokenTransfer, 25 | TransactionOperation, 26 | } from '@tzkt/sdk-api'; 27 | 28 | export enum EventType { 29 | Init = 0, 30 | Data = 1, 31 | Reorg = 2, 32 | } 33 | 34 | export interface Event { 35 | type: EventType; 36 | state: number; 37 | } 38 | 39 | export interface Message extends Event { 40 | data?: 41 | | Account 42 | | State 43 | | Array; 44 | } 45 | 46 | export type TezosOperation = 47 | | ActivationOperation 48 | | BallotOperation 49 | | DelegationOperation 50 | | DoubleBakingOperation 51 | | DoubleEndorsingOperation 52 | | EndorsementOperation 53 | | NonceRevelationOperation 54 | | OriginationOperation 55 | | ProposalOperation 56 | | RevealOperation 57 | | TransactionOperation 58 | | RegisterConstantOperation 59 | | PreendorsementOperation 60 | | DoublePreendorsingOperation 61 | | RevelationPenaltyOperation 62 | | SetDepositsLimitOperation 63 | | MigrationOperation 64 | | EndorsingRewardOperation 65 | | BakingOperation; 66 | 67 | export interface AccountSubscriptionParameters { 68 | addresses?: Array; 69 | } 70 | 71 | export interface OperationSubscriptionParameters { 72 | address?: string; 73 | types?: Array; 74 | codeHash?: number; 75 | } 76 | 77 | export interface BigMapSubscriptionParameters { 78 | contract?: string; 79 | ptr?: number; 80 | path?: string; 81 | tags?: Array; 82 | } 83 | 84 | export interface TokenTransferSubscriptionParameters { 85 | account?: string; 86 | contract?: string; 87 | tokenId?: string; 88 | } 89 | 90 | export interface EventsConfig { 91 | url: string; 92 | reconnect?: boolean; 93 | } 94 | 95 | export enum BIGMAPTAG { 96 | METADATA = 'metadata', 97 | TOKEN_METADATA = 'token_metadata', 98 | } 99 | 100 | export enum CHANNEL { 101 | HEAD = 'head', 102 | ACCOUNT = 'account', 103 | BLOCKS = 'blocks', 104 | OPERATIONS = 'operations', 105 | BIGMAPS = 'bigmaps', 106 | TRANSFERS = 'transfers', 107 | } 108 | 109 | export enum METHOD { 110 | HEAD = 'SubscribeToHead', 111 | ACCOUNT = 'SubscribeToAccount', 112 | BLOCKS = 'SubscribeToBlocks', 113 | OPERATIONS = 'SubscribeToOperations', 114 | BIGMAPS = 'SubscribeToBigMaps', 115 | TRANSFERS = 'SubscribeToTokenTransfers', 116 | } 117 | 118 | export function channelToMethod(channel: CHANNEL): METHOD { 119 | switch (channel) { 120 | case CHANNEL.HEAD: { 121 | return METHOD.HEAD; 122 | } 123 | case CHANNEL.ACCOUNT: { 124 | return METHOD.ACCOUNT; 125 | } 126 | case CHANNEL.BLOCKS: { 127 | return METHOD.BLOCKS; 128 | } 129 | case CHANNEL.OPERATIONS: { 130 | return METHOD.OPERATIONS; 131 | } 132 | case CHANNEL.BIGMAPS: { 133 | return METHOD.BIGMAPS; 134 | } 135 | case CHANNEL.TRANSFERS: { 136 | return METHOD.TRANSFERS; 137 | } 138 | default: { 139 | throw new Error('Unknown channel: ' + channel); 140 | } 141 | } 142 | } 143 | 144 | export type BigMapTag = BIGMAPTAG.METADATA | BIGMAPTAG.TOKEN_METADATA; 145 | export type OperationKind = 146 | | 'transaction' 147 | | 'origination' 148 | | 'delegation' 149 | | 'reveal' 150 | | 'double_baking' 151 | | 'double_endorsing' 152 | | 'nonce_revelation' 153 | | 'activation' 154 | | 'proposal' 155 | | 'ballot' 156 | | 'endorsement' 157 | | 'register_constant' 158 | | 'preendorsement' 159 | | 'double_preendorsement' 160 | | 'revelation_penalty' 161 | | 'set_deposits_limit' 162 | | 'migration' 163 | | 'endorsing_reward' 164 | | 'baking'; 165 | 166 | export type ResponseTypes = 167 | | State 168 | | Account 169 | | Block 170 | | TezosOperation 171 | | BigMapUpdate 172 | | TokenTransfer; 173 | export type SubscriptionParameters = 174 | | AccountSubscriptionParameters 175 | | OperationSubscriptionParameters 176 | | BigMapSubscriptionParameters 177 | | TokenTransferSubscriptionParameters; 178 | -------------------------------------------------------------------------------- /packages/sdk-events/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "incremental": true, 4 | "target": "es2017", 5 | "outDir": "build/main", 6 | "rootDir": "src", 7 | "moduleResolution": "node16", 8 | "module": "commonjs", 9 | "declaration": true, 10 | "inlineSourceMap": true, 11 | "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, 12 | "resolveJsonModule": true /* Include modules imported with .json extension. */, 13 | 14 | "strict": true /* Enable all strict type-checking options. */, 15 | 16 | /* Strict Type-Checking Options */ 17 | // "noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */, 18 | // "strictNullChecks": true /* Enable strict null checks. */, 19 | // "strictFunctionTypes": true /* Enable strict checking of function types. */, 20 | // "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */, 21 | // "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, 22 | // "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, 23 | 24 | /* Additional Checks */ 25 | "noUnusedLocals": true /* Report errors on unused locals. */, 26 | "noUnusedParameters": true /* Report errors on unused parameters. */, 27 | "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, 28 | "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, 29 | 30 | /* Debugging Options */ 31 | "traceResolution": false /* Report module resolution log messages. */, 32 | "listEmittedFiles": false /* Print names of generated files part of the compilation. */, 33 | "listFiles": false /* Print names of files part of the compilation. */, 34 | "pretty": true /* Stylize errors and messages using color and context. */, 35 | 36 | /* Experimental Options */ 37 | // "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */, 38 | // "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */, 39 | 40 | "lib": ["es2017", "dom"], 41 | "types": ["node"], 42 | "typeRoots": ["node_modules/@types", "src/types"] 43 | }, 44 | "include": ["src/**/*.ts", ".eslintrc.js"], 45 | "exclude": ["node_modules/**"], 46 | "compileOnSave": false 47 | } 48 | -------------------------------------------------------------------------------- /packages/sdk-events/tsconfig.module.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "compilerOptions": { 4 | "target": "esnext", 5 | "outDir": "build/module", 6 | "module": "esnext" 7 | }, 8 | "exclude": [ 9 | "node_modules/**" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /typedoc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | out: 'build/typedoc', 3 | entryPoints: [ 4 | 'packages/sdk-api', 5 | 'packages/sdk-events', 6 | 'packages/ext-taquito' 7 | ], 8 | entryPointStrategy: 'packages', 9 | pluginPages: { 10 | pages: [ 11 | { 12 | title: 'VIRTUAL', 13 | childrenDir: __dirname, 14 | children: [ 15 | { 16 | title: 'Changelog', 17 | source: 'CHANGELOG.md' 18 | }, 19 | ] 20 | }, 21 | ] 22 | }, 23 | exclude: [ 24 | '**/*.spec.ts', 25 | '**/data/**', 26 | '**/dist/**', 27 | '**/node_modules/**', 28 | '**/rollup*.ts', 29 | '**/test/**', 30 | 'examples/**' 31 | ], 32 | name: 'TzKT SDK', 33 | excludePrivate: true, 34 | }; --------------------------------------------------------------------------------