create-dubhe 1.2.0-pre.60 → 1.2.0-pre.62
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/dubhe/sources/core/events.move +9 -9
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +16 -10
- package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move +41 -1
- package/templates/contract/sui-template/src/dubhe/sources/core/events.move +9 -9
- package/templates/contract/sui-template/src/dubhe/sources/systems/dapp_system.move +16 -10
- package/templates/contract/sui-template/src/dubhe/sources/systems/entity_id.move +41 -1
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/core/events.move +9 -9
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move +16 -10
- package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move +41 -1
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 defaultTargetDir = 'dubhe-template-project';\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.60\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"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 \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\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 \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm type-check\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\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/yargs-interactive\": \"^2.1.6\",\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"cross-spawn\": \"^7.0.3\",\n \"kolorist\": \"^1.7.0\",\n \"prompts\": \"^2.4.2\",\n \"tsc\": \"^2.0.4\",\n \"esmify\": \"^2.1.1\",\n \"browserify\": \"^17.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"prettier\": \"3.3.3\"\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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,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 defaultTargetDir = 'dubhe-template-project';\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.62\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"team@obelisk.build\",\n \"bin\": \"bin/cli.js\",\n \"files\": [\n \"bin\",\n \"dist\",\n \"templates\"\n ],\n \"scripts\": {\n \"dev\": \"tsup --watch\",\n \"build\": \"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 \"copy-templates\": \"tsx ./scripts/copy-templates.ts\",\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 \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"type-check\": \"tsc --noEmit\",\n \"validate\": \"pnpm format:check && pnpm type-check\"\n },\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"engines\": {\n \"node\": \">=22.0.0\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/0xobelisk/dubhe.git\"\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/yargs-interactive\": \"^2.1.6\",\n \"@types/cross-spawn\": \"^6.0.2\",\n \"@types/minimist\": \"^1.2.2\",\n \"@types/prompts\": \"^2.4.3\",\n \"cross-spawn\": \"^7.0.3\",\n \"kolorist\": \"^1.7.0\",\n \"prompts\": \"^2.4.2\",\n \"tsc\": \"^2.0.4\",\n \"esmify\": \"^2.1.1\",\n \"browserify\": \"^17.0.0\",\n \"eslint\": \"^8.56.0\",\n \"eslint-config-prettier\": \"^9.1.0\",\n \"prettier\": \"3.3.3\"\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,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,WAAW;AAAA,EAC5C;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,IACb,OAAO;AAAA,IACP,oBAAoB,CAAC,UAAU,WAAW;AAAA,EA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 +4,15 @@ use sui::event;
|
|
|
4
4
|
use std::ascii::String;
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
public struct
|
|
7
|
+
public struct Dubhe_Store_SetRecord has copy, drop {
|
|
8
8
|
dapp_key: String,
|
|
9
9
|
table_id: String,
|
|
10
10
|
key_tuple: vector<vector<u8>>,
|
|
11
11
|
value_tuple: vector<vector<u8>>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>):
|
|
15
|
-
|
|
14
|
+
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>): Dubhe_Store_SetRecord {
|
|
15
|
+
Dubhe_Store_SetRecord {
|
|
16
16
|
dapp_key,
|
|
17
17
|
table_id,
|
|
18
18
|
key_tuple,
|
|
@@ -24,7 +24,7 @@ public fun emit_store_set_record(dapp_key: String, table_id: String, key_tuple:
|
|
|
24
24
|
event::emit(new_store_set_record(dapp_key, table_id, key_tuple, value_tuple));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public struct
|
|
27
|
+
public struct Dubhe_Store_SetField has copy, drop {
|
|
28
28
|
dapp_key: String,
|
|
29
29
|
table_id: String,
|
|
30
30
|
key_tuple: vector<vector<u8>>,
|
|
@@ -32,8 +32,8 @@ public struct Store_SetField has copy, drop {
|
|
|
32
32
|
value: vector<u8>
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>):
|
|
36
|
-
|
|
35
|
+
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>): Dubhe_Store_SetField {
|
|
36
|
+
Dubhe_Store_SetField {
|
|
37
37
|
dapp_key,
|
|
38
38
|
table_id,
|
|
39
39
|
key_tuple,
|
|
@@ -46,14 +46,14 @@ public fun emit_store_set_field(dapp_key: String, table_id: String, key_tuple: v
|
|
|
46
46
|
event::emit(new_store_set_field(dapp_key, table_id, key_tuple, field_index, value));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
public struct
|
|
49
|
+
public struct Dubhe_Store_DeleteRecord has copy, drop {
|
|
50
50
|
dapp_key: String,
|
|
51
51
|
table_id: String,
|
|
52
52
|
key_tuple: vector<vector<u8>>
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>):
|
|
56
|
-
|
|
55
|
+
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>): Dubhe_Store_DeleteRecord {
|
|
56
|
+
Dubhe_Store_DeleteRecord {
|
|
57
57
|
dapp_key,
|
|
58
58
|
table_id,
|
|
59
59
|
key_tuple
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move
CHANGED
|
@@ -70,7 +70,7 @@ public fun set_record<DappKey: copy + drop>(
|
|
|
70
70
|
);
|
|
71
71
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
72
72
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
73
|
-
dapp_already_delegated_error(enabled);
|
|
73
|
+
dapp_already_delegated_error(!enabled);
|
|
74
74
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, 1);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -95,7 +95,7 @@ public fun set_field<DappKey: copy + drop>(
|
|
|
95
95
|
);
|
|
96
96
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
97
97
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
98
|
-
dapp_already_delegated_error(enabled);
|
|
98
|
+
dapp_already_delegated_error(!enabled);
|
|
99
99
|
charge_fee(dh, dapp_key, key_tuple, vector[value], 1);
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -115,7 +115,7 @@ public fun delete_record<DappKey: copy + drop>(
|
|
|
115
115
|
);
|
|
116
116
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
117
117
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
118
|
-
dapp_already_delegated_error(enabled);
|
|
118
|
+
dapp_already_delegated_error(!enabled);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/// Get a record
|
|
@@ -180,14 +180,14 @@ public fun create_dapp<DappKey: copy + drop>(
|
|
|
180
180
|
dapp_service::create_dapp(dh, dapp_key, ctx);
|
|
181
181
|
let dubhe_dapp_key = dapp_key::new();
|
|
182
182
|
if(!dapp_key::eq(&dapp_key, &dubhe_dapp_key)) {
|
|
183
|
-
initialize_metadata(dh,
|
|
184
|
-
initialize_fee_state(dh
|
|
183
|
+
initialize_metadata<DappKey>(dh, name, description, clock, ctx);
|
|
184
|
+
initialize_fee_state<DappKey>(dh);
|
|
185
|
+
initialize_dapp_proxy<DappKey>(dh);
|
|
185
186
|
};
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
public fun initialize_metadata<DappKey: copy + drop>(
|
|
189
|
+
public(package) fun initialize_metadata<DappKey: copy + drop>(
|
|
189
190
|
dh: &mut DappHub,
|
|
190
|
-
_: DappKey,
|
|
191
191
|
name: String,
|
|
192
192
|
description: String,
|
|
193
193
|
clock: &Clock,
|
|
@@ -218,9 +218,8 @@ public fun initialize_metadata<DappKey: copy + drop>(
|
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
public fun initialize_fee_state<DappKey: copy + drop>(
|
|
221
|
+
public(package) fun initialize_fee_state<DappKey: copy + drop>(
|
|
222
222
|
dh: &mut DappHub,
|
|
223
|
-
_: DappKey,
|
|
224
223
|
) {
|
|
225
224
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
226
225
|
let (free_credit, base_fee, byte_fee) = dapp_fee_config::get(dh);
|
|
@@ -236,6 +235,13 @@ public fun initialize_fee_state<DappKey: copy + drop>(
|
|
|
236
235
|
);
|
|
237
236
|
}
|
|
238
237
|
|
|
238
|
+
public(package) fun initialize_dapp_proxy<DappKey: copy + drop>(
|
|
239
|
+
dh: &mut DappHub,
|
|
240
|
+
) {
|
|
241
|
+
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
242
|
+
dapp_proxy::set(dh, dapp_key, @0x0, false);
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
public fun upgrade_dapp<DappKey: copy + drop>(
|
|
240
246
|
dh: &mut DappHub,
|
|
241
247
|
_: DappKey,
|
|
@@ -417,7 +423,7 @@ public fun set_storage<DappKey: copy + drop>(
|
|
|
417
423
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
418
424
|
dapp_proxy::ensure_has(dh, dapp_key);
|
|
419
425
|
let (delegator, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
420
|
-
dapp_not_been_delegated_error(
|
|
426
|
+
dapp_not_been_delegated_error(enabled);
|
|
421
427
|
no_permission_error(delegator == ctx.sender());
|
|
422
428
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, count);
|
|
423
429
|
dapp_service::set_record_internal(dh, dapp_key, table_id, key_tuple, value_tuple);
|
package/templates/101/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module dubhe::entity_id {
|
|
2
|
-
use sui::hash::blake2b256;
|
|
2
|
+
use sui::hash::{blake2b256, keccak256};
|
|
3
3
|
use sui::address;
|
|
4
4
|
use std::ascii::{String};
|
|
5
|
+
use std::vector;
|
|
6
|
+
use std::bcs;
|
|
7
|
+
use sui::object::{Self};
|
|
5
8
|
|
|
6
9
|
public fun asset_to_entity_id(name: String, asset_id: u256): address {
|
|
7
10
|
let mut raw_bytes = vector::empty();
|
|
@@ -11,4 +14,41 @@ module dubhe::entity_id {
|
|
|
11
14
|
let entity_id_bytes = blake2b256(&raw_bytes);
|
|
12
15
|
address::from_bytes(entity_id_bytes)
|
|
13
16
|
}
|
|
17
|
+
|
|
18
|
+
/// Generate entity key from an object
|
|
19
|
+
public fun object_address<T:key>(obj: &T): address {
|
|
20
|
+
obj.key().id().address()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Generate entity key from bytes using keccak256 hash
|
|
24
|
+
public fun entity_key_from_bytes(bytes: vector<u8>): address {
|
|
25
|
+
let hash_bytes = keccak256(&bytes);
|
|
26
|
+
address::from_bytes(hash_bytes)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Generate entity key from address concatenated with seed string
|
|
30
|
+
public fun entity_key_from_address_with_seed(object_id: address, seed: String): address {
|
|
31
|
+
let mut combined_bytes = vector::empty();
|
|
32
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
33
|
+
combined_bytes.append(seed.into_bytes());
|
|
34
|
+
entity_key_from_bytes(combined_bytes)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Generate entity key from address concatenated with u256 value
|
|
38
|
+
public fun entity_key_from_address_with_u256(object_id: address, x: u256): address {
|
|
39
|
+
let mut combined_bytes = vector::empty();
|
|
40
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
41
|
+
let x_bytes = bcs::to_bytes(&x);
|
|
42
|
+
combined_bytes.append(x_bytes);
|
|
43
|
+
entity_key_from_bytes(combined_bytes)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Generate entity key from u256 value (converts to address format)
|
|
47
|
+
/// This uses BCS serialization to convert u256 to bytes, then hashes
|
|
48
|
+
public fun entity_key_from_u256(x: u256): address {
|
|
49
|
+
let bytes = bcs::to_bytes(&x);
|
|
50
|
+
// Add a suffix to make it more unique, similar to the Aptos example
|
|
51
|
+
vector::append(&mut bytes, b"u256");
|
|
52
|
+
entity_key_from_bytes(bytes)
|
|
53
|
+
}
|
|
14
54
|
}
|
|
@@ -4,15 +4,15 @@ use sui::event;
|
|
|
4
4
|
use std::ascii::String;
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
public struct
|
|
7
|
+
public struct Dubhe_Store_SetRecord has copy, drop {
|
|
8
8
|
dapp_key: String,
|
|
9
9
|
table_id: String,
|
|
10
10
|
key_tuple: vector<vector<u8>>,
|
|
11
11
|
value_tuple: vector<vector<u8>>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>):
|
|
15
|
-
|
|
14
|
+
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>): Dubhe_Store_SetRecord {
|
|
15
|
+
Dubhe_Store_SetRecord {
|
|
16
16
|
dapp_key,
|
|
17
17
|
table_id,
|
|
18
18
|
key_tuple,
|
|
@@ -24,7 +24,7 @@ public fun emit_store_set_record(dapp_key: String, table_id: String, key_tuple:
|
|
|
24
24
|
event::emit(new_store_set_record(dapp_key, table_id, key_tuple, value_tuple));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public struct
|
|
27
|
+
public struct Dubhe_Store_SetField has copy, drop {
|
|
28
28
|
dapp_key: String,
|
|
29
29
|
table_id: String,
|
|
30
30
|
key_tuple: vector<vector<u8>>,
|
|
@@ -32,8 +32,8 @@ public struct Store_SetField has copy, drop {
|
|
|
32
32
|
value: vector<u8>
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>):
|
|
36
|
-
|
|
35
|
+
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>): Dubhe_Store_SetField {
|
|
36
|
+
Dubhe_Store_SetField {
|
|
37
37
|
dapp_key,
|
|
38
38
|
table_id,
|
|
39
39
|
key_tuple,
|
|
@@ -46,14 +46,14 @@ public fun emit_store_set_field(dapp_key: String, table_id: String, key_tuple: v
|
|
|
46
46
|
event::emit(new_store_set_field(dapp_key, table_id, key_tuple, field_index, value));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
public struct
|
|
49
|
+
public struct Dubhe_Store_DeleteRecord has copy, drop {
|
|
50
50
|
dapp_key: String,
|
|
51
51
|
table_id: String,
|
|
52
52
|
key_tuple: vector<vector<u8>>
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>):
|
|
56
|
-
|
|
55
|
+
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>): Dubhe_Store_DeleteRecord {
|
|
56
|
+
Dubhe_Store_DeleteRecord {
|
|
57
57
|
dapp_key,
|
|
58
58
|
table_id,
|
|
59
59
|
key_tuple
|
|
@@ -70,7 +70,7 @@ public fun set_record<DappKey: copy + drop>(
|
|
|
70
70
|
);
|
|
71
71
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
72
72
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
73
|
-
dapp_already_delegated_error(enabled);
|
|
73
|
+
dapp_already_delegated_error(!enabled);
|
|
74
74
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, 1);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -95,7 +95,7 @@ public fun set_field<DappKey: copy + drop>(
|
|
|
95
95
|
);
|
|
96
96
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
97
97
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
98
|
-
dapp_already_delegated_error(enabled);
|
|
98
|
+
dapp_already_delegated_error(!enabled);
|
|
99
99
|
charge_fee(dh, dapp_key, key_tuple, vector[value], 1);
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -115,7 +115,7 @@ public fun delete_record<DappKey: copy + drop>(
|
|
|
115
115
|
);
|
|
116
116
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
117
117
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
118
|
-
dapp_already_delegated_error(enabled);
|
|
118
|
+
dapp_already_delegated_error(!enabled);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/// Get a record
|
|
@@ -180,14 +180,14 @@ public fun create_dapp<DappKey: copy + drop>(
|
|
|
180
180
|
dapp_service::create_dapp(dh, dapp_key, ctx);
|
|
181
181
|
let dubhe_dapp_key = dapp_key::new();
|
|
182
182
|
if(!dapp_key::eq(&dapp_key, &dubhe_dapp_key)) {
|
|
183
|
-
initialize_metadata(dh,
|
|
184
|
-
initialize_fee_state(dh
|
|
183
|
+
initialize_metadata<DappKey>(dh, name, description, clock, ctx);
|
|
184
|
+
initialize_fee_state<DappKey>(dh);
|
|
185
|
+
initialize_dapp_proxy<DappKey>(dh);
|
|
185
186
|
};
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
public fun initialize_metadata<DappKey: copy + drop>(
|
|
189
|
+
public(package) fun initialize_metadata<DappKey: copy + drop>(
|
|
189
190
|
dh: &mut DappHub,
|
|
190
|
-
_: DappKey,
|
|
191
191
|
name: String,
|
|
192
192
|
description: String,
|
|
193
193
|
clock: &Clock,
|
|
@@ -218,9 +218,8 @@ public fun initialize_metadata<DappKey: copy + drop>(
|
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
public fun initialize_fee_state<DappKey: copy + drop>(
|
|
221
|
+
public(package) fun initialize_fee_state<DappKey: copy + drop>(
|
|
222
222
|
dh: &mut DappHub,
|
|
223
|
-
_: DappKey,
|
|
224
223
|
) {
|
|
225
224
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
226
225
|
let (free_credit, base_fee, byte_fee) = dapp_fee_config::get(dh);
|
|
@@ -236,6 +235,13 @@ public fun initialize_fee_state<DappKey: copy + drop>(
|
|
|
236
235
|
);
|
|
237
236
|
}
|
|
238
237
|
|
|
238
|
+
public(package) fun initialize_dapp_proxy<DappKey: copy + drop>(
|
|
239
|
+
dh: &mut DappHub,
|
|
240
|
+
) {
|
|
241
|
+
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
242
|
+
dapp_proxy::set(dh, dapp_key, @0x0, false);
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
public fun upgrade_dapp<DappKey: copy + drop>(
|
|
240
246
|
dh: &mut DappHub,
|
|
241
247
|
_: DappKey,
|
|
@@ -417,7 +423,7 @@ public fun set_storage<DappKey: copy + drop>(
|
|
|
417
423
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
418
424
|
dapp_proxy::ensure_has(dh, dapp_key);
|
|
419
425
|
let (delegator, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
420
|
-
dapp_not_been_delegated_error(
|
|
426
|
+
dapp_not_been_delegated_error(enabled);
|
|
421
427
|
no_permission_error(delegator == ctx.sender());
|
|
422
428
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, count);
|
|
423
429
|
dapp_service::set_record_internal(dh, dapp_key, table_id, key_tuple, value_tuple);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module dubhe::entity_id {
|
|
2
|
-
use sui::hash::blake2b256;
|
|
2
|
+
use sui::hash::{blake2b256, keccak256};
|
|
3
3
|
use sui::address;
|
|
4
4
|
use std::ascii::{String};
|
|
5
|
+
use std::vector;
|
|
6
|
+
use std::bcs;
|
|
7
|
+
use sui::object::{Self};
|
|
5
8
|
|
|
6
9
|
public fun asset_to_entity_id(name: String, asset_id: u256): address {
|
|
7
10
|
let mut raw_bytes = vector::empty();
|
|
@@ -11,4 +14,41 @@ module dubhe::entity_id {
|
|
|
11
14
|
let entity_id_bytes = blake2b256(&raw_bytes);
|
|
12
15
|
address::from_bytes(entity_id_bytes)
|
|
13
16
|
}
|
|
17
|
+
|
|
18
|
+
/// Generate entity key from an object
|
|
19
|
+
public fun object_address<T:key>(obj: &T): address {
|
|
20
|
+
obj.key().id().address()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Generate entity key from bytes using keccak256 hash
|
|
24
|
+
public fun entity_key_from_bytes(bytes: vector<u8>): address {
|
|
25
|
+
let hash_bytes = keccak256(&bytes);
|
|
26
|
+
address::from_bytes(hash_bytes)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Generate entity key from address concatenated with seed string
|
|
30
|
+
public fun entity_key_from_address_with_seed(object_id: address, seed: String): address {
|
|
31
|
+
let mut combined_bytes = vector::empty();
|
|
32
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
33
|
+
combined_bytes.append(seed.into_bytes());
|
|
34
|
+
entity_key_from_bytes(combined_bytes)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Generate entity key from address concatenated with u256 value
|
|
38
|
+
public fun entity_key_from_address_with_u256(object_id: address, x: u256): address {
|
|
39
|
+
let mut combined_bytes = vector::empty();
|
|
40
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
41
|
+
let x_bytes = bcs::to_bytes(&x);
|
|
42
|
+
combined_bytes.append(x_bytes);
|
|
43
|
+
entity_key_from_bytes(combined_bytes)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Generate entity key from u256 value (converts to address format)
|
|
47
|
+
/// This uses BCS serialization to convert u256 to bytes, then hashes
|
|
48
|
+
public fun entity_key_from_u256(x: u256): address {
|
|
49
|
+
let bytes = bcs::to_bytes(&x);
|
|
50
|
+
// Add a suffix to make it more unique, similar to the Aptos example
|
|
51
|
+
vector::append(&mut bytes, b"u256");
|
|
52
|
+
entity_key_from_bytes(bytes)
|
|
53
|
+
}
|
|
14
54
|
}
|
|
@@ -4,15 +4,15 @@ use sui::event;
|
|
|
4
4
|
use std::ascii::String;
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
public struct
|
|
7
|
+
public struct Dubhe_Store_SetRecord has copy, drop {
|
|
8
8
|
dapp_key: String,
|
|
9
9
|
table_id: String,
|
|
10
10
|
key_tuple: vector<vector<u8>>,
|
|
11
11
|
value_tuple: vector<vector<u8>>
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>):
|
|
15
|
-
|
|
14
|
+
public fun new_store_set_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, value_tuple: vector<vector<u8>>): Dubhe_Store_SetRecord {
|
|
15
|
+
Dubhe_Store_SetRecord {
|
|
16
16
|
dapp_key,
|
|
17
17
|
table_id,
|
|
18
18
|
key_tuple,
|
|
@@ -24,7 +24,7 @@ public fun emit_store_set_record(dapp_key: String, table_id: String, key_tuple:
|
|
|
24
24
|
event::emit(new_store_set_record(dapp_key, table_id, key_tuple, value_tuple));
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
public struct
|
|
27
|
+
public struct Dubhe_Store_SetField has copy, drop {
|
|
28
28
|
dapp_key: String,
|
|
29
29
|
table_id: String,
|
|
30
30
|
key_tuple: vector<vector<u8>>,
|
|
@@ -32,8 +32,8 @@ public struct Store_SetField has copy, drop {
|
|
|
32
32
|
value: vector<u8>
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>):
|
|
36
|
-
|
|
35
|
+
public fun new_store_set_field(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>, field_index: u8, value: vector<u8>): Dubhe_Store_SetField {
|
|
36
|
+
Dubhe_Store_SetField {
|
|
37
37
|
dapp_key,
|
|
38
38
|
table_id,
|
|
39
39
|
key_tuple,
|
|
@@ -46,14 +46,14 @@ public fun emit_store_set_field(dapp_key: String, table_id: String, key_tuple: v
|
|
|
46
46
|
event::emit(new_store_set_field(dapp_key, table_id, key_tuple, field_index, value));
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
public struct
|
|
49
|
+
public struct Dubhe_Store_DeleteRecord has copy, drop {
|
|
50
50
|
dapp_key: String,
|
|
51
51
|
table_id: String,
|
|
52
52
|
key_tuple: vector<vector<u8>>
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>):
|
|
56
|
-
|
|
55
|
+
public fun new_store_delete_record(dapp_key: String, table_id: String, key_tuple: vector<vector<u8>>): Dubhe_Store_DeleteRecord {
|
|
56
|
+
Dubhe_Store_DeleteRecord {
|
|
57
57
|
dapp_key,
|
|
58
58
|
table_id,
|
|
59
59
|
key_tuple
|
package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/dapp_system.move
CHANGED
|
@@ -70,7 +70,7 @@ public fun set_record<DappKey: copy + drop>(
|
|
|
70
70
|
);
|
|
71
71
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
72
72
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
73
|
-
dapp_already_delegated_error(enabled);
|
|
73
|
+
dapp_already_delegated_error(!enabled);
|
|
74
74
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, 1);
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -95,7 +95,7 @@ public fun set_field<DappKey: copy + drop>(
|
|
|
95
95
|
);
|
|
96
96
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
97
97
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
98
|
-
dapp_already_delegated_error(enabled);
|
|
98
|
+
dapp_already_delegated_error(!enabled);
|
|
99
99
|
charge_fee(dh, dapp_key, key_tuple, vector[value], 1);
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -115,7 +115,7 @@ public fun delete_record<DappKey: copy + drop>(
|
|
|
115
115
|
);
|
|
116
116
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
117
117
|
let (_, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
118
|
-
dapp_already_delegated_error(enabled);
|
|
118
|
+
dapp_already_delegated_error(!enabled);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/// Get a record
|
|
@@ -180,14 +180,14 @@ public fun create_dapp<DappKey: copy + drop>(
|
|
|
180
180
|
dapp_service::create_dapp(dh, dapp_key, ctx);
|
|
181
181
|
let dubhe_dapp_key = dapp_key::new();
|
|
182
182
|
if(!dapp_key::eq(&dapp_key, &dubhe_dapp_key)) {
|
|
183
|
-
initialize_metadata(dh,
|
|
184
|
-
initialize_fee_state(dh
|
|
183
|
+
initialize_metadata<DappKey>(dh, name, description, clock, ctx);
|
|
184
|
+
initialize_fee_state<DappKey>(dh);
|
|
185
|
+
initialize_dapp_proxy<DappKey>(dh);
|
|
185
186
|
};
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
public fun initialize_metadata<DappKey: copy + drop>(
|
|
189
|
+
public(package) fun initialize_metadata<DappKey: copy + drop>(
|
|
189
190
|
dh: &mut DappHub,
|
|
190
|
-
_: DappKey,
|
|
191
191
|
name: String,
|
|
192
192
|
description: String,
|
|
193
193
|
clock: &Clock,
|
|
@@ -218,9 +218,8 @@ public fun initialize_metadata<DappKey: copy + drop>(
|
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
public fun initialize_fee_state<DappKey: copy + drop>(
|
|
221
|
+
public(package) fun initialize_fee_state<DappKey: copy + drop>(
|
|
222
222
|
dh: &mut DappHub,
|
|
223
|
-
_: DappKey,
|
|
224
223
|
) {
|
|
225
224
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
226
225
|
let (free_credit, base_fee, byte_fee) = dapp_fee_config::get(dh);
|
|
@@ -236,6 +235,13 @@ public fun initialize_fee_state<DappKey: copy + drop>(
|
|
|
236
235
|
);
|
|
237
236
|
}
|
|
238
237
|
|
|
238
|
+
public(package) fun initialize_dapp_proxy<DappKey: copy + drop>(
|
|
239
|
+
dh: &mut DappHub,
|
|
240
|
+
) {
|
|
241
|
+
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
242
|
+
dapp_proxy::set(dh, dapp_key, @0x0, false);
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
public fun upgrade_dapp<DappKey: copy + drop>(
|
|
240
246
|
dh: &mut DappHub,
|
|
241
247
|
_: DappKey,
|
|
@@ -417,7 +423,7 @@ public fun set_storage<DappKey: copy + drop>(
|
|
|
417
423
|
let dapp_key = type_info::get_type_name_string<DappKey>();
|
|
418
424
|
dapp_proxy::ensure_has(dh, dapp_key);
|
|
419
425
|
let (delegator, enabled) = dapp_proxy::get(dh, dapp_key);
|
|
420
|
-
dapp_not_been_delegated_error(
|
|
426
|
+
dapp_not_been_delegated_error(enabled);
|
|
421
427
|
no_permission_error(delegator == ctx.sender());
|
|
422
428
|
charge_fee(dh, dapp_key, key_tuple, value_tuple, count);
|
|
423
429
|
dapp_service::set_record_internal(dh, dapp_key, table_id, key_tuple, value_tuple);
|
package/templates/nextjs/sui-template/packages/contracts/src/dubhe/sources/systems/entity_id.move
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
module dubhe::entity_id {
|
|
2
|
-
use sui::hash::blake2b256;
|
|
2
|
+
use sui::hash::{blake2b256, keccak256};
|
|
3
3
|
use sui::address;
|
|
4
4
|
use std::ascii::{String};
|
|
5
|
+
use std::vector;
|
|
6
|
+
use std::bcs;
|
|
7
|
+
use sui::object::{Self};
|
|
5
8
|
|
|
6
9
|
public fun asset_to_entity_id(name: String, asset_id: u256): address {
|
|
7
10
|
let mut raw_bytes = vector::empty();
|
|
@@ -11,4 +14,41 @@ module dubhe::entity_id {
|
|
|
11
14
|
let entity_id_bytes = blake2b256(&raw_bytes);
|
|
12
15
|
address::from_bytes(entity_id_bytes)
|
|
13
16
|
}
|
|
17
|
+
|
|
18
|
+
/// Generate entity key from an object
|
|
19
|
+
public fun object_address<T:key>(obj: &T): address {
|
|
20
|
+
obj.key().id().address()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Generate entity key from bytes using keccak256 hash
|
|
24
|
+
public fun entity_key_from_bytes(bytes: vector<u8>): address {
|
|
25
|
+
let hash_bytes = keccak256(&bytes);
|
|
26
|
+
address::from_bytes(hash_bytes)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Generate entity key from address concatenated with seed string
|
|
30
|
+
public fun entity_key_from_address_with_seed(object_id: address, seed: String): address {
|
|
31
|
+
let mut combined_bytes = vector::empty();
|
|
32
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
33
|
+
combined_bytes.append(seed.into_bytes());
|
|
34
|
+
entity_key_from_bytes(combined_bytes)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// Generate entity key from address concatenated with u256 value
|
|
38
|
+
public fun entity_key_from_address_with_u256(object_id: address, x: u256): address {
|
|
39
|
+
let mut combined_bytes = vector::empty();
|
|
40
|
+
combined_bytes.append(address::into_bytes(object_id));
|
|
41
|
+
let x_bytes = bcs::to_bytes(&x);
|
|
42
|
+
combined_bytes.append(x_bytes);
|
|
43
|
+
entity_key_from_bytes(combined_bytes)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// Generate entity key from u256 value (converts to address format)
|
|
47
|
+
/// This uses BCS serialization to convert u256 to bytes, then hashes
|
|
48
|
+
public fun entity_key_from_u256(x: u256): address {
|
|
49
|
+
let bytes = bcs::to_bytes(&x);
|
|
50
|
+
// Add a suffix to make it more unique, similar to the Aptos example
|
|
51
|
+
vector::append(&mut bytes, b"u256");
|
|
52
|
+
entity_key_from_bytes(bytes)
|
|
53
|
+
}
|
|
14
54
|
}
|