From 9ee35fd50c2453d5ce65e8ce7ce5dc33b39e0191 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 17 Jul 2023 13:47:42 -0400 Subject: [PATCH 01/26] chore(transfer): upgrade to @kadena/client:v1.0.0-alpha.4 --- common/config/rush/pnpm-lock.yaml | 64 +++++---- packages/apps/transfer/package.json | 10 +- .../src/components/Global/Ace/index.tsx | 23 +++- .../src/pages/faucet/existing/index.tsx | 16 ++- .../cross-chain-transfer-finisher/index.tsx | 76 +++++------ .../pages/transfer/module-explorer/index.tsx | 37 +----- .../modules/[module]/functions/[defun].tsx | 109 ++++++++++++++++ .../modules/[module]/functions/styles.ts | 39 ++++++ .../chains/[chain]/modules/[module]/index.tsx | 123 ++++++++++++++++++ .../chains/[chain]/modules/[module]/styles.ts | 39 ++++++ .../pages/transfer/module-explorer/styles.ts | 5 - .../get-transfer-data.ts | 4 +- .../transfer/src/services/faucet/index.ts | 64 ++++----- .../src/services/modules/describe-module.ts | 48 ++++--- .../src/services/modules/list-module.ts | 34 ++--- .../transfer-tracker/get-transfer-status.ts | 1 - packages/tools/cookbook/package.json | 4 +- 17 files changed, 517 insertions(+), 179 deletions(-) create mode 100644 packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/[defun].tsx create mode 100644 packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/styles.ts create mode 100644 packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx create mode 100644 packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/styles.ts diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index e4a0afb540..ef698c6c80 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -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': 1.0.0-alpha.4 '@kadena/cryptography-utils': workspace:* '@kadena/pactjs': workspace:* '@kadena/pactjs-cli': 0.1.5 + '@kadena/pactjs-generator': workspace:* '@kadena/react-components': workspace:* '@kadena/react-ui': workspace:* '@kadena/types': workspace:* @@ -327,6 +328,7 @@ 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 @@ -336,6 +338,7 @@ importers: '@kadena/client': 0.6.1 '@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 @@ -1025,7 +1028,7 @@ importers: '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* '@kadena/chainweb-node-client': workspace:* - '@kadena/client': 0.6.1 + '@kadena/client': 1.0.0-alpha.4 '@kadena/cryptography-utils': workspace:* '@kadena/pactjs-cli': 0.1.5 '@kadena/types': workspace:* @@ -1039,7 +1042,7 @@ importers: ts-node: ~10.8.2 dependencies: '@kadena/chainweb-node-client': link:../../libs/chainweb-node-client - '@kadena/client': 0.6.1 + '@kadena/client': 1.0.0-alpha.4 '@kadena/cryptography-utils': link:../../libs/cryptography-utils devDependencies: '@kadena-dev/eslint-config': link:../eslint-config @@ -6980,13 +6983,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,13 +6997,13 @@ packages: - encoding dev: false - /@kadena/chainweb-node-client/0.4.1_encoding@0.1.13: - resolution: {integrity: sha512-AgAEEQy+5ZLMXrP2rI8xZuxbEUNWyk7vh0q4Ti909F2HwHPP1mAp56nZZMlNGKUm6A16BasXmsND1Pow4H95Mw==} + /@kadena/chainweb-node-client/0.4.2_encoding@0.1.13: + 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_encoding@0.1.13 node-fetch: 2.6.12_encoding@0.1.13 @@ -7008,13 +7011,13 @@ packages: - encoding dev: false - /@kadena/client/0.6.1: - resolution: {integrity: sha512-2F3kyzrHItq/nBYGWRqnGWpiATDT6+xoBxiXrFqiq8ZLDhLMxvc0DHmB5INIDRHfYjbts/tKgFPfuQOk7Si2Og==} + /@kadena/client/1.0.0-alpha.4: + resolution: {integrity: sha512-hh5OnFmtAafEY2H9rT8CEDiYbbXefAG4A4gRgorDiqvhZcJB/Z40Hd6fwSGbX4OdAnGg4IRhugUslrMr9dqyoQ==} 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 + '@kadena/chainweb-node-client': 0.4.2_encoding@0.1.13 + '@kadena/cryptography-utils': 0.3.6 + '@kadena/pactjs': 0.3.0 + '@kadena/types': 0.4.0 '@walletconnect/sign-client': 2.8.6 '@walletconnect/types': 2.8.6 cross-fetch: 3.1.8_encoding@0.1.13 @@ -7029,10 +7032,10 @@ packages: - 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 @@ -7070,15 +7073,15 @@ packages: yaml: 2.1.3 dev: true - /@kadena/pactjs/0.2.11: - resolution: {integrity: sha512-98ojO20l3ijp8rkCSokadm2NRMgigtduSB/5/QqRVa4WUMf5ROS01ocF6fzdp7GVUbBYaw1FEfslv6MXtz++IA==} + /@kadena/pactjs/0.3.0: + resolution: {integrity: sha512-b0qIeJ3eAbuOaEbV9dNi9zzxciooeJWzSaeycKDhTbEWAbnKD6pXWRcYPojG2t0pNwMQZyb2kIRIV93D08E5bA==} 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: @@ -24421,6 +24424,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 diff --git a/packages/apps/transfer/package.json b/packages/apps/transfer/package.json index 8ff490738a..90e233b330 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": "1.0.0-alpha.4", "@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..df0e9afef1 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 Onchange { + (value: string): void; +} + export interface IAceEditorProps { code?: string; + width?: string; + height?: string; + readonly?: boolean; + onChange?: Onchange; } -const AceViewerComponent: FC = ({ code }) => ( +const AceViewerComponent: FC = ({ + code, + width, + height, + readonly, + onChange, +}) => ( ); diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 58c4598091..40fa78680b 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -1,4 +1,4 @@ -import { ICommandResult } from '@kadena/chainweb-node-client'; +import { IPollResponse, ICommandResult } from '@kadena/chainweb-node-client'; import { Breadcrumbs, Button, @@ -49,6 +49,20 @@ const ExistingAccountFaucetPage: FC = () => { message?: string; }>({ status: 'idle' }); + const onPoll = async ( + transaction: any, + pollRequest: Promise, + ): Promise => { + const request = await pollRequest; + const result = request[transaction.requestKey!]?.result; + const status = result?.status; + if (status === 'failure') { + const apiErrorMessage = (result.error as { message: string }).message; + + setRequestStatus({ status: 'erroneous', message: apiErrorMessage }); + } + }; + const onFormSubmit = useCallback( async (data: FormData) => { setRequestStatus({ status: 'processing' }); 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..55f542b68a 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 @@ -135,44 +135,44 @@ const CrossChainTransferFinisher: FC = () => { kadenaXChainGas, ); - if (!(contCommand instanceof ContCommand) && contCommand.error) { - setTxError(contCommand.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 }); - } - } + // if (!(contCommand instanceof ContCommand) && contCommand.error) { + // setTxError(contCommand.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 }); + // } + // } }; const showInputError = 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..cf01462939 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,15 @@ 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 +19,6 @@ import useTranslation from 'next-translate/useTranslation'; import React, { ChangeEventHandler, FC, - SyntheticEvent, useCallback, useEffect, useMemo, @@ -42,10 +28,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(); @@ -124,24 +108,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..7ac4f53c0b --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/functions/[defun].tsx @@ -0,0 +1,109 @@ +import { Pact, signWithChainweaver, getClient, isSignedCommand } 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, { useEffect, useState } from 'react'; +import ScopedEval from 'scoped-eval'; + +const AceViewer = dynamic(import('@/components/Global/Ace'), { + ssr: false, +}); + +const FunctionPage = () => { + 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 = () => { + setOutput(''); + const scopedEval = new ScopedEval(); + console.log(code); + 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..98c03051ce --- /dev/null +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/networks/[network]/chains/[chain]/modules/[module]/index.tsx @@ -0,0 +1,123 @@ +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, { useEffect, useState } from 'react'; + +const ModulePage = () => { + Debug('kadena-transfer:pages:transfer:module-explorer:module'); + const { t } = useTranslation('common'); + const [pactCode, setPactCode] = useState(''); + const [functions, setFunctions] = useState({}); + const [capabilities, setCapabilities] = 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 data = await describeModule( + moduleName, + chainId, + typedNetwork, + kadenaConstants.DEFAULT_SENDER, + kadenaConstants.GAS_PRICE, + 1000, + ); + + setPactCode(data?.code || ''); + + const moduleNameParts = moduleName.split('.'); + const namespace = + moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; + + const pactModule = new StringContractDefinition({ + contract: data?.code || '', + namespace, + }); + + console.log(pactModule); + + setCapabilities(pactModule._raw[moduleName].defcaps); + setFunctions(pactModule._raw[moduleName].defuns); + }; + + 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')}

