diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e4a0afb540..23b96e59cd 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -15,7 +15,7 @@ importers: '@google-analytics/data': ~3.2.2 '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': workspace:* '@kadena/react-components': workspace:* '@kadena/react-ui': workspace:* '@kadena/types': workspace:* @@ -115,7 +115,7 @@ importers: '@babel/preset-typescript': 7.22.5 '@kadena-dev/eslint-config': link:../../tools/eslint-config '@kadena-dev/heft-rig': link:../../tools/heft-rig - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': link:../../tools/pactjs-cli '@kadena/types': link:../../libs/types '@percy/cli': 1.24.2 '@percy/cypress': 3.1.2_cypress@12.12.0 @@ -158,7 +158,7 @@ importers: specifiers: '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': workspace:* '@pothos/core': ~3.24.0 '@pothos/plugin-prisma': ~3.39.0 '@pothos/plugin-relay': ~3.32.0 @@ -195,7 +195,7 @@ importers: devDependencies: '@kadena-dev/eslint-config': link:../../tools/eslint-config '@kadena-dev/heft-rig': link:../../tools/heft-rig - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': link:../../tools/pactjs-cli '@rushstack/eslint-config': 3.3.2_eslint@8.44.0 '@rushstack/heft': 0.50.7_@types+node@16.18.38 '@types/debug': 4.1.8 @@ -215,7 +215,7 @@ importers: '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': workspace:* '@radix-ui/colors': ~0.1.8 '@radix-ui/react-icons': ~1.1.1 '@rushstack/eslint-config': ~3.3.0 @@ -260,7 +260,7 @@ importers: '@kadena-dev/eslint-config': link:../../tools/eslint-config '@kadena-dev/heft-rig': link:../../tools/heft-rig '@kadena-dev/markdown': link:../../tools/remark-plugins - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': link:../../tools/pactjs-cli '@rushstack/eslint-config': 3.3.2_eslint@8.44.0+typescript@5.0.4 '@rushstack/heft': 0.50.7_@types+node@16.18.38 '@types/heft-jest': 1.0.3 @@ -278,11 +278,12 @@ importers: '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* - '@kadena/chainweb-node-client': 0.4.1 - '@kadena/client': 0.6.1 + '@kadena/chainweb-node-client': 0.4.2 + '@kadena/client': workspace:* '@kadena/cryptography-utils': workspace:* '@kadena/pactjs': workspace:* - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': workspace:* + '@kadena/pactjs-generator': workspace:* '@kadena/react-components': workspace:* '@kadena/react-ui': workspace:* '@kadena/types': workspace:* @@ -327,15 +328,17 @@ importers: react-dom: ^18.2.0 react-hook-form: ~7.45.0 react-scripts: 5.0.1 + scoped-eval: ~0.4.2 sort-package-json: ~2.4.1 typescript: 5.0.4 zod: ~3.18.0 dependencies: '@hookform/resolvers': 3.1.1_react-hook-form@7.45.2 - '@kadena/chainweb-node-client': 0.4.1 - '@kadena/client': 0.6.1 + '@kadena/chainweb-node-client': 0.4.2 + '@kadena/client': link:../../libs/client '@kadena/cryptography-utils': link:../../libs/cryptography-utils '@kadena/pactjs': link:../../libs/pactjs + '@kadena/pactjs-generator': link:../../libs/pactjs-generator '@kadena/react-components': link:../../libs/react-components '@kadena/react-ui': link:../../libs/react-ui '@radix-ui/colors': 0.1.9 @@ -351,6 +354,7 @@ importers: react-dom: 18.2.0_react@18.2.0 react-hook-form: 7.45.2_react@18.2.0 react-scripts: 5.0.1_774e68646b4e4594d2106b3ba6959211 + scoped-eval: 0.4.2 zod: 3.18.0 devDependencies: '@jest/reporters': 29.5.0 @@ -358,7 +362,7 @@ importers: '@kadena-dev/eslint-config': link:../../tools/eslint-config '@kadena-dev/heft-rig': link:../../tools/heft-rig '@kadena-dev/markdown': link:../../tools/remark-plugins - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': link:../../tools/pactjs-cli '@kadena/types': link:../../libs/types '@rushstack/eslint-config': 3.3.2_eslint@8.44.0+typescript@5.0.4 '@rushstack/heft': 0.50.7_@types+node@16.18.38 @@ -1025,9 +1029,9 @@ importers: '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* '@kadena/chainweb-node-client': workspace:* - '@kadena/client': 0.6.1 + '@kadena/client': workspace:* '@kadena/cryptography-utils': workspace:* - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': workspace:* '@kadena/types': workspace:* '@rushstack/eslint-config': ~3.3.0 '@rushstack/heft': ~0.50.6 @@ -1039,13 +1043,13 @@ importers: ts-node: ~10.8.2 dependencies: '@kadena/chainweb-node-client': link:../../libs/chainweb-node-client - '@kadena/client': 0.6.1 + '@kadena/client': link:../../libs/client '@kadena/cryptography-utils': link:../../libs/cryptography-utils devDependencies: '@kadena-dev/eslint-config': link:../eslint-config '@kadena-dev/heft-rig': link:../heft-rig '@kadena-dev/markdown': link:../remark-plugins - '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-cli': link:../pactjs-cli '@kadena/types': link:../../libs/types '@rushstack/eslint-config': 3.3.2_eslint@8.44.0 '@rushstack/heft': 0.50.7_@types+node@16.18.38 @@ -6980,13 +6984,13 @@ packages: resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==} dev: true - /@kadena/chainweb-node-client/0.4.1: - resolution: {integrity: sha512-AgAEEQy+5ZLMXrP2rI8xZuxbEUNWyk7vh0q4Ti909F2HwHPP1mAp56nZZMlNGKUm6A16BasXmsND1Pow4H95Mw==} + /@kadena/chainweb-node-client/0.4.2: + resolution: {integrity: sha512-jNSnp2f7/rBXmie8AtysjP4HKdZajlJne5zliF9PvZv/aXhtYoz2DkOuaFrCyxk5+BQXnfrHGxzJXTCF9dOjaw==} requiresBuild: true dependencies: - '@kadena/cryptography-utils': 0.3.5 - '@kadena/pactjs': 0.2.11 - '@kadena/types': 0.3.5 + '@kadena/cryptography-utils': 0.3.6 + '@kadena/pactjs': 0.3.0 + '@kadena/types': 0.4.0 '@types/isomorphic-fetch': 0.0.36 cross-fetch: 3.1.8 node-fetch: 2.6.12 @@ -6994,45 +6998,10 @@ packages: - encoding dev: false - /@kadena/chainweb-node-client/0.4.1_encoding@0.1.13: - resolution: {integrity: sha512-AgAEEQy+5ZLMXrP2rI8xZuxbEUNWyk7vh0q4Ti909F2HwHPP1mAp56nZZMlNGKUm6A16BasXmsND1Pow4H95Mw==} - requiresBuild: true - dependencies: - '@kadena/cryptography-utils': 0.3.5 - '@kadena/pactjs': 0.2.11 - '@kadena/types': 0.3.5 - '@types/isomorphic-fetch': 0.0.36 - cross-fetch: 3.1.8_encoding@0.1.13 - node-fetch: 2.6.12_encoding@0.1.13 - transitivePeerDependencies: - - encoding - dev: false - - /@kadena/client/0.6.1: - resolution: {integrity: sha512-2F3kyzrHItq/nBYGWRqnGWpiATDT6+xoBxiXrFqiq8ZLDhLMxvc0DHmB5INIDRHfYjbts/tKgFPfuQOk7Si2Og==} - dependencies: - '@kadena/chainweb-node-client': 0.4.1_encoding@0.1.13 - '@kadena/cryptography-utils': 0.3.5 - '@kadena/pactjs': 0.2.11 - '@kadena/types': 0.3.5 - '@walletconnect/sign-client': 2.8.6 - '@walletconnect/types': 2.8.6 - cross-fetch: 3.1.8_encoding@0.1.13 - debug: 4.3.4 - encoding: 0.1.13 - yaml: 2.1.3 - transitivePeerDependencies: - - '@react-native-async-storage/async-storage' - - bufferutil - - lokijs - - supports-color - - utf-8-validate - dev: false - - /@kadena/cryptography-utils/0.3.5: - resolution: {integrity: sha512-z1dVWirsdrGBknmNXK3owsrVSxw65ooH7bWmYpn6UNiRpI6vzg1n+gj8fIUOQHcvLuq7dA57VfrGnNKWKW2pgQ==} + /@kadena/cryptography-utils/0.3.6: + resolution: {integrity: sha512-TsVmWRlqvJZDTf5Dzo21P4mwvHtyfFWT5xa5Mr2oz1m9GBsafQ8CmZfRwrdxIvw2ZppNdmU2V4ji0we9N9AARQ==} dependencies: - '@kadena/types': 0.3.5 + '@kadena/types': 0.4.0 blakejs: 1.2.1 buffer: 6.0.3 tweetnacl: 1.0.3 @@ -7044,41 +7013,15 @@ packages: lodash.kebabcase: 4.1.1 dev: false - /@kadena/pactjs-cli/0.1.5: - resolution: {integrity: sha512-mo1OJQGQ7gjNkQ3q0cU6r+RrZwQ3fTQaCrln079PWxiUOMoK5OUtbNYPHNt0hr6ZOqkmybNFEW7j/I8rPCHGaA==} - hasBin: true - dependencies: - '@kadena/pactjs-generator': 0.1.13 - commander: 9.5.0 - cross-fetch: 3.1.8 - debug: 4.3.4 - mkdirp: 1.0.4 - rimraf: 3.0.2 - yaml: 2.1.3 - zod: 3.18.0 - transitivePeerDependencies: - - encoding - - supports-color - dev: true - - /@kadena/pactjs-generator/0.1.13: - resolution: {integrity: sha512-VOliWyJ1X/2hav/FktOOi6HeoVY+P5DNs9+axWmu96Oce5Wdy7MX4Rlqz3Q9eJi/za36NRUNxtD9q1G7NJmB7g==} + /@kadena/pactjs/0.3.0: + resolution: {integrity: sha512-b0qIeJ3eAbuOaEbV9dNi9zzxciooeJWzSaeycKDhTbEWAbnKD6pXWRcYPojG2t0pNwMQZyb2kIRIV93D08E5bA==} dependencies: - memfs: 3.5.3 - moo: 0.5.2 - nearley: 2.20.1 - yaml: 2.1.3 - dev: true - - /@kadena/pactjs/0.2.11: - resolution: {integrity: sha512-98ojO20l3ijp8rkCSokadm2NRMgigtduSB/5/QqRVa4WUMf5ROS01ocF6fzdp7GVUbBYaw1FEfslv6MXtz++IA==} - dependencies: - '@kadena/types': 0.3.5 + '@kadena/types': 0.4.0 bignumber.js: 9.1.1 dev: false - /@kadena/types/0.3.5: - resolution: {integrity: sha512-BuQo6ll3ARQqC7/V1BTnKLZp1UrKMtS0a7NbRX7HT+0XYYcteixMUUf/AiPBBEKsSmD+TDlWQvEE7eapPP7ykA==} + /@kadena/types/0.4.0: + resolution: {integrity: sha512-fXId5LebFigIcMMG2JlPW/wMNf5sw81VqjoCVh7TmZnuMvT9YJDsYQahD8qdrXWxbFAssRXyIEe4oPsm2aQ5/Q==} dev: false /@leichtgewicht/ip-codec/2.0.4: @@ -14740,6 +14683,7 @@ packages: /discontinuous-range/1.0.0: resolution: {integrity: sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==} + dev: false /dlv/1.1.3: resolution: {integrity: sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==} @@ -20909,6 +20853,7 @@ packages: /moo/0.5.2: resolution: {integrity: sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==} + dev: false /mri/1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -20985,6 +20930,7 @@ packages: moo: 0.5.2 railroad-diagrams: 1.0.0 randexp: 0.4.6 + dev: false /negotiator/0.6.3: resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==} @@ -23260,6 +23206,7 @@ packages: /railroad-diagrams/1.0.0: resolution: {integrity: sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==} + dev: false /ramda/0.29.0: resolution: {integrity: sha512-BBea6L67bYLtdbOqfp8f58fPMqEwx0doL+pAi8TZyp2YWz8R9G8z9x75CZI8W+ftqhFHCpEX2cRnUUXK130iKA==} @@ -23271,6 +23218,7 @@ packages: dependencies: discontinuous-range: 1.0.0 ret: 0.1.15 + dev: false /randombytes/2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} @@ -24190,6 +24138,7 @@ packages: /ret/0.1.15: resolution: {integrity: sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==} engines: {node: '>=0.12'} + dev: false /retry-request/5.0.2: resolution: {integrity: sha512-wfI3pk7EE80lCIXprqh7ym48IHYdwmAAzESdbU8Q9l7pnRCk9LEhpbOTNKjz6FARLm/Bl5m+4F0ABxOkYUujSQ==} @@ -24421,6 +24370,11 @@ packages: ajv-formats: 2.1.1 ajv-keywords: 5.1.0_ajv@8.12.0 + /scoped-eval/0.4.2: + resolution: {integrity: sha512-cewe5fPPQz1CfEcTdQtUnPCCaX2GWoGHuKnRjtkFfKu1EQlhaQEDjWs366X/1YzlwjgWuiR1tanAqbECssLtkw==} + engines: {node: '>=10.0.0'} + dev: false + /scuid/1.1.0: resolution: {integrity: sha512-MuCAyrGZcTLfQoH2XoBlQ8C6bzwN88XT/0slOGz0pn8+gIP85BOAfYa44ZXQUTOwRwPU0QvgU+V+OSajl/59Xg==} dev: true @@ -25664,7 +25618,7 @@ packages: schema-utils: 3.3.0 serialize-javascript: 6.0.1 terser: 5.18.2 - webpack: 5.73.0 + webpack: 5.73.0_webpack-cli@4.10.0 /terser/5.18.2: resolution: {integrity: sha512-Ah19JS86ypbJzTzvUCX7KOsEIhDaRONungA4aYBjEP3JZRf4ocuDzTg4QWZnPn9DEMiMYGJPiSOy7aykoCc70w==} @@ -27619,6 +27573,7 @@ packages: /zod/3.18.0: resolution: {integrity: sha512-gwTm8RfUCe8l9rDwN5r2A17DkAa8Ez4Yl4yXqc5VqeGaXaJahzYYXbTwvhroZi0SNBqTwh/bKm2N0mpCzuw4bA==} + dev: false /zod/3.21.4: resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 07f44f55d6..a8b411c128 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "f84ebd663b68ddc35b1ca0a226de3b73703576be", + "pnpmShrinkwrapHash": "2fed2990a8bc2bb4d427da20cab9aee46b9ae580", "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" } diff --git a/packages/apps/docs/package.json b/packages/apps/docs/package.json index 1f99678f7d..0500b4e303 100644 --- a/packages/apps/docs/package.json +++ b/packages/apps/docs/package.json @@ -64,7 +64,7 @@ "@babel/preset-typescript": "^7.21.0", "@kadena-dev/eslint-config": "workspace:*", "@kadena-dev/heft-rig": "workspace:*", - "@kadena/pactjs-cli": "0.1.5", + "@kadena/pactjs-cli": "workspace:*", "@kadena/types": "workspace:*", "@percy/cli": "~1.24.0", "@percy/cypress": "~3.1.2", diff --git a/packages/apps/graph-client/package.json b/packages/apps/graph-client/package.json index dfbd04a2d1..2f82ab4537 100644 --- a/packages/apps/graph-client/package.json +++ b/packages/apps/graph-client/package.json @@ -42,7 +42,7 @@ "@kadena-dev/eslint-config": "workspace:*", "@kadena-dev/heft-rig": "workspace:*", "@kadena-dev/markdown": "workspace:*", - "@kadena/pactjs-cli": "0.1.5", + "@kadena/pactjs-cli": "workspace:*", "@rushstack/eslint-config": "~3.3.0", "@rushstack/heft": "~0.50.6", "@types/heft-jest": "~1.0.3", diff --git a/packages/apps/graph/package.json b/packages/apps/graph/package.json index 5587e89778..4908908e5c 100644 --- a/packages/apps/graph/package.json +++ b/packages/apps/graph/package.json @@ -35,7 +35,7 @@ "devDependencies": { "@kadena-dev/eslint-config": "workspace:*", "@kadena-dev/heft-rig": "workspace:*", - "@kadena/pactjs-cli": "0.1.5", + "@kadena/pactjs-cli": "workspace:*", "@rushstack/eslint-config": "~3.3.0", "@rushstack/heft": "~0.50.6", "@types/debug": "~4.1.7", diff --git a/packages/apps/transfer/package.json b/packages/apps/transfer/package.json index 8ff490738a..5978379d77 100644 --- a/packages/apps/transfer/package.json +++ b/packages/apps/transfer/package.json @@ -20,8 +20,8 @@ "test": "jest --silent" }, "dependencies": { - "@kadena/chainweb-node-client": "0.4.1", - "@kadena/client": "0.6.1", + "@kadena/chainweb-node-client": "0.4.2", + "@kadena/client": "workspace:*", "@kadena/cryptography-utils": "workspace:*", "@kadena/pactjs": "workspace:*", "@kadena/react-components": "workspace:*", @@ -40,7 +40,9 @@ "react-scripts": "5.0.1", "react-hook-form": "~7.45.0", "@hookform/resolvers": "~3.1.1", - "zod": "~3.18.0" + "zod": "~3.18.0", + "@kadena/pactjs-generator": "workspace:*", + "scoped-eval": "~0.4.2" }, "devDependencies": { "@jest/reporters": "~29.5.0", @@ -48,7 +50,7 @@ "@kadena-dev/eslint-config": "workspace:*", "@kadena-dev/heft-rig": "workspace:*", "@kadena-dev/markdown": "workspace:*", - "@kadena/pactjs-cli": "0.1.5", + "@kadena/pactjs-cli": "workspace:*", "@kadena/types": "workspace:*", "@rushstack/eslint-config": "~3.3.0", "@rushstack/heft": "~0.50.6", diff --git a/packages/apps/transfer/src/components/Global/Ace/index.tsx b/packages/apps/transfer/src/components/Global/Ace/index.tsx index 87f6d999e6..3f77e81d18 100644 --- a/packages/apps/transfer/src/components/Global/Ace/index.tsx +++ b/packages/apps/transfer/src/components/Global/Ace/index.tsx @@ -8,28 +8,43 @@ import 'ace-builds/src-noconflict/theme-monokai'; import 'ace-builds/src-noconflict/theme-one_dark'; import 'ace-builds/src-noconflict/ext-language_tools'; +export interface IOnchange { + (value: string): void; +} + export interface IAceEditorProps { code?: string; + width?: string; + height?: string; + readonly?: boolean; + onChange?: IOnchange; } -const AceViewerComponent: FC = ({ code }) => ( +const AceViewerComponent: FC = ({ + code, + width, + height, + readonly, + onChange, +}) => ( ); diff --git a/packages/apps/transfer/src/constants/client.ts b/packages/apps/transfer/src/constants/client.ts new file mode 100644 index 0000000000..0119261d54 --- /dev/null +++ b/packages/apps/transfer/src/constants/client.ts @@ -0,0 +1,5 @@ +import { getClient } from '@kadena/client'; + +const client = getClient(); + +export default client; diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 58c4598091..fd8ca60d21 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -38,6 +38,20 @@ const isCustomError = (error: unknown): error is ICommandResult => { return error !== null && typeof error === 'object' && 'result' in error; }; +interface IFundExistingAccountResponseBody { + result: { + status: string; + error: + | undefined + | { + message: string; + }; + }; +} + +interface IFundExistingAccountResponse + extends Record {} + const ExistingAccountFaucetPage: FC = () => { const { t } = useTranslation('common'); @@ -54,7 +68,23 @@ const ExistingAccountFaucetPage: FC = () => { setRequestStatus({ status: 'processing' }); try { - await fundExistingAccount(accountName, chainID, AMOUNT_OF_COINS_FUNDED); + const result = (await fundExistingAccount( + accountName, + chainID, + AMOUNT_OF_COINS_FUNDED, + )) as IFundExistingAccountResponse; + + const error = Object.values(result).find( + (response) => response.result.status === 'failure', + ); + + if (error) { + setRequestStatus({ + status: 'erroneous', + message: error.result.error?.message || t('An error occurred.'), + }); + return; + } setRequestStatus({ status: 'successful' }); } catch (err) { diff --git a/packages/apps/transfer/src/pages/home/index.tsx b/packages/apps/transfer/src/pages/home/index.tsx index fb3b698496..175fad2e35 100644 --- a/packages/apps/transfer/src/pages/home/index.tsx +++ b/packages/apps/transfer/src/pages/home/index.tsx @@ -1,4 +1,4 @@ -import { Breadcrumbs, Grid } from '@kadena/react-ui'; +import { Grid } from '@kadena/react-ui'; import routes from '@/constants/routes'; import { diff --git a/packages/apps/transfer/src/pages/transfer/cross-chain-transfer-finisher/index.tsx b/packages/apps/transfer/src/pages/transfer/cross-chain-transfer-finisher/index.tsx index d46c8cee67..6336823672 100644 --- a/packages/apps/transfer/src/pages/transfer/cross-chain-transfer-finisher/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/cross-chain-transfer-finisher/index.tsx @@ -1,5 +1,3 @@ -import { IPollResponse } from '@kadena/chainweb-node-client'; -import { ContCommand } from '@kadena/client'; import { Breadcrumbs, Button, @@ -8,7 +6,7 @@ import { TrackerCard, } from '@kadena/react-ui'; -import { getKadenaConstantByNetwork } from '@/constants/kadena'; +import client from '@/constants/client'; import { chainNetwork } from '@/constants/network'; import { useAppContext } from '@/context/app-context'; import { @@ -50,13 +48,6 @@ import React, { useState, } from 'react'; -interface IPactResultError { - status: 'failure'; - error: { - message: string; - }; -} - const CrossChainTransferFinisher: FC = () => { const debug = Debug( 'kadena-transfer:pages:transfer:cross-chain-transfer-finisher', @@ -121,57 +112,48 @@ const CrossChainTransferFinisher: FC = () => { return; } - const host = getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId: pollResults.tx.receiver.chain, - }); + const networkId = chainNetwork[network].network; - const contCommand = await finishXChainTransfer( + const options = { + networkId: networkId, + chainId: pollResults.tx.sender.chain, + }; + + const proof = await client.pollCreateSpv( requestKey, - pollResults.tx.step, - pollResults.tx.rollback, - network, pollResults.tx.receiver.chain, + options, + ); + + const status = await client.listen(requestKey, options); + + const pactId = status.continuation?.pactId; + + const requestKeyOrError = await finishXChainTransfer( + { + pactId, + proof, + rollback: false, + step: 1, + }, + pollResults.tx.receiver.chain, + networkId, kadenaXChainGas, ); - if (!(contCommand instanceof ContCommand) && contCommand.error) { - setTxError(contCommand.error); + if (typeof requestKeyOrError !== 'string') { + setTxError((requestKeyOrError as { error: string }).error); } - if (contCommand instanceof ContCommand) { - try { - const pollResult = await contCommand.pollUntil(host, { - onPoll: async (transaction, pollRequest): Promise => { - debug(`Polling ${requestKey}.\nStatus: ${transaction.status}`); - setFinalResults({ - requestKey: transaction.requestKey, - status: transaction.status, - }); - debug(await pollRequest); - const data: IPollResponse = await pollRequest; - - // Show correct error message - if ( - Object.keys(data).length > 0 && - Object.values(data)[0].result.status === 'failure' - ) { - const errorResult: IPactResultError = Object.values(data)[0] - .result as IPactResultError; - if (errorResult !== undefined) { - setTxError(errorResult.error.message); - } - } - }, - }); - setFinalResults({ - requestKey: pollResult.reqKey, - status: pollResult.result.status, - }); - } catch (tx) { - debug(tx); - setFinalResults({ ...tx }); - } + try { + const result = await client.listen(requestKeyOrError as string); + setFinalResults({ + requestKey: result.reqKey, + status: result.result.status, + }); + } catch (tx) { + debug(tx); + setFinalResults({ ...tx }); } }; diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx index 6c054f96c4..c2f8b03f1b 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -1,28 +1,16 @@ import { Breadcrumbs, TextField } from '@kadena/react-ui'; -import dynamic from 'next/dynamic'; - -const AceViewer = dynamic(import('@/components/Global/Ace'), { - ssr: false, -}); - import { StyledAccountForm, - StyledCodeViewerContainer, StyledForm, StyledList, StyledListItem, - StyledResultContainer, } from './styles'; import { ChainSelect } from '@/components/Global'; import { kadenaConstants } from '@/constants/kadena'; import { useAppContext } from '@/context/app-context'; import { usePersistentChainID } from '@/hooks'; -import { - type IModuleResult, - describeModule, -} from '@/services/modules/describe-module'; import { type IModulesResult, listModules, @@ -32,7 +20,6 @@ import useTranslation from 'next-translate/useTranslation'; import React, { ChangeEventHandler, FC, - SyntheticEvent, useCallback, useEffect, useMemo, @@ -42,10 +29,8 @@ import React, { const ModuleExplorer: FC = () => { Debug('kadena-transfer:pages:transfer:module-explorer'); const { t } = useTranslation('common'); - const [moduleName, setModuleName] = useState(''); const [moduleSearch, setModuleSearch] = useState(''); const [modules, setModules] = useState({}); - const [results, setResults] = useState({}); const { network } = useAppContext(); const [chainID, onChainSelectChange] = usePersistentChainID(); @@ -73,27 +58,6 @@ const ModuleExplorer: FC = () => { [modules, moduleSearch], ); - useEffect(() => { - if (!moduleName) { - return; - } - - const fetchModule = async (): Promise => { - const data = await describeModule( - moduleName, - chainID, - network, - kadenaConstants.DEFAULT_SENDER, - kadenaConstants.GAS_PRICE, - 1000, - ); - - setResults(data); - }; - - fetchModule().catch(console.error); - }, [chainID, moduleName, network]); - const onModuleNameChange = useCallback>( (e) => { setModuleSearch(e.target.value); @@ -124,24 +88,15 @@ const ModuleExplorer: FC = () => { {!filteredModules?.length && t('No modules found.')} {filteredModules?.map((module) => ( - ) => - setModuleName(e.currentTarget.dataset.moduleName || '') - } - > - {module} + + + {module} + ))} - {Boolean(results.code) && ( - - - - - - )} ); }; diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/[defun].tsx b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/[defun].tsx new file mode 100644 index 0000000000..a7e2db5ba6 --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/[defun].tsx @@ -0,0 +1,124 @@ +import { + getClient, + isSignedCommand, + Pact, + signWithChainweaver, +} from '@kadena/client'; +import { Button } from '@kadena/react-components'; + +import { Container, EditorGrid } from './styles'; + +import Debug from 'debug'; +import dynamic from 'next/dynamic'; +import { useRouter } from 'next/router'; +import useTranslation from 'next-translate/useTranslation'; +import React, { FC, useEffect, useState } from 'react'; +import ScopedEval from 'scoped-eval'; + +const AceViewer = dynamic(import('@/components/Global/Ace'), { + ssr: false, +}); + +const FunctionPage: FC = () => { + Debug('kadena-transfer:pages:transfer:module-explorer:module:function'); + const { t } = useTranslation('common'); + const [snippet, setSnippet] = useState(''); + const [code, setCode] = useState(''); + const [output, setOutput] = useState(''); + const [log, setLog] = useState(''); + const [timestamp, setTimestamp] = useState(0); + const router = useRouter(); + const { network, chain, module, defun } = router.query; + + useEffect(() => { + setOutput(`${output}\n${log}`.trim()); + }, [timestamp]); + + const Logger = { + log(data: string) { + setLog(data); + setTimestamp(new Date().getTime()); + }, + }; + + const runSnippet = (): void => { + setOutput(''); + const scopedEval = new ScopedEval(); + scopedEval.eval(code, { + Pact, + getClient, + signWithChainweaver, + isSignedCommand, + Logger, + }); + }; + + useEffect(() => { + if (!network || !chain || !module || !defun) { + return; + } + + const fetchSnippet = async (): Promise => { + const snippetUrl = `https://raw.githubusercontent.com/jessevanmuijden/snippets/main/networks/${network}/chains/${chain}/modules/${module}/functions/${defun}.js`; + const response = await fetch(snippetUrl); + if (response.status === 200) { + const body = await response.text(); + setSnippet(body); + } + }; + + fetchSnippet().catch(console.error); + }, [chain, module, network, defun]); + + return ( + +

+ {t('Function')}: {defun} +

+
+ {t('Module')}: {module} +
+
+ {t('Network')}: {network} +
+
+ {t('Chain')}: {chain} +
+ +
+

{t('JavaScript')}

+ + <> + {snippet.length && ( + + )} + + setCode(value)} + /> +
+
+

{t('Output')}

+ +
+
+
+ ); +}; + +export default FunctionPage; diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/styles.ts b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/styles.ts new file mode 100644 index 0000000000..8d59607feb --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/styles.ts @@ -0,0 +1,39 @@ +import { styled } from '@kadena/react-components'; + +export const Container = styled('div', { + padding: '2rem', +}); + +export const EditorGrid = styled('div', { + display: 'grid', + gridTemplateColumns: 'repeat(2, 1fr)', + gridTemplateRows: '1fr', + gridColumnGap: '1rem', + gridRowGap: '1rem', + marginTop: '2rem', +}); + +export const Details = styled('div', { + fontSize: '$base', + padding: '$2', + background: 'rgba(71, 79, 82, 0.4)', + borderRadius: '$sm', + boxSizing: 'borderBox', +}); + +export const StyledListItem = styled('div', { + py: '$3', + px: '$6', + color: '#FFFFFF', + cursor: 'pointer', + textOverflow: 'ellipsis', + overflow: 'hidden', + '&:first-child': { + borderTopLeftRadius: '$1', + borderTopRightRadius: '$1', + }, + '&:last-child': { + borderBottomLeftRadius: '$1', + borderBottomRightRadius: '$1', + }, +}); diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx new file mode 100644 index 0000000000..e5c72b86b8 --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx @@ -0,0 +1,142 @@ +import { ChainwebChainId } from '@kadena/chainweb-node-client'; +import { StringContractDefinition } from '@kadena/pactjs-generator'; + +import { kadenaConstants, Network } from '@/constants/kadena'; +import { convertIntToChainId } from '@/services/utils/utils'; +import dynamic from 'next/dynamic'; +import { useRouter } from 'next/router'; + +const AceViewer = dynamic(import('@/components/Global/Ace'), { + ssr: false, +}); + +import { Container, Details, EditorGrid, StyledListItem } from './styles'; + +import { describeModule } from '@/services/modules/describe-module'; +import Debug from 'debug'; +import useTranslation from 'next-translate/useTranslation'; +import React, { FC, useEffect, useState } from 'react'; + +const ModulePage: FC = () => { + Debug('kadena-transfer:pages:transfer:module-explorer:module'); + const { t } = useTranslation('common'); + const [pactCode, setPactCode] = useState(''); + const [functions, setFunctions] = useState< + Record | undefined + >({}); + const [capabilities, setCapabilities] = useState< + Record | undefined + >({}); + const [interfaces, setInterfaces] = useState([]); + const router = useRouter(); + const { network, chain, module } = router.query; + + useEffect(() => { + if (!network || !chain || !module) { + return; + } + + const typedNetwork = (network instanceof Array + ? network[0] + : network) as unknown as Network; + const chainId: ChainwebChainId = convertIntToChainId( + (chain instanceof Array ? chain[0] : chain) as unknown as number, + ); + const moduleName: string = module as string; + + const fetchModule = async (): Promise => { + const { result } = await describeModule( + moduleName, + chainId, + typedNetwork, + kadenaConstants.DEFAULT_SENDER, + kadenaConstants.GAS_PRICE, + 1000, + ); + + if (result.status === 'failure' && 'error' in result) { + throw new Error(JSON.stringify(result.error)); + } + + const resultSuccess = result as unknown as { + data: { + code: string; + interfaces: string[]; + }; + }; + + const pactCode = resultSuccess.data.code || ''; + setPactCode(pactCode); + + const moduleNameParts = moduleName.split('.'); + const namespace = + moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; + + const pactModule = new StringContractDefinition({ + contract: pactCode, + namespace, + }); + + setCapabilities(pactModule.getCapabilities(moduleName)); + setFunctions(pactModule.getMethods(moduleName)); + setInterfaces(resultSuccess.data.interfaces || []); + }; + + fetchModule().catch(console.error); + }, [chain, module, network]); + return ( + +

+ {t('Module')}: {module} +

+
+ {t('Network')}: {network} +
+
+ {t('Chain')}: {chain} +
+ +
+

{t('Pact')}

+ +
+
+

{t('Details')}

+
+

{t('Functions')}

+ {!Object.keys(functions || {})?.length && + t('No functions in this module.')} + {Object.keys(functions || {})?.map((key) => ( + + + {key} + + + ))} +

{t('Capabilities')}

+ {!Object.keys(capabilities || {})?.length && + t('No capabilities in this module.')} + {Object.keys(capabilities || {})?.map((key) => ( + + + {key} + + + ))} +

{t('Constants')}

+

{t('Pacts')}

+

{t('Interfaces')}

+ {interfaces.map((key) => ( + {key} + ))} +
+
+
+
+ ); +}; +export default ModulePage; diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/styles.ts b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/styles.ts new file mode 100644 index 0000000000..8d59607feb --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/styles.ts @@ -0,0 +1,39 @@ +import { styled } from '@kadena/react-components'; + +export const Container = styled('div', { + padding: '2rem', +}); + +export const EditorGrid = styled('div', { + display: 'grid', + gridTemplateColumns: 'repeat(2, 1fr)', + gridTemplateRows: '1fr', + gridColumnGap: '1rem', + gridRowGap: '1rem', + marginTop: '2rem', +}); + +export const Details = styled('div', { + fontSize: '$base', + padding: '$2', + background: 'rgba(71, 79, 82, 0.4)', + borderRadius: '$sm', + boxSizing: 'borderBox', +}); + +export const StyledListItem = styled('div', { + py: '$3', + px: '$6', + color: '#FFFFFF', + cursor: 'pointer', + textOverflow: 'ellipsis', + overflow: 'hidden', + '&:first-child': { + borderTopLeftRadius: '$1', + borderTopRightRadius: '$1', + }, + '&:last-child': { + borderBottomLeftRadius: '$1', + borderBottomRightRadius: '$1', + }, +}); diff --git a/packages/apps/transfer/src/pages/transfer/module-explorer/styles.ts b/packages/apps/transfer/src/pages/transfer/module-explorer/styles.ts index 009560d416..1ae560c82c 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/styles.ts +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/styles.ts @@ -68,9 +68,4 @@ export const StyledListItem = styled('div', { borderBottomLeftRadius: '$1', borderBottomRightRadius: '$1', }, - '&:hover': { - background: 'rgba(5, 5, 5, 0.5);', - fontWeight: '$medium', - textDecorationLine: 'underline', - }, }); diff --git a/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts b/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts index 202948f2dd..b00cd591b3 100644 --- a/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts +++ b/packages/apps/transfer/src/services/cross-chain-transfer-finish/finish-xchain-transfer.ts @@ -1,15 +1,11 @@ import { - ChainwebChainId, - ChainwebNetworkId, -} from '@kadena/chainweb-node-client'; -import { ContCommand, getContCommand } from '@kadena/client'; + ChainId, + ICommand, + IContinuationPayloadObject, + Pact, +} from '@kadena/client'; -import { - getKadenaConstantByNetwork, - kadenaConstants, - Network, -} from '@/constants/kadena'; -import { chainNetwork } from '@/constants/network'; +import client from '@/constants/client'; import Debug from 'debug'; export interface ITransferResult { @@ -18,57 +14,27 @@ export interface ITransferResult { } const debug = Debug('kadena-transfer:services:finish-xchain-transfer'); -const gasLimit: number = kadenaConstants.GAS_LIMIT; -const gasPrice: number = kadenaConstants.GAS_PRICE; export async function finishXChainTransfer( - requestKey: string, - step: number, - rollback: boolean, - network: Network, - chainId: ChainwebChainId, - sender: string, -): Promise { + continuation: IContinuationPayloadObject['cont'], + targetChainId: ChainId, + networkId: string, + gasPayer: string = 'kadena-xchain-gas', +): Promise { debug(finishXChainTransfer.name); - const host = getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId, - }); try { - const contCommand = await getContCommand( - requestKey, - chainId, - host, - step + 1, - rollback, - ); - - contCommand.setMeta( - { - chainId, - sender, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ); - - contCommand.createCommand(); - - const localResult = await contCommand.local(host, { - preflight: false, - signatureVerification: false, - }); - - if (localResult.result.status !== 'success') { - debug(localResult.result.error.message); - return { error: localResult.result.error.message }; - } - - await contCommand.send(host); - - return contCommand; + const continuationTransaction = Pact.builder + .continuation(continuation) + .setNetworkId(networkId) + .setMeta({ + chainId: targetChainId, + sender: gasPayer, + // this needs to be below 850 if you want to use gas-station otherwise the gas-station does + gasLimit: 850, + }) + .createTransaction(); + return await client.submit(continuationTransaction as ICommand); } catch (e) { debug(e.message); return { error: e.message }; diff --git a/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts b/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts index d7f94bf0c2..b77d1015af 100644 --- a/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts +++ b/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts @@ -1,9 +1,5 @@ -import { - ChainwebChainId, - ICommandResult, - IPollResponse, -} from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; +import { ChainwebChainId, ICommandResult } from '@kadena/chainweb-node-client'; +import { getClient } from '@kadena/client'; import { IPactEvent, IPactExec, PactValue } from '@kadena/types'; import { getKadenaConstantByNetwork, Network } from '@/constants/kadena'; @@ -63,52 +59,42 @@ export async function getTransferData({ return { error: t('Invalid length of request key') }; } - const pactCommand = new PactCommand(); - - pactCommand.requestKey = requestKey; - try { const chainInfoPromises = Array.from(new Array(20)).map((item, chainId) => { const host = getKadenaConstantByNetwork(network).apiHost({ networkId: chainNetwork[network].network, chainId: convertIntToChainId(chainId), }); - return pactCommand.poll(host); + const { getStatus } = getClient(host); + return getStatus(requestKey); }); const chainInfos = await Promise.all(chainInfoPromises); - const found: { chainId: number; tx: ICommandResult } | undefined = - chainInfos.reduce( - ( - acc: { chainId: number; tx: ICommandResult } | undefined, - curr: IPollResponse, - chain: number, - array: IPollResponse[], - ) => { - array.splice(chain - 1); - if (curr[requestKey] !== undefined) { - return { chainId: chain, tx: curr[validatedRequestKey] }; - } - }, - undefined, - ); + const request = chainInfos.find((chainInfo) => requestKey in chainInfo); - if (found === undefined) { + if (!request) { return { error: t('No request key found') }; } + const found = request[requestKey]; + + const { events, result } = found; + + if ('error' in result) { + return result.error; + // return { error: ('message' in result.error ? (result.error.message as string) : 'An error occurred.' }; + } + const [senderAccount, receiverAccount, guard, targetChain, amount] = // eslint-disable-next-line @typescript-eslint/no-explicit-any - found.tx?.continuation?.continuation.args as Array; + found?.continuation?.continuation.args as Array; - const { step, stepHasRollback, pactId } = found.tx - ?.continuation as IPactExec; - const { events, result } = found.tx; + const { step, stepHasRollback, pactId } = found?.continuation as IPactExec; return { tx: { sender: { - chain: found.chainId.toString() as ChainwebChainId, + chain: '1', // todo: fix typing. // found.chainId.toString() as ChainwebChainId, account: senderAccount, }, receiver: { diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 7c72445a35..f5fe7f59f4 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -1,9 +1,8 @@ import { ChainwebChainId, ChainwebNetworkId, - IPollResponse, } from '@kadena/chainweb-node-client'; -import { ICommandBuilder, IPactCommand, Pact } from '@kadena/client'; +import { getClient, isSignedCommand, Pact } from '@kadena/client'; import { genKeyPair, sign } from '@kadena/cryptography-utils'; import { PactNumber } from '@kadena/pactjs'; @@ -29,29 +28,31 @@ export const fundExistingAccount = async ( account: string, chainId: ChainwebChainId, amount = 100, - onPoll?: ( - transaction: IPactCommand & ICommandBuilder>, - pollRequest: Promise, - ) => void, ): Promise => { debug(fundExistingAccount.name); const keyPair = genKeyPair(); - const transactionBuilder = Pact.modules['user.coin-faucet'] - ['request-coin'](account, new PactNumber(amount).toPactDecimal()) - .addCap('coin.GAS', FAUCET_PUBLIC_KEY) - .addCap( - 'coin.TRANSFER', - keyPair.publicKey, - SENDER_ACCOUNT, - account, - new PactNumber(amount).toPactDecimal(), + const transaction = Pact.builder + .execution( + Pact.modules['user.coin-faucet']['request-coin']( + account, + new PactNumber(amount).toPactDecimal(), + ), ) - .setMeta({ sender: SENDER_OPERATION_ACCOUNT, chainId }, NETWORK_ID); + .addSigner(FAUCET_PUBLIC_KEY, (withCap) => [withCap('coin.GAS')]) + .addSigner(keyPair.publicKey, (withCap) => [ + withCap( + 'coin.TRANSFER', + SENDER_ACCOUNT, + account, + new PactNumber(amount).toPactDecimal(), + ), + ]) + .setMeta({ sender: SENDER_OPERATION_ACCOUNT, chainId }) + .setNetworkId(NETWORK_ID) + .createTransaction(); - const command = transactionBuilder.createCommand(); - - const signature1 = sign(command.cmd, { + const signature1 = sign(transaction.cmd, { publicKey: FAUCET_PUBLIC_KEY, secretKey: FAUCET_PRIVATE_KEY, }); @@ -60,28 +61,26 @@ export const fundExistingAccount = async ( throw new Error('Failed to sign transaction'); } - const signature2 = sign(command.cmd, keyPair); + const signature2 = sign(transaction.cmd, keyPair); if (signature2.sig === undefined) { throw new Error('Failed to sign transaction'); } - transactionBuilder.addSignatures( - { - pubKey: FAUCET_PUBLIC_KEY, - sig: signature1.sig, - }, - { pubKey: keyPair.publicKey, sig: signature2.sig }, - ); - const apiHost = getKadenaConstantByNetwork('TESTNET').apiHost({ networkId: NETWORK_ID, chainId, }); - await transactionBuilder.send(apiHost); + transaction.sigs = [{ sig: signature1.sig }, { sig: signature2.sig }]; - return await transactionBuilder.pollUntil(apiHost, { - onPoll, - }); + const { submit, pollStatus } = getClient(apiHost); + + if (!isSignedCommand(transaction)) { + throw new Error('Transaction is not signed'); + } + + const requestKeys = await submit(transaction); + + return await pollStatus(requestKeys); }; diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 9359d5ecaf..e52a40a6a2 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,6 +1,8 @@ -import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; -import { createExp } from '@kadena/pactjs'; +import { + ChainwebChainId, + ILocalCommandResult, +} from '@kadena/chainweb-node-client'; +import { getClient, Pact } from '@kadena/client'; import { getKadenaConstantByNetwork, @@ -10,12 +12,6 @@ import { import { chainNetwork } from '@/constants/network'; import Debug from 'debug'; -export interface IModuleResult { - reqKey?: string; - status?: string; - code?: string; -} - const debug = Debug('kadena-transfer:services:describe-module'); export const describeModule = async ( @@ -26,30 +22,24 @@ export const describeModule = async ( gasPrice: number = kadenaConstants.GAS_PRICE, gasLimit: number = kadenaConstants.GAS_LIMIT, ttl: number = kadenaConstants.API_TTL, -): Promise => { +): Promise => { debug(describeModule.name); - - const pactCommand = new PactCommand(); - pactCommand.code = createExp(`describe-module "${moduleName}"`); - - pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); - - const response = await pactCommand.local( + const networkId = chainNetwork[network].network; + const { local } = getClient( getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, + networkId, chainId, }), - { - signatureVerification: false, - preflight: false, - }, ); - const { reqKey, result } = response; + const transaction = Pact.builder + .execution(`(describe-module "${moduleName}")`) + .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) + .setNetworkId(networkId) + .createTransaction(); - return { - reqKey, - status: result.status, - code: result.data?.code, - }; + return await local(transaction, { + preflight: false, + signatureVerification: false, + }); }; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index a6bea2b941..24bf1ac51c 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -1,6 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; -import { createExp } from '@kadena/pactjs'; +import { getClient, Pact } from '@kadena/client'; import { getKadenaConstantByNetwork, @@ -26,27 +25,29 @@ export const listModules = async ( ttl: number = kadenaConstants.API_TTL, ): Promise => { debug(listModules.name); - const pactCommand = new PactCommand(); - - pactCommand.code = createExp('list-modules'); - - pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); - - const response = await pactCommand.local( + const networkId = chainNetwork[network].network; + const { local } = getClient( getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, + networkId, chainId, }), - { - preflight: false, - signatureVerification: false, - }, ); + const transaction = Pact.builder + .execution('(list-modules)') + .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) + .setNetworkId(networkId) + .createTransaction(); + + const response = await local(transaction, { + preflight: false, + signatureVerification: false, + }); + const { result } = response; return { status: result.status, - data: result.data, + data: 'data' in result ? (result.data as string[]) : [], }; }; diff --git a/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts b/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts index 3c9f284270..ac40fc7c83 100644 --- a/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts +++ b/packages/apps/transfer/src/services/transfer-tracker/get-transfer-status.ts @@ -1,16 +1,10 @@ -import { - ChainwebChainId, - ChainwebNetworkId, -} from '@kadena/chainweb-node-client'; -import { getContCommand, pollSpvProof } from '@kadena/client'; +import { ChainwebChainId } from '@kadena/chainweb-node-client'; +import { ICommand, Pact } from '@kadena/client'; import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data'; -import { - getKadenaConstantByNetwork, - kadenaConstants, - Network, -} from '@/constants/kadena'; +import client from '@/constants/client'; +import { Network } from '@/constants/kadena'; import { chainNetwork } from '@/constants/network'; import Debug from 'debug'; import { Translate } from 'next-translate'; @@ -170,53 +164,53 @@ export async function getXChainTransferInfo({ }): Promise { debug(getXChainTransferInfo.name); try { - const proofApiHost = getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, + const networkId = chainNetwork[network].network; + + const senderOptions = { + networkId, chainId: senderChain, - }); - const apiHost = getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId: receiverChain, - }); - const gasLimit: number = kadenaConstants.GAS_LIMIT; - const gasPrice: number = kadenaConstants.GAS_PRICE; + }; - const contCommand = await getContCommand( + const proof = await client.pollCreateSpv( requestKey, receiverChain, - proofApiHost, - 1, - false, + senderOptions, ); + const status = await client.listen(requestKey, senderOptions); + const pactId = status.continuation?.pactId; - contCommand - .setMeta( - { - chainId: receiverChain, - sender: senderAccount, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ) - .createCommand(); + const continuationTransaction = Pact.builder + .continuation({ + pactId, + proof, + rollback: false, + step: 1, + }) + .setNetworkId(networkId) + .setMeta({ chainId: receiverChain }) + .createTransaction(); - const response = await contCommand.local(apiHost, { - preflight: false, - signatureVerification: false, - }); + const response = await client.dirtyRead( + continuationTransaction as ICommand, + ); - if ( - String(response?.result?.error?.type) === 'EvalError' && - String(response?.result?.error?.message).includes('pact completed') - ) { - return { - id: StatusId.Success, - status: t('Success'), - description: t('Transfer completed successfully'), - senderAccount: senderAccount, - receiverChain: receiverChain, + if ('error' in response?.result) { + const error = response.result as unknown as { + type: string; + message: string; }; + if ( + String(error.type) === 'EvalError' && + String(error.message).includes('pact completed') + ) { + return { + id: StatusId.Success, + status: t('Success'), + description: t('Transfer completed successfully'), + senderAccount: senderAccount, + receiverChain: receiverChain, + }; + } } if (response?.result?.status === 'success') { @@ -266,19 +260,17 @@ export async function checkForProof({ onPoll?: (status: IStatusData) => void; }; t: Translate; -}): Promise { +}): Promise { debug(checkForProof.name); const { onPoll = () => {} } = { ...options }; try { - const apiHost = getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId: senderChain, - }); let count = 0; - return await pollSpvProof(requestKey, receiverChain, apiHost, { + return client.pollCreateSpv(requestKey, receiverChain, { + networkId: chainNetwork[network].network, + chainId: senderChain, onPoll: () => { // Avoid status update on first two polls (to avoid flickering) if (count > 1) { diff --git a/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts b/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts index 029d0861c8..8a389a4dc1 100644 --- a/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts +++ b/packages/libs/client-examples/src/example-contract/crosschain-transfer.ts @@ -89,7 +89,7 @@ export async function doCrossChainTransfer( pactId: status.continuation?.pactId, proof, rollback: false, - step: '1', + step: 1, }, to.chainId, ), diff --git a/packages/tools/cookbook/README.md b/packages/tools/cookbook/README.md index b6fe96b089..ebd8d269c5 100644 --- a/packages/tools/cookbook/README.md +++ b/packages/tools/cookbook/README.md @@ -51,7 +51,7 @@ In depth documentation for setting up and using @kadena/client can be found at Example: Running the transfer-create script: ```sh -ts-node src/accounts/transfer-create.ts senderAccount receiverAccount 1 +ts-node src/accounts/transfer-create-with-chainweaver.ts senderAccount receiverAccount 1 ``` ## Notes diff --git a/packages/tools/cookbook/package.json b/packages/tools/cookbook/package.json index 551a62d2cf..a7efb8fba3 100644 --- a/packages/tools/cookbook/package.json +++ b/packages/tools/cookbook/package.json @@ -22,14 +22,14 @@ }, "dependencies": { "@kadena/chainweb-node-client": "workspace:*", - "@kadena/client": "0.6.1", + "@kadena/client": "workspace:*", "@kadena/cryptography-utils": "workspace:*" }, "devDependencies": { "@kadena-dev/eslint-config": "workspace:*", "@kadena-dev/heft-rig": "workspace:*", "@kadena-dev/markdown": "workspace:*", - "@kadena/pactjs-cli": "0.1.5", + "@kadena/pactjs-cli": "workspace:*", "@kadena/types": "workspace:*", "@rushstack/eslint-config": "~3.3.0", "@rushstack/heft": "~0.50.6", diff --git a/packages/tools/cookbook/src/accounts/create-account.ts b/packages/tools/cookbook/src/accounts/create-account.ts index f8812ef6a0..639e7d7a7b 100644 --- a/packages/tools/cookbook/src/accounts/create-account.ts +++ b/packages/tools/cookbook/src/accounts/create-account.ts @@ -1,14 +1,15 @@ -import { ISendResponse } from '@kadena/chainweb-node-client'; -import { Pact, signWithChainweaver } from '@kadena/client'; +import { + getClient, + isSignedCommand, + Pact, + signWithChainweaver, +} from '@kadena/client'; import { accountKey } from '../utils/account-key'; import { apiHost } from '../utils/api-host'; -// eslint-disable-next-line import/no-unresolved -- TODO FILE NOT FOUND -import { pollTransactions } from '../utils/poll-transactions'; const HELP: string = `Usage example: \n\nts-node create-account.js k:{gasProviderPublicKey} k:{receiverPublicKey}`; -const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' | undefined = - 'testnet04'; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 4) { @@ -30,37 +31,33 @@ async function createAccount( receiver: string, ): Promise { const gasProviderPublicKey = accountKey(gasProvider); - const guardData: Record = { - ks: { + + const transaction = Pact.builder + .execution( + Pact.modules.coin['create-account'](receiver, () => '(read-keyset "ks")'), + ) + .addData('ks', { keys: [accountKey(receiver)], pred: 'keys-all', - }, - }; - - const transactionBuilder = await Pact.modules.coin['create-account']( - receiver, - () => '(read-keyset "ks")', - ) - .addData(guardData) - .addCap('coin.GAS', gasProviderPublicKey) - .setMeta({ sender: gasProvider }, NETWORK_ID); + }) + .addSigner(gasProviderPublicKey, (withCap: any) => [withCap('coin.GAS')]) + .setMeta({ chainId: '1', sender: gasProvider }) + .setNetworkId(NETWORK_ID) + .createTransaction(); - const signedTransactions = await signWithChainweaver(transactionBuilder); + const signedTransaction = await signWithChainweaver(transaction); - const sendRequests = signedTransactions.map((tx) => { - console.log(`Sending transaction: ${tx.code}`); - return tx.send(API_HOST); - }); + if (!isSignedCommand(signedTransaction)) { + console.error('Command is not signed.'); + return; + } - const sendResponses = await Promise.all(sendRequests); + const { submit, pollStatus } = getClient(API_HOST); - sendResponses.map(async function startPolling( - sendResponse: ISendResponse, - ): Promise { - console.log('Send response: ', sendResponse); - const requestKey = (await sendRequests[0]).requestKeys[0]; - await pollTransactions([requestKey], API_HOST); - }); + const requestKey = await submit(signedTransaction); + console.log('request key', requestKey); + const result = await pollStatus(requestKey); + console.log(result); } createAccount(gasProvider, receiver).catch(console.error); diff --git a/packages/tools/cookbook/src/accounts/details.ts b/packages/tools/cookbook/src/accounts/details.ts index d80c2b2ccf..36eafd10df 100644 --- a/packages/tools/cookbook/src/accounts/details.ts +++ b/packages/tools/cookbook/src/accounts/details.ts @@ -1,4 +1,4 @@ -import { Pact } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { apiHost } from '../utils/api-host'; @@ -18,7 +18,17 @@ const [account] = process.argv.slice(2); * @return */ async function details(account: string): Promise { - const response = await Pact.modules.coin.details(account).local(apiHost()); + const { local } = getClient(apiHost()); + + const transaction = Pact.builder + .execution(Pact.modules.coin.details(account)) + .setMeta({ chainId: '1' }) + .createTransaction(); + + const response = await local(transaction, { + preflight: false, + signatureVerification: false, + }); console.log(JSON.stringify(response, null, 2)); } diff --git a/packages/tools/cookbook/src/accounts/get-balance.ts b/packages/tools/cookbook/src/accounts/get-balance.ts index 5c8d74ebc5..698b0b66ba 100644 --- a/packages/tools/cookbook/src/accounts/get-balance.ts +++ b/packages/tools/cookbook/src/accounts/get-balance.ts @@ -1,4 +1,4 @@ -import { Pact } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { apiHost } from '../utils/api-host'; @@ -18,9 +18,17 @@ const [account] = process.argv.slice(2); * @return */ async function getBalance(account: string): Promise { - const response = await Pact.modules.coin['get-balance'](account).local( - apiHost(), - ); + const { local } = getClient(apiHost()); + + const transaction = Pact.builder + .execution(Pact.modules.coin['get-balance'](account)) + .setMeta({ chainId: '1' }) + .createTransaction(); + + const response = await local(transaction, { + preflight: false, + signatureVerification: false, + }); console.log(JSON.stringify(response, null, 2)); } diff --git a/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts b/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts index 15a969d1bb..802254961a 100644 --- a/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts +++ b/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts @@ -1,12 +1,16 @@ -import { Pact, signWithChainweaver } from '@kadena/client'; +import { + getClient, + isSignedCommand, + Pact, + signWithChainweaver, +} from '@kadena/client'; import { IPactDecimal } from '@kadena/types'; import { accountKey } from '../utils/account-key'; import { apiHost } from '../utils/api-host'; -const HELP: string = `Usage example: \n\nts-node transfer-create.js k:{senderPublicKey} k:{receiverPublicKey} {amount}`; -const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' | undefined = - 'testnet04'; +const HELP: string = `Usage example: \n\nts-node transfer-create-with-chainweaver.ts k:{senderPublicKey} k:{receiverPublicKey} {amount}`; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 5) { @@ -30,40 +34,42 @@ async function transferCreate( amount: number, ): Promise { const senderPublicKey = accountKey(sender); - const guardData: Record = { - ks: { - keys: [accountKey(receiver)], - pred: 'keys-all', - }, - }; - const pactDecimal: IPactDecimal = { decimal: `${amount}` }; - const transactionBuilder = Pact.modules.coin['transfer-create']( - sender, - receiver, - () => '(read-keyset "ks")', - pactDecimal, - ) - .addData(guardData) - .addCap('coin.GAS', senderPublicKey) - .addCap('coin.TRANSFER', senderPublicKey, sender, receiver, pactDecimal) - .setMeta({ sender }, NETWORK_ID); + const { submit, pollStatus } = getClient(API_HOST); + + const transaction = Pact.builder + .execution( + Pact.modules.coin['transfer-create']( + sender, + receiver, + () => '(read-keyset "ks")', + pactDecimal, + ), + ) + .addData('ks', { + keys: [accountKey(receiver)], + pred: 'keys-all', + }) + .addSigner(senderPublicKey, (withCap: any) => [ + withCap('coin.TRANSFER', sender, receiver, pactDecimal), + withCap('coin.GAS'), + ]) + .setMeta({ chainId: '1', sender: sender }) + .setNetworkId(NETWORK_ID) + .createTransaction(); - await signWithChainweaver(transactionBuilder); + const signedTransaction = await signWithChainweaver(transaction); - await transactionBuilder.send(API_HOST); - const pollResult = await transactionBuilder.pollUntil(API_HOST, { - onPoll: async (transaction, pollRequest): Promise => { - console.log( - `Polling ${transaction.requestKey}.\nStatus: ${transaction.status}`, - ); - console.log(await pollRequest); - }, - }); + if (!isSignedCommand(signedTransaction)) { + console.error('Command is not signed.'); + return; + } - console.log('Polling Completed.'); - console.log(pollResult); + const requestKey = await submit(signedTransaction); + console.log('request key', requestKey); + const result = await pollStatus(requestKey); + console.log(result); } transferCreate(sender, receiver, Number(transferAmount)).catch(console.error); diff --git a/packages/tools/cookbook/src/accounts/transfer-create-with-private-key.ts b/packages/tools/cookbook/src/accounts/transfer-create-with-private-key.ts index f59e4e8018..233fe4dd62 100644 --- a/packages/tools/cookbook/src/accounts/transfer-create-with-private-key.ts +++ b/packages/tools/cookbook/src/accounts/transfer-create-with-private-key.ts @@ -1,12 +1,11 @@ -import { PactCommand } from '@kadena/client'; +import { getClient, isSignedCommand, Pact } from '@kadena/client'; import { sign } from '@kadena/cryptography-utils'; import { accountKey } from '../utils/account-key'; import { apiHost } from '../utils/api-host'; const HELP: string = `Usage example: \n\nts-node transfer-create.js k:{senderPublicKey} {senderPrivateKey} k:{receiverPublicKey} {amount}`; -const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' | undefined = - 'testnet04'; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 6) { @@ -33,26 +32,23 @@ async function transferCreate( amount: number, ): Promise { const senderPublicKey = accountKey(sender); - const guardData: Record = { - ks: { - keys: [accountKey(receiver)], - pred: 'keys-all', - }, - }; - const pactDecimal = { decimal: `${amount}` }; - const transactionBuilder = new PactCommand(); - transactionBuilder.code = `(coin.transfer "${sender}" "${receiver}" ${amount})`; - transactionBuilder - .addData(guardData) - .addCap('coin.GAS', senderPublicKey) - .addCap('coin.TRANSFER', senderPublicKey, sender, receiver, pactDecimal) - .setMeta({ chainId: '1', sender }, NETWORK_ID); - - const cmd = transactionBuilder.createCommand(); + const transaction = Pact.builder + .execution(Pact.modules.coin.transfer(sender, receiver, pactDecimal)) + .addData('ks', { + keys: [accountKey(receiver)], + pred: 'keys-all', + }) + .addSigner(senderPublicKey, (withCap: any) => [ + withCap('coin.TRANSFER', sender, receiver, pactDecimal), + withCap('coin.GAS'), + ]) + .setMeta({ chainId: '1', sender }) + .setNetworkId(NETWORK_ID) + .createTransaction(); - const sig = sign(cmd.cmd, { + const sig = sign(transaction.cmd, { publicKey: senderPublicKey, secretKey: senderPrivateKey, }); @@ -61,21 +57,19 @@ async function transferCreate( throw new Error('Failed to sign transaction'); } - transactionBuilder.addSignatures({ pubKey: senderPublicKey, sig: sig.sig }); + transaction.sigs = [{ sig: sig.sig }]; - await transactionBuilder.send(API_HOST); + const { submit, pollStatus } = getClient(API_HOST); - const pollResult = await transactionBuilder.pollUntil(API_HOST, { - onPoll: async (transaction, pollRequest): Promise => { - console.log( - `Polling ${transaction.requestKey}.\nStatus: ${transaction.status}`, - ); - console.log(await pollRequest); - }, - }); + if (!isSignedCommand(transaction)) { + throw new Error('Command was not signed.'); + } + + const requestKey = await submit(transaction); + const result = await pollStatus(requestKey); console.log('Polling Completed.'); - console.log(pollResult); + console.log(result); } transferCreate(