create-dubhe 1.2.0-pre.123 → 1.2.0-pre.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +16 -1
- package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/Move.lock +2 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +1 -0
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2 -2
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +6 -6
- package/templates/contract/sui-template/src/dubhe/Move.lock +2 -2
- package/templates/contract/sui-template/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +1 -0
- package/templates/contract/sui-template/src/dubhe/sources/tests/fee_test.move +2 -2
- package/templates/contract/sui-template/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/contract/sui-template/src/dubhe/sources/tests/user_storage_test.move +6 -6
- package/templates/contract/sui-template/src/template/sources/codegen/dapp_key.move +16 -1
- package/templates/contract/sui-template/src/template/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/docker-compose.yml +2 -5
- package/templates/nextjs/sui-farm/packages/client/src/app/admin/page.tsx +618 -0
- package/templates/nextjs/sui-farm/packages/client/src/app/components/ProxyCard.tsx +1 -4
- package/templates/nextjs/sui-farm/packages/client/src/app/hooks/useSessionKey.ts +2 -4
- package/templates/nextjs/sui-farm/packages/client/src/app/page.tsx +125 -17
- package/templates/nextjs/sui-farm/packages/client/src/app/providers.tsx +4 -7
- package/templates/nextjs/sui-farm/packages/contracts/Dockerfile +1 -1
- package/templates/nextjs/sui-farm/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-farm/packages/contracts/src/harvest/sources/systems/crow_system.move +1 -5
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-template/packages/contracts/src/counter/sources/codegen/user_storage_init.move +6 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/Move.lock +2 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move +16 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +1 -0
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/fee_test.move +2 -2
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move +1 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move +6 -6
package/dist/cli.js
CHANGED
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bin/cli.ts","../src/config/chains.ts","../package.json","../src/exists.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport glob from 'fast-glob';\nimport yargsInteractive from 'yargs-interactive';\nimport { CHAINS } from '../config/chains';\nimport packageJson from '../../package.json';\nimport { exists } from '../exists';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst cwd = process.cwd();\n\nconst init = async () => {\n // Prepare chain options\n const chainChoices = CHAINS.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 1: Choose project name and chain\n const firstStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n projectName: {\n describe: 'Name your project',\n type: 'input'\n },\n chain: {\n describe: 'Pick your chain',\n type: 'list',\n choices: chainChoices.map((c) => c.value)\n },\n dubheVersion: {\n describe: 'The version of Dubhe packages to use, defaults to latest',\n type: 'input',\n default: packageJson.version\n }\n });\n\n const { projectName, chain, dubheVersion } = firstStep;\n if (!projectName) throw new Error('No project name provided.');\n\n // Get available templates based on the selected chain\n const selectedChain = CHAINS.find((c) => c.value === chain);\n if (!selectedChain) {\n throw new Error('Invalid chain selection');\n }\n\n // Prepare platform options\n const platformChoices = selectedChain.supportedTemplates.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 2: Choose platform\n const secondStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n platform: {\n describe: 'Pick your platform',\n type: 'list',\n choices: platformChoices.map((c) => c.value)\n }\n });\n\n const { platform } = secondStep;\n\n const selectedTemplate = selectedChain.supportedTemplates.find((t) => t.value === platform);\n if (!selectedTemplate) {\n throw new Error('Invalid platform selection');\n }\n\n const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);\n const pkgManager = pkgInfo ? pkgInfo.name : 'npm';\n\n const sourceDir = path.join(\n __dirname,\n '..',\n 'templates',\n selectedTemplate.path.replace('{chain}', chain)\n );\n\n if (!(await exists(sourceDir))) {\n throw new Error(`Template directory not found: ${sourceDir}`);\n }\n\n const destDir = path.join(process.cwd(), projectName);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const files = await glob('**/*', { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, 'utf-8');\n await fs.writeFile(destFile, source.replaceAll(/{{dubhe-version}}/g, dubheVersion), 'utf-8');\n } else if (/\\.gitignore_$/.test(sourceFile)) {\n await fs.copyFile(sourceFile, destFile.replace(/_$/, ''));\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n const cdProjectName = path.relative(cwd, destDir);\n\n const styles = {\n success: '\\x1b[32m%s\\x1b[0m',\n info: '\\x1b[36m%s\\x1b[0m',\n command: '\\x1b[33m%s\\x1b[0m',\n separator: '\\x1b[90m%s\\x1b[0m'\n };\n\n console.log('\\n' + '='.repeat(60));\n console.log(styles.success, '🎉 Project creation successful!');\n console.log(styles.info, `📁 Project location: ${destDir}`);\n console.log(styles.separator, '-'.repeat(60));\n console.log(styles.info, 'Next steps:\\n');\n\n if (destDir !== cwd) {\n console.log(\n styles.command,\n ` cd ${cdProjectName.includes(' ') ? `\"${cdProjectName}\"` : cdProjectName}`\n );\n }\n\n const actualTemplate = selectedTemplate.value;\n\n switch (actualTemplate) {\n case '101':\n case 'web':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n console.log(styles.command, ` ${pkgManager} run dev`);\n break;\n case 'contract':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n break;\n }\n\n console.log(styles.separator, '\\n' + '='.repeat(60) + '\\n');\n};\n\nfunction pkgFromUserAgent(userAgent: string | undefined) {\n if (!userAgent) return undefined;\n const pkgSpec = userAgent.split(' ')[0];\n const pkgSpecArr = pkgSpec.split('/');\n return {\n name: pkgSpecArr[0],\n version: pkgSpecArr[1]\n };\n}\n\ninit().catch((e) => {\n console.error(e);\n});\n","interface Template {\n title: string;\n description: string;\n value: string;\n path: string;\n}\n\ninterface Chain {\n title: string;\n description: string;\n value: string;\n supportedTemplates: Template[];\n}\n\nconst TEMPLATES = {\n QUICK_START: {\n title: '101',\n description: 'Quick start',\n value: '101',\n path: '101/{chain}-template'\n },\n WEB: {\n title: 'Web',\n description: 'Web template',\n value: 'web',\n path: 'nextjs/{chain}-template'\n },\n CONTRACT: {\n title: 'Contract',\n description: 'Contract template',\n value: 'contract',\n path: 'contract/{chain}-template'\n }\n} as const;\n\nexport const CHAINS: Chain[] = [\n {\n title: 'sui',\n description: 'Sui',\n value: 'sui',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'aptos',\n description: 'Aptos',\n value: 'aptos',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'rooch',\n description: 'Rooch',\n value: 'rooch',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'initia',\n description: 'Initia',\n value: 'initia',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'movement',\n description: 'Movement',\n value: 'movement',\n supportedTemplates: [TEMPLATES.QUICK_START]\n }\n];\n","{\n \"name\": \"create-dubhe\",\n \"version\": \"1.2.0-pre.123\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\n },\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run type-check && pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"cocos-js-build\": \"cd cocos-lib-builder && npm i && browserify aptos.js -p esmify > ../templates/cocos/aptos-template/assets/lib/dubhe.js && browserify sui.js -p esmify > ../templates/cocos/sui-template/assets/lib/dubhe.js\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"lint\": \"eslint . --ext .ts\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm lint && pnpm type-check\"\n },\n \"dependencies\": {\n \"browser-resolve\": \"^2.0.0\",\n \"browser-sync\": \"^2.29.3\",\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"browserify\": \"^17.0.0\",\n \"cross-spawn\": \"^7.0.3\",\n \"eslint\": \"^9.0.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"esmify\": \"^2.1.1\",\n \"kolorist\": \"^1.7.0\",\n \"prettier\": \"3.3.3\",\n \"prompts\": \"^2.4.2\",\n \"typescript\": \"^5.8.3\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import fs from 'node:fs/promises';\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,OAAOA,SAAQ;AACf,OAAO,UAAU;AACjB,OAAO,UAAU;AACjB,OAAO,sBAAsB;;;ACU7B,IAAM,YAAY;AAAA,EAChB,aAAa;AAAA,IACX,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,UAAU;AAAA,IACR,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AACF;AAEO,IAAM,SAAkB;AAAA,EAC7B;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,aA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IAAI,OAAO,SAAS,KAAK,UAAU,UAAU;AACrD,cAAQ,IAAI,OAAO,SAAS,KAAK,UAAU,eAAe;AAC1D;AAAA,EACJ;AAEA,UAAQ,IAAI,OAAO,WAAW,OAAO,IAAI,OAAO,EAAE,IAAI,IAAI;AAC5D;AAEA,SAAS,iBAAiB,WAA+B;AACvD,MAAI,CAAC,UAAW,QAAO;AACvB,QAAM,UAAU,UAAU,MAAM,GAAG,EAAE,CAAC;AACtC,QAAM,aAAa,QAAQ,MAAM,GAAG;AACpC,SAAO;AAAA,IACL,MAAM,WAAW,CAAC;AAAA,IAClB,SAAS,WAAW,CAAC;AAAA,EACvB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACjB,CAAC;","names":["fs","path","fs"]}
|
|
1
|
+
{"version":3,"sources":["../src/bin/cli.ts","../src/config/chains.ts","../package.json","../src/exists.ts"],"sourcesContent":["import { fileURLToPath } from 'node:url';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\nimport glob from 'fast-glob';\nimport yargsInteractive from 'yargs-interactive';\nimport { CHAINS } from '../config/chains';\nimport packageJson from '../../package.json';\nimport { exists } from '../exists';\n\nconst __filename = fileURLToPath(import.meta.url);\nconst __dirname = path.dirname(__filename);\n\nconst cwd = process.cwd();\n\nconst init = async () => {\n // Prepare chain options\n const chainChoices = CHAINS.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 1: Choose project name and chain\n const firstStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n projectName: {\n describe: 'Name your project',\n type: 'input'\n },\n chain: {\n describe: 'Pick your chain',\n type: 'list',\n choices: chainChoices.map((c) => c.value)\n },\n dubheVersion: {\n describe: 'The version of Dubhe packages to use, defaults to latest',\n type: 'input',\n default: packageJson.version\n }\n });\n\n const { projectName, chain, dubheVersion } = firstStep;\n if (!projectName) throw new Error('No project name provided.');\n\n // Get available templates based on the selected chain\n const selectedChain = CHAINS.find((c) => c.value === chain);\n if (!selectedChain) {\n throw new Error('Invalid chain selection');\n }\n\n // Prepare platform options\n const platformChoices = selectedChain.supportedTemplates.map(({ title, description, value }) => ({\n name: `${title} - ${description}`,\n value\n }));\n\n // Step 2: Choose platform\n const secondStep = await yargsInteractive()\n .usage('$0 [args]')\n .interactive({\n interactive: { default: true },\n platform: {\n describe: 'Pick your platform',\n type: 'list',\n choices: platformChoices.map((c) => c.value)\n }\n });\n\n const { platform } = secondStep;\n\n const selectedTemplate = selectedChain.supportedTemplates.find((t) => t.value === platform);\n if (!selectedTemplate) {\n throw new Error('Invalid platform selection');\n }\n\n const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);\n const pkgManager = pkgInfo ? pkgInfo.name : 'npm';\n\n const sourceDir = path.join(\n __dirname,\n '..',\n 'templates',\n selectedTemplate.path.replace('{chain}', chain)\n );\n\n if (!(await exists(sourceDir))) {\n throw new Error(`Template directory not found: ${sourceDir}`);\n }\n\n const destDir = path.join(process.cwd(), projectName);\n if (await exists(destDir)) {\n throw new Error(`Target directory \"${destDir}\" already exists.`);\n }\n\n const files = await glob('**/*', { cwd: sourceDir, dot: true });\n\n for (const filename of files) {\n const sourceFile = path.join(sourceDir, filename);\n const destFile = path.join(destDir, filename);\n\n await fs.mkdir(path.dirname(destFile), { recursive: true });\n\n if (/package\\.json$/.test(sourceFile)) {\n const source = await fs.readFile(sourceFile, 'utf-8');\n await fs.writeFile(destFile, source.replaceAll(/{{dubhe-version}}/g, dubheVersion), 'utf-8');\n } else if (/\\.gitignore_$/.test(sourceFile)) {\n await fs.copyFile(sourceFile, destFile.replace(/_$/, ''));\n } else {\n await fs.copyFile(sourceFile, destFile);\n }\n }\n\n const cdProjectName = path.relative(cwd, destDir);\n\n const styles = {\n success: '\\x1b[32m%s\\x1b[0m',\n info: '\\x1b[36m%s\\x1b[0m',\n command: '\\x1b[33m%s\\x1b[0m',\n separator: '\\x1b[90m%s\\x1b[0m'\n };\n\n console.log('\\n' + '='.repeat(60));\n console.log(styles.success, '🎉 Project creation successful!');\n console.log(styles.info, `📁 Project location: ${destDir}`);\n console.log(styles.separator, '-'.repeat(60));\n console.log(styles.info, 'Next steps:\\n');\n\n if (destDir !== cwd) {\n console.log(\n styles.command,\n ` cd ${cdProjectName.includes(' ') ? `\"${cdProjectName}\"` : cdProjectName}`\n );\n }\n\n const actualTemplate = selectedTemplate.value;\n\n switch (actualTemplate) {\n case '101':\n case 'web':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n console.log(styles.command, ` ${pkgManager} run dev`);\n break;\n case 'contract':\n console.log(styles.command, ` ${pkgManager} install`);\n console.log(styles.command, ` ${pkgManager} dubhe doctor`);\n break;\n }\n\n console.log(styles.separator, '\\n' + '='.repeat(60) + '\\n');\n};\n\nfunction pkgFromUserAgent(userAgent: string | undefined) {\n if (!userAgent) return undefined;\n const pkgSpec = userAgent.split(' ')[0];\n const pkgSpecArr = pkgSpec.split('/');\n return {\n name: pkgSpecArr[0],\n version: pkgSpecArr[1]\n };\n}\n\ninit().catch((e) => {\n console.error(e);\n});\n","interface Template {\n title: string;\n description: string;\n value: string;\n path: string;\n}\n\ninterface Chain {\n title: string;\n description: string;\n value: string;\n supportedTemplates: Template[];\n}\n\nconst TEMPLATES = {\n QUICK_START: {\n title: '101',\n description: 'Quick start',\n value: '101',\n path: '101/{chain}-template'\n },\n WEB: {\n title: 'Web',\n description: 'Web template',\n value: 'web',\n path: 'nextjs/{chain}-template'\n },\n CONTRACT: {\n title: 'Contract',\n description: 'Contract template',\n value: 'contract',\n path: 'contract/{chain}-template'\n }\n} as const;\n\nexport const CHAINS: Chain[] = [\n {\n title: 'sui',\n description: 'Sui',\n value: 'sui',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'aptos',\n description: 'Aptos',\n value: 'aptos',\n supportedTemplates: [TEMPLATES.QUICK_START, TEMPLATES.WEB, TEMPLATES.CONTRACT]\n },\n {\n title: 'rooch',\n description: 'Rooch',\n value: 'rooch',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'initia',\n description: 'Initia',\n value: 'initia',\n supportedTemplates: [TEMPLATES.QUICK_START]\n },\n {\n title: 'movement',\n description: 'Movement',\n value: 'movement',\n supportedTemplates: [TEMPLATES.QUICK_START]\n }\n];\n","{\n \"name\": \"create-dubhe\",\n \"version\": \"1.2.0-pre.124\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\n },\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"type\": \"module\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"build\": \"pnpm run type-check && pnpm run build:js\",\n \"build:js\": \"tsup && pnpm run copy-templates\",\n \"clean\": \"pnpm run clean:js\",\n \"clean:js\": \"shx rm -rf dist\",\n \"cocos-js-build\": \"cd cocos-lib-builder && npm i && browserify aptos.js -p esmify > ../templates/cocos/aptos-template/assets/lib/dubhe.js && browserify sui.js -p esmify > ../templates/cocos/sui-template/assets/lib/dubhe.js\",\n \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\n \"dev\": \"tsup --watch\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"lint\": \"eslint . --ext .ts\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm lint && pnpm type-check\"\n },\n \"dependencies\": {\n \"browser-resolve\": \"^2.0.0\",\n \"browser-sync\": \"^2.29.3\",\n \"fast-glob\": \"^3.3.3\",\n \"yargs-interactive\": \"^3.0.1\"\n },\n \"devDependencies\": {\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"@types/yargs-interactive\": \"^2.1.6\",\n \"browserify\": \"^17.0.0\",\n \"cross-spawn\": \"^7.0.3\",\n \"eslint\": \"^9.0.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"esmify\": \"^2.1.1\",\n \"kolorist\": \"^1.7.0\",\n \"prettier\": \"3.3.3\",\n \"prompts\": \"^2.4.2\",\n \"typescript\": \"^5.8.3\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n","import fs from 'node:fs/promises';\n\nexport async function exists(path: string) {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,OAAOA,SAAQ;AACf,OAAO,UAAU;AACjB,OAAO,UAAU;AACjB,OAAO,sBAAsB;;;ACU7B,IAAM,YAAY;AAAA,EAChB,aAAa;AAAA,IACX,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA,UAAU;AAAA,IACR,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AACF;AAEO,IAAM,SAAkB;AAAA,EAC7B;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,aAAa,UAAU,KAAK,UAAU,QAAQ;AAAA,EAC/E;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,aAAa,UAAU,KAAK,UAAU,QAAQ;AAAA,EAC/E;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,WAAW;AAAA,EAC5C;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aA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O;AAAA,IACL,MAAM,WAAW,CAAC;AAAA,IAClB,SAAS,WAAW,CAAC;AAAA,EACvB;AACF;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACjB,CAAC;","names":["fs","path","fs"]}
|
package/package.json
CHANGED
package/templates/101/sui-template/packages/contracts/src/counter/sources/codegen/dapp_key.move
CHANGED
|
@@ -8,10 +8,25 @@ module counter::dapp_key {
|
|
|
8
8
|
use sui::address;
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
-
///
|
|
11
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
12
|
+
///
|
|
13
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
14
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
15
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
16
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
17
|
+
/// as proof that the call originated from inside this package — an
|
|
18
|
+
/// external PTB cannot fabricate that proof.
|
|
19
|
+
///
|
|
20
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
21
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
22
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
23
|
+
/// user data or register UserStorages without going through the DApp's
|
|
24
|
+
/// own entry functions.
|
|
12
25
|
|
|
13
26
|
public struct DappKey has copy, drop {}
|
|
14
27
|
|
|
28
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
29
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
15
30
|
public(package) fun new(): DappKey {
|
|
16
31
|
DappKey {}
|
|
17
32
|
}
|
|
@@ -6,17 +6,21 @@
|
|
|
6
6
|
module counter::user_storage_init {
|
|
7
7
|
use dubhe::dapp_service::{DappHub, DappStorage};
|
|
8
8
|
use dubhe::dapp_system;
|
|
9
|
+
use counter::dapp_key;
|
|
9
10
|
use counter::dapp_key::DappKey;
|
|
11
|
+
use counter::migrate;
|
|
10
12
|
|
|
11
13
|
/// Create a UserStorage for the transaction sender within this DApp.
|
|
12
14
|
/// Must be called once before the user can interact with any user-level resources.
|
|
13
|
-
/// Aborts if the DApp
|
|
15
|
+
/// Aborts if the DApp version does not match this package, the DApp is paused,
|
|
16
|
+
/// or the framework version has advanced.
|
|
14
17
|
#[allow(lint(public_entry))]
|
|
15
18
|
public entry fun init_user_storage(
|
|
16
19
|
dapp_hub: &DappHub,
|
|
17
20
|
dapp_storage: &mut DappStorage,
|
|
18
21
|
ctx: &mut TxContext,
|
|
19
22
|
) {
|
|
20
|
-
dapp_system::
|
|
23
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
24
|
+
dapp_system::create_user_storage(dapp_key::new(), dapp_hub, dapp_storage, ctx);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
@@ -42,6 +42,6 @@ deps = { MoveStdlib = "MoveStdlib" }
|
|
|
42
42
|
|
|
43
43
|
[env.mainnet]
|
|
44
44
|
chain-id = "35834a8a"
|
|
45
|
-
original-published-id = "
|
|
46
|
-
latest-published-id = "
|
|
45
|
+
original-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
46
|
+
latest-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
47
47
|
published-version = "1"
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/codegen/dapp_key.move
CHANGED
|
@@ -8,10 +8,25 @@ module dubhe::dapp_key {
|
|
|
8
8
|
use sui::address;
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
-
///
|
|
11
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
12
|
+
///
|
|
13
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
14
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
15
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
16
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
17
|
+
/// as proof that the call originated from inside this package — an
|
|
18
|
+
/// external PTB cannot fabricate that proof.
|
|
19
|
+
///
|
|
20
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
21
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
22
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
23
|
+
/// user data or register UserStorages without going through the DApp's
|
|
24
|
+
/// own entry functions.
|
|
12
25
|
|
|
13
26
|
public struct DappKey has copy, drop {}
|
|
14
27
|
|
|
28
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
29
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
15
30
|
public(package) fun new(): DappKey {
|
|
16
31
|
DappKey {}
|
|
17
32
|
}
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move
CHANGED
|
@@ -147,6 +147,7 @@ public fun create_dapp<DappKey: copy + drop>(
|
|
|
147
147
|
/// canonical owner also cannot create a duplicate while their storage is held
|
|
148
148
|
/// by the proxy.
|
|
149
149
|
public fun create_user_storage<DappKey: copy + drop>(
|
|
150
|
+
_auth: DappKey,
|
|
150
151
|
dapp_hub: &DappHub,
|
|
151
152
|
dapp_storage: &mut DappStorage,
|
|
152
153
|
ctx: &mut TxContext,
|
|
@@ -700,7 +700,7 @@ fun test_create_user_storage_succeeds_at_correct_version() {
|
|
|
700
700
|
// Framework version == FRAMEWORK_VERSION (1) — must succeed.
|
|
701
701
|
assert!(dapp_service::framework_version(&dh) == dapp_system::framework_version());
|
|
702
702
|
|
|
703
|
-
dapp_system::create_user_storage
|
|
703
|
+
dapp_system::create_user_storage(FeeKey {}, &dh, &mut ds, ctx);
|
|
704
704
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
705
705
|
|
|
706
706
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -753,7 +753,7 @@ fun test_create_user_storage_aborts_after_framework_version_bump() {
|
|
|
753
753
|
dapp_service::set_framework_version(&mut dh, 2);
|
|
754
754
|
|
|
755
755
|
// This package still has FRAMEWORK_VERSION = 1, so the call must abort.
|
|
756
|
-
dapp_system::create_user_storage
|
|
756
|
+
dapp_system::create_user_storage(FeeKey {}, &dh, &mut ds, ctx);
|
|
757
757
|
|
|
758
758
|
dapp_system::destroy_dapp_hub(dh);
|
|
759
759
|
dapp_system::destroy_dapp_storage(ds);
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/integration_test.move
CHANGED
|
@@ -251,7 +251,7 @@ fun test_user_can_always_create_storage() {
|
|
|
251
251
|
test_scenario::next_tx(&mut scenario, USER_A);
|
|
252
252
|
{
|
|
253
253
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
254
|
-
dapp_system::create_user_storage
|
|
254
|
+
dapp_system::create_user_storage(GameKey {}, &dh, &mut ds, ctx);
|
|
255
255
|
assert!(dapp_service::has_registered_user_storage(&ds, USER_A));
|
|
256
256
|
};
|
|
257
257
|
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/tests/user_storage_test.move
CHANGED
|
@@ -83,7 +83,7 @@ fun test_create_user_storage_registers_address() {
|
|
|
83
83
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
84
84
|
|
|
85
85
|
assert!(!dapp_service::has_registered_user_storage(&ds, sender));
|
|
86
|
-
dapp_system::create_user_storage
|
|
86
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
87
87
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
88
88
|
|
|
89
89
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -101,9 +101,9 @@ fun test_create_user_storage_twice_aborts() {
|
|
|
101
101
|
let (dh, mut ds) = setup(&mut scenario);
|
|
102
102
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
103
103
|
|
|
104
|
-
dapp_system::create_user_storage
|
|
104
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
105
105
|
// Second call from the same address must abort with user_storage_already_exists.
|
|
106
|
-
dapp_system::create_user_storage
|
|
106
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
107
107
|
|
|
108
108
|
dapp_system::destroy_dapp_hub(dh);
|
|
109
109
|
dapp_system::destroy_dapp_storage(ds);
|
|
@@ -122,13 +122,13 @@ fun test_different_users_can_each_create_one_user_storage() {
|
|
|
122
122
|
|
|
123
123
|
// user_a creates their storage.
|
|
124
124
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
125
|
-
dapp_system::create_user_storage
|
|
125
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
126
126
|
assert!(dapp_service::has_registered_user_storage(&ds, user_a));
|
|
127
127
|
|
|
128
128
|
// user_b creates theirs in a new tx.
|
|
129
129
|
test_scenario::next_tx(&mut scenario, user_b);
|
|
130
130
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
131
|
-
dapp_system::create_user_storage
|
|
131
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
132
132
|
assert!(dapp_service::has_registered_user_storage(&ds, user_b));
|
|
133
133
|
|
|
134
134
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -150,7 +150,7 @@ fun test_create_user_storage_succeeds_after_registration_check() {
|
|
|
150
150
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
151
151
|
|
|
152
152
|
// Must succeed.
|
|
153
|
-
dapp_system::create_user_storage
|
|
153
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
154
154
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
155
155
|
|
|
156
156
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -42,6 +42,6 @@ deps = { MoveStdlib = "MoveStdlib" }
|
|
|
42
42
|
|
|
43
43
|
[env.mainnet]
|
|
44
44
|
chain-id = "35834a8a"
|
|
45
|
-
original-published-id = "
|
|
46
|
-
latest-published-id = "
|
|
45
|
+
original-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
46
|
+
latest-published-id = "0x6cb54e8bbcf59cc976584330689073500af755b12d85bf4f56d7eea9f232b8aa"
|
|
47
47
|
published-version = "1"
|
|
@@ -8,10 +8,25 @@ module dubhe::dapp_key {
|
|
|
8
8
|
use sui::address;
|
|
9
9
|
use std::ascii::String;
|
|
10
10
|
|
|
11
|
-
///
|
|
11
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
12
|
+
///
|
|
13
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
14
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
15
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
16
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
17
|
+
/// as proof that the call originated from inside this package — an
|
|
18
|
+
/// external PTB cannot fabricate that proof.
|
|
19
|
+
///
|
|
20
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
21
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
22
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
23
|
+
/// user data or register UserStorages without going through the DApp's
|
|
24
|
+
/// own entry functions.
|
|
12
25
|
|
|
13
26
|
public struct DappKey has copy, drop {}
|
|
14
27
|
|
|
28
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
29
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
15
30
|
public(package) fun new(): DappKey {
|
|
16
31
|
DappKey {}
|
|
17
32
|
}
|
|
@@ -147,6 +147,7 @@ public fun create_dapp<DappKey: copy + drop>(
|
|
|
147
147
|
/// canonical owner also cannot create a duplicate while their storage is held
|
|
148
148
|
/// by the proxy.
|
|
149
149
|
public fun create_user_storage<DappKey: copy + drop>(
|
|
150
|
+
_auth: DappKey,
|
|
150
151
|
dapp_hub: &DappHub,
|
|
151
152
|
dapp_storage: &mut DappStorage,
|
|
152
153
|
ctx: &mut TxContext,
|
|
@@ -700,7 +700,7 @@ fun test_create_user_storage_succeeds_at_correct_version() {
|
|
|
700
700
|
// Framework version == FRAMEWORK_VERSION (1) — must succeed.
|
|
701
701
|
assert!(dapp_service::framework_version(&dh) == dapp_system::framework_version());
|
|
702
702
|
|
|
703
|
-
dapp_system::create_user_storage
|
|
703
|
+
dapp_system::create_user_storage(FeeKey {}, &dh, &mut ds, ctx);
|
|
704
704
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
705
705
|
|
|
706
706
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -753,7 +753,7 @@ fun test_create_user_storage_aborts_after_framework_version_bump() {
|
|
|
753
753
|
dapp_service::set_framework_version(&mut dh, 2);
|
|
754
754
|
|
|
755
755
|
// This package still has FRAMEWORK_VERSION = 1, so the call must abort.
|
|
756
|
-
dapp_system::create_user_storage
|
|
756
|
+
dapp_system::create_user_storage(FeeKey {}, &dh, &mut ds, ctx);
|
|
757
757
|
|
|
758
758
|
dapp_system::destroy_dapp_hub(dh);
|
|
759
759
|
dapp_system::destroy_dapp_storage(ds);
|
|
@@ -251,7 +251,7 @@ fun test_user_can_always_create_storage() {
|
|
|
251
251
|
test_scenario::next_tx(&mut scenario, USER_A);
|
|
252
252
|
{
|
|
253
253
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
254
|
-
dapp_system::create_user_storage
|
|
254
|
+
dapp_system::create_user_storage(GameKey {}, &dh, &mut ds, ctx);
|
|
255
255
|
assert!(dapp_service::has_registered_user_storage(&ds, USER_A));
|
|
256
256
|
};
|
|
257
257
|
|
|
@@ -83,7 +83,7 @@ fun test_create_user_storage_registers_address() {
|
|
|
83
83
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
84
84
|
|
|
85
85
|
assert!(!dapp_service::has_registered_user_storage(&ds, sender));
|
|
86
|
-
dapp_system::create_user_storage
|
|
86
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
87
87
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
88
88
|
|
|
89
89
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -101,9 +101,9 @@ fun test_create_user_storage_twice_aborts() {
|
|
|
101
101
|
let (dh, mut ds) = setup(&mut scenario);
|
|
102
102
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
103
103
|
|
|
104
|
-
dapp_system::create_user_storage
|
|
104
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
105
105
|
// Second call from the same address must abort with user_storage_already_exists.
|
|
106
|
-
dapp_system::create_user_storage
|
|
106
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
107
107
|
|
|
108
108
|
dapp_system::destroy_dapp_hub(dh);
|
|
109
109
|
dapp_system::destroy_dapp_storage(ds);
|
|
@@ -122,13 +122,13 @@ fun test_different_users_can_each_create_one_user_storage() {
|
|
|
122
122
|
|
|
123
123
|
// user_a creates their storage.
|
|
124
124
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
125
|
-
dapp_system::create_user_storage
|
|
125
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
126
126
|
assert!(dapp_service::has_registered_user_storage(&ds, user_a));
|
|
127
127
|
|
|
128
128
|
// user_b creates theirs in a new tx.
|
|
129
129
|
test_scenario::next_tx(&mut scenario, user_b);
|
|
130
130
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
131
|
-
dapp_system::create_user_storage
|
|
131
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
132
132
|
assert!(dapp_service::has_registered_user_storage(&ds, user_b));
|
|
133
133
|
|
|
134
134
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -150,7 +150,7 @@ fun test_create_user_storage_succeeds_after_registration_check() {
|
|
|
150
150
|
let ctx = test_scenario::ctx(&mut scenario);
|
|
151
151
|
|
|
152
152
|
// Must succeed.
|
|
153
|
-
dapp_system::create_user_storage
|
|
153
|
+
dapp_system::create_user_storage(UsTestKey {}, &dh, &mut ds, ctx);
|
|
154
154
|
assert!(dapp_service::has_registered_user_storage(&ds, sender));
|
|
155
155
|
|
|
156
156
|
dapp_system::destroy_dapp_hub(dh);
|
|
@@ -9,10 +9,25 @@ module template::dapp_key {
|
|
|
9
9
|
use sui::address;
|
|
10
10
|
use std::ascii::String;
|
|
11
11
|
|
|
12
|
-
///
|
|
12
|
+
/// DappKey — package-level authorization token for this DApp.
|
|
13
|
+
///
|
|
14
|
+
/// SECURITY: `new()` is intentionally `public(package)`.
|
|
15
|
+
/// Only code compiled into this package can construct a DappKey instance.
|
|
16
|
+
/// All framework write functions (`set_record`, `set_field`,
|
|
17
|
+
/// `take_record`, `create_user_storage`, …) require `_auth: DappKey`
|
|
18
|
+
/// as proof that the call originated from inside this package — an
|
|
19
|
+
/// external PTB cannot fabricate that proof.
|
|
20
|
+
///
|
|
21
|
+
/// NEVER change `new()` to `public`, and never accept a DappKey
|
|
22
|
+
/// value as a parameter from an external caller. Either mistake removes
|
|
23
|
+
/// every package-level access guard, allowing any PTB to write arbitrary
|
|
24
|
+
/// user data or register UserStorages without going through the DApp's
|
|
25
|
+
/// own entry functions.
|
|
13
26
|
|
|
14
27
|
public struct DappKey has copy, drop {}
|
|
15
28
|
|
|
29
|
+
/// Constructs an authorization token. Callable only from within this package.
|
|
30
|
+
/// Pass the result as `_auth` to any framework function that requires it.
|
|
16
31
|
public(package) fun new(): DappKey {
|
|
17
32
|
DappKey {}
|
|
18
33
|
}
|
|
@@ -7,17 +7,21 @@
|
|
|
7
7
|
module template::user_storage_init {
|
|
8
8
|
use dubhe::dapp_service::{DappHub, DappStorage};
|
|
9
9
|
use dubhe::dapp_system;
|
|
10
|
+
use template::dapp_key;
|
|
10
11
|
use template::dapp_key::DappKey;
|
|
12
|
+
use template::migrate;
|
|
11
13
|
|
|
12
14
|
/// Create a UserStorage for the transaction sender within this DApp.
|
|
13
15
|
/// Must be called once before the user can interact with any user-level resources.
|
|
14
|
-
/// Aborts if the DApp
|
|
16
|
+
/// Aborts if the DApp version does not match this package, the DApp is paused,
|
|
17
|
+
/// or the framework version has advanced.
|
|
15
18
|
#[allow(lint(public_entry))]
|
|
16
19
|
public entry fun init_user_storage(
|
|
17
20
|
dapp_hub: &DappHub,
|
|
18
21
|
dapp_storage: &mut DappStorage,
|
|
19
22
|
ctx: &mut TxContext,
|
|
20
23
|
) {
|
|
21
|
-
dapp_system::
|
|
24
|
+
dapp_system::ensure_latest_version<DappKey>(dapp_storage, migrate::on_chain_version());
|
|
25
|
+
dapp_system::create_user_storage(dapp_key::new(), dapp_hub, dapp_storage, ctx);
|
|
22
26
|
}
|
|
23
27
|
}
|
|
@@ -17,19 +17,16 @@ services:
|
|
|
17
17
|
retries: 5
|
|
18
18
|
|
|
19
19
|
graphql-server:
|
|
20
|
-
build:
|
|
21
|
-
# Build context is monorepo root so Dockerfile can COPY from packages/graphql-server
|
|
22
|
-
context: ../../..
|
|
23
|
-
dockerfile: templates/nextjs/sui-farm/packages/contracts/Dockerfile
|
|
20
|
+
build: ./packages/contracts
|
|
24
21
|
ports:
|
|
25
22
|
- '4000:4000'
|
|
26
23
|
environment:
|
|
27
24
|
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/postgres
|
|
28
|
-
- NODE_ENV=development
|
|
29
25
|
depends_on:
|
|
30
26
|
postgres:
|
|
31
27
|
condition: service_healthy
|
|
32
28
|
restart: always
|
|
29
|
+
command: npx @0xobelisk/graphql-server start
|
|
33
30
|
healthcheck:
|
|
34
31
|
test: ['CMD', 'wget', '-qO-', 'http://127.0.0.1:4000/health']
|
|
35
32
|
interval: 10s
|