+
+
+
+
+ ); +}; +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/get-transfer-data.ts b/packages/apps/transfer/src/services/cross-chain-transfer-finish/get-transfer-data.ts index d7f94bf0c2..3d4c0bd377 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 @@ -3,7 +3,7 @@ import { ICommandResult, IPollResponse, } from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; +import { Pact } from '@kadena/client'; import { IPactEvent, IPactExec, PactValue } from '@kadena/types'; import { getKadenaConstantByNetwork, Network } from '@/constants/kadena'; @@ -63,7 +63,7 @@ export async function getTransferData({ return { error: t('Invalid length of request key') }; } - const pactCommand = new PactCommand(); + const pactCommand = Pact.builder.createTransaction(); pactCommand.requestKey = requestKey; diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 7c72445a35..0c369b384a 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -3,7 +3,7 @@ import { 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 +29,32 @@ 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 transactionBuilder = 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: any) => [withCap('coin.GAS')]) + .addSigner(keyPair.publicKey, (withCap: any) => [ + withCap( + 'coin.TRANSFER', + SENDER_ACCOUNT, + account, + new PactNumber(amount).toPactDecimal(), + ), + ]) + .setMeta({ sender: SENDER_OPERATION_ACCOUNT, chainId }) + .setNetworkId(NETWORK_ID); - const command = transactionBuilder.createCommand(); + const transaction = transactionBuilder.createTransaction(); - const signature1 = sign(command.cmd, { + const signature1 = sign(transaction.cmd, { publicKey: FAUCET_PUBLIC_KEY, secretKey: FAUCET_PRIVATE_KEY, }); @@ -60,28 +63,29 @@ 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..832d322ea1 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,5 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; +import { Pact, getClient } from '@kadena/client'; import { createExp } from '@kadena/pactjs'; import { @@ -28,22 +28,38 @@ export const describeModule = async ( ttl: number = kadenaConstants.API_TTL, ): Promise => { debug(describeModule.name); + const networkId = chainNetwork[network].network; + const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({ + networkId, + chainId, + })); - const pactCommand = new PactCommand(); - pactCommand.code = createExp(`describe-module "${moduleName}"`); - - pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); - - const response = await pactCommand.local( - getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId, - }), - { - signatureVerification: false, - preflight: false, - }, - ); + const transaction = Pact.builder + .execution(Pact.modules['describe-module'](moduleName)) + .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) + .setNetworkId(networkId) + .createTransaction(); + + const response = await local(transaction, { + preflight: false, + signatureVerification: false, + }); + + // const pactCommand = new PactCommand(); + // pactCommand.code = createExp(`describe-module "${moduleName}"`); + + // pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); + + // const response = await pactCommand.local( + // getKadenaConstantByNetwork(network).apiHost({ + // networkId: chainNetwork[network].network, + // chainId, + // }), + // { + // signatureVerification: false, + // preflight: false, + // }, + // ); const { reqKey, result } = response; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index a6bea2b941..8f3ac7a486 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -1,5 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { PactCommand } from '@kadena/client'; +import { Pact, getClient } from '@kadena/client'; import { createExp } from '@kadena/pactjs'; import { @@ -26,22 +26,22 @@ 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( - getKadenaConstantByNetwork(network).apiHost({ - networkId: chainNetwork[network].network, - chainId, - }), - { - preflight: false, - signatureVerification: false, - }, - ); + const networkId = chainNetwork[network].network; + const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({ + networkId, + chainId, + })); + + const transaction = Pact.builder + .execution(Pact.modules['list-modules']()) + .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) + .setNetworkId(networkId) + .createTransaction(); + + const response = await local(transaction, { + preflight: false, + signatureVerification: false, + }); const { result } = response; 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..f4a2565284 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 @@ -3,7 +3,6 @@ import { ChainwebNetworkId, } from '@kadena/chainweb-node-client'; import { getContCommand, pollSpvProof } from '@kadena/client'; - import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data'; import { diff --git a/packages/tools/cookbook/package.json b/packages/tools/cookbook/package.json index 551a62d2cf..3dc650945d 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": "1.0.0-alpha.4", "@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", From 9ca9ea264b8164e97b0d3fc9d9a18e6b37772acf Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Wed, 19 Jul 2023 10:55:55 -0400 Subject: [PATCH 02/26] fix(cookbook): transfer-create-with-chainweaver --- packages/tools/cookbook/README.md | 2 +- .../transfer-create-with-chainweaver.ts | 69 ++++++++++--------- 2 files changed, 38 insertions(+), 33 deletions(-) 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/src/accounts/transfer-create-with-chainweaver.ts b/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts index 15a969d1bb..b2df607ec1 100644 --- a/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts +++ b/packages/tools/cookbook/src/accounts/transfer-create-with-chainweaver.ts @@ -1,11 +1,11 @@ -import { Pact, signWithChainweaver } from '@kadena/client'; +import { Pact, signWithChainweaver, getClient, isSignedCommand } 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 = +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); @@ -30,40 +30,45 @@ 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); From e6b74200413c8cb2149fbd8277fb91f16cc6d03b Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Wed, 19 Jul 2023 12:09:21 -0400 Subject: [PATCH 03/26] fix(cookbook): transfer-create-with-private-key --- .../transfer/src/services/faucet/index.ts | 7 +-- .../transfer-create-with-private-key.ts | 57 +++++++++---------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 0c369b384a..04a3d83d8a 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -33,7 +33,7 @@ export const fundExistingAccount = async ( debug(fundExistingAccount.name); const keyPair = genKeyPair(); - const transactionBuilder = Pact.builder + const transaction = Pact.builder .execution( Pact.modules['user.coin-faucet']['request-coin']( account, @@ -50,9 +50,8 @@ export const fundExistingAccount = async ( ), ]) .setMeta({ sender: SENDER_OPERATION_ACCOUNT, chainId }) - .setNetworkId(NETWORK_ID); - - const transaction = transactionBuilder.createTransaction(); + .setNetworkId(NETWORK_ID) + .createTransaction(); const signature1 = sign(transaction.cmd, { publicKey: FAUCET_PUBLIC_KEY, 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..b944e802a3 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,11 +1,11 @@ -import { PactCommand } from '@kadena/client'; +import { Pact, getClient, isSignedCommand } 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 = +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); @@ -33,26 +33,25 @@ 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 +60,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( From b7aeb46a8522931deb7d31bda4445f862a0aa679 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 03:55:31 -0400 Subject: [PATCH 04/26] fix(cookbook): get-balance --- .../tools/cookbook/src/accounts/get-balance.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/tools/cookbook/src/accounts/get-balance.ts b/packages/tools/cookbook/src/accounts/get-balance.ts index 5c8d74ebc5..bbcf65e9e9 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 { Pact, getClient } 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)); } From e3a4cb38596b2689269d20d3b26b514dd50ea3ba Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 03:58:46 -0400 Subject: [PATCH 05/26] fix(cookbook): coin.details --- packages/tools/cookbook/src/accounts/details.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/tools/cookbook/src/accounts/details.ts b/packages/tools/cookbook/src/accounts/details.ts index d80c2b2ccf..e7b33f1573 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 { Pact, getClient } 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)); } From d91f9dd933bd4fa9d208838680cb6a422ba7ae66 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 04:42:20 -0400 Subject: [PATCH 06/26] fix(cookbook): coin.create-account --- .../cookbook/src/accounts/create-account.ts | 61 ++++++++++--------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/tools/cookbook/src/accounts/create-account.ts b/packages/tools/cookbook/src/accounts/create-account.ts index f8812ef6a0..d582e9e169 100644 --- a/packages/tools/cookbook/src/accounts/create-account.ts +++ b/packages/tools/cookbook/src/accounts/create-account.ts @@ -1,13 +1,10 @@ -import { ISendResponse } from '@kadena/chainweb-node-client'; -import { Pact, signWithChainweaver } from '@kadena/client'; +import { Pact, signWithChainweaver, getClient, isSignedCommand } 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 = +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); @@ -30,37 +27,41 @@ 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); From 345c510cfea50d17a75e1ed91874b598a857ce16 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 06:20:23 -0400 Subject: [PATCH 07/26] fix(transfer): faucet/existing --- .../src/pages/faucet/existing/index.tsx | 41 ++++++++++++------- .../transfer/src/services/faucet/index.ts | 6 +-- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 40fa78680b..9f0c9c94b4 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -1,4 +1,7 @@ +<<<<<<< HEAD import { IPollResponse, ICommandResult } from '@kadena/chainweb-node-client'; +======= +>>>>>>> 4e308226 (fix(transfer): faucet/existing) import { Breadcrumbs, Button, @@ -38,6 +41,17 @@ const isCustomError = (error: unknown): error is ICommandResult => { return error !== null && typeof error === 'object' && 'result' in error; }; +interface FundExistingAccountResponseBody { + result: { + status: string; + error: undefined | { + message: string; + }; + }; +} + +interface FundExistingAccountResponse extends Record {} + const ExistingAccountFaucetPage: FC = () => { const { t } = useTranslation('common'); @@ -49,26 +63,23 @@ const ExistingAccountFaucetPage: FC = () => { message?: string; }>({ status: 'idle' }); - const onPoll = async ( - transaction: any, - pollRequest: Promise, - ): Promise => { - const request = await pollRequest; - const result = request[transaction.requestKey!]?.result; - const status = result?.status; - if (status === 'failure') { - const apiErrorMessage = (result.error as { message: string }).message; - - setRequestStatus({ status: 'erroneous', message: apiErrorMessage }); - } - }; - const onFormSubmit = useCallback( async (data: FormData) => { setRequestStatus({ status: 'processing' }); try { - await fundExistingAccount(accountName, chainID, AMOUNT_OF_COINS_FUNDED); + const result = await fundExistingAccount( + accountName, + chainID, + AMOUNT_OF_COINS_FUNDED, + ) as FundExistingAccountResponse; + + 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/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 04a3d83d8a..66e6271deb 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -1,8 +1,4 @@ -import { - ChainwebChainId, - ChainwebNetworkId, - IPollResponse, -} from '@kadena/chainweb-node-client'; +import { ChainwebChainId, ChainwebNetworkId } from '@kadena/chainweb-node-client'; import { getClient, isSignedCommand, Pact } from '@kadena/client'; import { genKeyPair, sign } from '@kadena/cryptography-utils'; import { PactNumber } from '@kadena/pactjs'; From ba03401746ddf02b8bf4ec163fffeb6dcc2c2eb7 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 15:30:24 -0400 Subject: [PATCH 08/26] fix(transfer): transfer-tracker --- .../get-transfer-data.ts | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) 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 3d4c0bd377..3a1c944323 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,8 @@ import { ChainwebChainId, ICommandResult, - IPollResponse, } from '@kadena/chainweb-node-client'; -import { Pact } from '@kadena/client'; +import { getClient } from '@kadena/client'; import { IPactEvent, IPactExec, PactValue } from '@kadena/types'; import { getKadenaConstantByNetwork, Network } from '@/constants/kadena'; @@ -63,52 +62,44 @@ export async function getTransferData({ return { error: t('Invalid length of request key') }; } - const pactCommand = Pact.builder.createTransaction(); - - 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; + + const errorMessage = result.error?.message; + + if (errorMessage) { + return { error: errorMessage }; + } + 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 + const { step, stepHasRollback, pactId } = found ?.continuation as IPactExec; - const { events, result } = found.tx; return { tx: { sender: { - chain: found.chainId.toString() as ChainwebChainId, + chain: "1", // todo: fix typing. // found.chainId.toString() as ChainwebChainId, account: senderAccount, }, receiver: { From 34cf1024d99d8c247934112aee4246c8cb746a03 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Thu, 20 Jul 2023 17:38:54 -0400 Subject: [PATCH 09/26] chore(transfer): linting --- .../src/pages/faucet/existing/index.tsx | 19 +++++++----- .../pages/transfer/module-explorer/index.tsx | 1 + .../modules/[module]/functions/[defun].tsx | 22 +++++++++++-- .../get-transfer-data.ts | 12 +++---- .../transfer/src/services/faucet/index.ts | 10 +++--- .../src/services/modules/describe-module.ts | 12 ++++--- .../src/services/modules/list-module.ts | 12 ++++--- .../transfer-tracker/get-transfer-status.ts | 1 + .../cookbook/src/accounts/create-account.ts | 24 ++++++-------- .../tools/cookbook/src/accounts/details.ts | 2 +- .../cookbook/src/accounts/get-balance.ts | 2 +- .../transfer-create-with-chainweaver.ts | 31 ++++++++++--------- .../transfer-create-with-private-key.ts | 15 ++++----- 13 files changed, 90 insertions(+), 73 deletions(-) diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 9f0c9c94b4..a9740e4596 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -44,13 +44,16 @@ const isCustomError = (error: unknown): error is ICommandResult => { interface FundExistingAccountResponseBody { result: { status: string; - error: undefined | { - message: string; - }; + error: + | undefined + | { + message: string; + }; }; } -interface FundExistingAccountResponse extends Record {} +interface FundExistingAccountResponse + extends Record {} const ExistingAccountFaucetPage: FC = () => { const { t } = useTranslation('common'); @@ -68,13 +71,15 @@ const ExistingAccountFaucetPage: FC = () => { setRequestStatus({ status: 'processing' }); try { - const result = await fundExistingAccount( + const result = (await fundExistingAccount( accountName, chainID, AMOUNT_OF_COINS_FUNDED, - ) as FundExistingAccountResponse; + )) as FundExistingAccountResponse; - const error = Object.values(result).find(response => response.result.status === 'failure'); + 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.')}); 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 cf01462939..72c724b0c7 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -1,4 +1,5 @@ import { Breadcrumbs, TextField } from '@kadena/react-ui'; + import { StyledAccountForm, StyledForm, 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 index 7ac4f53c0b..02ebc01a3e 100644 --- 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 @@ -1,4 +1,9 @@ -import { Pact, signWithChainweaver, getClient, isSignedCommand } from '@kadena/client'; +import { + getClient, + isSignedCommand, + Pact, + signWithChainweaver, +} from '@kadena/client'; import { Button } from '@kadena/react-components'; import { Container, EditorGrid } from './styles'; @@ -40,7 +45,13 @@ const FunctionPage = () => { setOutput(''); const scopedEval = new ScopedEval(); console.log(code); - scopedEval.eval(code, { Pact, getClient, signWithChainweaver, isSignedCommand, Logger }); + scopedEval.eval(code, { + Pact, + getClient, + signWithChainweaver, + isSignedCommand, + Logger, + }); }; useEffect(() => { @@ -95,7 +106,12 @@ const FunctionPage = () => { )} - setCode(value)} /> + setCode(value)} + />

{t('Output')}

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 3a1c944323..ed6212db6a 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,7 +1,4 @@ -import { - ChainwebChainId, - ICommandResult, -} from '@kadena/chainweb-node-client'; +import { ChainwebChainId, ICommandResult } from '@kadena/chainweb-node-client'; import { getClient } from '@kadena/client'; import { IPactEvent, IPactExec, PactValue } from '@kadena/types'; @@ -73,7 +70,7 @@ export async function getTransferData({ }); const chainInfos = await Promise.all(chainInfoPromises); - const request = chainInfos.find(chainInfo => requestKey in chainInfo); + const request = chainInfos.find((chainInfo) => requestKey in chainInfo); if (!request) { return { error: t('No request key found') }; @@ -93,13 +90,12 @@ export async function getTransferData({ // eslint-disable-next-line @typescript-eslint/no-explicit-any found?.continuation?.continuation.args as Array; - const { step, stepHasRollback, pactId } = found - ?.continuation as IPactExec; + const { step, stepHasRollback, pactId } = found?.continuation as IPactExec; return { tx: { sender: { - chain: "1", // todo: fix typing. // 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 66e6271deb..9fcddc30d3 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -1,4 +1,7 @@ -import { ChainwebChainId, ChainwebNetworkId } from '@kadena/chainweb-node-client'; +import { + ChainwebChainId, + ChainwebNetworkId, +} from '@kadena/chainweb-node-client'; import { getClient, isSignedCommand, Pact } from '@kadena/client'; import { genKeyPair, sign } from '@kadena/cryptography-utils'; import { PactNumber } from '@kadena/pactjs'; @@ -69,10 +72,7 @@ export const fundExistingAccount = async ( chainId, }); - transaction.sigs = [ - { sig: signature1.sig }, - { sig: signature2.sig }, - ]; + transaction.sigs = [{ sig: signature1.sig }, { sig: signature2.sig }]; const { submit, pollStatus } = getClient(apiHost); diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 832d322ea1..4045f5d701 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,5 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { Pact, getClient } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { createExp } from '@kadena/pactjs'; import { @@ -29,10 +29,12 @@ export const describeModule = async ( ): Promise => { debug(describeModule.name); const networkId = chainNetwork[network].network; - const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({ - networkId, - chainId, - })); + const { local } = getClient( + getKadenaConstantByNetwork(network).apiHost({ + networkId, + chainId, + }), + ); const transaction = Pact.builder .execution(Pact.modules['describe-module'](moduleName)) diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index 8f3ac7a486..e0107b287f 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -1,5 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; -import { Pact, getClient } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { createExp } from '@kadena/pactjs'; import { @@ -27,10 +27,12 @@ export const listModules = async ( ): Promise => { debug(listModules.name); const networkId = chainNetwork[network].network; - const { local } = getClient(getKadenaConstantByNetwork(network).apiHost({ - networkId, - chainId, - })); + const { local } = getClient( + getKadenaConstantByNetwork(network).apiHost({ + networkId, + chainId, + }), + ); const transaction = Pact.builder .execution(Pact.modules['list-modules']()) 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 f4a2565284..3c9f284270 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 @@ -3,6 +3,7 @@ import { ChainwebNetworkId, } from '@kadena/chainweb-node-client'; import { getContCommand, pollSpvProof } from '@kadena/client'; + import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data'; import { diff --git a/packages/tools/cookbook/src/accounts/create-account.ts b/packages/tools/cookbook/src/accounts/create-account.ts index d582e9e169..639e7d7a7b 100644 --- a/packages/tools/cookbook/src/accounts/create-account.ts +++ b/packages/tools/cookbook/src/accounts/create-account.ts @@ -1,11 +1,15 @@ -import { Pact, signWithChainweaver, getClient, isSignedCommand } from '@kadena/client'; +import { + getClient, + isSignedCommand, + Pact, + signWithChainweaver, +} from '@kadena/client'; import { accountKey } from '../utils/account-key'; import { apiHost } from '../utils/api-host'; const HELP: string = `Usage example: \n\nts-node create-account.js k:{gasProviderPublicKey} k:{receiverPublicKey}`; -const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = - 'testnet04'; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 4) { @@ -30,18 +34,13 @@ async function createAccount( const transaction = Pact.builder .execution( - Pact.modules.coin['create-account']( - receiver, - () => '(read-keyset "ks")', - ) + Pact.modules.coin['create-account'](receiver, () => '(read-keyset "ks")'), ) .addData('ks', { keys: [accountKey(receiver)], pred: 'keys-all', }) - .addSigner(gasProviderPublicKey, (withCap: any) => [ - withCap('coin.GAS'), - ]) + .addSigner(gasProviderPublicKey, (withCap: any) => [withCap('coin.GAS')]) .setMeta({ chainId: '1', sender: gasProvider }) .setNetworkId(NETWORK_ID) .createTransaction(); @@ -53,10 +52,7 @@ async function createAccount( return; } - const { - submit, - pollStatus, - } = getClient(API_HOST); + const { submit, pollStatus } = getClient(API_HOST); const requestKey = await submit(signedTransaction); console.log('request key', requestKey); diff --git a/packages/tools/cookbook/src/accounts/details.ts b/packages/tools/cookbook/src/accounts/details.ts index e7b33f1573..36eafd10df 100644 --- a/packages/tools/cookbook/src/accounts/details.ts +++ b/packages/tools/cookbook/src/accounts/details.ts @@ -1,4 +1,4 @@ -import { Pact, getClient } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { apiHost } from '../utils/api-host'; diff --git a/packages/tools/cookbook/src/accounts/get-balance.ts b/packages/tools/cookbook/src/accounts/get-balance.ts index bbcf65e9e9..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, getClient } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { apiHost } from '../utils/api-host'; 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 b2df607ec1..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, getClient, isSignedCommand } 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-with-chainweaver.ts k:{senderPublicKey} k:{receiverPublicKey} {amount}`; -const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = - 'testnet04'; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 5) { @@ -32,27 +36,24 @@ async function transferCreate( const senderPublicKey = accountKey(sender); const pactDecimal: IPactDecimal = { decimal: `${amount}` }; - const { - submit, - pollStatus, - } = getClient(API_HOST); + const { submit, pollStatus } = getClient(API_HOST); const transaction = Pact.builder .execution( - Pact.modules.coin['transfer-create']( - sender, - receiver, - () => '(read-keyset "ks")', - pactDecimal - ) + 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'), + withCap('coin.TRANSFER', sender, receiver, pactDecimal), + withCap('coin.GAS'), ]) .setMeta({ chainId: '1', sender: sender }) .setNetworkId(NETWORK_ID) 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 b944e802a3..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 { Pact, getClient, isSignedCommand } 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' = - 'testnet04'; +const NETWORK_ID: 'testnet04' | 'mainnet01' | 'development' = 'testnet04'; const API_HOST: string = apiHost('1', 'testnet.', NETWORK_ID); if (process.argv.length !== 6) { @@ -36,16 +35,14 @@ async function transferCreate( const pactDecimal = { decimal: `${amount}` }; const transaction = Pact.builder - .execution( - Pact.modules['coin'].transfer(sender, receiver, pactDecimal) - ) + .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'), + withCap('coin.TRANSFER', sender, receiver, pactDecimal), + withCap('coin.GAS'), ]) .setMeta({ chainId: '1', sender }) .setNetworkId(NETWORK_ID) @@ -60,7 +57,7 @@ async function transferCreate( throw new Error('Failed to sign transaction'); } - transaction.sigs = [ { sig: sig.sig } ]; + transaction.sigs = [{ sig: sig.sig }]; const { submit, pollStatus } = getClient(API_HOST); From d0770e10a69bc9539a24792bd2c338f5a866d7ad Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Fri, 21 Jul 2023 05:47:35 -0400 Subject: [PATCH 10/26] chore(transfer): fix build --- .../apps/transfer/src/constants/client.ts | 5 + .../src/pages/faucet/existing/index.tsx | 2 +- .../transfer/account-transactions/index.tsx | 2 +- .../cross-chain-transfer-finisher/index.tsx | 24 ++-- .../pages/transfer/module-explorer/index.tsx | 25 +--- .../chains/[chain]/modules/[module]/index.tsx | 4 +- .../finish-xchain-transfer.ts | 60 +++++---- .../get-transfer-data.ts | 7 +- .../src/services/modules/describe-module.ts | 22 +--- .../src/services/modules/list-module.ts | 6 +- .../transfer-tracker/get-transfer-status.ts | 124 +++++++++--------- .../example-contract/crosschain-transfer.ts | 2 +- 12 files changed, 128 insertions(+), 155 deletions(-) create mode 100644 packages/apps/transfer/src/constants/client.ts diff --git a/packages/apps/transfer/src/constants/client.ts b/packages/apps/transfer/src/constants/client.ts new file mode 100644 index 0000000000..7bddf180ee --- /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 a9740e4596..3bf7107a06 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -148,7 +148,7 @@ const ExistingAccountFaucetPage: FC = () => { }} helperText={errors.name?.message ?? ''} /> - + {
- + { return; } - const host = getKadenaConstantByNetwork(network).apiHost({ + const proof = await client.pollCreateSpv(requestKey, pollResults.tx.receiver.chain, { networkId: chainNetwork[network].network, - chainId: pollResults.tx.receiver.chain, + chainId: pollResults.tx.sender.chain, }); - const contCommand = await finishXChainTransfer( - requestKey, - pollResults.tx.step, - pollResults.tx.rollback, - network, - pollResults.tx.receiver.chain, - kadenaXChainGas, - ); + console.log(proof); + + // const contCommand = await finishXChainTransfer( + // requestKey, + // pollResults.tx.step, + // pollResults.tx.rollback, + // network, + // pollResults.tx.receiver.chain, + // kadenaXChainGas, + // ); // if (!(contCommand instanceof ContCommand) && contCommand.error) { // setTxError(contCommand.error); 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 72c724b0c7..5d13397f86 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -58,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); @@ -94,7 +73,7 @@ const ModuleExplorer: FC = () => { - + { {filteredModules?.map((module) => ( {module} 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 index 98c03051ce..19e98d338a 100644 --- 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 @@ -62,8 +62,8 @@ const ModulePage = () => { console.log(pactModule); - setCapabilities(pactModule._raw[moduleName].defcaps); - setFunctions(pactModule._raw[moduleName].defuns); + // setCapabilities(pactModule._raw[moduleName].defcaps); + // setFunctions(pactModule._raw[moduleName].defuns); }; fetchModule().catch(console.error); 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..ce4e593d45 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 @@ -2,7 +2,7 @@ import { ChainwebChainId, ChainwebNetworkId, } from '@kadena/chainweb-node-client'; -import { ContCommand, getContCommand } from '@kadena/client'; +import { getClient, Pact } from '@kadena/client'; import { getKadenaConstantByNetwork, @@ -28,47 +28,49 @@ export async function finishXChainTransfer( network: Network, chainId: ChainwebChainId, sender: string, -): Promise { +): Promise { debug(finishXChainTransfer.name); const host = getKadenaConstantByNetwork(network).apiHost({ networkId: chainNetwork[network].network, chainId, }); + const { pollStatus } = getClient(); + try { - const contCommand = await getContCommand( - requestKey, - chainId, - host, - step + 1, - rollback, - ); + // const contCommand = await getContCommand( + // chainId, + // host, + // step + 1, + // rollback, + // ); - contCommand.setMeta( - { - chainId, - sender, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ); + // contCommand.setMeta( + // { + // chainId, + // sender, + // gasLimit, + // gasPrice, + // }, + // chainNetwork[network].network as ChainwebNetworkId, + // ); - contCommand.createCommand(); + // contCommand.createCommand(); - const localResult = await contCommand.local(host, { - preflight: false, - signatureVerification: false, - }); + // 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 }; - } + // if (localResult.result.status !== 'success') { + // debug(localResult.result.error.message); + // return { error: localResult.result.error.message }; + // } - await contCommand.send(host); + // await contCommand.send(host); - return contCommand; + // return contCommand; + throw new Error('testing'); } 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 ed6212db6a..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 @@ -80,10 +80,9 @@ export async function getTransferData({ const { events, result } = found; - const errorMessage = result.error?.message; - - if (errorMessage) { - return { error: errorMessage }; + 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] = diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 4045f5d701..b3bf003624 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -36,8 +36,10 @@ export const describeModule = async ( }), ); + const modules: any = Pact.modules; + const describe: any = modules['describe-module']; const transaction = Pact.builder - .execution(Pact.modules['describe-module'](moduleName)) + .execution(describe(moduleName)) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -47,27 +49,11 @@ export const describeModule = async ( signatureVerification: false, }); - // const pactCommand = new PactCommand(); - // pactCommand.code = createExp(`describe-module "${moduleName}"`); - - // pactCommand.setMeta({ gasLimit, gasPrice, ttl, sender, chainId }); - - // const response = await pactCommand.local( - // getKadenaConstantByNetwork(network).apiHost({ - // networkId: chainNetwork[network].network, - // chainId, - // }), - // { - // signatureVerification: false, - // preflight: false, - // }, - // ); - const { reqKey, result } = response; return { reqKey, status: result.status, - code: result.data?.code, + code: ('data' in result) ? (result.data as string) : '', }; }; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index e0107b287f..92d354c581 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 { getClient, Pact } from '@kadena/client'; -import { createExp } from '@kadena/pactjs'; import { getKadenaConstantByNetwork, @@ -34,8 +33,9 @@ export const listModules = async ( }), ); + const modules: any = Pact.modules; const transaction = Pact.builder - .execution(Pact.modules['list-modules']()) + .execution(modules['list-modules']()) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -49,6 +49,6 @@ export const listModules = async ( 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..d5f23be2c4 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 @@ -2,7 +2,6 @@ import { ChainwebChainId, ChainwebNetworkId, } from '@kadena/chainweb-node-client'; -import { getContCommand, pollSpvProof } from '@kadena/client'; import { getTransferData } from '../cross-chain-transfer-finish/get-transfer-data'; @@ -181,53 +180,53 @@ export async function getXChainTransferInfo({ const gasLimit: number = kadenaConstants.GAS_LIMIT; const gasPrice: number = kadenaConstants.GAS_PRICE; - const contCommand = await getContCommand( - requestKey, - receiverChain, - proofApiHost, - 1, - false, - ); + // const contCommand = await getContCommand( + // requestKey, + // receiverChain, + // proofApiHost, + // 1, + // false, + // ); - contCommand - .setMeta( - { - chainId: receiverChain, - sender: senderAccount, - gasLimit, - gasPrice, - }, - chainNetwork[network].network as ChainwebNetworkId, - ) - .createCommand(); + // contCommand + // .setMeta( + // { + // chainId: receiverChain, + // sender: senderAccount, + // gasLimit, + // gasPrice, + // }, + // chainNetwork[network].network as ChainwebNetworkId, + // ) + // .createCommand(); - const response = await contCommand.local(apiHost, { - preflight: false, - signatureVerification: false, - }); + // const response = await contCommand.local(apiHost, { + // preflight: false, + // signatureVerification: false, + // }); - 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 ( + // 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 (response?.result?.status === 'success') { - return { - id: StatusId.Pending, - status: t('Pending'), - description: t('Transfer pending - waiting for continuation command'), - senderAccount: senderAccount, - receiverChain: receiverChain, - }; - } + // if (response?.result?.status === 'success') { + // return { + // id: StatusId.Pending, + // status: t('Pending'), + // description: t('Transfer pending - waiting for continuation command'), + // senderAccount: senderAccount, + // receiverChain: receiverChain, + // }; + // } return { id: StatusId.Error, @@ -278,24 +277,25 @@ export async function checkForProof({ }); let count = 0; - return await pollSpvProof(requestKey, receiverChain, apiHost, { - onPoll: () => { - // Avoid status update on first two polls (to avoid flickering) - if (count > 1) { - onPoll({ - id: StatusId.Pending, - status: t('Pending'), - description: t('Transfer pending - waiting for proof'), - senderAccount, - senderChain, - receiverAccount, - receiverChain, - amount, - }); - } - count++; - }, - }); + // return await pollSpvProof(requestKey, receiverChain, apiHost, { + // onPoll: () => { + // // Avoid status update on first two polls (to avoid flickering) + // if (count > 1) { + // onPoll({ + // id: StatusId.Pending, + // status: t('Pending'), + // description: t('Transfer pending - waiting for proof'), + // senderAccount, + // senderChain, + // receiverAccount, + // receiverChain, + // amount, + // }); + // } + // count++; + // }, + // }); + return new Promise(() => undefined) } catch (error) { debug(error); onPoll({ 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, ), From 7a167d36144b4cae7ce330acf480f165050040ee Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Fri, 21 Jul 2023 11:59:32 -0400 Subject: [PATCH 11/26] fix(transfer): tracker & cross-chain finisher --- .../src/components/Global/Ace/index.tsx | 4 +- .../apps/transfer/src/constants/client.ts | 2 +- .../src/pages/faucet/existing/index.tsx | 14 +- .../apps/transfer/src/pages/home/index.tsx | 2 +- .../transfer/account-transactions/index.tsx | 6 +- .../cross-chain-transfer-finisher/index.tsx | 104 +++++------- .../pages/transfer/module-explorer/index.tsx | 6 +- .../modules/[module]/functions/[defun].tsx | 9 +- .../chains/[chain]/modules/[module]/index.tsx | 19 ++- .../finish-xchain-transfer.ts | 80 +++------ .../transfer/src/services/faucet/index.ts | 4 +- .../src/services/modules/describe-module.ts | 7 +- .../src/services/modules/list-module.ts | 3 +- .../transfer-tracker/get-transfer-status.ts | 154 ++++++++---------- 14 files changed, 177 insertions(+), 237 deletions(-) diff --git a/packages/apps/transfer/src/components/Global/Ace/index.tsx b/packages/apps/transfer/src/components/Global/Ace/index.tsx index df0e9afef1..3f77e81d18 100644 --- a/packages/apps/transfer/src/components/Global/Ace/index.tsx +++ b/packages/apps/transfer/src/components/Global/Ace/index.tsx @@ -8,7 +8,7 @@ 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 Onchange { +export interface IOnchange { (value: string): void; } @@ -17,7 +17,7 @@ export interface IAceEditorProps { width?: string; height?: string; readonly?: boolean; - onChange?: Onchange; + onChange?: IOnchange; } const AceViewerComponent: FC = ({ diff --git a/packages/apps/transfer/src/constants/client.ts b/packages/apps/transfer/src/constants/client.ts index 7bddf180ee..0119261d54 100644 --- a/packages/apps/transfer/src/constants/client.ts +++ b/packages/apps/transfer/src/constants/client.ts @@ -1,4 +1,4 @@ -import { getClient } from "@kadena/client"; +import { getClient } from '@kadena/client'; const client = getClient(); diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 3bf7107a06..4da5230748 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -41,7 +41,7 @@ const isCustomError = (error: unknown): error is ICommandResult => { return error !== null && typeof error === 'object' && 'result' in error; }; -interface FundExistingAccountResponseBody { +interface IFundExistingAccountResponseBody { result: { status: string; error: @@ -52,8 +52,8 @@ interface FundExistingAccountResponseBody { }; } -interface FundExistingAccountResponse - extends Record {} +interface IFundExistingAccountResponse + extends Record {} const ExistingAccountFaucetPage: FC = () => { const { t } = useTranslation('common'); @@ -75,7 +75,7 @@ const ExistingAccountFaucetPage: FC = () => { accountName, chainID, AMOUNT_OF_COINS_FUNDED, - )) as FundExistingAccountResponse; + )) as IFundExistingAccountResponse; const error = Object.values(result).find( (response) => response.result.status === 'failure', @@ -148,7 +148,11 @@ const ExistingAccountFaucetPage: FC = () => { }} helperText={errors.name?.message ?? ''} /> - + { - + { const debug = Debug( @@ -121,60 +112,49 @@ const CrossChainTransferFinisher: FC = () => { return; } - const proof = await client.pollCreateSpv(requestKey, pollResults.tx.receiver.chain, { - networkId: chainNetwork[network].network, + const networkId = chainNetwork[network].network; + + const options = { + networkId: networkId, chainId: pollResults.tx.sender.chain, - }); + }; - console.log(proof); - - // const contCommand = await finishXChainTransfer( - // requestKey, - // pollResults.tx.step, - // pollResults.tx.rollback, - // network, - // pollResults.tx.receiver.chain, - // kadenaXChainGas, - // ); - - // if (!(contCommand instanceof ContCommand) && contCommand.error) { - // setTxError(contCommand.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 }); - // } - // } + const proof = await client.pollCreateSpv( + requestKey, + 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 (typeof requestKeyOrError !== 'string') { + setTxError((requestKeyOrError as { error: string }).error); + } + + try { + const result = await client.listen(requestKeyOrError as string); + setFinalResults({ + requestKey: result.reqKey, + status: result.result.status, + }); + } catch (tx) { + debug(tx); + setFinalResults({ ...tx }); + } }; const showInputError = 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 5d13397f86..f7558b6c11 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -73,7 +73,11 @@ const ModuleExplorer: FC = () => { - + { +const FunctionPage: FC = () => { Debug('kadena-transfer:pages:transfer:module-explorer:module:function'); const { t } = useTranslation('common'); const [snippet, setSnippet] = useState(''); @@ -32,7 +32,7 @@ const FunctionPage = () => { useEffect(() => { setOutput(`${output}\n${log}`.trim()); - }, [timestamp]); + }, [timestamp, output, log]); const Logger = { log(data: string) { @@ -41,10 +41,9 @@ const FunctionPage = () => { }, }; - const runSnippet = () => { + const runSnippet = (): void => { setOutput(''); const scopedEval = new ScopedEval(); - console.log(code); scopedEval.eval(code, { Pact, getClient, 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 index 19e98d338a..89d438416c 100644 --- 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 @@ -15,14 +15,15 @@ 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, { useEffect, useState } from 'react'; +import React, { FC, useEffect, useState } from 'react'; -const ModulePage = () => { +const ModulePage: FC = () => { Debug('kadena-transfer:pages:transfer:module-explorer:module'); const { t } = useTranslation('common'); const [pactCode, setPactCode] = useState(''); const [functions, setFunctions] = useState({}); const [capabilities, setCapabilities] = useState({}); + const [interfaces, setInterfaces] = useState([]); const router = useRouter(); const { network, chain, module } = router.query; @@ -49,21 +50,20 @@ const ModulePage = () => { 1000, ); - setPactCode(data?.code || ''); + setPactCode(data?.code.code || ''); const moduleNameParts = moduleName.split('.'); const namespace = moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; const pactModule = new StringContractDefinition({ - contract: data?.code || '', + contract: data?.code.code || '', namespace, }); - console.log(pactModule); - - // setCapabilities(pactModule._raw[moduleName].defcaps); - // setFunctions(pactModule._raw[moduleName].defuns); + setCapabilities(pactModule._raw[moduleName].defcaps); + setFunctions(pactModule._raw[moduleName].defuns); + setInterfaces(data?.code.interfaces); }; fetchModule().catch(console.error); @@ -114,6 +114,9 @@ const ModulePage = () => {

{t('Constants')}

{t('Pacts')}

{t('Interfaces')}

+ {interfaces.map((key) => ( + {key} + ))}
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 ce4e593d45..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 { getClient, Pact } 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,59 +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, - }); - - const { pollStatus } = getClient(); try { - // const contCommand = await getContCommand( - // 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; - throw new Error('testing'); + 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/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 9fcddc30d3..977f4ba0da 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -39,8 +39,8 @@ export const fundExistingAccount = async ( new PactNumber(amount).toPactDecimal(), ), ) - .addSigner(FAUCET_PUBLIC_KEY, (withCap: any) => [withCap('coin.GAS')]) - .addSigner(keyPair.publicKey, (withCap: any) => [ + .addSigner(FAUCET_PUBLIC_KEY, (withCap) => [withCap('coin.GAS')]) + .addSigner(keyPair.publicKey, (withCap) => [ withCap( 'coin.TRANSFER', SENDER_ACCOUNT, diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index b3bf003624..50e9ac6d8a 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,6 +1,5 @@ import { ChainwebChainId } from '@kadena/chainweb-node-client'; import { getClient, Pact } from '@kadena/client'; -import { createExp } from '@kadena/pactjs'; import { getKadenaConstantByNetwork, @@ -36,10 +35,8 @@ export const describeModule = async ( }), ); - const modules: any = Pact.modules; - const describe: any = modules['describe-module']; const transaction = Pact.builder - .execution(describe(moduleName)) + .execution(Pact.modules['describe-module'](moduleName)) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -54,6 +51,6 @@ export const describeModule = async ( return { reqKey, status: result.status, - code: ('data' in result) ? (result.data as string) : '', + code: 'data' in result ? (result.data as string) : '', }; }; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index 92d354c581..7e63ac6b4c 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -33,9 +33,8 @@ export const listModules = async ( }), ); - const modules: any = Pact.modules; const transaction = Pact.builder - .execution(modules['list-modules']()) + .execution(Pact.modules['list-modules']()) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); 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 d5f23be2c4..60a532d297 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,15 +1,10 @@ -import { - ChainwebChainId, - ChainwebNetworkId, -} from '@kadena/chainweb-node-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'; @@ -169,64 +164,58 @@ 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( - // requestKey, - // receiverChain, - // proofApiHost, - // 1, - // false, - // ); + const proof = await client.pollCreateSpv( + requestKey, + receiverChain, + 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 ( + 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 (response?.result?.status === 'success') { - // return { - // id: StatusId.Pending, - // status: t('Pending'), - // description: t('Transfer pending - waiting for continuation command'), - // senderAccount: senderAccount, - // receiverChain: receiverChain, - // }; - // } + if (response?.result?.status === 'success') { + return { + id: StatusId.Pending, + status: t('Pending'), + description: t('Transfer pending - waiting for continuation command'), + senderAccount: senderAccount, + receiverChain: receiverChain, + }; + } return { id: StatusId.Error, @@ -265,37 +254,34 @@ export async function checkForProof({ onPoll?: (status: IStatusData) => void; }; t: Translate; -}): Promise { +}): Promise { debug(checkForProof.name); const { onPoll = () => {} } = { ...options }; try { - const apiHost = getKadenaConstantByNetwork(network).apiHost({ + let count = 0; + + 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) { + onPoll({ + id: StatusId.Pending, + status: t('Pending'), + description: t('Transfer pending - waiting for proof'), + senderAccount, + senderChain, + receiverAccount, + receiverChain, + amount, + }); + } + count++; + }, }); - let count = 0; - - // return await pollSpvProof(requestKey, receiverChain, apiHost, { - // onPoll: () => { - // // Avoid status update on first two polls (to avoid flickering) - // if (count > 1) { - // onPoll({ - // id: StatusId.Pending, - // status: t('Pending'), - // description: t('Transfer pending - waiting for proof'), - // senderAccount, - // senderChain, - // receiverAccount, - // receiverChain, - // amount, - // }); - // } - // count++; - // }, - // }); - return new Promise(() => undefined) } catch (error) { debug(error); onPoll({ From 2b9d1b8f22d7983ea6cefaa2c6199e293df68e6a Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Sat, 22 Jul 2023 13:33:58 -0400 Subject: [PATCH 12/26] fix(transfer): get pact capabilities & functions --- .../chains/[chain]/modules/[module]/index.tsx | 24 +++++++++---------- .../transfer/src/services/faucet/index.ts | 4 ++-- .../src/services/modules/describe-module.ts | 5 +++- 3 files changed, 18 insertions(+), 15 deletions(-) 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 index 89d438416c..098e5d0d83 100644 --- 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 @@ -21,9 +21,9 @@ const ModulePage: FC = () => { Debug('kadena-transfer:pages:transfer:module-explorer:module'); const { t } = useTranslation('common'); const [pactCode, setPactCode] = useState(''); - const [functions, setFunctions] = useState({}); - const [capabilities, setCapabilities] = useState({}); - const [interfaces, setInterfaces] = useState([]); + const [functions, setFunctions] = useState | undefined>({}); + const [capabilities, setCapabilities] = useState | undefined>({}); + const [interfaces, setInterfaces] = useState([]); const router = useRouter(); const { network, chain, module } = router.query; @@ -50,20 +50,20 @@ const ModulePage: FC = () => { 1000, ); - setPactCode(data?.code.code || ''); + setPactCode(data.code?.code || ''); const moduleNameParts = moduleName.split('.'); const namespace = moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; const pactModule = new StringContractDefinition({ - contract: data?.code.code || '', + contract: data?.code?.code || '', namespace, }); - setCapabilities(pactModule._raw[moduleName].defcaps); - setFunctions(pactModule._raw[moduleName].defuns); - setInterfaces(data?.code.interfaces); + setCapabilities(pactModule.getCapabilities(moduleName)); + setFunctions(pactModule.getMethods(moduleName)); + setInterfaces(data.code?.interfaces || []); }; fetchModule().catch(console.error); @@ -88,9 +88,9 @@ const ModulePage: FC = () => {

{t('Details')}

{t('Functions')}

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

{t('Capabilities')}

- {!Object.keys(capabilities)?.length && + {!Object.keys(capabilities || {})?.length && t('No capabilities in this module.')} - {Object.keys(capabilities)?.map((key) => ( + {Object.keys(capabilities || {})?.map((key) => (
[withCap('coin.GAS')]) - .addSigner(keyPair.publicKey, (withCap) => [ + .addSigner(FAUCET_PUBLIC_KEY, (withCap: any) => [withCap('coin.GAS')]) + .addSigner(keyPair.publicKey, (withCap: any) => [ withCap( 'coin.TRANSFER', SENDER_ACCOUNT, diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 50e9ac6d8a..1f300f16f6 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -12,7 +12,10 @@ import Debug from 'debug'; export interface IModuleResult { reqKey?: string; status?: string; - code?: string; + code?: { + code: string; + interfaces: string[]; + }; } const debug = Debug('kadena-transfer:services:describe-module'); From 671745987111800ab183e3a7f09b46c4a9ed3534 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 06:18:16 -0400 Subject: [PATCH 13/26] fix(transfer): use workspace:* as version for dependencies --- common/config/rush/pnpm-lock.yaml | 79 ++-------------------------- packages/apps/transfer/package.json | 4 +- packages/tools/cookbook/package.json | 2 +- 3 files changed, 8 insertions(+), 77 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index ef698c6c80..09b27b9eda 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -278,8 +278,8 @@ importers: '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* - '@kadena/chainweb-node-client': 0.4.2 - '@kadena/client': 1.0.0-alpha.4 + '@kadena/chainweb-node-client': workspace:* + '@kadena/client': workspace:* '@kadena/cryptography-utils': workspace:* '@kadena/pactjs': workspace:* '@kadena/pactjs-cli': 0.1.5 @@ -1028,7 +1028,7 @@ importers: '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* '@kadena/chainweb-node-client': workspace:* - '@kadena/client': 1.0.0-alpha.4 + '@kadena/client': workspace:* '@kadena/cryptography-utils': workspace:* '@kadena/pactjs-cli': 0.1.5 '@kadena/types': workspace:* @@ -1042,7 +1042,7 @@ importers: ts-node: ~10.8.2 dependencies: '@kadena/chainweb-node-client': link:../../libs/chainweb-node-client - '@kadena/client': 1.0.0-alpha.4 + '@kadena/client': link:../../libs/client '@kadena/cryptography-utils': link:../../libs/cryptography-utils devDependencies: '@kadena-dev/eslint-config': link:../eslint-config @@ -6983,64 +6983,6 @@ packages: resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==} dev: true - /@kadena/chainweb-node-client/0.4.2: - resolution: {integrity: sha512-jNSnp2f7/rBXmie8AtysjP4HKdZajlJne5zliF9PvZv/aXhtYoz2DkOuaFrCyxk5+BQXnfrHGxzJXTCF9dOjaw==} - requiresBuild: true - dependencies: - '@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 - transitivePeerDependencies: - - encoding - dev: false - - /@kadena/chainweb-node-client/0.4.2_encoding@0.1.13: - resolution: {integrity: sha512-jNSnp2f7/rBXmie8AtysjP4HKdZajlJne5zliF9PvZv/aXhtYoz2DkOuaFrCyxk5+BQXnfrHGxzJXTCF9dOjaw==} - requiresBuild: true - dependencies: - '@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_encoding@0.1.13 - node-fetch: 2.6.12_encoding@0.1.13 - transitivePeerDependencies: - - encoding - dev: false - - /@kadena/client/1.0.0-alpha.4: - resolution: {integrity: sha512-hh5OnFmtAafEY2H9rT8CEDiYbbXefAG4A4gRgorDiqvhZcJB/Z40Hd6fwSGbX4OdAnGg4IRhugUslrMr9dqyoQ==} - dependencies: - '@kadena/chainweb-node-client': 0.4.2_encoding@0.1.13 - '@kadena/cryptography-utils': 0.3.6 - '@kadena/pactjs': 0.3.0 - '@kadena/types': 0.4.0 - '@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.6: - resolution: {integrity: sha512-TsVmWRlqvJZDTf5Dzo21P4mwvHtyfFWT5xa5Mr2oz1m9GBsafQ8CmZfRwrdxIvw2ZppNdmU2V4ji0we9N9AARQ==} - dependencies: - '@kadena/types': 0.4.0 - blakejs: 1.2.1 - buffer: 6.0.3 - tweetnacl: 1.0.3 - dev: false - /@kadena/fonts/0.0.1: resolution: {integrity: sha512-epUOJbW96Yd827XQD2/6Ibow9qcevgPhVKsUhfzG9L26U4PLMMWZ0KXxIoFQ6DKpQa9xE4GK8DkPzn30pJb+3Q==} dependencies: @@ -7073,17 +7015,6 @@ packages: yaml: 2.1.3 dev: true - /@kadena/pactjs/0.3.0: - resolution: {integrity: sha512-b0qIeJ3eAbuOaEbV9dNi9zzxciooeJWzSaeycKDhTbEWAbnKD6pXWRcYPojG2t0pNwMQZyb2kIRIV93D08E5bA==} - dependencies: - '@kadena/types': 0.4.0 - bignumber.js: 9.1.1 - dev: false - - /@kadena/types/0.4.0: - resolution: {integrity: sha512-fXId5LebFigIcMMG2JlPW/wMNf5sw81VqjoCVh7TmZnuMvT9YJDsYQahD8qdrXWxbFAssRXyIEe4oPsm2aQ5/Q==} - dev: false - /@leichtgewicht/ip-codec/2.0.4: resolution: {integrity: sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==} dev: false @@ -25672,7 +25603,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==} diff --git a/packages/apps/transfer/package.json b/packages/apps/transfer/package.json index 90e233b330..a1263f958c 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.2", - "@kadena/client": "1.0.0-alpha.4", + "@kadena/chainweb-node-client": "workspace:*", + "@kadena/client": "workspace:*", "@kadena/cryptography-utils": "workspace:*", "@kadena/pactjs": "workspace:*", "@kadena/react-components": "workspace:*", diff --git a/packages/tools/cookbook/package.json b/packages/tools/cookbook/package.json index 3dc650945d..a7efb8fba3 100644 --- a/packages/tools/cookbook/package.json +++ b/packages/tools/cookbook/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@kadena/chainweb-node-client": "workspace:*", - "@kadena/client": "1.0.0-alpha.4", + "@kadena/client": "workspace:*", "@kadena/cryptography-utils": "workspace:*" }, "devDependencies": { From 32700e7130b2da4b5ef9e6d49834c9edd694f8b5 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 06:51:47 -0400 Subject: [PATCH 14/26] fix(transfer): pass pact command as string to exection() --- .../modules/[module]/functions/[defun].tsx | 2 +- .../chains/[chain]/modules/[module]/index.tsx | 8 ++++---- .../src/services/modules/describe-module.ts | 17 +++++++++++------ .../src/services/modules/list-module.ts | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) 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 index ff60053fc8..a7e2db5ba6 100644 --- 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 @@ -32,7 +32,7 @@ const FunctionPage: FC = () => { useEffect(() => { setOutput(`${output}\n${log}`.trim()); - }, [timestamp, output, log]); + }, [timestamp]); const Logger = { log(data: string) { 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 index 098e5d0d83..18409122bb 100644 --- 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 @@ -41,7 +41,7 @@ const ModulePage: FC = () => { const moduleName: string = module as string; const fetchModule = async (): Promise => { - const data = await describeModule( + const { data } = await describeModule( moduleName, chainId, typedNetwork, @@ -50,20 +50,20 @@ const ModulePage: FC = () => { 1000, ); - setPactCode(data.code?.code || ''); + setPactCode(data?.code || ''); const moduleNameParts = moduleName.split('.'); const namespace = moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; const pactModule = new StringContractDefinition({ - contract: data?.code?.code || '', + contract: data?.code || '', namespace, }); setCapabilities(pactModule.getCapabilities(moduleName)); setFunctions(pactModule.getMethods(moduleName)); - setInterfaces(data.code?.interfaces || []); + setInterfaces(data?.interfaces || []); }; fetchModule().catch(console.error); diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 1f300f16f6..2ec66cfcb3 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -8,14 +8,12 @@ import { } from '@/constants/kadena'; import { chainNetwork } from '@/constants/network'; import Debug from 'debug'; +import { PactValue } from '../../../../../libs/types/lib'; export interface IModuleResult { reqKey?: string; status?: string; - code?: { - code: string; - interfaces: string[]; - }; + data?: PactValue; } const debug = Debug('kadena-transfer:services:describe-module'); @@ -39,7 +37,7 @@ export const describeModule = async ( ); const transaction = Pact.builder - .execution(Pact.modules['describe-module'](moduleName)) + .execution(`(describe-module "${moduleName}")`) .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); @@ -51,9 +49,16 @@ export const describeModule = async ( const { reqKey, result } = response; + if (result.status === 'failure') { + return { + reqKey, + status: result.status, + }; + } + return { reqKey, status: result.status, - code: 'data' in result ? (result.data as string) : '', + data: result.data, }; }; diff --git a/packages/apps/transfer/src/services/modules/list-module.ts b/packages/apps/transfer/src/services/modules/list-module.ts index 7e63ac6b4c..24bf1ac51c 100644 --- a/packages/apps/transfer/src/services/modules/list-module.ts +++ b/packages/apps/transfer/src/services/modules/list-module.ts @@ -34,7 +34,7 @@ export const listModules = async ( ); const transaction = Pact.builder - .execution(Pact.modules['list-modules']()) + .execution('(list-modules)') .setMeta({ gasLimit, gasPrice, ttl, sender, chainId }) .setNetworkId(networkId) .createTransaction(); From 8c431e9ec63974ec98f2e10e3b36cd23a9857244 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 07:23:18 -0400 Subject: [PATCH 15/26] fix(transfer): local() return value typing --- .../chains/[chain]/modules/[module]/index.tsx | 19 +++++++++---- .../src/services/modules/describe-module.ts | 28 ++----------------- 2 files changed, 17 insertions(+), 30 deletions(-) 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 index 18409122bb..ee0ee46a6e 100644 --- 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 @@ -1,6 +1,5 @@ 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'; @@ -41,7 +40,7 @@ const ModulePage: FC = () => { const moduleName: string = module as string; const fetchModule = async (): Promise => { - const { data } = await describeModule( + const { result } = await describeModule( moduleName, chainId, typedNetwork, @@ -50,20 +49,30 @@ const ModulePage: FC = () => { 1000, ); - setPactCode(data?.code || ''); + if (result.status === 'failure') { + throw new Error(JSON.stringify(result.error)); + } + + const r = (result as unknown) as { + data: { + code: string; + interfaces: string[]; + } + } + setPactCode(r.data.code || ''); const moduleNameParts = moduleName.split('.'); const namespace = moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; const pactModule = new StringContractDefinition({ - contract: data?.code || '', + contract: r.data.code || '', namespace, }); setCapabilities(pactModule.getCapabilities(moduleName)); setFunctions(pactModule.getMethods(moduleName)); - setInterfaces(data?.interfaces || []); + setInterfaces(r.data.interfaces || []); }; fetchModule().catch(console.error); diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index 2ec66cfcb3..d2c11eea7b 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,4 +1,4 @@ -import { ChainwebChainId } from '@kadena/chainweb-node-client'; +import { ChainwebChainId, ILocalCommandResult } from '@kadena/chainweb-node-client'; import { getClient, Pact } from '@kadena/client'; import { @@ -8,13 +8,6 @@ import { } from '@/constants/kadena'; import { chainNetwork } from '@/constants/network'; import Debug from 'debug'; -import { PactValue } from '../../../../../libs/types/lib'; - -export interface IModuleResult { - reqKey?: string; - status?: string; - data?: PactValue; -} const debug = Debug('kadena-transfer:services:describe-module'); @@ -26,7 +19,7 @@ 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 networkId = chainNetwork[network].network; const { local } = getClient( @@ -42,23 +35,8 @@ export const describeModule = async ( .setNetworkId(networkId) .createTransaction(); - const response = await local(transaction, { + return await local(transaction, { preflight: false, signatureVerification: false, }); - - const { reqKey, result } = response; - - if (result.status === 'failure') { - return { - reqKey, - status: result.status, - }; - } - - return { - reqKey, - status: result.status, - data: result.data, - }; }; From d3d91e60cd417a73ee272b436f589cfa615f7646 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 07:33:10 -0400 Subject: [PATCH 16/26] fix(transfer): distinguish PactResultError better --- .../chains/[chain]/modules/[module]/index.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 index ee0ee46a6e..46dfbf0f65 100644 --- 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 @@ -49,30 +49,32 @@ const ModulePage: FC = () => { 1000, ); - if (result.status === 'failure') { + if (result.status === 'failure' && 'error' in result) { throw new Error(JSON.stringify(result.error)); } - const r = (result as unknown) as { + const resultSuccess = (result as unknown) as { data: { code: string; interfaces: string[]; } } - setPactCode(r.data.code || ''); + + const pactCode = resultSuccess.data.code || ''; + setPactCode(pactCode); const moduleNameParts = moduleName.split('.'); const namespace = moduleNameParts.length > 1 ? moduleNameParts[0] : undefined; const pactModule = new StringContractDefinition({ - contract: r.data.code || '', + contract: pactCode, namespace, }); setCapabilities(pactModule.getCapabilities(moduleName)); setFunctions(pactModule.getMethods(moduleName)); - setInterfaces(r.data.interfaces || []); + setInterfaces(resultSuccess.data.interfaces || []); }; fetchModule().catch(console.error); From 07eebf6478aa2383263f129d93aa5d049d2b01bf Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 07:53:18 -0400 Subject: [PATCH 17/26] fix(transfer): build issues --- .../transfer/src/services/faucet/index.ts | 4 +-- .../src/services/modules/describe-module.ts | 5 +++- .../transfer-tracker/get-transfer-status.ts | 26 ++++++++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 9fcddc30d3..977f4ba0da 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -39,8 +39,8 @@ export const fundExistingAccount = async ( new PactNumber(amount).toPactDecimal(), ), ) - .addSigner(FAUCET_PUBLIC_KEY, (withCap: any) => [withCap('coin.GAS')]) - .addSigner(keyPair.publicKey, (withCap: any) => [ + .addSigner(FAUCET_PUBLIC_KEY, (withCap) => [withCap('coin.GAS')]) + .addSigner(keyPair.publicKey, (withCap) => [ withCap( 'coin.TRANSFER', SENDER_ACCOUNT, diff --git a/packages/apps/transfer/src/services/modules/describe-module.ts b/packages/apps/transfer/src/services/modules/describe-module.ts index d2c11eea7b..e52a40a6a2 100644 --- a/packages/apps/transfer/src/services/modules/describe-module.ts +++ b/packages/apps/transfer/src/services/modules/describe-module.ts @@ -1,4 +1,7 @@ -import { ChainwebChainId, ILocalCommandResult } from '@kadena/chainweb-node-client'; +import { + ChainwebChainId, + ILocalCommandResult, +} from '@kadena/chainweb-node-client'; import { getClient, Pact } from '@kadena/client'; import { 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 60a532d297..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 @@ -194,17 +194,23 @@ export async function getXChainTransferInfo({ 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') { From a41d7528e870439a20687a3e5a6f1fa310338546 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 08:06:55 -0400 Subject: [PATCH 18/26] fix(transfer): linting & ts-ignore --- .../chains/[chain]/modules/[module]/index.tsx | 15 ++++++++++----- .../apps/transfer/src/services/faucet/index.ts | 2 ++ 2 files changed, 12 insertions(+), 5 deletions(-) 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 index 46dfbf0f65..e5c72b86b8 100644 --- 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 @@ -1,5 +1,6 @@ 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'; @@ -20,8 +21,12 @@ const ModulePage: FC = () => { Debug('kadena-transfer:pages:transfer:module-explorer:module'); const { t } = useTranslation('common'); const [pactCode, setPactCode] = useState(''); - const [functions, setFunctions] = useState | undefined>({}); - const [capabilities, setCapabilities] = useState | undefined>({}); + 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; @@ -53,12 +58,12 @@ const ModulePage: FC = () => { throw new Error(JSON.stringify(result.error)); } - const resultSuccess = (result as unknown) as { + const resultSuccess = result as unknown as { data: { code: string; interfaces: string[]; - } - } + }; + }; const pactCode = resultSuccess.data.code || ''; setPactCode(pactCode); diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 977f4ba0da..f450fa85a8 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -39,8 +39,10 @@ export const fundExistingAccount = async ( new PactNumber(amount).toPactDecimal(), ), ) + //@ts-ignore .addSigner(FAUCET_PUBLIC_KEY, (withCap) => [withCap('coin.GAS')]) .addSigner(keyPair.publicKey, (withCap) => [ + //@ts-ignore withCap( 'coin.TRANSFER', SENDER_ACCOUNT, From a2a5de7d459e76465f391fc733833f587ab2b366 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 09:19:04 -0400 Subject: [PATCH 19/26] fix(transfer): use @kadena/pactjs-cli:workspace:* --- common/config/rush/pnpm-lock.yaml | 58 +++++++------------ common/config/rush/repo-state.json | 2 +- packages/apps/docs/package.json | 2 +- packages/apps/graph-client/package.json | 2 +- packages/apps/graph/package.json | 2 +- .../src/pages/faucet/existing/index.tsx | 1 - .../transfer/account-transactions/index.tsx | 1 - .../pages/transfer/module-explorer/index.tsx | 1 - .../transfer/src/services/faucet/index.ts | 2 - 9 files changed, 24 insertions(+), 47 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 09b27b9eda..c3da21559f 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 @@ -282,7 +282,7 @@ importers: '@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:* @@ -334,8 +334,8 @@ importers: 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': link:../../libs/chainweb-node-client + '@kadena/client': link:../../libs/client '@kadena/cryptography-utils': link:../../libs/cryptography-utils '@kadena/pactjs': link:../../libs/pactjs '@kadena/pactjs-generator': link:../../libs/pactjs-generator @@ -354,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 @@ -361,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 @@ -1030,7 +1031,7 @@ importers: '@kadena/chainweb-node-client': workspace:* '@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 @@ -1048,7 +1049,7 @@ importers: '@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 @@ -6989,32 +6990,6 @@ 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==} - dependencies: - memfs: 3.5.3 - moo: 0.5.2 - nearley: 2.20.1 - yaml: 2.1.3 - dev: true - /@leichtgewicht/ip-codec/2.0.4: resolution: {integrity: sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==} dev: false @@ -14674,6 +14649,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==} @@ -20843,6 +20819,7 @@ packages: /moo/0.5.2: resolution: {integrity: sha512-iSAJLHYKnX41mKcJKjqvnAN9sf0LMDTXDEvFv+ffuRR9a1MIuXLjMNL6EsnDHSkKLTWNqQQ5uo61P4EbU4NU+Q==} + dev: false /mri/1.2.0: resolution: {integrity: sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==} @@ -20919,6 +20896,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==} @@ -23194,6 +23172,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==} @@ -23205,6 +23184,7 @@ packages: dependencies: discontinuous-range: 1.0.0 ret: 0.1.15 + dev: false /randombytes/2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} @@ -24124,6 +24104,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==} @@ -27558,6 +27539,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..4f62dcd5a9 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": "14f58180b4481d5493f46499af00b8b9a02067f3", "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/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 4da5230748..7b3a1012d7 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -151,7 +151,6 @@ const ExistingAccountFaucetPage: FC = () => { diff --git a/packages/apps/transfer/src/pages/transfer/account-transactions/index.tsx b/packages/apps/transfer/src/pages/transfer/account-transactions/index.tsx index 81dab54b1d..08c16fa9d4 100644 --- a/packages/apps/transfer/src/pages/transfer/account-transactions/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/account-transactions/index.tsx @@ -131,7 +131,6 @@ const CheckTransactions: FC = () => { 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 f7558b6c11..78369f23c8 100644 --- a/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx +++ b/packages/apps/transfer/src/pages/transfer/module-explorer/index.tsx @@ -76,7 +76,6 @@ const ModuleExplorer: FC = () => { [withCap('coin.GAS')]) .addSigner(keyPair.publicKey, (withCap) => [ - //@ts-ignore withCap( 'coin.TRANSFER', SENDER_ACCOUNT, From 130448ff9c918d3952a22bc33a0cd96a69a33fcc Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Mon, 24 Jul 2023 09:31:32 -0400 Subject: [PATCH 20/26] fix(transfer): prettier --- packages/apps/transfer/src/pages/faucet/existing/index.tsx | 5 +---- .../src/pages/transfer/account-transactions/index.tsx | 5 +---- .../transfer/src/pages/transfer/module-explorer/index.tsx | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 7b3a1012d7..c7b49d695a 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -148,10 +148,7 @@ const ExistingAccountFaucetPage: FC = () => { }} helperText={errors.name?.message ?? ''} /> - + { - + { - + Date: Tue, 25 Jul 2023 07:34:26 -0400 Subject: [PATCH 21/26] fix(transfer): resolve conflict --- packages/apps/transfer/src/pages/faucet/existing/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index c7b49d695a..2dd3b9a0a0 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -1,7 +1,4 @@ -<<<<<<< HEAD -import { IPollResponse, ICommandResult } from '@kadena/chainweb-node-client'; -======= ->>>>>>> 4e308226 (fix(transfer): faucet/existing) +import { ICommandResult } from '@kadena/chainweb-node-client'; import { Breadcrumbs, Button, From 67bcd2913d343fac38d7ef7dd3d58fcfe46dddbe Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Tue, 25 Jul 2023 07:53:08 -0400 Subject: [PATCH 22/26] fix(transfer): fix typo --- packages/apps/transfer/src/services/faucet/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apps/transfer/src/services/faucet/index.ts b/packages/apps/transfer/src/services/faucet/index.ts index 977f4ba0da..f5fe7f59f4 100644 --- a/packages/apps/transfer/src/services/faucet/index.ts +++ b/packages/apps/transfer/src/services/faucet/index.ts @@ -82,5 +82,5 @@ export const fundExistingAccount = async ( const requestKeys = await submit(transaction); - return await pollStatus(requestKeys; + return await pollStatus(requestKeys); }; From 89140256664caadd40f2f930afe51d40eeb475eb Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Tue, 25 Jul 2023 08:12:35 -0400 Subject: [PATCH 23/26] fix(transfer): prettier --- packages/apps/transfer/src/pages/faucet/existing/index.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/apps/transfer/src/pages/faucet/existing/index.tsx b/packages/apps/transfer/src/pages/faucet/existing/index.tsx index 2dd3b9a0a0..fd8ca60d21 100644 --- a/packages/apps/transfer/src/pages/faucet/existing/index.tsx +++ b/packages/apps/transfer/src/pages/faucet/existing/index.tsx @@ -79,7 +79,10 @@ const ExistingAccountFaucetPage: FC = () => { ); if (error) { - setRequestStatus({ status: 'erroneous', message: error.result.error?.message || t('An error occurred.')}); + setRequestStatus({ + status: 'erroneous', + message: error.result.error?.message || t('An error occurred.'), + }); return; } From 896dc11c0da095defe157d867a791311da4e91ee Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Tue, 25 Jul 2023 08:28:03 -0400 Subject: [PATCH 24/26] fix(transfer): use published build of chainweb-node-client --- packages/apps/transfer/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apps/transfer/package.json b/packages/apps/transfer/package.json index a1263f958c..5978379d77 100644 --- a/packages/apps/transfer/package.json +++ b/packages/apps/transfer/package.json @@ -20,7 +20,7 @@ "test": "jest --silent" }, "dependencies": { - "@kadena/chainweb-node-client": "workspace:*", + "@kadena/chainweb-node-client": "0.4.2", "@kadena/client": "workspace:*", "@kadena/cryptography-utils": "workspace:*", "@kadena/pactjs": "workspace:*", From 57a93a5d88ad778358fff421b3cfc85a430a5169 Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Tue, 25 Jul 2023 08:33:17 -0400 Subject: [PATCH 25/26] fix(transfer): update shrinkwrap --- common/config/rush/pnpm-lock.yaml | 38 ++++++++++++++++++++++++++++-- common/config/rush/repo-state.json | 2 +- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index c3da21559f..23b96e59cd 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -278,7 +278,7 @@ importers: '@kadena-dev/eslint-config': workspace:* '@kadena-dev/heft-rig': workspace:* '@kadena-dev/markdown': workspace:* - '@kadena/chainweb-node-client': workspace:* + '@kadena/chainweb-node-client': 0.4.2 '@kadena/client': workspace:* '@kadena/cryptography-utils': workspace:* '@kadena/pactjs': workspace:* @@ -334,7 +334,7 @@ importers: zod: ~3.18.0 dependencies: '@hookform/resolvers': 3.1.1_react-hook-form@7.45.2 - '@kadena/chainweb-node-client': link:../../libs/chainweb-node-client + '@kadena/chainweb-node-client': 0.4.2 '@kadena/client': link:../../libs/client '@kadena/cryptography-utils': link:../../libs/cryptography-utils '@kadena/pactjs': link:../../libs/pactjs @@ -6984,12 +6984,46 @@ packages: resolution: {integrity: sha512-dfLbk+PwWvFzSxwk3n5ySL0hfBog779o8h68wK/7/APo/7cgyWp5jcXockbxdk5kFRkbeXWm4Fbi9FrdN381sA==} dev: true + /@kadena/chainweb-node-client/0.4.2: + resolution: {integrity: sha512-jNSnp2f7/rBXmie8AtysjP4HKdZajlJne5zliF9PvZv/aXhtYoz2DkOuaFrCyxk5+BQXnfrHGxzJXTCF9dOjaw==} + requiresBuild: true + dependencies: + '@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 + transitivePeerDependencies: + - encoding + dev: false + + /@kadena/cryptography-utils/0.3.6: + resolution: {integrity: sha512-TsVmWRlqvJZDTf5Dzo21P4mwvHtyfFWT5xa5Mr2oz1m9GBsafQ8CmZfRwrdxIvw2ZppNdmU2V4ji0we9N9AARQ==} + dependencies: + '@kadena/types': 0.4.0 + blakejs: 1.2.1 + buffer: 6.0.3 + tweetnacl: 1.0.3 + dev: false + /@kadena/fonts/0.0.1: resolution: {integrity: sha512-epUOJbW96Yd827XQD2/6Ibow9qcevgPhVKsUhfzG9L26U4PLMMWZ0KXxIoFQ6DKpQa9xE4GK8DkPzn30pJb+3Q==} dependencies: lodash.kebabcase: 4.1.1 dev: false + /@kadena/pactjs/0.3.0: + resolution: {integrity: sha512-b0qIeJ3eAbuOaEbV9dNi9zzxciooeJWzSaeycKDhTbEWAbnKD6pXWRcYPojG2t0pNwMQZyb2kIRIV93D08E5bA==} + dependencies: + '@kadena/types': 0.4.0 + bignumber.js: 9.1.1 + dev: false + + /@kadena/types/0.4.0: + resolution: {integrity: sha512-fXId5LebFigIcMMG2JlPW/wMNf5sw81VqjoCVh7TmZnuMvT9YJDsYQahD8qdrXWxbFAssRXyIEe4oPsm2aQ5/Q==} + dev: false + /@leichtgewicht/ip-codec/2.0.4: resolution: {integrity: sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==} dev: false diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 4f62dcd5a9..40414d0926 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": "14f58180b4481d5493f46499af00b8b9a02067f3", + "pnpmShrinkwrapHash": "bed88c869c331bc54d13649902aac0d52ba3fbae", "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" } From 35d679b579d804789fa5ac0095f34f6b3d74208e Mon Sep 17 00:00:00 2001 From: Jesse van Muijden Date: Tue, 25 Jul 2023 08:39:05 -0400 Subject: [PATCH 26/26] fix(transfer): update shrinkwrap --- common/config/rush/repo-state.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index 40414d0926..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": "bed88c869c331bc54d13649902aac0d52ba3fbae", + "pnpmShrinkwrapHash": "2fed2990a8bc2bb4d427da20cab9aee46b9ae580", "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" }