From 36cd34474289f2396f782f6b6956d0a1638918dd Mon Sep 17 00:00:00 2001 From: Ronan Date: Wed, 7 Aug 2024 01:25:47 -0600 Subject: [PATCH] Use @mysten/sui package --- package-lock.json | 502 +++--------------- package.json | 4 +- src/cli/index.ts | 14 +- .../_dependencies/source/0x1/ascii/structs.ts | 36 +- .../source/0x1/bit-vector/structs.ts | 21 +- .../source/0x1/fixed-point32/structs.ts | 21 +- src/codegen/_dependencies/source/0x1/index.ts | 2 +- src/codegen/_dependencies/source/0x1/init.ts | 2 +- .../source/0x1/option/structs.ts | 25 +- .../source/0x1/string/structs.ts | 21 +- .../source/0x1/type-name/structs.ts | 21 +- .../source/0x2/authenticator-state/structs.ts | 83 ++- .../_dependencies/source/0x2/bag/structs.ts | 21 +- .../source/0x2/balance/structs.ts | 42 +- .../_dependencies/source/0x2/bcs/structs.ts | 21 +- .../source/0x2/bls12381/structs.ts | 66 +-- .../source/0x2/borrow/structs.ts | 42 +- .../_dependencies/source/0x2/clock/structs.ts | 21 +- .../_dependencies/source/0x2/coin/structs.ts | 112 ++-- .../source/0x2/deny-list/structs.ts | 36 +- .../source/0x2/display/structs.ts | 59 +- .../source/0x2/dynamic-field/structs.ts | 25 +- .../0x2/dynamic-object-field/structs.ts | 25 +- .../source/0x2/groth16/structs.ts | 66 +-- .../source/0x2/group-ops/structs.ts | 25 +- src/codegen/_dependencies/source/0x2/index.ts | 2 +- src/codegen/_dependencies/source/0x2/init.ts | 32 +- .../source/0x2/kiosk-extension/structs.ts | 40 +- .../_dependencies/source/0x2/kiosk/structs.ts | 166 +++--- .../source/0x2/linked-table/structs.ts | 46 +- .../source/0x2/object-bag/structs.ts | 21 +- .../source/0x2/object-table/structs.ts | 25 +- .../source/0x2/object/structs.ts | 36 +- .../source/0x2/package/structs.ts | 66 +-- .../source/0x2/priority-queue/structs.ts | 44 +- .../source/0x2/random/structs.ts | 51 +- .../_dependencies/source/0x2/sui/structs.ts | 21 +- .../source/0x2/table-vec/structs.ts | 25 +- .../_dependencies/source/0x2/table/structs.ts | 25 +- .../_dependencies/source/0x2/token/structs.ts | 112 ++-- .../source/0x2/transfer-policy/structs.ts | 110 ++-- .../source/0x2/transfer/structs.ts | 25 +- .../source/0x2/tx-context/structs.ts | 21 +- .../_dependencies/source/0x2/url/structs.ts | 21 +- .../source/0x2/vec-map/structs.ts | 44 +- .../source/0x2/vec-set/structs.ts | 25 +- .../source/0x2/versioned/structs.ts | 36 +- .../source/0x2/zklogin-verified-id/structs.ts | 21 +- .../0x2/zklogin-verified-issuer/structs.ts | 21 +- .../index.ts | 2 +- .../locker/structs.ts | 25 +- .../time-locked-balance/structs.ts | 25 +- src/codegen/_framework/init-loader.ts | 13 + src/codegen/_framework/init-source.ts | 11 - src/codegen/_framework/loader.ts | 19 +- src/codegen/_framework/reified.ts | 13 +- src/codegen/_framework/util.ts | 245 ++++++--- src/codegen/mineral/icon/functions.ts | 4 +- src/codegen/mineral/index.ts | 2 +- src/codegen/mineral/init.ts | 2 +- src/codegen/mineral/mine/functions.ts | 37 +- src/codegen/mineral/mine/structs.ts | 178 +++---- src/codegen/mineral/miner/functions.ts | 24 +- src/codegen/mineral/miner/structs.ts | 21 +- src/common.ts | 34 +- src/index.ts | 14 +- 66 files changed, 1332 insertions(+), 1686 deletions(-) create mode 100644 src/codegen/_framework/init-loader.ts delete mode 100644 src/codegen/_framework/init-source.ts diff --git a/package-lock.json b/package-lock.json index 4979306..a251550 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,8 +5,8 @@ "packages": { "": { "dependencies": { - "@mysten/bcs": "^0.11.1", - "@mysten/sui.js": "^0.54.1", + "@mysten/bcs": "^1.0.4", + "@mysten/sui": "^1.5.0", "@noble/hashes": "^1.4.0", "chalk": "^5.3.0", "commander": "^12.0.0", @@ -40,9 +40,9 @@ } }, "node_modules/@0no-co/graphqlsp": { - "version": "1.12.8", - "resolved": "https://registry.npmjs.org/@0no-co/graphqlsp/-/graphqlsp-1.12.8.tgz", - "integrity": "sha512-arW3ZzifyKIJhehoAlsP069AX73EN6q358bOCf+8z00PmfPR2DSxq7uGGSj0oFNe3vEDtGYl88HmFEWQ+0+dwQ==", + "version": "1.12.12", + "resolved": "https://registry.npmjs.org/@0no-co/graphqlsp/-/graphqlsp-1.12.12.tgz", + "integrity": "sha512-BmCAc/q3tQcIwXxKoxubYaB23s2fWMMmNGSlY9mgQvWiReBS8ZutPZSf11OADfwTv1J1JIazU6q6OFX+cEp8PQ==", "dependencies": { "@gql.tada/internal": "^1.0.0", "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0" @@ -52,19 +52,6 @@ "typescript": "^5.0.0" } }, - "node_modules/@ampproject/remapping": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", - "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", - "peer": true, - "dependencies": { - "@jridgewell/gen-mapping": "^0.3.5", - "@jridgewell/trace-mapping": "^0.3.24" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/@babel/generator": { "version": "7.18.2", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.18.2.tgz", @@ -97,17 +84,6 @@ "node": ">=6.9.0" } }, - "node_modules/@babel/parser": { - "version": "7.24.7", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.7.tgz", - "integrity": "sha512-9uUYRm6OqQrCqQdG1iCBwBPZgN8ciDBro2nIOFaiRz1/BCxaI7CNvQbDHvsArAC7Tw9Hda/B3U+6ui9u4HWXPw==", - "bin": { - "parser": "bin/babel-parser.js" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/@babel/types": { "version": "7.19.0", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.19.0.tgz", @@ -563,26 +539,34 @@ } }, "node_modules/@gql.tada/cli-utils": { - "version": "1.3.10", - "resolved": "https://registry.npmjs.org/@gql.tada/cli-utils/-/cli-utils-1.3.10.tgz", - "integrity": "sha512-wmKW/4UuDR9rkgpXnzP2skftNO4Kc/LNkFImKXe0waus+ipvJLaV3dwQ1CghKQ1THzWl2KLp/yJ80BdFWA+HzA==", - "dependencies": { - "@0no-co/graphqlsp": "^1.12.8", - "@gql.tada/internal": "1.0.1", - "@vue/compiler-dom": "^3.4.23", - "@vue/language-core": "^2.0.17", - "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0", - "svelte2tsx": "^0.7.6" + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@gql.tada/cli-utils/-/cli-utils-1.6.0.tgz", + "integrity": "sha512-RYWpoWVm6/ypvDp7UTzh3UrEgIJq2+HaUlAcbdLzKdO8ZfFgP16gBpxtYvbRPWwQEjn5HMGgpzIBh7Kftp10PA==", + "dependencies": { + "@0no-co/graphqlsp": "^1.12.9", + "@gql.tada/internal": "1.0.6", + "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0" }, "peerDependencies": { + "@0no-co/graphqlsp": "^1.12.9", + "@gql.tada/svelte-support": "1.0.1", + "@gql.tada/vue-support": "1.0.1", "graphql": "^15.5.0 || ^16.0.0 || ^17.0.0", "typescript": "^5.0.0" + }, + "peerDependenciesMeta": { + "@gql.tada/svelte-support": { + "optional": true + }, + "@gql.tada/vue-support": { + "optional": true + } } }, "node_modules/@gql.tada/internal": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@gql.tada/internal/-/internal-1.0.1.tgz", - "integrity": "sha512-VglE9pEUqCD7YwytLehI1RiEpxJsEkO+8onrMI8DEFTcrn+Irv2tQfPUHBC0LjtY5sFgoodCSLIcnxyZOKggYA==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@gql.tada/internal/-/internal-1.0.6.tgz", + "integrity": "sha512-K5dKMqqU0pcNWS+/i6EnoUGvA7lW2Agwl+nepZOEWbGpG80aJxXfL+yAvaHihP5VqGZFOygyc3NDBo1mm+Z4KQ==", "dependencies": { "@0no-co/graphql.web": "^1.0.5" }, @@ -808,71 +792,39 @@ "dev": true }, "node_modules/@mysten/bcs": { - "version": "0.11.1", - "resolved": "https://registry.npmjs.org/@mysten/bcs/-/bcs-0.11.1.tgz", - "integrity": "sha512-xP85isNSYUCHd3O/g+TmZYmg4wK6cU8q/n/MebkIGP4CYVJZz2wU/G24xIZ3wI+0iTop4dfgA5kYrg/DQKCUzA==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@mysten/bcs/-/bcs-1.0.4.tgz", + "integrity": "sha512-6JoQi59GN/dVEBCNq8Rj4uOR0niDrJqDx/2gNQWXANwJakHIGH0AMniHrXP41B2dF+mZ3HVmh9Hi3otiEVQTrQ==", "dependencies": { - "bs58": "^5.0.0" + "bs58": "^6.0.0" } }, "node_modules/@mysten/sui": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@mysten/sui/-/sui-1.1.2.tgz", - "integrity": "sha512-S1MfGvbkUxKGd39bfA6G21UVwJSSgJW8uKHinSByjt86+YKvSZxlF5zr6RVKcP4Rn8gl5ytMbZQfCPn+0nuGTg==", - "peer": true, + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@mysten/sui/-/sui-1.5.0.tgz", + "integrity": "sha512-RRB3EPiEbtfhkTW+p1Hc9Hf8zM+hGrAhhjyzMqCWhjnWuF7yM+5PL3jLcTZaZe+jGjFP9lKGol/0uOWVtfGL5w==", "dependencies": { "@graphql-typed-document-node/core": "^3.2.0", - "@mysten/bcs": "1.0.2", - "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1", - "@scure/bip32": "^1.3.1", - "@scure/bip39": "^1.2.1", + "@mysten/bcs": "1.0.4", + "@noble/curves": "^1.4.2", + "@noble/hashes": "^1.4.0", + "@scure/bip32": "^1.4.0", + "@scure/bip39": "^1.3.0", "@suchipi/femver": "^1.0.0", "bech32": "^2.0.0", - "gql.tada": "^1.7.0", - "graphql": "^16.8.1", + "gql.tada": "^1.8.2", + "graphql": "^16.9.0", "tweetnacl": "^1.0.3", - "valibot": "^0.25.0" + "valibot": "^0.36.0" }, "engines": { "node": ">=18" } }, - "node_modules/@mysten/sui.js": { - "version": "0.54.1", - "resolved": "https://registry.npmjs.org/@mysten/sui.js/-/sui.js-0.54.1.tgz", - "integrity": "sha512-TSmGIX7U9O/uS9EKIQdv7/S69KTbBhMJVelXCafJE6IJw8iB9cN9uLu0+uklkBSDrbRmLSEY70jMr3uRFjReIg==", - "dependencies": { - "@graphql-typed-document-node/core": "^3.2.0", - "@mysten/bcs": "0.11.1", - "@noble/curves": "^1.1.0", - "@noble/hashes": "^1.3.1", - "@scure/bip32": "^1.3.1", - "@scure/bip39": "^1.2.1", - "@suchipi/femver": "^1.0.0", - "bech32": "^2.0.0", - "gql.tada": "^1.7.0", - "graphql": "^16.8.1", - "superstruct": "^1.0.3", - "tweetnacl": "^1.0.3" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/@mysten/sui/node_modules/@mysten/bcs": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@mysten/bcs/-/bcs-1.0.2.tgz", - "integrity": "sha512-haHT0km/9yIIe8lwo8gDFxGLnoxfRF4WmEVCz4lDXbEVQRsZkF0zB97kukiwMjDuFBaGVUhrOMCLz6td8tSMaQ==", - "peer": true, - "dependencies": { - "bs58": "^5.0.0" - } - }, "node_modules/@noble/curves": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.0.tgz", - "integrity": "sha512-p+4cb332SFCrReJkCYe8Xzm0OWi4Jji5jVdIZRL/PmacmDkFNw6MrrV+gGpiPxLHbV+zKFRywUWbaseT+tZRXg==", + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.4.2.tgz", + "integrity": "sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==", "dependencies": { "@noble/hashes": "1.4.0" }, @@ -1176,70 +1128,6 @@ "@types/node": "*" } }, - "node_modules/@volar/language-core": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@volar/language-core/-/language-core-2.3.0.tgz", - "integrity": "sha512-pvhL24WUh3VDnv7Yw5N1sjhPtdx7q9g+Wl3tggmnkMcyK8GcCNElF2zHiKznryn0DiUGk+eez/p2qQhz+puuHw==", - "dependencies": { - "@volar/source-map": "2.3.0" - } - }, - "node_modules/@volar/source-map": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@volar/source-map/-/source-map-2.3.0.tgz", - "integrity": "sha512-G/228aZjAOGhDjhlyZ++nDbKrS9uk+5DMaEstjvzglaAw7nqtDyhnQAsYzUg6BMP9BtwZ59RIw5HGePrutn00Q==", - "dependencies": { - "muggle-string": "^0.4.0" - } - }, - "node_modules/@vue/compiler-core": { - "version": "3.4.29", - "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.4.29.tgz", - "integrity": "sha512-TFKiRkKKsRCKvg/jTSSKK7mYLJEQdUiUfykbG49rubC9SfDyvT2JrzTReopWlz2MxqeLyxh9UZhvxEIBgAhtrg==", - "dependencies": { - "@babel/parser": "^7.24.7", - "@vue/shared": "3.4.29", - "entities": "^4.5.0", - "estree-walker": "^2.0.2", - "source-map-js": "^1.2.0" - } - }, - "node_modules/@vue/compiler-dom": { - "version": "3.4.29", - "resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.4.29.tgz", - "integrity": "sha512-A6+iZ2fKIEGnfPJejdB7b1FlJzgiD+Y/sxxKwJWg1EbJu6ZPgzaPQQ51ESGNv0CP6jm6Z7/pO6Ia8Ze6IKrX7w==", - "dependencies": { - "@vue/compiler-core": "3.4.29", - "@vue/shared": "3.4.29" - } - }, - "node_modules/@vue/language-core": { - "version": "2.0.21", - "resolved": "https://registry.npmjs.org/@vue/language-core/-/language-core-2.0.21.tgz", - "integrity": "sha512-vjs6KwnCK++kIXT+eI63BGpJHfHNVJcUCr3RnvJsccT3vbJnZV5IhHR2puEkoOkIbDdp0Gqi1wEnv3hEd3WsxQ==", - "dependencies": { - "@volar/language-core": "~2.3.0-alpha.15", - "@vue/compiler-dom": "^3.4.0", - "@vue/shared": "^3.4.0", - "computeds": "^0.0.1", - "minimatch": "^9.0.3", - "path-browserify": "^1.0.1", - "vue-template-compiler": "^2.7.14" - }, - "peerDependencies": { - "typescript": "*" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, - "node_modules/@vue/shared": { - "version": "3.4.29", - "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.4.29.tgz", - "integrity": "sha512-hQ2gAQcBO/CDpC82DCrinJNgOHI2v+FA7BDW4lMSPeBpQ7sRe2OLHWe5cph1s7D8DUQAwRt18dBDfJJ220APEA==" - }, "node_modules/@webassemblyjs/ast": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.12.1.tgz", @@ -1576,15 +1464,6 @@ "node": ">= 8" } }, - "node_modules/aria-query": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", - "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", - "peer": true, - "dependencies": { - "dequal": "^2.0.3" - } - }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", @@ -1609,24 +1488,15 @@ "node": ">= 4.0.0" } }, - "node_modules/axobject-query": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.0.0.tgz", - "integrity": "sha512-+60uv1hiVFhHZeO+Lz0RYzsVHy5Wr1ayX0mwda9KPDVLNJgZ1T9Ny7VmFbLDzxsH0D87I86vgj3gFrjTJUYznw==", - "peer": true, - "dependencies": { - "dequal": "^2.0.3" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, "node_modules/base-x": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/base-x/-/base-x-4.0.0.tgz", - "integrity": "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw==" + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-5.0.0.tgz", + "integrity": "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ==" }, "node_modules/base64-js": { "version": "1.5.1", @@ -1779,6 +1649,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, "dependencies": { "balanced-match": "^1.0.0" } @@ -1826,11 +1697,11 @@ } }, "node_modules/bs58": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/bs58/-/bs58-5.0.0.tgz", - "integrity": "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ==", + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-6.0.0.tgz", + "integrity": "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw==", "dependencies": { - "base-x": "^4.0.0" + "base-x": "^5.0.0" } }, "node_modules/buffer": { @@ -1997,28 +1868,6 @@ "node": ">=6" } }, - "node_modules/code-red": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/code-red/-/code-red-1.0.4.tgz", - "integrity": "sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==", - "peer": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.15", - "@types/estree": "^1.0.1", - "acorn": "^8.10.0", - "estree-walker": "^3.0.3", - "periscopic": "^3.1.0" - } - }, - "node_modules/code-red/node_modules/estree-walker": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", - "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", - "peer": true, - "dependencies": { - "@types/estree": "^1.0.0" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -2093,11 +1942,6 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, - "node_modules/computeds": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/computeds/-/computeds-0.0.1.tgz", - "integrity": "sha512-7CEBgcMjVmitjYo5q8JTJVra6X5mQ20uTThdK+0kR7UEaDrAWEQcRiBtWJzga4eRpP6afNwwLsX2SET2JhVB1Q==" - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -2189,24 +2033,6 @@ "node": ">=4.8" } }, - "node_modules/css-tree": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", - "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", - "peer": true, - "dependencies": { - "mdn-data": "2.0.30", - "source-map-js": "^1.0.1" - }, - "engines": { - "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" - } - }, - "node_modules/de-indent": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz", - "integrity": "sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==" - }, "node_modules/debug": { "version": "4.3.5", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", @@ -2244,11 +2070,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/dedent-js": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/dedent-js/-/dedent-js-1.0.1.tgz", - "integrity": "sha512-OUepMozQULMLUmhxS95Vudo0jb0UchLimi3+pQ2plj61Fcy8axbP9hbiD4Sz6DPqn6XG3kfmziVfQ1rSys5AJQ==" - }, "node_modules/deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", @@ -2336,15 +2157,6 @@ "node": ">= 0.8" } }, - "node_modules/dequal": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", - "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", @@ -2506,17 +2318,6 @@ "node": ">=10.13.0" } }, - "node_modules/entities": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", - "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", - "engines": { - "node": ">=0.12" - }, - "funding": { - "url": "https://github.com/fb55/entities?sponsor=1" - } - }, "node_modules/envinfo": { "version": "7.13.0", "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.13.0.tgz", @@ -2646,11 +2447,6 @@ "node": ">=4.0" } }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==" - }, "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", @@ -3303,13 +3099,14 @@ } }, "node_modules/gql.tada": { - "version": "1.7.6", - "resolved": "https://registry.npmjs.org/gql.tada/-/gql.tada-1.7.6.tgz", - "integrity": "sha512-wuFq2qmWFFQETV1qz2rWqIJ65qlLxxpiuMEDOB7zqmWnKGHYQ2k/bttyDGOKwroK2cgPZ8TGhzzaUQj9MZmwxw==", + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/gql.tada/-/gql.tada-1.8.5.tgz", + "integrity": "sha512-A6uwkWjy0Pq6A804T4pnrBtnGG5XBSaordSNW2loxWqeov+FqEaOI5+Oy/Be2NIrSpxaM0TQhV1+xtYxsxJOjw==", "dependencies": { "@0no-co/graphql.web": "^1.0.5", - "@gql.tada/cli-utils": "1.3.10", - "@gql.tada/internal": "1.0.1" + "@0no-co/graphqlsp": "^1.12.9", + "@gql.tada/cli-utils": "1.6.0", + "@gql.tada/internal": "1.0.6" }, "bin": { "gql-tada": "bin/cli.js", @@ -3325,9 +3122,9 @@ "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, "node_modules/graphql": { - "version": "16.8.2", - "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.2.tgz", - "integrity": "sha512-cvVIBILwuoSyD54U4cF/UXDh5yAobhNV/tPygI4lZhgOIJQE/WLWC4waBRb4I6bDVYb3OVx3lfHbaQOEoUD5sg==", + "version": "16.9.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", + "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -3402,14 +3199,6 @@ "node": ">= 0.4" } }, - "node_modules/he": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", - "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", - "bin": { - "he": "bin/he" - } - }, "node_modules/hpack.js": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/hpack.js/-/hpack.js-2.1.6.tgz", @@ -3778,15 +3567,6 @@ "node": ">=0.10.0" } }, - "node_modules/is-reference": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.2.tgz", - "integrity": "sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==", - "peer": true, - "dependencies": { - "@types/estree": "*" - } - }, "node_modules/is-stream": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", @@ -3967,12 +3747,6 @@ "node": ">=8.9.0" } }, - "node_modules/locate-character": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/locate-character/-/locate-character-3.0.0.tgz", - "integrity": "sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==", - "peer": true - }, "node_modules/locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -3989,14 +3763,6 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "node_modules/lower-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", - "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", - "dependencies": { - "tslib": "^2.0.3" - } - }, "node_modules/lru-cache": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-9.1.2.tgz", @@ -4005,21 +3771,6 @@ "node": "14 || >=16.14" } }, - "node_modules/magic-string": { - "version": "0.30.10", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", - "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", - "peer": true, - "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.15" - } - }, - "node_modules/mdn-data": { - "version": "2.0.30", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", - "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", - "peer": true - }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -4151,6 +3902,7 @@ "version": "9.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "dev": true, "dependencies": { "brace-expansion": "^2.0.1" }, @@ -4201,11 +3953,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/muggle-string": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/muggle-string/-/muggle-string-0.4.1.tgz", - "integrity": "sha512-VNTrAak/KhO2i8dqqnqnAHOa3cYBwXEZe9h+D5h/1ZqFSTEFHdM65lR7RoIqq3tBBYavsOXV84NoHXZ0AkPyqQ==" - }, "node_modules/multicast-dns": { "version": "7.2.5", "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-7.2.5.tgz", @@ -4282,15 +4029,6 @@ "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, - "node_modules/no-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", - "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", - "dependencies": { - "lower-case": "^2.0.2", - "tslib": "^2.0.3" - } - }, "node_modules/node-abi": { "version": "3.65.0", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.65.0.tgz", @@ -4555,20 +4293,6 @@ "node": ">= 0.8" } }, - "node_modules/pascal-case": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/pascal-case/-/pascal-case-3.1.2.tgz", - "integrity": "sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==", - "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3" - } - }, - "node_modules/path-browserify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-1.0.1.tgz", - "integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==" - }, "node_modules/path-exists": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", @@ -4638,26 +4362,6 @@ "node": ">=8" } }, - "node_modules/periscopic": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-3.1.0.tgz", - "integrity": "sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==", - "peer": true, - "dependencies": { - "@types/estree": "^1.0.0", - "estree-walker": "^3.0.0", - "is-reference": "^3.0.0" - } - }, - "node_modules/periscopic/node_modules/estree-walker": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", - "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", - "peer": true, - "dependencies": { - "@types/estree": "^1.0.0" - } - }, "node_modules/picocolors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", @@ -5499,14 +5203,6 @@ "node": ">= 8" } }, - "node_modules/source-map-js": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", - "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/source-map-support": { "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", @@ -5667,14 +5363,6 @@ "node": ">=0.10.0" } }, - "node_modules/superstruct": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/superstruct/-/superstruct-1.0.4.tgz", - "integrity": "sha512-7JpaAoX2NGyoFlI9NBh66BQXGONc+uE+MRS5i2iOBKuS4e+ccgMDjATgZldkah+33DakBxDHiss9kvUcGAO8UQ==", - "engines": { - "node": ">=14.0.0" - } - }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -5697,53 +5385,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/svelte": { - "version": "4.2.18", - "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.18.tgz", - "integrity": "sha512-d0FdzYIiAePqRJEb90WlJDkjUEx42xhivxN8muUBmfZnP+tzUgz12DJ2hRJi8sIHCME7jeK1PTMgKPSfTd8JrA==", - "peer": true, - "dependencies": { - "@ampproject/remapping": "^2.2.1", - "@jridgewell/sourcemap-codec": "^1.4.15", - "@jridgewell/trace-mapping": "^0.3.18", - "@types/estree": "^1.0.1", - "acorn": "^8.9.0", - "aria-query": "^5.3.0", - "axobject-query": "^4.0.0", - "code-red": "^1.0.3", - "css-tree": "^2.3.1", - "estree-walker": "^3.0.3", - "is-reference": "^3.0.1", - "locate-character": "^3.0.0", - "magic-string": "^0.30.4", - "periscopic": "^3.1.0" - }, - "engines": { - "node": ">=16" - } - }, - "node_modules/svelte/node_modules/estree-walker": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", - "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", - "peer": true, - "dependencies": { - "@types/estree": "^1.0.0" - } - }, - "node_modules/svelte2tsx": { - "version": "0.7.10", - "resolved": "https://registry.npmjs.org/svelte2tsx/-/svelte2tsx-0.7.10.tgz", - "integrity": "sha512-POOXaTncPGjwXMj6NVSRvdNj8KFqqLabFtXsQal3WyPy4X5raGsiDST2+ELhceKwfHk79/hR3qGUeU7KxYo4vQ==", - "dependencies": { - "dedent-js": "^1.0.1", - "pascal-case": "^3.1.1" - }, - "peerDependencies": { - "svelte": "^3.55 || ^4.0.0-next.0 || ^4.0 || ^5.0.0-next.0", - "typescript": "^4.9.4 || ^5.0.0" - } - }, "node_modules/tapable": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz", @@ -5978,7 +5619,8 @@ "node_modules/tslib": { "version": "2.6.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.3.tgz", - "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==" + "integrity": "sha512-xNvxJEOUiWPGhUuUdQgAJPKOOJfGnIyKySOc09XkKsgdUV/3E2zvwZYdejjmRgPCgcym1juLH3226yA7sEFJKQ==", + "dev": true }, "node_modules/tunnel-agent": { "version": "0.6.0", @@ -6126,10 +5768,9 @@ } }, "node_modules/valibot": { - "version": "0.25.0", - "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.25.0.tgz", - "integrity": "sha512-cmD0ca15oyAbT75iYLNW6uU6doAeIwYfOshpXka/E1Bx4frzbkrgb7gvkI7K0YK/DVOksei4FfxWfRoBP3NFTg==", - "peer": true + "version": "0.36.0", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.36.0.tgz", + "integrity": "sha512-CjF1XN4sUce8sBK9TixrDqFM7RwNkuXdJu174/AwmQUB62QbCQADg5lLe8ldBalFgtj1uKj+pKwDJiNo4Mn+eQ==" }, "node_modules/vary": { "version": "1.1.2", @@ -6140,15 +5781,6 @@ "node": ">= 0.8" } }, - "node_modules/vue-template-compiler": { - "version": "2.7.16", - "resolved": "https://registry.npmjs.org/vue-template-compiler/-/vue-template-compiler-2.7.16.tgz", - "integrity": "sha512-AYbUWAJHLGGQM7+cNTELw+KsOG9nl2CnSv467WobS5Cv9uk3wFcnr1Etsz2sEIHEZvw1U+o9mRlEO6QbZvUPGQ==", - "dependencies": { - "de-indent": "^1.0.2", - "he": "^1.2.0" - } - }, "node_modules/watchpack": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.1.tgz", diff --git a/package.json b/package.json index 33063fe..d7cf47f 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "build:worker": "esbuild src/worker.ts --bundle --outfile=public/worker.js" }, "dependencies": { - "@mysten/bcs": "^0.11.1", - "@mysten/sui.js": "^0.54.1", + "@mysten/bcs": "^1.0.4", + "@mysten/sui": "^1.5.0", "@noble/hashes": "^1.4.0", "chalk": "^5.3.0", "commander": "^12.0.0", diff --git a/src/cli/index.ts b/src/cli/index.ts index 8c3d8fe..fa317de 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -10,20 +10,20 @@ import { epochReset } from "../codegen/mineral/mine/functions"; import { Config, MINE } from "../codegen/mineral/mine/structs"; import { Miner } from "../codegen/mineral/miner/structs"; -import { bcs } from "@mysten/sui.js/bcs"; -import { decodeSuiPrivateKey } from "@mysten/sui.js/cryptography"; +import { bcs } from "@mysten/sui/bcs"; +import { decodeSuiPrivateKey } from "@mysten/sui/cryptography"; import { SuiTransactionBlockResponse, SuiClient, getFullnodeUrl, -} from "@mysten/sui.js/client"; -import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; +} from "@mysten/sui/client"; +import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; import { SUI_TYPE_ARG, SUI_DECIMALS, SUI_CLOCK_OBJECT_ID, -} from "@mysten/sui.js/utils"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; +} from "@mysten/sui/utils"; +import { Transaction } from "@mysten/sui/transactions"; import { MineProgress, @@ -376,7 +376,7 @@ async function execReset( client: SuiClient, wallet: Ed25519Keypair ): Promise { - const txb = new TransactionBlock(); + const txb = new Transaction(); epochReset(txb, { config: constants.CONFIG, buses: constants.BUSES.map((x) => diff --git a/src/codegen/_dependencies/source/0x1/ascii/structs.ts b/src/codegen/_dependencies/source/0x1/ascii/structs.ts index 9dc1406..ed17379 100644 --- a/src/codegen/_dependencies/source/0x1/ascii/structs.ts +++ b/src/codegen/_dependencies/source/0x1/ascii/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V8} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Char =============================== */ -export function isChar(type: string): boolean { type = compressSuiType(type); return type === "0x1::ascii::Char"; } +export function isChar(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::ascii::Char`; } export interface CharFields { byte: ToField<"u8"> } export type CharReified = Reified< Char, CharFields >; -export class Char implements StructClass { static readonly $typeName = "0x1::ascii::Char"; static readonly $numTypeParams = 0; +export class Char implements StructClass { static readonly $typeName = `${PKG_V8}::ascii::Char`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Char.$typeName; - - readonly $fullTypeName: "0x1::ascii::Char"; - - readonly $typeArgs: []; + readonly $typeName = Char.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::ascii::Char`; readonly $typeArgs: []; readonly $isPhantom = Char.$isPhantom; readonly byte: ToField<"u8"> - private constructor(typeArgs: [], fields: CharFields, ) { this.$fullTypeName = composeSuiType( Char.$typeName, ...typeArgs ) as "0x1::ascii::Char"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: CharFields, ) { this.$fullTypeName = composeSuiType( Char.$typeName, ...typeArgs ) as `${typeof PKG_V8}::ascii::Char`; this.$typeArgs = typeArgs; this.byte = fields.byte; } - static reified( ): CharReified { return { typeName: Char.$typeName, fullTypeName: composeSuiType( Char.$typeName, ...[] ) as "0x1::ascii::Char", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Char.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Char.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Char.fromBcs( data, ), bcs: Char.bcs, fromJSONField: (field: any) => Char.fromJSONField( field, ), fromJSON: (json: Record) => Char.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Char.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Char.fetch( client, id, ), new: ( fields: CharFields, ) => { return new Char( [], fields ) }, kind: "StructClassReified", } } + static reified( ): CharReified { return { typeName: Char.$typeName, fullTypeName: composeSuiType( Char.$typeName, ...[] ) as `${typeof PKG_V8}::ascii::Char`, typeArgs: [ ] as [], isPhantom: Char.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Char.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Char.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Char.fromBcs( data, ), bcs: Char.bcs, fromJSONField: (field: any) => Char.fromJSONField( field, ), fromJSON: (json: Record) => Char.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Char.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Char.fetch( client, id, ), new: ( fields: CharFields, ) => { return new Char( [], fields ) }, kind: "StructClassReified", } } static get r() { return Char.reified() } @@ -65,33 +63,30 @@ export class Char implements StructClass { static readonly $typeName = "0x1::asc static fromSuiParsedData( content: SuiParsedData ): Char { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isChar(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Char object`); } return Char.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Char object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isChar(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Char object`); } + return Char.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== String =============================== */ -export function isString(type: string): boolean { type = compressSuiType(type); return type === "0x1::ascii::String"; } +export function isString(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::ascii::String`; } export interface StringFields { bytes: ToField> } export type StringReified = Reified< String, StringFields >; -export class String implements StructClass { static readonly $typeName = "0x1::ascii::String"; static readonly $numTypeParams = 0; +export class String implements StructClass { static readonly $typeName = `${PKG_V8}::ascii::String`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = String.$typeName; - - readonly $fullTypeName: "0x1::ascii::String"; - - readonly $typeArgs: []; + readonly $typeName = String.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::ascii::String`; readonly $typeArgs: []; readonly $isPhantom = String.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as "0x1::ascii::String"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as `${typeof PKG_V8}::ascii::String`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as "0x1::ascii::String", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } } + static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as `${typeof PKG_V8}::ascii::String`, typeArgs: [ ] as [], isPhantom: String.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } } static get r() { return String.reified() } @@ -130,6 +125,7 @@ export class String implements StructClass { static readonly $typeName = "0x1::a static fromSuiParsedData( content: SuiParsedData ): String { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isString(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a String object`); } return String.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching String object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isString(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a String object`); } + return String.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x1/bit-vector/structs.ts b/src/codegen/_dependencies/source/0x1/bit-vector/structs.ts index 7c72dcc..383aafd 100644 --- a/src/codegen/_dependencies/source/0x1/bit-vector/structs.ts +++ b/src/codegen/_dependencies/source/0x1/bit-vector/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V8} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== BitVector =============================== */ -export function isBitVector(type: string): boolean { type = compressSuiType(type); return type === "0x1::bit_vector::BitVector"; } +export function isBitVector(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::bit_vector::BitVector`; } export interface BitVectorFields { length: ToField<"u64">; bitField: ToField> } export type BitVectorReified = Reified< BitVector, BitVectorFields >; -export class BitVector implements StructClass { static readonly $typeName = "0x1::bit_vector::BitVector"; static readonly $numTypeParams = 0; +export class BitVector implements StructClass { static readonly $typeName = `${PKG_V8}::bit_vector::BitVector`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = BitVector.$typeName; - - readonly $fullTypeName: "0x1::bit_vector::BitVector"; - - readonly $typeArgs: []; + readonly $typeName = BitVector.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::bit_vector::BitVector`; readonly $typeArgs: []; readonly $isPhantom = BitVector.$isPhantom; readonly length: ToField<"u64">; readonly bitField: ToField> - private constructor(typeArgs: [], fields: BitVectorFields, ) { this.$fullTypeName = composeSuiType( BitVector.$typeName, ...typeArgs ) as "0x1::bit_vector::BitVector"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BitVectorFields, ) { this.$fullTypeName = composeSuiType( BitVector.$typeName, ...typeArgs ) as `${typeof PKG_V8}::bit_vector::BitVector`; this.$typeArgs = typeArgs; this.length = fields.length;; this.bitField = fields.bitField; } - static reified( ): BitVectorReified { return { typeName: BitVector.$typeName, fullTypeName: composeSuiType( BitVector.$typeName, ...[] ) as "0x1::bit_vector::BitVector", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => BitVector.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BitVector.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BitVector.fromBcs( data, ), bcs: BitVector.bcs, fromJSONField: (field: any) => BitVector.fromJSONField( field, ), fromJSON: (json: Record) => BitVector.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BitVector.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BitVector.fetch( client, id, ), new: ( fields: BitVectorFields, ) => { return new BitVector( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BitVectorReified { return { typeName: BitVector.$typeName, fullTypeName: composeSuiType( BitVector.$typeName, ...[] ) as `${typeof PKG_V8}::bit_vector::BitVector`, typeArgs: [ ] as [], isPhantom: BitVector.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => BitVector.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BitVector.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BitVector.fromBcs( data, ), bcs: BitVector.bcs, fromJSONField: (field: any) => BitVector.fromJSONField( field, ), fromJSON: (json: Record) => BitVector.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BitVector.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BitVector.fetch( client, id, ), new: ( fields: BitVectorFields, ) => { return new BitVector( [], fields ) }, kind: "StructClassReified", } } static get r() { return BitVector.reified() } @@ -65,6 +63,7 @@ export class BitVector implements StructClass { static readonly $typeName = "0x1 static fromSuiParsedData( content: SuiParsedData ): BitVector { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBitVector(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a BitVector object`); } return BitVector.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching BitVector object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBitVector(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a BitVector object`); } + return BitVector.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x1/fixed-point32/structs.ts b/src/codegen/_dependencies/source/0x1/fixed-point32/structs.ts index 13de6dd..2e47e28 100644 --- a/src/codegen/_dependencies/source/0x1/fixed-point32/structs.ts +++ b/src/codegen/_dependencies/source/0x1/fixed-point32/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V8} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== FixedPoint32 =============================== */ -export function isFixedPoint32(type: string): boolean { type = compressSuiType(type); return type === "0x1::fixed_point32::FixedPoint32"; } +export function isFixedPoint32(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::fixed_point32::FixedPoint32`; } export interface FixedPoint32Fields { value: ToField<"u64"> } export type FixedPoint32Reified = Reified< FixedPoint32, FixedPoint32Fields >; -export class FixedPoint32 implements StructClass { static readonly $typeName = "0x1::fixed_point32::FixedPoint32"; static readonly $numTypeParams = 0; +export class FixedPoint32 implements StructClass { static readonly $typeName = `${PKG_V8}::fixed_point32::FixedPoint32`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = FixedPoint32.$typeName; - - readonly $fullTypeName: "0x1::fixed_point32::FixedPoint32"; - - readonly $typeArgs: []; + readonly $typeName = FixedPoint32.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::fixed_point32::FixedPoint32`; readonly $typeArgs: []; readonly $isPhantom = FixedPoint32.$isPhantom; readonly value: ToField<"u64"> - private constructor(typeArgs: [], fields: FixedPoint32Fields, ) { this.$fullTypeName = composeSuiType( FixedPoint32.$typeName, ...typeArgs ) as "0x1::fixed_point32::FixedPoint32"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: FixedPoint32Fields, ) { this.$fullTypeName = composeSuiType( FixedPoint32.$typeName, ...typeArgs ) as `${typeof PKG_V8}::fixed_point32::FixedPoint32`; this.$typeArgs = typeArgs; this.value = fields.value; } - static reified( ): FixedPoint32Reified { return { typeName: FixedPoint32.$typeName, fullTypeName: composeSuiType( FixedPoint32.$typeName, ...[] ) as "0x1::fixed_point32::FixedPoint32", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => FixedPoint32.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => FixedPoint32.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => FixedPoint32.fromBcs( data, ), bcs: FixedPoint32.bcs, fromJSONField: (field: any) => FixedPoint32.fromJSONField( field, ), fromJSON: (json: Record) => FixedPoint32.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => FixedPoint32.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => FixedPoint32.fetch( client, id, ), new: ( fields: FixedPoint32Fields, ) => { return new FixedPoint32( [], fields ) }, kind: "StructClassReified", } } + static reified( ): FixedPoint32Reified { return { typeName: FixedPoint32.$typeName, fullTypeName: composeSuiType( FixedPoint32.$typeName, ...[] ) as `${typeof PKG_V8}::fixed_point32::FixedPoint32`, typeArgs: [ ] as [], isPhantom: FixedPoint32.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => FixedPoint32.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => FixedPoint32.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => FixedPoint32.fromBcs( data, ), bcs: FixedPoint32.bcs, fromJSONField: (field: any) => FixedPoint32.fromJSONField( field, ), fromJSON: (json: Record) => FixedPoint32.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => FixedPoint32.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => FixedPoint32.fetch( client, id, ), new: ( fields: FixedPoint32Fields, ) => { return new FixedPoint32( [], fields ) }, kind: "StructClassReified", } } static get r() { return FixedPoint32.reified() } @@ -64,6 +62,7 @@ export class FixedPoint32 implements StructClass { static readonly $typeName = " static fromSuiParsedData( content: SuiParsedData ): FixedPoint32 { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isFixedPoint32(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a FixedPoint32 object`); } return FixedPoint32.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching FixedPoint32 object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isFixedPoint32(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a FixedPoint32 object`); } + return FixedPoint32.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x1/index.ts b/src/codegen/_dependencies/source/0x1/index.ts index a137e0d..a3cede9 100644 --- a/src/codegen/_dependencies/source/0x1/index.ts +++ b/src/codegen/_dependencies/source/0x1/index.ts @@ -1 +1 @@ -export const PACKAGE_ID = "0x1"; export const PUBLISHED_AT = "0x1"; +export const PACKAGE_ID = "0x1"; export const PUBLISHED_AT = "0x1"; export const PKG_V8 = "0x1"; diff --git a/src/codegen/_dependencies/source/0x1/init.ts b/src/codegen/_dependencies/source/0x1/init.ts index 3d84a94..22cbb73 100644 --- a/src/codegen/_dependencies/source/0x1/init.ts +++ b/src/codegen/_dependencies/source/0x1/init.ts @@ -10,7 +10,7 @@ export function registerClasses(loader: StructClassLoader) { loader.register(fix loader.register(option.Option); loader.register(ascii.Char); loader.register(ascii.String); +loader.register(bitVector.BitVector); loader.register(string.String); loader.register(typeName.TypeName); -loader.register(bitVector.BitVector); } diff --git a/src/codegen/_dependencies/source/0x1/option/structs.ts b/src/codegen/_dependencies/source/0x1/option/structs.ts index 7e8f2a8..c023fde 100644 --- a/src/codegen/_dependencies/source/0x1/option/structs.ts +++ b/src/codegen/_dependencies/source/0x1/option/structs.ts @@ -1,34 +1,32 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, Vector, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V8} from "../index"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Option =============================== */ -export function isOption(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x1::option::Option<"); } +export function isOption(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V8}::option::Option` + '<'); } export interface OptionFields { vec: ToField> } export type OptionReified = Reified< Option, OptionFields >; -export class Option implements StructClass { static readonly $typeName = "0x1::option::Option"; static readonly $numTypeParams = 1; +export class Option implements StructClass { static readonly $typeName = `${PKG_V8}::option::Option`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; __inner: Element = null as unknown as Element; // for type checking in reified.ts -; readonly $typeName = Option.$typeName; - - readonly $fullTypeName: `0x1::option::Option<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; +; readonly $typeName = Option.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::option::Option<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = Option.$isPhantom; readonly vec: ToField> - private constructor(typeArgs: [ToTypeStr], fields: OptionFields, ) { this.$fullTypeName = composeSuiType( Option.$typeName, ...typeArgs ) as `0x1::option::Option<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: OptionFields, ) { this.$fullTypeName = composeSuiType( Option.$typeName, ...typeArgs ) as `${typeof PKG_V8}::option::Option<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.vec = fields.vec; } - static reified>( Element: Element ): OptionReified> { return { typeName: Option.$typeName, fullTypeName: composeSuiType( Option.$typeName, ...[extractType(Element)] ) as `0x1::option::Option<${ToTypeStr>}>`, typeArgs: [ extractType(Element) ] as [ToTypeStr>], reifiedTypeArgs: [Element], fromFields: (fields: Record) => Option.fromFields( Element, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Option.fromFieldsWithTypes( Element, item, ), fromBcs: (data: Uint8Array) => Option.fromBcs( Element, data, ), bcs: Option.bcs(toBcs(Element)), fromJSONField: (field: any) => Option.fromJSONField( Element, field, ), fromJSON: (json: Record) => Option.fromJSON( Element, json, ), fromSuiParsedData: (content: SuiParsedData) => Option.fromSuiParsedData( Element, content, ), fetch: async (client: SuiClient, id: string) => Option.fetch( client, Element, id, ), new: ( fields: OptionFields>, ) => { return new Option( [extractType(Element)], fields ) }, kind: "StructClassReified", } } + static reified>( Element: Element ): OptionReified> { return { typeName: Option.$typeName, fullTypeName: composeSuiType( Option.$typeName, ...[extractType(Element)] ) as `${typeof PKG_V8}::option::Option<${ToTypeStr>}>`, typeArgs: [ extractType(Element) ] as [ToTypeStr>], isPhantom: Option.$isPhantom, reifiedTypeArgs: [Element], fromFields: (fields: Record) => Option.fromFields( Element, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Option.fromFieldsWithTypes( Element, item, ), fromBcs: (data: Uint8Array) => Option.fromBcs( Element, data, ), bcs: Option.bcs(toBcs(Element)), fromJSONField: (field: any) => Option.fromJSONField( Element, field, ), fromJSON: (json: Record) => Option.fromJSON( Element, json, ), fromSuiParsedData: (content: SuiParsedData) => Option.fromSuiParsedData( Element, content, ), fetch: async (client: SuiClient, id: string) => Option.fetch( client, Element, id, ), new: ( fields: OptionFields>, ) => { return new Option( [extractType(Element)], fields ) }, kind: "StructClassReified", } } static get r() { return Option.reified } @@ -69,6 +67,9 @@ export class Option implements StructClass { stati static fromSuiParsedData>( typeArg: Element, content: SuiParsedData ): Option> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isOption(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Option object`); } return Option.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: Element, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Option object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isOption(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Option object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Option.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x1/string/structs.ts b/src/codegen/_dependencies/source/0x1/string/structs.ts index 7b61978..25a9c7c 100644 --- a/src/codegen/_dependencies/source/0x1/string/structs.ts +++ b/src/codegen/_dependencies/source/0x1/string/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V8} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== String =============================== */ -export function isString(type: string): boolean { type = compressSuiType(type); return type === "0x1::string::String"; } +export function isString(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::string::String`; } export interface StringFields { bytes: ToField> } export type StringReified = Reified< String, StringFields >; -export class String implements StructClass { static readonly $typeName = "0x1::string::String"; static readonly $numTypeParams = 0; +export class String implements StructClass { static readonly $typeName = `${PKG_V8}::string::String`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = String.$typeName; - - readonly $fullTypeName: "0x1::string::String"; - - readonly $typeArgs: []; + readonly $typeName = String.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::string::String`; readonly $typeArgs: []; readonly $isPhantom = String.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as "0x1::string::String"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as `${typeof PKG_V8}::string::String`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as "0x1::string::String", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } } + static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as `${typeof PKG_V8}::string::String`, typeArgs: [ ] as [], isPhantom: String.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } } static get r() { return String.reified() } @@ -65,6 +63,7 @@ export class String implements StructClass { static readonly $typeName = "0x1::s static fromSuiParsedData( content: SuiParsedData ): String { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isString(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a String object`); } return String.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching String object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isString(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a String object`); } + return String.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x1/type-name/structs.ts b/src/codegen/_dependencies/source/0x1/type-name/structs.ts index df54686..68405fb 100644 --- a/src/codegen/_dependencies/source/0x1/type-name/structs.ts +++ b/src/codegen/_dependencies/source/0x1/type-name/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../ascii/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V8} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== TypeName =============================== */ -export function isTypeName(type: string): boolean { type = compressSuiType(type); return type === "0x1::type_name::TypeName"; } +export function isTypeName(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::type_name::TypeName`; } export interface TypeNameFields { name: ToField } export type TypeNameReified = Reified< TypeName, TypeNameFields >; -export class TypeName implements StructClass { static readonly $typeName = "0x1::type_name::TypeName"; static readonly $numTypeParams = 0; +export class TypeName implements StructClass { static readonly $typeName = `${PKG_V8}::type_name::TypeName`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = TypeName.$typeName; - - readonly $fullTypeName: "0x1::type_name::TypeName"; - - readonly $typeArgs: []; + readonly $typeName = TypeName.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::type_name::TypeName`; readonly $typeArgs: []; readonly $isPhantom = TypeName.$isPhantom; readonly name: ToField - private constructor(typeArgs: [], fields: TypeNameFields, ) { this.$fullTypeName = composeSuiType( TypeName.$typeName, ...typeArgs ) as "0x1::type_name::TypeName"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: TypeNameFields, ) { this.$fullTypeName = composeSuiType( TypeName.$typeName, ...typeArgs ) as `${typeof PKG_V8}::type_name::TypeName`; this.$typeArgs = typeArgs; this.name = fields.name; } - static reified( ): TypeNameReified { return { typeName: TypeName.$typeName, fullTypeName: composeSuiType( TypeName.$typeName, ...[] ) as "0x1::type_name::TypeName", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => TypeName.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TypeName.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => TypeName.fromBcs( data, ), bcs: TypeName.bcs, fromJSONField: (field: any) => TypeName.fromJSONField( field, ), fromJSON: (json: Record) => TypeName.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => TypeName.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => TypeName.fetch( client, id, ), new: ( fields: TypeNameFields, ) => { return new TypeName( [], fields ) }, kind: "StructClassReified", } } + static reified( ): TypeNameReified { return { typeName: TypeName.$typeName, fullTypeName: composeSuiType( TypeName.$typeName, ...[] ) as `${typeof PKG_V8}::type_name::TypeName`, typeArgs: [ ] as [], isPhantom: TypeName.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => TypeName.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TypeName.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => TypeName.fromBcs( data, ), bcs: TypeName.bcs, fromJSONField: (field: any) => TypeName.fromJSONField( field, ), fromJSON: (json: Record) => TypeName.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => TypeName.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => TypeName.fetch( client, id, ), new: ( fields: TypeNameFields, ) => { return new TypeName( [], fields ) }, kind: "StructClassReified", } } static get r() { return TypeName.reified() } @@ -65,6 +63,7 @@ export class TypeName implements StructClass { static readonly $typeName = "0x1: static fromSuiParsedData( content: SuiParsedData ): TypeName { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTypeName(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TypeName object`); } return TypeName.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TypeName object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTypeName(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TypeName object`); } + return TypeName.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/authenticator-state/structs.ts b/src/codegen/_dependencies/source/0x2/authenticator-state/structs.ts index 769e588..3001c72 100644 --- a/src/codegen/_dependencies/source/0x2/authenticator-state/structs.ts +++ b/src/codegen/_dependencies/source/0x2/authenticator-state/structs.ts @@ -2,33 +2,31 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../../0x1/string/structs"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== ActiveJwk =============================== */ -export function isActiveJwk(type: string): boolean { type = compressSuiType(type); return type === "0x2::authenticator_state::ActiveJwk"; } +export function isActiveJwk(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::authenticator_state::ActiveJwk`; } export interface ActiveJwkFields { jwkId: ToField; jwk: ToField; epoch: ToField<"u64"> } export type ActiveJwkReified = Reified< ActiveJwk, ActiveJwkFields >; -export class ActiveJwk implements StructClass { static readonly $typeName = "0x2::authenticator_state::ActiveJwk"; static readonly $numTypeParams = 0; +export class ActiveJwk implements StructClass { static readonly $typeName = `${PKG_V25}::authenticator_state::ActiveJwk`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = ActiveJwk.$typeName; - - readonly $fullTypeName: "0x2::authenticator_state::ActiveJwk"; - - readonly $typeArgs: []; + readonly $typeName = ActiveJwk.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::authenticator_state::ActiveJwk`; readonly $typeArgs: []; readonly $isPhantom = ActiveJwk.$isPhantom; readonly jwkId: ToField; readonly jwk: ToField; readonly epoch: ToField<"u64"> - private constructor(typeArgs: [], fields: ActiveJwkFields, ) { this.$fullTypeName = composeSuiType( ActiveJwk.$typeName, ...typeArgs ) as "0x2::authenticator_state::ActiveJwk"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ActiveJwkFields, ) { this.$fullTypeName = composeSuiType( ActiveJwk.$typeName, ...typeArgs ) as `${typeof PKG_V25}::authenticator_state::ActiveJwk`; this.$typeArgs = typeArgs; this.jwkId = fields.jwkId;; this.jwk = fields.jwk;; this.epoch = fields.epoch; } - static reified( ): ActiveJwkReified { return { typeName: ActiveJwk.$typeName, fullTypeName: composeSuiType( ActiveJwk.$typeName, ...[] ) as "0x2::authenticator_state::ActiveJwk", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => ActiveJwk.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ActiveJwk.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ActiveJwk.fromBcs( data, ), bcs: ActiveJwk.bcs, fromJSONField: (field: any) => ActiveJwk.fromJSONField( field, ), fromJSON: (json: Record) => ActiveJwk.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ActiveJwk.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ActiveJwk.fetch( client, id, ), new: ( fields: ActiveJwkFields, ) => { return new ActiveJwk( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ActiveJwkReified { return { typeName: ActiveJwk.$typeName, fullTypeName: composeSuiType( ActiveJwk.$typeName, ...[] ) as `${typeof PKG_V25}::authenticator_state::ActiveJwk`, typeArgs: [ ] as [], isPhantom: ActiveJwk.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => ActiveJwk.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ActiveJwk.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ActiveJwk.fromBcs( data, ), bcs: ActiveJwk.bcs, fromJSONField: (field: any) => ActiveJwk.fromJSONField( field, ), fromJSON: (json: Record) => ActiveJwk.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ActiveJwk.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ActiveJwk.fetch( client, id, ), new: ( fields: ActiveJwkFields, ) => { return new ActiveJwk( [], fields ) }, kind: "StructClassReified", } } static get r() { return ActiveJwk.reified() } @@ -67,33 +65,30 @@ export class ActiveJwk implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): ActiveJwk { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isActiveJwk(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ActiveJwk object`); } return ActiveJwk.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ActiveJwk object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isActiveJwk(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ActiveJwk object`); } + return ActiveJwk.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== AuthenticatorState =============================== */ -export function isAuthenticatorState(type: string): boolean { type = compressSuiType(type); return type === "0x2::authenticator_state::AuthenticatorState"; } +export function isAuthenticatorState(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::authenticator_state::AuthenticatorState`; } export interface AuthenticatorStateFields { id: ToField; version: ToField<"u64"> } export type AuthenticatorStateReified = Reified< AuthenticatorState, AuthenticatorStateFields >; -export class AuthenticatorState implements StructClass { static readonly $typeName = "0x2::authenticator_state::AuthenticatorState"; static readonly $numTypeParams = 0; - - readonly $typeName = AuthenticatorState.$typeName; +export class AuthenticatorState implements StructClass { static readonly $typeName = `${PKG_V25}::authenticator_state::AuthenticatorState`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $fullTypeName: "0x2::authenticator_state::AuthenticatorState"; - - readonly $typeArgs: []; + readonly $typeName = AuthenticatorState.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::authenticator_state::AuthenticatorState`; readonly $typeArgs: []; readonly $isPhantom = AuthenticatorState.$isPhantom; readonly id: ToField; readonly version: ToField<"u64"> - private constructor(typeArgs: [], fields: AuthenticatorStateFields, ) { this.$fullTypeName = composeSuiType( AuthenticatorState.$typeName, ...typeArgs ) as "0x2::authenticator_state::AuthenticatorState"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: AuthenticatorStateFields, ) { this.$fullTypeName = composeSuiType( AuthenticatorState.$typeName, ...typeArgs ) as `${typeof PKG_V25}::authenticator_state::AuthenticatorState`; this.$typeArgs = typeArgs; this.id = fields.id;; this.version = fields.version; } - static reified( ): AuthenticatorStateReified { return { typeName: AuthenticatorState.$typeName, fullTypeName: composeSuiType( AuthenticatorState.$typeName, ...[] ) as "0x2::authenticator_state::AuthenticatorState", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => AuthenticatorState.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AuthenticatorState.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AuthenticatorState.fromBcs( data, ), bcs: AuthenticatorState.bcs, fromJSONField: (field: any) => AuthenticatorState.fromJSONField( field, ), fromJSON: (json: Record) => AuthenticatorState.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AuthenticatorState.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AuthenticatorState.fetch( client, id, ), new: ( fields: AuthenticatorStateFields, ) => { return new AuthenticatorState( [], fields ) }, kind: "StructClassReified", } } + static reified( ): AuthenticatorStateReified { return { typeName: AuthenticatorState.$typeName, fullTypeName: composeSuiType( AuthenticatorState.$typeName, ...[] ) as `${typeof PKG_V25}::authenticator_state::AuthenticatorState`, typeArgs: [ ] as [], isPhantom: AuthenticatorState.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => AuthenticatorState.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AuthenticatorState.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AuthenticatorState.fromBcs( data, ), bcs: AuthenticatorState.bcs, fromJSONField: (field: any) => AuthenticatorState.fromJSONField( field, ), fromJSON: (json: Record) => AuthenticatorState.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AuthenticatorState.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AuthenticatorState.fetch( client, id, ), new: ( fields: AuthenticatorStateFields, ) => { return new AuthenticatorState( [], fields ) }, kind: "StructClassReified", } } static get r() { return AuthenticatorState.reified() } @@ -132,33 +127,30 @@ export class AuthenticatorState implements StructClass { static readonly $typeNa static fromSuiParsedData( content: SuiParsedData ): AuthenticatorState { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isAuthenticatorState(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a AuthenticatorState object`); } return AuthenticatorState.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching AuthenticatorState object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isAuthenticatorState(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a AuthenticatorState object`); } + return AuthenticatorState.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== AuthenticatorStateInner =============================== */ -export function isAuthenticatorStateInner(type: string): boolean { type = compressSuiType(type); return type === "0x2::authenticator_state::AuthenticatorStateInner"; } +export function isAuthenticatorStateInner(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::authenticator_state::AuthenticatorStateInner`; } export interface AuthenticatorStateInnerFields { version: ToField<"u64">; activeJwks: ToField> } export type AuthenticatorStateInnerReified = Reified< AuthenticatorStateInner, AuthenticatorStateInnerFields >; -export class AuthenticatorStateInner implements StructClass { static readonly $typeName = "0x2::authenticator_state::AuthenticatorStateInner"; static readonly $numTypeParams = 0; - - readonly $typeName = AuthenticatorStateInner.$typeName; - - readonly $fullTypeName: "0x2::authenticator_state::AuthenticatorStateInner"; +export class AuthenticatorStateInner implements StructClass { static readonly $typeName = `${PKG_V25}::authenticator_state::AuthenticatorStateInner`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = AuthenticatorStateInner.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::authenticator_state::AuthenticatorStateInner`; readonly $typeArgs: []; readonly $isPhantom = AuthenticatorStateInner.$isPhantom; readonly version: ToField<"u64">; readonly activeJwks: ToField> - private constructor(typeArgs: [], fields: AuthenticatorStateInnerFields, ) { this.$fullTypeName = composeSuiType( AuthenticatorStateInner.$typeName, ...typeArgs ) as "0x2::authenticator_state::AuthenticatorStateInner"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: AuthenticatorStateInnerFields, ) { this.$fullTypeName = composeSuiType( AuthenticatorStateInner.$typeName, ...typeArgs ) as `${typeof PKG_V25}::authenticator_state::AuthenticatorStateInner`; this.$typeArgs = typeArgs; this.version = fields.version;; this.activeJwks = fields.activeJwks; } - static reified( ): AuthenticatorStateInnerReified { return { typeName: AuthenticatorStateInner.$typeName, fullTypeName: composeSuiType( AuthenticatorStateInner.$typeName, ...[] ) as "0x2::authenticator_state::AuthenticatorStateInner", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => AuthenticatorStateInner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AuthenticatorStateInner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AuthenticatorStateInner.fromBcs( data, ), bcs: AuthenticatorStateInner.bcs, fromJSONField: (field: any) => AuthenticatorStateInner.fromJSONField( field, ), fromJSON: (json: Record) => AuthenticatorStateInner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AuthenticatorStateInner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AuthenticatorStateInner.fetch( client, id, ), new: ( fields: AuthenticatorStateInnerFields, ) => { return new AuthenticatorStateInner( [], fields ) }, kind: "StructClassReified", } } + static reified( ): AuthenticatorStateInnerReified { return { typeName: AuthenticatorStateInner.$typeName, fullTypeName: composeSuiType( AuthenticatorStateInner.$typeName, ...[] ) as `${typeof PKG_V25}::authenticator_state::AuthenticatorStateInner`, typeArgs: [ ] as [], isPhantom: AuthenticatorStateInner.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => AuthenticatorStateInner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AuthenticatorStateInner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AuthenticatorStateInner.fromBcs( data, ), bcs: AuthenticatorStateInner.bcs, fromJSONField: (field: any) => AuthenticatorStateInner.fromJSONField( field, ), fromJSON: (json: Record) => AuthenticatorStateInner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AuthenticatorStateInner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AuthenticatorStateInner.fetch( client, id, ), new: ( fields: AuthenticatorStateInnerFields, ) => { return new AuthenticatorStateInner( [], fields ) }, kind: "StructClassReified", } } static get r() { return AuthenticatorStateInner.reified() } @@ -182,7 +174,7 @@ export class AuthenticatorStateInner implements StructClass { static readonly $t toJSONField() { return { - version: this.version.toString(),activeJwks: fieldToJSON>(`vector<0x2::authenticator_state::ActiveJwk>`, this.activeJwks), + version: this.version.toString(),activeJwks: fieldToJSON>(`vector<${ActiveJwk.$typeName}>`, this.activeJwks), } } @@ -197,33 +189,30 @@ export class AuthenticatorStateInner implements StructClass { static readonly $t static fromSuiParsedData( content: SuiParsedData ): AuthenticatorStateInner { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isAuthenticatorStateInner(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a AuthenticatorStateInner object`); } return AuthenticatorStateInner.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching AuthenticatorStateInner object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isAuthenticatorStateInner(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a AuthenticatorStateInner object`); } + return AuthenticatorStateInner.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== JWK =============================== */ -export function isJWK(type: string): boolean { type = compressSuiType(type); return type === "0x2::authenticator_state::JWK"; } +export function isJWK(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::authenticator_state::JWK`; } export interface JWKFields { kty: ToField; e: ToField; n: ToField; alg: ToField } export type JWKReified = Reified< JWK, JWKFields >; -export class JWK implements StructClass { static readonly $typeName = "0x2::authenticator_state::JWK"; static readonly $numTypeParams = 0; - - readonly $typeName = JWK.$typeName; +export class JWK implements StructClass { static readonly $typeName = `${PKG_V25}::authenticator_state::JWK`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $fullTypeName: "0x2::authenticator_state::JWK"; - - readonly $typeArgs: []; + readonly $typeName = JWK.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::authenticator_state::JWK`; readonly $typeArgs: []; readonly $isPhantom = JWK.$isPhantom; readonly kty: ToField; readonly e: ToField; readonly n: ToField; readonly alg: ToField - private constructor(typeArgs: [], fields: JWKFields, ) { this.$fullTypeName = composeSuiType( JWK.$typeName, ...typeArgs ) as "0x2::authenticator_state::JWK"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: JWKFields, ) { this.$fullTypeName = composeSuiType( JWK.$typeName, ...typeArgs ) as `${typeof PKG_V25}::authenticator_state::JWK`; this.$typeArgs = typeArgs; this.kty = fields.kty;; this.e = fields.e;; this.n = fields.n;; this.alg = fields.alg; } - static reified( ): JWKReified { return { typeName: JWK.$typeName, fullTypeName: composeSuiType( JWK.$typeName, ...[] ) as "0x2::authenticator_state::JWK", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => JWK.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => JWK.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => JWK.fromBcs( data, ), bcs: JWK.bcs, fromJSONField: (field: any) => JWK.fromJSONField( field, ), fromJSON: (json: Record) => JWK.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => JWK.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => JWK.fetch( client, id, ), new: ( fields: JWKFields, ) => { return new JWK( [], fields ) }, kind: "StructClassReified", } } + static reified( ): JWKReified { return { typeName: JWK.$typeName, fullTypeName: composeSuiType( JWK.$typeName, ...[] ) as `${typeof PKG_V25}::authenticator_state::JWK`, typeArgs: [ ] as [], isPhantom: JWK.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => JWK.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => JWK.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => JWK.fromBcs( data, ), bcs: JWK.bcs, fromJSONField: (field: any) => JWK.fromJSONField( field, ), fromJSON: (json: Record) => JWK.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => JWK.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => JWK.fetch( client, id, ), new: ( fields: JWKFields, ) => { return new JWK( [], fields ) }, kind: "StructClassReified", } } static get r() { return JWK.reified() } @@ -262,33 +251,30 @@ export class JWK implements StructClass { static readonly $typeName = "0x2::auth static fromSuiParsedData( content: SuiParsedData ): JWK { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isJWK(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a JWK object`); } return JWK.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching JWK object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isJWK(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a JWK object`); } + return JWK.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== JwkId =============================== */ -export function isJwkId(type: string): boolean { type = compressSuiType(type); return type === "0x2::authenticator_state::JwkId"; } +export function isJwkId(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::authenticator_state::JwkId`; } export interface JwkIdFields { iss: ToField; kid: ToField } export type JwkIdReified = Reified< JwkId, JwkIdFields >; -export class JwkId implements StructClass { static readonly $typeName = "0x2::authenticator_state::JwkId"; static readonly $numTypeParams = 0; +export class JwkId implements StructClass { static readonly $typeName = `${PKG_V25}::authenticator_state::JwkId`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = JwkId.$typeName; - - readonly $fullTypeName: "0x2::authenticator_state::JwkId"; - - readonly $typeArgs: []; + readonly $typeName = JwkId.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::authenticator_state::JwkId`; readonly $typeArgs: []; readonly $isPhantom = JwkId.$isPhantom; readonly iss: ToField; readonly kid: ToField - private constructor(typeArgs: [], fields: JwkIdFields, ) { this.$fullTypeName = composeSuiType( JwkId.$typeName, ...typeArgs ) as "0x2::authenticator_state::JwkId"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: JwkIdFields, ) { this.$fullTypeName = composeSuiType( JwkId.$typeName, ...typeArgs ) as `${typeof PKG_V25}::authenticator_state::JwkId`; this.$typeArgs = typeArgs; this.iss = fields.iss;; this.kid = fields.kid; } - static reified( ): JwkIdReified { return { typeName: JwkId.$typeName, fullTypeName: composeSuiType( JwkId.$typeName, ...[] ) as "0x2::authenticator_state::JwkId", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => JwkId.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => JwkId.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => JwkId.fromBcs( data, ), bcs: JwkId.bcs, fromJSONField: (field: any) => JwkId.fromJSONField( field, ), fromJSON: (json: Record) => JwkId.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => JwkId.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => JwkId.fetch( client, id, ), new: ( fields: JwkIdFields, ) => { return new JwkId( [], fields ) }, kind: "StructClassReified", } } + static reified( ): JwkIdReified { return { typeName: JwkId.$typeName, fullTypeName: composeSuiType( JwkId.$typeName, ...[] ) as `${typeof PKG_V25}::authenticator_state::JwkId`, typeArgs: [ ] as [], isPhantom: JwkId.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => JwkId.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => JwkId.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => JwkId.fromBcs( data, ), bcs: JwkId.bcs, fromJSONField: (field: any) => JwkId.fromJSONField( field, ), fromJSON: (json: Record) => JwkId.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => JwkId.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => JwkId.fetch( client, id, ), new: ( fields: JwkIdFields, ) => { return new JwkId( [], fields ) }, kind: "StructClassReified", } } static get r() { return JwkId.reified() } @@ -327,6 +313,7 @@ export class JwkId implements StructClass { static readonly $typeName = "0x2::au static fromSuiParsedData( content: SuiParsedData ): JwkId { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isJwkId(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a JwkId object`); } return JwkId.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching JwkId object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isJwkId(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a JwkId object`); } + return JwkId.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/bag/structs.ts b/src/codegen/_dependencies/source/0x2/bag/structs.ts index d18ceb6..4f1e0e3 100644 --- a/src/codegen/_dependencies/source/0x2/bag/structs.ts +++ b/src/codegen/_dependencies/source/0x2/bag/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Bag =============================== */ -export function isBag(type: string): boolean { type = compressSuiType(type); return type === "0x2::bag::Bag"; } +export function isBag(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bag::Bag`; } export interface BagFields { id: ToField; size: ToField<"u64"> } export type BagReified = Reified< Bag, BagFields >; -export class Bag implements StructClass { static readonly $typeName = "0x2::bag::Bag"; static readonly $numTypeParams = 0; +export class Bag implements StructClass { static readonly $typeName = `${PKG_V25}::bag::Bag`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Bag.$typeName; - - readonly $fullTypeName: "0x2::bag::Bag"; - - readonly $typeArgs: []; + readonly $typeName = Bag.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bag::Bag`; readonly $typeArgs: []; readonly $isPhantom = Bag.$isPhantom; readonly id: ToField; readonly size: ToField<"u64"> - private constructor(typeArgs: [], fields: BagFields, ) { this.$fullTypeName = composeSuiType( Bag.$typeName, ...typeArgs ) as "0x2::bag::Bag"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BagFields, ) { this.$fullTypeName = composeSuiType( Bag.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bag::Bag`; this.$typeArgs = typeArgs; this.id = fields.id;; this.size = fields.size; } - static reified( ): BagReified { return { typeName: Bag.$typeName, fullTypeName: composeSuiType( Bag.$typeName, ...[] ) as "0x2::bag::Bag", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Bag.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Bag.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Bag.fromBcs( data, ), bcs: Bag.bcs, fromJSONField: (field: any) => Bag.fromJSONField( field, ), fromJSON: (json: Record) => Bag.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Bag.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Bag.fetch( client, id, ), new: ( fields: BagFields, ) => { return new Bag( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BagReified { return { typeName: Bag.$typeName, fullTypeName: composeSuiType( Bag.$typeName, ...[] ) as `${typeof PKG_V25}::bag::Bag`, typeArgs: [ ] as [], isPhantom: Bag.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Bag.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Bag.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Bag.fromBcs( data, ), bcs: Bag.bcs, fromJSONField: (field: any) => Bag.fromJSONField( field, ), fromJSON: (json: Record) => Bag.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Bag.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Bag.fetch( client, id, ), new: ( fields: BagFields, ) => { return new Bag( [], fields ) }, kind: "StructClassReified", } } static get r() { return Bag.reified() } @@ -65,6 +63,7 @@ export class Bag implements StructClass { static readonly $typeName = "0x2::bag: static fromSuiParsedData( content: SuiParsedData ): Bag { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBag(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Bag object`); } return Bag.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Bag object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBag(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Bag object`); } + return Bag.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/balance/structs.ts b/src/codegen/_dependencies/source/0x2/balance/structs.ts index 04ec1be..c44bf27 100644 --- a/src/codegen/_dependencies/source/0x2/balance/structs.ts +++ b/src/codegen/_dependencies/source/0x2/balance/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Balance =============================== */ -export function isBalance(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::balance::Balance<"); } +export function isBalance(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::balance::Balance` + '<'); } export interface BalanceFields { value: ToField<"u64"> } export type BalanceReified = Reified< Balance, BalanceFields >; -export class Balance implements StructClass { static readonly $typeName = "0x2::balance::Balance"; static readonly $numTypeParams = 1; +export class Balance implements StructClass { static readonly $typeName = `${PKG_V25}::balance::Balance`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Balance.$typeName; - - readonly $fullTypeName: `0x2::balance::Balance<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Balance.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::balance::Balance<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Balance.$isPhantom; readonly value: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: BalanceFields, ) { this.$fullTypeName = composeSuiType( Balance.$typeName, ...typeArgs ) as `0x2::balance::Balance<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: BalanceFields, ) { this.$fullTypeName = composeSuiType( Balance.$typeName, ...typeArgs ) as `${typeof PKG_V25}::balance::Balance<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.value = fields.value; } - static reified>( T: T ): BalanceReified> { return { typeName: Balance.$typeName, fullTypeName: composeSuiType( Balance.$typeName, ...[extractType(T)] ) as `0x2::balance::Balance<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Balance.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Balance.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Balance.fromBcs( T, data, ), bcs: Balance.bcs, fromJSONField: (field: any) => Balance.fromJSONField( T, field, ), fromJSON: (json: Record) => Balance.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Balance.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Balance.fetch( client, T, id, ), new: ( fields: BalanceFields>, ) => { return new Balance( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): BalanceReified> { return { typeName: Balance.$typeName, fullTypeName: composeSuiType( Balance.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::balance::Balance<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Balance.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Balance.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Balance.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Balance.fromBcs( T, data, ), bcs: Balance.bcs, fromJSONField: (field: any) => Balance.fromJSONField( T, field, ), fromJSON: (json: Record) => Balance.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Balance.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Balance.fetch( client, T, id, ), new: ( fields: BalanceFields>, ) => { return new Balance( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Balance.reified } @@ -64,33 +62,32 @@ export class Balance implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Balance> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBalance(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Balance object`); } return Balance.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Balance object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBalance(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Balance object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Balance.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Supply =============================== */ -export function isSupply(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::balance::Supply<"); } +export function isSupply(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::balance::Supply` + '<'); } export interface SupplyFields { value: ToField<"u64"> } export type SupplyReified = Reified< Supply, SupplyFields >; -export class Supply implements StructClass { static readonly $typeName = "0x2::balance::Supply"; static readonly $numTypeParams = 1; +export class Supply implements StructClass { static readonly $typeName = `${PKG_V25}::balance::Supply`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Supply.$typeName; - - readonly $fullTypeName: `0x2::balance::Supply<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Supply.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::balance::Supply<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Supply.$isPhantom; readonly value: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: SupplyFields, ) { this.$fullTypeName = composeSuiType( Supply.$typeName, ...typeArgs ) as `0x2::balance::Supply<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: SupplyFields, ) { this.$fullTypeName = composeSuiType( Supply.$typeName, ...typeArgs ) as `${typeof PKG_V25}::balance::Supply<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.value = fields.value; } - static reified>( T: T ): SupplyReified> { return { typeName: Supply.$typeName, fullTypeName: composeSuiType( Supply.$typeName, ...[extractType(T)] ) as `0x2::balance::Supply<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Supply.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Supply.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Supply.fromBcs( T, data, ), bcs: Supply.bcs, fromJSONField: (field: any) => Supply.fromJSONField( T, field, ), fromJSON: (json: Record) => Supply.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Supply.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Supply.fetch( client, T, id, ), new: ( fields: SupplyFields>, ) => { return new Supply( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): SupplyReified> { return { typeName: Supply.$typeName, fullTypeName: composeSuiType( Supply.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::balance::Supply<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Supply.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Supply.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Supply.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Supply.fromBcs( T, data, ), bcs: Supply.bcs, fromJSONField: (field: any) => Supply.fromJSONField( T, field, ), fromJSON: (json: Record) => Supply.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Supply.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Supply.fetch( client, T, id, ), new: ( fields: SupplyFields>, ) => { return new Supply( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Supply.reified } @@ -129,6 +126,9 @@ export class Supply implements StructClass { stat static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Supply> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isSupply(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Supply object`); } return Supply.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Supply object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isSupply(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Supply object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Supply.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/bcs/structs.ts b/src/codegen/_dependencies/source/0x2/bcs/structs.ts index 38874d4..5eacb37 100644 --- a/src/codegen/_dependencies/source/0x2/bcs/structs.ts +++ b/src/codegen/_dependencies/source/0x2/bcs/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== BCS =============================== */ -export function isBCS(type: string): boolean { type = compressSuiType(type); return type === "0x2::bcs::BCS"; } +export function isBCS(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bcs::BCS`; } export interface BCSFields { bytes: ToField> } export type BCSReified = Reified< BCS, BCSFields >; -export class BCS implements StructClass { static readonly $typeName = "0x2::bcs::BCS"; static readonly $numTypeParams = 0; +export class BCS implements StructClass { static readonly $typeName = `${PKG_V25}::bcs::BCS`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = BCS.$typeName; - - readonly $fullTypeName: "0x2::bcs::BCS"; - - readonly $typeArgs: []; + readonly $typeName = BCS.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bcs::BCS`; readonly $typeArgs: []; readonly $isPhantom = BCS.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [], fields: BCSFields, ) { this.$fullTypeName = composeSuiType( BCS.$typeName, ...typeArgs ) as "0x2::bcs::BCS"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BCSFields, ) { this.$fullTypeName = composeSuiType( BCS.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bcs::BCS`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): BCSReified { return { typeName: BCS.$typeName, fullTypeName: composeSuiType( BCS.$typeName, ...[] ) as "0x2::bcs::BCS", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => BCS.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BCS.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BCS.fromBcs( data, ), bcs: BCS.bcs, fromJSONField: (field: any) => BCS.fromJSONField( field, ), fromJSON: (json: Record) => BCS.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BCS.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BCS.fetch( client, id, ), new: ( fields: BCSFields, ) => { return new BCS( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BCSReified { return { typeName: BCS.$typeName, fullTypeName: composeSuiType( BCS.$typeName, ...[] ) as `${typeof PKG_V25}::bcs::BCS`, typeArgs: [ ] as [], isPhantom: BCS.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => BCS.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BCS.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BCS.fromBcs( data, ), bcs: BCS.bcs, fromJSONField: (field: any) => BCS.fromJSONField( field, ), fromJSON: (json: Record) => BCS.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BCS.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BCS.fetch( client, id, ), new: ( fields: BCSFields, ) => { return new BCS( [], fields ) }, kind: "StructClassReified", } } static get r() { return BCS.reified() } @@ -65,6 +63,7 @@ export class BCS implements StructClass { static readonly $typeName = "0x2::bcs: static fromSuiParsedData( content: SuiParsedData ): BCS { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBCS(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a BCS object`); } return BCS.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching BCS object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBCS(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a BCS object`); } + return BCS.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/bls12381/structs.ts b/src/codegen/_dependencies/source/0x2/bls12381/structs.ts index 28cd0d4..ff24453 100644 --- a/src/codegen/_dependencies/source/0x2/bls12381/structs.ts +++ b/src/codegen/_dependencies/source/0x2/bls12381/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== G1 =============================== */ -export function isG1(type: string): boolean { type = compressSuiType(type); return type === "0x2::bls12381::G1"; } +export function isG1(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bls12381::G1`; } export interface G1Fields { dummyField: ToField<"bool"> } export type G1Reified = Reified< G1, G1Fields >; -export class G1 implements StructClass { static readonly $typeName = "0x2::bls12381::G1"; static readonly $numTypeParams = 0; +export class G1 implements StructClass { static readonly $typeName = `${PKG_V25}::bls12381::G1`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = G1.$typeName; - - readonly $fullTypeName: "0x2::bls12381::G1"; - - readonly $typeArgs: []; + readonly $typeName = G1.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bls12381::G1`; readonly $typeArgs: []; readonly $isPhantom = G1.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: G1Fields, ) { this.$fullTypeName = composeSuiType( G1.$typeName, ...typeArgs ) as "0x2::bls12381::G1"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: G1Fields, ) { this.$fullTypeName = composeSuiType( G1.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bls12381::G1`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): G1Reified { return { typeName: G1.$typeName, fullTypeName: composeSuiType( G1.$typeName, ...[] ) as "0x2::bls12381::G1", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => G1.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => G1.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => G1.fromBcs( data, ), bcs: G1.bcs, fromJSONField: (field: any) => G1.fromJSONField( field, ), fromJSON: (json: Record) => G1.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => G1.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => G1.fetch( client, id, ), new: ( fields: G1Fields, ) => { return new G1( [], fields ) }, kind: "StructClassReified", } } + static reified( ): G1Reified { return { typeName: G1.$typeName, fullTypeName: composeSuiType( G1.$typeName, ...[] ) as `${typeof PKG_V25}::bls12381::G1`, typeArgs: [ ] as [], isPhantom: G1.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => G1.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => G1.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => G1.fromBcs( data, ), bcs: G1.bcs, fromJSONField: (field: any) => G1.fromJSONField( field, ), fromJSON: (json: Record) => G1.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => G1.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => G1.fetch( client, id, ), new: ( fields: G1Fields, ) => { return new G1( [], fields ) }, kind: "StructClassReified", } } static get r() { return G1.reified() } @@ -64,33 +62,30 @@ export class G1 implements StructClass { static readonly $typeName = "0x2::bls12 static fromSuiParsedData( content: SuiParsedData ): G1 { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isG1(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a G1 object`); } return G1.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching G1 object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isG1(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a G1 object`); } + return G1.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== G2 =============================== */ -export function isG2(type: string): boolean { type = compressSuiType(type); return type === "0x2::bls12381::G2"; } +export function isG2(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bls12381::G2`; } export interface G2Fields { dummyField: ToField<"bool"> } export type G2Reified = Reified< G2, G2Fields >; -export class G2 implements StructClass { static readonly $typeName = "0x2::bls12381::G2"; static readonly $numTypeParams = 0; +export class G2 implements StructClass { static readonly $typeName = `${PKG_V25}::bls12381::G2`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = G2.$typeName; - - readonly $fullTypeName: "0x2::bls12381::G2"; - - readonly $typeArgs: []; + readonly $typeName = G2.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bls12381::G2`; readonly $typeArgs: []; readonly $isPhantom = G2.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: G2Fields, ) { this.$fullTypeName = composeSuiType( G2.$typeName, ...typeArgs ) as "0x2::bls12381::G2"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: G2Fields, ) { this.$fullTypeName = composeSuiType( G2.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bls12381::G2`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): G2Reified { return { typeName: G2.$typeName, fullTypeName: composeSuiType( G2.$typeName, ...[] ) as "0x2::bls12381::G2", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => G2.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => G2.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => G2.fromBcs( data, ), bcs: G2.bcs, fromJSONField: (field: any) => G2.fromJSONField( field, ), fromJSON: (json: Record) => G2.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => G2.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => G2.fetch( client, id, ), new: ( fields: G2Fields, ) => { return new G2( [], fields ) }, kind: "StructClassReified", } } + static reified( ): G2Reified { return { typeName: G2.$typeName, fullTypeName: composeSuiType( G2.$typeName, ...[] ) as `${typeof PKG_V25}::bls12381::G2`, typeArgs: [ ] as [], isPhantom: G2.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => G2.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => G2.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => G2.fromBcs( data, ), bcs: G2.bcs, fromJSONField: (field: any) => G2.fromJSONField( field, ), fromJSON: (json: Record) => G2.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => G2.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => G2.fetch( client, id, ), new: ( fields: G2Fields, ) => { return new G2( [], fields ) }, kind: "StructClassReified", } } static get r() { return G2.reified() } @@ -129,33 +124,30 @@ export class G2 implements StructClass { static readonly $typeName = "0x2::bls12 static fromSuiParsedData( content: SuiParsedData ): G2 { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isG2(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a G2 object`); } return G2.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching G2 object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isG2(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a G2 object`); } + return G2.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== GT =============================== */ -export function isGT(type: string): boolean { type = compressSuiType(type); return type === "0x2::bls12381::GT"; } +export function isGT(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bls12381::GT`; } export interface GTFields { dummyField: ToField<"bool"> } export type GTReified = Reified< GT, GTFields >; -export class GT implements StructClass { static readonly $typeName = "0x2::bls12381::GT"; static readonly $numTypeParams = 0; +export class GT implements StructClass { static readonly $typeName = `${PKG_V25}::bls12381::GT`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = GT.$typeName; - - readonly $fullTypeName: "0x2::bls12381::GT"; - - readonly $typeArgs: []; + readonly $typeName = GT.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bls12381::GT`; readonly $typeArgs: []; readonly $isPhantom = GT.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: GTFields, ) { this.$fullTypeName = composeSuiType( GT.$typeName, ...typeArgs ) as "0x2::bls12381::GT"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: GTFields, ) { this.$fullTypeName = composeSuiType( GT.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bls12381::GT`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): GTReified { return { typeName: GT.$typeName, fullTypeName: composeSuiType( GT.$typeName, ...[] ) as "0x2::bls12381::GT", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => GT.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => GT.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => GT.fromBcs( data, ), bcs: GT.bcs, fromJSONField: (field: any) => GT.fromJSONField( field, ), fromJSON: (json: Record) => GT.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => GT.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => GT.fetch( client, id, ), new: ( fields: GTFields, ) => { return new GT( [], fields ) }, kind: "StructClassReified", } } + static reified( ): GTReified { return { typeName: GT.$typeName, fullTypeName: composeSuiType( GT.$typeName, ...[] ) as `${typeof PKG_V25}::bls12381::GT`, typeArgs: [ ] as [], isPhantom: GT.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => GT.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => GT.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => GT.fromBcs( data, ), bcs: GT.bcs, fromJSONField: (field: any) => GT.fromJSONField( field, ), fromJSON: (json: Record) => GT.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => GT.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => GT.fetch( client, id, ), new: ( fields: GTFields, ) => { return new GT( [], fields ) }, kind: "StructClassReified", } } static get r() { return GT.reified() } @@ -194,33 +186,30 @@ export class GT implements StructClass { static readonly $typeName = "0x2::bls12 static fromSuiParsedData( content: SuiParsedData ): GT { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isGT(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a GT object`); } return GT.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching GT object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isGT(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a GT object`); } + return GT.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Scalar =============================== */ -export function isScalar(type: string): boolean { type = compressSuiType(type); return type === "0x2::bls12381::Scalar"; } +export function isScalar(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::bls12381::Scalar`; } export interface ScalarFields { dummyField: ToField<"bool"> } export type ScalarReified = Reified< Scalar, ScalarFields >; -export class Scalar implements StructClass { static readonly $typeName = "0x2::bls12381::Scalar"; static readonly $numTypeParams = 0; +export class Scalar implements StructClass { static readonly $typeName = `${PKG_V25}::bls12381::Scalar`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Scalar.$typeName; - - readonly $fullTypeName: "0x2::bls12381::Scalar"; - - readonly $typeArgs: []; + readonly $typeName = Scalar.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::bls12381::Scalar`; readonly $typeArgs: []; readonly $isPhantom = Scalar.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: ScalarFields, ) { this.$fullTypeName = composeSuiType( Scalar.$typeName, ...typeArgs ) as "0x2::bls12381::Scalar"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ScalarFields, ) { this.$fullTypeName = composeSuiType( Scalar.$typeName, ...typeArgs ) as `${typeof PKG_V25}::bls12381::Scalar`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): ScalarReified { return { typeName: Scalar.$typeName, fullTypeName: composeSuiType( Scalar.$typeName, ...[] ) as "0x2::bls12381::Scalar", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Scalar.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Scalar.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Scalar.fromBcs( data, ), bcs: Scalar.bcs, fromJSONField: (field: any) => Scalar.fromJSONField( field, ), fromJSON: (json: Record) => Scalar.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Scalar.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Scalar.fetch( client, id, ), new: ( fields: ScalarFields, ) => { return new Scalar( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ScalarReified { return { typeName: Scalar.$typeName, fullTypeName: composeSuiType( Scalar.$typeName, ...[] ) as `${typeof PKG_V25}::bls12381::Scalar`, typeArgs: [ ] as [], isPhantom: Scalar.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Scalar.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Scalar.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Scalar.fromBcs( data, ), bcs: Scalar.bcs, fromJSONField: (field: any) => Scalar.fromJSONField( field, ), fromJSON: (json: Record) => Scalar.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Scalar.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Scalar.fetch( client, id, ), new: ( fields: ScalarFields, ) => { return new Scalar( [], fields ) }, kind: "StructClassReified", } } static get r() { return Scalar.reified() } @@ -259,6 +248,7 @@ export class Scalar implements StructClass { static readonly $typeName = "0x2::b static fromSuiParsedData( content: SuiParsedData ): Scalar { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isScalar(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Scalar object`); } return Scalar.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Scalar object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isScalar(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Scalar object`); } + return Scalar.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/borrow/structs.ts b/src/codegen/_dependencies/source/0x2/borrow/structs.ts index 33bbaf8..41db280 100644 --- a/src/codegen/_dependencies/source/0x2/borrow/structs.ts +++ b/src/codegen/_dependencies/source/0x2/borrow/structs.ts @@ -1,33 +1,31 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Option} from "../../0x1/option/structs"; +import {PKG_V25} from "../index"; import {ID} from "../object/structs"; -import {BcsType, bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== Borrow =============================== */ -export function isBorrow(type: string): boolean { type = compressSuiType(type); return type === "0x2::borrow::Borrow"; } +export function isBorrow(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::borrow::Borrow`; } export interface BorrowFields { ref: ToField<"address">; obj: ToField } export type BorrowReified = Reified< Borrow, BorrowFields >; -export class Borrow implements StructClass { static readonly $typeName = "0x2::borrow::Borrow"; static readonly $numTypeParams = 0; +export class Borrow implements StructClass { static readonly $typeName = `${PKG_V25}::borrow::Borrow`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Borrow.$typeName; - - readonly $fullTypeName: "0x2::borrow::Borrow"; - - readonly $typeArgs: []; + readonly $typeName = Borrow.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::borrow::Borrow`; readonly $typeArgs: []; readonly $isPhantom = Borrow.$isPhantom; readonly ref: ToField<"address">; readonly obj: ToField - private constructor(typeArgs: [], fields: BorrowFields, ) { this.$fullTypeName = composeSuiType( Borrow.$typeName, ...typeArgs ) as "0x2::borrow::Borrow"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BorrowFields, ) { this.$fullTypeName = composeSuiType( Borrow.$typeName, ...typeArgs ) as `${typeof PKG_V25}::borrow::Borrow`; this.$typeArgs = typeArgs; this.ref = fields.ref;; this.obj = fields.obj; } - static reified( ): BorrowReified { return { typeName: Borrow.$typeName, fullTypeName: composeSuiType( Borrow.$typeName, ...[] ) as "0x2::borrow::Borrow", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Borrow.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Borrow.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Borrow.fromBcs( data, ), bcs: Borrow.bcs, fromJSONField: (field: any) => Borrow.fromJSONField( field, ), fromJSON: (json: Record) => Borrow.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Borrow.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Borrow.fetch( client, id, ), new: ( fields: BorrowFields, ) => { return new Borrow( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BorrowReified { return { typeName: Borrow.$typeName, fullTypeName: composeSuiType( Borrow.$typeName, ...[] ) as `${typeof PKG_V25}::borrow::Borrow`, typeArgs: [ ] as [], isPhantom: Borrow.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Borrow.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Borrow.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Borrow.fromBcs( data, ), bcs: Borrow.bcs, fromJSONField: (field: any) => Borrow.fromJSONField( field, ), fromJSON: (json: Record) => Borrow.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Borrow.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Borrow.fetch( client, id, ), new: ( fields: BorrowFields, ) => { return new Borrow( [], fields ) }, kind: "StructClassReified", } } static get r() { return Borrow.reified() } @@ -66,33 +64,30 @@ export class Borrow implements StructClass { static readonly $typeName = "0x2::b static fromSuiParsedData( content: SuiParsedData ): Borrow { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBorrow(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Borrow object`); } return Borrow.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Borrow object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBorrow(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Borrow object`); } + return Borrow.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Referent =============================== */ -export function isReferent(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::borrow::Referent<"); } +export function isReferent(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::borrow::Referent` + '<'); } export interface ReferentFields { id: ToField<"address">; value: ToField> } export type ReferentReified = Reified< Referent, ReferentFields >; -export class Referent implements StructClass { static readonly $typeName = "0x2::borrow::Referent"; static readonly $numTypeParams = 1; - - readonly $typeName = Referent.$typeName; +export class Referent implements StructClass { static readonly $typeName = `${PKG_V25}::borrow::Referent`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; - readonly $fullTypeName: `0x2::borrow::Referent<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; + readonly $typeName = Referent.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::borrow::Referent<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = Referent.$isPhantom; readonly id: ToField<"address">; readonly value: ToField> - private constructor(typeArgs: [ToTypeStr], fields: ReferentFields, ) { this.$fullTypeName = composeSuiType( Referent.$typeName, ...typeArgs ) as `0x2::borrow::Referent<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: ReferentFields, ) { this.$fullTypeName = composeSuiType( Referent.$typeName, ...typeArgs ) as `${typeof PKG_V25}::borrow::Referent<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.value = fields.value; } - static reified>( T: T ): ReferentReified> { return { typeName: Referent.$typeName, fullTypeName: composeSuiType( Referent.$typeName, ...[extractType(T)] ) as `0x2::borrow::Referent<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Referent.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Referent.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Referent.fromBcs( T, data, ), bcs: Referent.bcs(toBcs(T)), fromJSONField: (field: any) => Referent.fromJSONField( T, field, ), fromJSON: (json: Record) => Referent.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Referent.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Referent.fetch( client, T, id, ), new: ( fields: ReferentFields>, ) => { return new Referent( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ReferentReified> { return { typeName: Referent.$typeName, fullTypeName: composeSuiType( Referent.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::borrow::Referent<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], isPhantom: Referent.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Referent.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Referent.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Referent.fromBcs( T, data, ), bcs: Referent.bcs(toBcs(T)), fromJSONField: (field: any) => Referent.fromJSONField( T, field, ), fromJSON: (json: Record) => Referent.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Referent.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Referent.fetch( client, T, id, ), new: ( fields: ReferentFields>, ) => { return new Referent( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Referent.reified } @@ -118,7 +113,7 @@ export class Referent implements StructClass { static re toJSONField() { return { - id: this.id,value: fieldToJSON>(`0x1::option::Option<${this.$typeArgs[0]}>`, this.value), + id: this.id,value: fieldToJSON>(`${Option.$typeName}<${this.$typeArgs[0]}>`, this.value), } } @@ -133,6 +128,9 @@ export class Referent implements StructClass { static re static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Referent> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isReferent(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Referent object`); } return Referent.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Referent object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isReferent(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Referent object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Referent.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/clock/structs.ts b/src/codegen/_dependencies/source/0x2/clock/structs.ts index 2324cfe..d85ba91 100644 --- a/src/codegen/_dependencies/source/0x2/clock/structs.ts +++ b/src/codegen/_dependencies/source/0x2/clock/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Clock =============================== */ -export function isClock(type: string): boolean { type = compressSuiType(type); return type === "0x2::clock::Clock"; } +export function isClock(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::clock::Clock`; } export interface ClockFields { id: ToField; timestampMs: ToField<"u64"> } export type ClockReified = Reified< Clock, ClockFields >; -export class Clock implements StructClass { static readonly $typeName = "0x2::clock::Clock"; static readonly $numTypeParams = 0; +export class Clock implements StructClass { static readonly $typeName = `${PKG_V25}::clock::Clock`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Clock.$typeName; - - readonly $fullTypeName: "0x2::clock::Clock"; - - readonly $typeArgs: []; + readonly $typeName = Clock.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::clock::Clock`; readonly $typeArgs: []; readonly $isPhantom = Clock.$isPhantom; readonly id: ToField; readonly timestampMs: ToField<"u64"> - private constructor(typeArgs: [], fields: ClockFields, ) { this.$fullTypeName = composeSuiType( Clock.$typeName, ...typeArgs ) as "0x2::clock::Clock"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ClockFields, ) { this.$fullTypeName = composeSuiType( Clock.$typeName, ...typeArgs ) as `${typeof PKG_V25}::clock::Clock`; this.$typeArgs = typeArgs; this.id = fields.id;; this.timestampMs = fields.timestampMs; } - static reified( ): ClockReified { return { typeName: Clock.$typeName, fullTypeName: composeSuiType( Clock.$typeName, ...[] ) as "0x2::clock::Clock", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Clock.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Clock.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Clock.fromBcs( data, ), bcs: Clock.bcs, fromJSONField: (field: any) => Clock.fromJSONField( field, ), fromJSON: (json: Record) => Clock.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Clock.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Clock.fetch( client, id, ), new: ( fields: ClockFields, ) => { return new Clock( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ClockReified { return { typeName: Clock.$typeName, fullTypeName: composeSuiType( Clock.$typeName, ...[] ) as `${typeof PKG_V25}::clock::Clock`, typeArgs: [ ] as [], isPhantom: Clock.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Clock.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Clock.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Clock.fromBcs( data, ), bcs: Clock.bcs, fromJSONField: (field: any) => Clock.fromJSONField( field, ), fromJSON: (json: Record) => Clock.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Clock.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Clock.fetch( client, id, ), new: ( fields: ClockFields, ) => { return new Clock( [], fields ) }, kind: "StructClassReified", } } static get r() { return Clock.reified() } @@ -65,6 +63,7 @@ export class Clock implements StructClass { static readonly $typeName = "0x2::cl static fromSuiParsedData( content: SuiParsedData ): Clock { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isClock(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Clock object`); } return Clock.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Clock object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isClock(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Clock object`); } + return Clock.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/coin/structs.ts b/src/codegen/_dependencies/source/0x2/coin/structs.ts index 2623a7a..3656be2 100644 --- a/src/codegen/_dependencies/source/0x2/coin/structs.ts +++ b/src/codegen/_dependencies/source/0x2/coin/structs.ts @@ -1,37 +1,35 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {String as String1} from "../../0x1/ascii/structs"; import {Option} from "../../0x1/option/structs"; import {String} from "../../0x1/string/structs"; import {Balance, Supply} from "../balance/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; import {Url} from "../url/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Coin =============================== */ -export function isCoin(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::Coin<"); } +export function isCoin(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::Coin` + '<'); } export interface CoinFields { id: ToField; balance: ToField> } export type CoinReified = Reified< Coin, CoinFields >; -export class Coin implements StructClass { static readonly $typeName = "0x2::coin::Coin"; static readonly $numTypeParams = 1; +export class Coin implements StructClass { static readonly $typeName = `${PKG_V25}::coin::Coin`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Coin.$typeName; - - readonly $fullTypeName: `0x2::coin::Coin<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Coin.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::Coin<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Coin.$isPhantom; readonly id: ToField; readonly balance: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: CoinFields, ) { this.$fullTypeName = composeSuiType( Coin.$typeName, ...typeArgs ) as `0x2::coin::Coin<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: CoinFields, ) { this.$fullTypeName = composeSuiType( Coin.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::Coin<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.balance = fields.balance; } - static reified>( T: T ): CoinReified> { return { typeName: Coin.$typeName, fullTypeName: composeSuiType( Coin.$typeName, ...[extractType(T)] ) as `0x2::coin::Coin<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Coin.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Coin.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Coin.fromBcs( T, data, ), bcs: Coin.bcs, fromJSONField: (field: any) => Coin.fromJSONField( T, field, ), fromJSON: (json: Record) => Coin.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Coin.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Coin.fetch( client, T, id, ), new: ( fields: CoinFields>, ) => { return new Coin( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): CoinReified> { return { typeName: Coin.$typeName, fullTypeName: composeSuiType( Coin.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::Coin<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Coin.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Coin.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Coin.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Coin.fromBcs( T, data, ), bcs: Coin.bcs, fromJSONField: (field: any) => Coin.fromJSONField( T, field, ), fromJSON: (json: Record) => Coin.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Coin.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Coin.fetch( client, T, id, ), new: ( fields: CoinFields>, ) => { return new Coin( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Coin.reified } @@ -70,33 +68,32 @@ export class Coin implements StructClass { static static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Coin> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isCoin(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Coin object`); } return Coin.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Coin object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isCoin(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Coin object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Coin.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== CoinMetadata =============================== */ -export function isCoinMetadata(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::CoinMetadata<"); } +export function isCoinMetadata(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::CoinMetadata` + '<'); } export interface CoinMetadataFields { id: ToField; decimals: ToField<"u8">; name: ToField; symbol: ToField; description: ToField; iconUrl: ToField> } export type CoinMetadataReified = Reified< CoinMetadata, CoinMetadataFields >; -export class CoinMetadata implements StructClass { static readonly $typeName = "0x2::coin::CoinMetadata"; static readonly $numTypeParams = 1; - - readonly $typeName = CoinMetadata.$typeName; - - readonly $fullTypeName: `0x2::coin::CoinMetadata<${PhantomToTypeStr}>`; +export class CoinMetadata implements StructClass { static readonly $typeName = `${PKG_V25}::coin::CoinMetadata`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = CoinMetadata.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::CoinMetadata<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = CoinMetadata.$isPhantom; readonly id: ToField; readonly decimals: ToField<"u8">; readonly name: ToField; readonly symbol: ToField; readonly description: ToField; readonly iconUrl: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: CoinMetadataFields, ) { this.$fullTypeName = composeSuiType( CoinMetadata.$typeName, ...typeArgs ) as `0x2::coin::CoinMetadata<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: CoinMetadataFields, ) { this.$fullTypeName = composeSuiType( CoinMetadata.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::CoinMetadata<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.decimals = fields.decimals;; this.name = fields.name;; this.symbol = fields.symbol;; this.description = fields.description;; this.iconUrl = fields.iconUrl; } - static reified>( T: T ): CoinMetadataReified> { return { typeName: CoinMetadata.$typeName, fullTypeName: composeSuiType( CoinMetadata.$typeName, ...[extractType(T)] ) as `0x2::coin::CoinMetadata<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => CoinMetadata.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => CoinMetadata.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => CoinMetadata.fromBcs( T, data, ), bcs: CoinMetadata.bcs, fromJSONField: (field: any) => CoinMetadata.fromJSONField( T, field, ), fromJSON: (json: Record) => CoinMetadata.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => CoinMetadata.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => CoinMetadata.fetch( client, T, id, ), new: ( fields: CoinMetadataFields>, ) => { return new CoinMetadata( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): CoinMetadataReified> { return { typeName: CoinMetadata.$typeName, fullTypeName: composeSuiType( CoinMetadata.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::CoinMetadata<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: CoinMetadata.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => CoinMetadata.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => CoinMetadata.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => CoinMetadata.fromBcs( T, data, ), bcs: CoinMetadata.bcs, fromJSONField: (field: any) => CoinMetadata.fromJSONField( T, field, ), fromJSON: (json: Record) => CoinMetadata.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => CoinMetadata.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => CoinMetadata.fetch( client, T, id, ), new: ( fields: CoinMetadataFields>, ) => { return new CoinMetadata( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return CoinMetadata.reified } @@ -120,7 +117,7 @@ export class CoinMetadata implements StructClass toJSONField() { return { - id: this.id,decimals: this.decimals,name: this.name,symbol: this.symbol,description: this.description,iconUrl: fieldToJSON>(`0x1::option::Option<0x2::url::Url>`, this.iconUrl), + id: this.id,decimals: this.decimals,name: this.name,symbol: this.symbol,description: this.description,iconUrl: fieldToJSON>(`${Option.$typeName}<${Url.$typeName}>`, this.iconUrl), } } @@ -135,33 +132,32 @@ export class CoinMetadata implements StructClass static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): CoinMetadata> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isCoinMetadata(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a CoinMetadata object`); } return CoinMetadata.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching CoinMetadata object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isCoinMetadata(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a CoinMetadata object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return CoinMetadata.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== CurrencyCreated =============================== */ -export function isCurrencyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::CurrencyCreated<"); } +export function isCurrencyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::CurrencyCreated` + '<'); } export interface CurrencyCreatedFields { decimals: ToField<"u8"> } export type CurrencyCreatedReified = Reified< CurrencyCreated, CurrencyCreatedFields >; -export class CurrencyCreated implements StructClass { static readonly $typeName = "0x2::coin::CurrencyCreated"; static readonly $numTypeParams = 1; - - readonly $typeName = CurrencyCreated.$typeName; +export class CurrencyCreated implements StructClass { static readonly $typeName = `${PKG_V25}::coin::CurrencyCreated`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::coin::CurrencyCreated<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = CurrencyCreated.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::CurrencyCreated<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = CurrencyCreated.$isPhantom; readonly decimals: ToField<"u8"> - private constructor(typeArgs: [PhantomToTypeStr], fields: CurrencyCreatedFields, ) { this.$fullTypeName = composeSuiType( CurrencyCreated.$typeName, ...typeArgs ) as `0x2::coin::CurrencyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: CurrencyCreatedFields, ) { this.$fullTypeName = composeSuiType( CurrencyCreated.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::CurrencyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.decimals = fields.decimals; } - static reified>( T: T ): CurrencyCreatedReified> { return { typeName: CurrencyCreated.$typeName, fullTypeName: composeSuiType( CurrencyCreated.$typeName, ...[extractType(T)] ) as `0x2::coin::CurrencyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => CurrencyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => CurrencyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => CurrencyCreated.fromBcs( T, data, ), bcs: CurrencyCreated.bcs, fromJSONField: (field: any) => CurrencyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => CurrencyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => CurrencyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => CurrencyCreated.fetch( client, T, id, ), new: ( fields: CurrencyCreatedFields>, ) => { return new CurrencyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): CurrencyCreatedReified> { return { typeName: CurrencyCreated.$typeName, fullTypeName: composeSuiType( CurrencyCreated.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::CurrencyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: CurrencyCreated.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => CurrencyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => CurrencyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => CurrencyCreated.fromBcs( T, data, ), bcs: CurrencyCreated.bcs, fromJSONField: (field: any) => CurrencyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => CurrencyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => CurrencyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => CurrencyCreated.fetch( client, T, id, ), new: ( fields: CurrencyCreatedFields>, ) => { return new CurrencyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return CurrencyCreated.reified } @@ -200,33 +196,32 @@ export class CurrencyCreated implements StructCla static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): CurrencyCreated> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isCurrencyCreated(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a CurrencyCreated object`); } return CurrencyCreated.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching CurrencyCreated object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isCurrencyCreated(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a CurrencyCreated object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return CurrencyCreated.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== DenyCap =============================== */ -export function isDenyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::DenyCap<"); } +export function isDenyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::DenyCap` + '<'); } export interface DenyCapFields { id: ToField } export type DenyCapReified = Reified< DenyCap, DenyCapFields >; -export class DenyCap implements StructClass { static readonly $typeName = "0x2::coin::DenyCap"; static readonly $numTypeParams = 1; +export class DenyCap implements StructClass { static readonly $typeName = `${PKG_V25}::coin::DenyCap`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = DenyCap.$typeName; - - readonly $fullTypeName: `0x2::coin::DenyCap<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = DenyCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::DenyCap<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = DenyCap.$isPhantom; readonly id: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: DenyCapFields, ) { this.$fullTypeName = composeSuiType( DenyCap.$typeName, ...typeArgs ) as `0x2::coin::DenyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: DenyCapFields, ) { this.$fullTypeName = composeSuiType( DenyCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::DenyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified>( T: T ): DenyCapReified> { return { typeName: DenyCap.$typeName, fullTypeName: composeSuiType( DenyCap.$typeName, ...[extractType(T)] ) as `0x2::coin::DenyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => DenyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DenyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => DenyCap.fromBcs( T, data, ), bcs: DenyCap.bcs, fromJSONField: (field: any) => DenyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => DenyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => DenyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => DenyCap.fetch( client, T, id, ), new: ( fields: DenyCapFields>, ) => { return new DenyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): DenyCapReified> { return { typeName: DenyCap.$typeName, fullTypeName: composeSuiType( DenyCap.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::DenyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: DenyCap.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => DenyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DenyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => DenyCap.fromBcs( T, data, ), bcs: DenyCap.bcs, fromJSONField: (field: any) => DenyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => DenyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => DenyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => DenyCap.fetch( client, T, id, ), new: ( fields: DenyCapFields>, ) => { return new DenyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return DenyCap.reified } @@ -265,33 +260,32 @@ export class DenyCap implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): DenyCap> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isDenyCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a DenyCap object`); } return DenyCap.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching DenyCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isDenyCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a DenyCap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return DenyCap.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== RegulatedCoinMetadata =============================== */ -export function isRegulatedCoinMetadata(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::RegulatedCoinMetadata<"); } +export function isRegulatedCoinMetadata(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::RegulatedCoinMetadata` + '<'); } export interface RegulatedCoinMetadataFields { id: ToField; coinMetadataObject: ToField; denyCapObject: ToField } export type RegulatedCoinMetadataReified = Reified< RegulatedCoinMetadata, RegulatedCoinMetadataFields >; -export class RegulatedCoinMetadata implements StructClass { static readonly $typeName = "0x2::coin::RegulatedCoinMetadata"; static readonly $numTypeParams = 1; - - readonly $typeName = RegulatedCoinMetadata.$typeName; - - readonly $fullTypeName: `0x2::coin::RegulatedCoinMetadata<${PhantomToTypeStr}>`; +export class RegulatedCoinMetadata implements StructClass { static readonly $typeName = `${PKG_V25}::coin::RegulatedCoinMetadata`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = RegulatedCoinMetadata.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::RegulatedCoinMetadata<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = RegulatedCoinMetadata.$isPhantom; readonly id: ToField; readonly coinMetadataObject: ToField; readonly denyCapObject: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: RegulatedCoinMetadataFields, ) { this.$fullTypeName = composeSuiType( RegulatedCoinMetadata.$typeName, ...typeArgs ) as `0x2::coin::RegulatedCoinMetadata<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: RegulatedCoinMetadataFields, ) { this.$fullTypeName = composeSuiType( RegulatedCoinMetadata.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::RegulatedCoinMetadata<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.coinMetadataObject = fields.coinMetadataObject;; this.denyCapObject = fields.denyCapObject; } - static reified>( T: T ): RegulatedCoinMetadataReified> { return { typeName: RegulatedCoinMetadata.$typeName, fullTypeName: composeSuiType( RegulatedCoinMetadata.$typeName, ...[extractType(T)] ) as `0x2::coin::RegulatedCoinMetadata<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => RegulatedCoinMetadata.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RegulatedCoinMetadata.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RegulatedCoinMetadata.fromBcs( T, data, ), bcs: RegulatedCoinMetadata.bcs, fromJSONField: (field: any) => RegulatedCoinMetadata.fromJSONField( T, field, ), fromJSON: (json: Record) => RegulatedCoinMetadata.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RegulatedCoinMetadata.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RegulatedCoinMetadata.fetch( client, T, id, ), new: ( fields: RegulatedCoinMetadataFields>, ) => { return new RegulatedCoinMetadata( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): RegulatedCoinMetadataReified> { return { typeName: RegulatedCoinMetadata.$typeName, fullTypeName: composeSuiType( RegulatedCoinMetadata.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::RegulatedCoinMetadata<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: RegulatedCoinMetadata.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => RegulatedCoinMetadata.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RegulatedCoinMetadata.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RegulatedCoinMetadata.fromBcs( T, data, ), bcs: RegulatedCoinMetadata.bcs, fromJSONField: (field: any) => RegulatedCoinMetadata.fromJSONField( T, field, ), fromJSON: (json: Record) => RegulatedCoinMetadata.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RegulatedCoinMetadata.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RegulatedCoinMetadata.fetch( client, T, id, ), new: ( fields: RegulatedCoinMetadataFields>, ) => { return new RegulatedCoinMetadata( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return RegulatedCoinMetadata.reified } @@ -330,33 +324,32 @@ export class RegulatedCoinMetadata implements Str static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): RegulatedCoinMetadata> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRegulatedCoinMetadata(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a RegulatedCoinMetadata object`); } return RegulatedCoinMetadata.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching RegulatedCoinMetadata object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRegulatedCoinMetadata(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a RegulatedCoinMetadata object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return RegulatedCoinMetadata.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TreasuryCap =============================== */ -export function isTreasuryCap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::coin::TreasuryCap<"); } +export function isTreasuryCap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::coin::TreasuryCap` + '<'); } export interface TreasuryCapFields { id: ToField; totalSupply: ToField> } export type TreasuryCapReified = Reified< TreasuryCap, TreasuryCapFields >; -export class TreasuryCap implements StructClass { static readonly $typeName = "0x2::coin::TreasuryCap"; static readonly $numTypeParams = 1; - - readonly $typeName = TreasuryCap.$typeName; +export class TreasuryCap implements StructClass { static readonly $typeName = `${PKG_V25}::coin::TreasuryCap`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::coin::TreasuryCap<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TreasuryCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::coin::TreasuryCap<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TreasuryCap.$isPhantom; readonly id: ToField; readonly totalSupply: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: TreasuryCapFields, ) { this.$fullTypeName = composeSuiType( TreasuryCap.$typeName, ...typeArgs ) as `0x2::coin::TreasuryCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TreasuryCapFields, ) { this.$fullTypeName = composeSuiType( TreasuryCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::coin::TreasuryCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.totalSupply = fields.totalSupply; } - static reified>( T: T ): TreasuryCapReified> { return { typeName: TreasuryCap.$typeName, fullTypeName: composeSuiType( TreasuryCap.$typeName, ...[extractType(T)] ) as `0x2::coin::TreasuryCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TreasuryCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TreasuryCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TreasuryCap.fromBcs( T, data, ), bcs: TreasuryCap.bcs, fromJSONField: (field: any) => TreasuryCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TreasuryCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TreasuryCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TreasuryCap.fetch( client, T, id, ), new: ( fields: TreasuryCapFields>, ) => { return new TreasuryCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TreasuryCapReified> { return { typeName: TreasuryCap.$typeName, fullTypeName: composeSuiType( TreasuryCap.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::coin::TreasuryCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TreasuryCap.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TreasuryCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TreasuryCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TreasuryCap.fromBcs( T, data, ), bcs: TreasuryCap.bcs, fromJSONField: (field: any) => TreasuryCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TreasuryCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TreasuryCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TreasuryCap.fetch( client, T, id, ), new: ( fields: TreasuryCapFields>, ) => { return new TreasuryCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TreasuryCap.reified } @@ -395,6 +388,9 @@ export class TreasuryCap implements StructClass { static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TreasuryCap> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTreasuryCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TreasuryCap object`); } return TreasuryCap.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TreasuryCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTreasuryCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TreasuryCap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TreasuryCap.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/deny-list/structs.ts b/src/codegen/_dependencies/source/0x2/deny-list/structs.ts index 0ef1c10..64ce16f 100644 --- a/src/codegen/_dependencies/source/0x2/deny-list/structs.ts +++ b/src/codegen/_dependencies/source/0x2/deny-list/structs.ts @@ -2,35 +2,33 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, ToTypeStr as ToPhantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {Bag} from "../bag/structs"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; import {Table} from "../table/structs"; import {VecSet} from "../vec-set/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== DenyList =============================== */ -export function isDenyList(type: string): boolean { type = compressSuiType(type); return type === "0x2::deny_list::DenyList"; } +export function isDenyList(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::deny_list::DenyList`; } export interface DenyListFields { id: ToField; lists: ToField } export type DenyListReified = Reified< DenyList, DenyListFields >; -export class DenyList implements StructClass { static readonly $typeName = "0x2::deny_list::DenyList"; static readonly $numTypeParams = 0; +export class DenyList implements StructClass { static readonly $typeName = `${PKG_V25}::deny_list::DenyList`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = DenyList.$typeName; - - readonly $fullTypeName: "0x2::deny_list::DenyList"; - - readonly $typeArgs: []; + readonly $typeName = DenyList.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::deny_list::DenyList`; readonly $typeArgs: []; readonly $isPhantom = DenyList.$isPhantom; readonly id: ToField; readonly lists: ToField - private constructor(typeArgs: [], fields: DenyListFields, ) { this.$fullTypeName = composeSuiType( DenyList.$typeName, ...typeArgs ) as "0x2::deny_list::DenyList"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: DenyListFields, ) { this.$fullTypeName = composeSuiType( DenyList.$typeName, ...typeArgs ) as `${typeof PKG_V25}::deny_list::DenyList`; this.$typeArgs = typeArgs; this.id = fields.id;; this.lists = fields.lists; } - static reified( ): DenyListReified { return { typeName: DenyList.$typeName, fullTypeName: composeSuiType( DenyList.$typeName, ...[] ) as "0x2::deny_list::DenyList", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => DenyList.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DenyList.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => DenyList.fromBcs( data, ), bcs: DenyList.bcs, fromJSONField: (field: any) => DenyList.fromJSONField( field, ), fromJSON: (json: Record) => DenyList.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => DenyList.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => DenyList.fetch( client, id, ), new: ( fields: DenyListFields, ) => { return new DenyList( [], fields ) }, kind: "StructClassReified", } } + static reified( ): DenyListReified { return { typeName: DenyList.$typeName, fullTypeName: composeSuiType( DenyList.$typeName, ...[] ) as `${typeof PKG_V25}::deny_list::DenyList`, typeArgs: [ ] as [], isPhantom: DenyList.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => DenyList.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DenyList.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => DenyList.fromBcs( data, ), bcs: DenyList.bcs, fromJSONField: (field: any) => DenyList.fromJSONField( field, ), fromJSON: (json: Record) => DenyList.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => DenyList.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => DenyList.fetch( client, id, ), new: ( fields: DenyListFields, ) => { return new DenyList( [], fields ) }, kind: "StructClassReified", } } static get r() { return DenyList.reified() } @@ -69,33 +67,30 @@ export class DenyList implements StructClass { static readonly $typeName = "0x2: static fromSuiParsedData( content: SuiParsedData ): DenyList { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isDenyList(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a DenyList object`); } return DenyList.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching DenyList object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isDenyList(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a DenyList object`); } + return DenyList.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== PerTypeList =============================== */ -export function isPerTypeList(type: string): boolean { type = compressSuiType(type); return type === "0x2::deny_list::PerTypeList"; } +export function isPerTypeList(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::deny_list::PerTypeList`; } export interface PerTypeListFields { id: ToField; deniedCount: ToField>; deniedAddresses: ToField>, ToPhantom>>> } export type PerTypeListReified = Reified< PerTypeList, PerTypeListFields >; -export class PerTypeList implements StructClass { static readonly $typeName = "0x2::deny_list::PerTypeList"; static readonly $numTypeParams = 0; +export class PerTypeList implements StructClass { static readonly $typeName = `${PKG_V25}::deny_list::PerTypeList`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = PerTypeList.$typeName; - - readonly $fullTypeName: "0x2::deny_list::PerTypeList"; - - readonly $typeArgs: []; + readonly $typeName = PerTypeList.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::deny_list::PerTypeList`; readonly $typeArgs: []; readonly $isPhantom = PerTypeList.$isPhantom; readonly id: ToField; readonly deniedCount: ToField>; readonly deniedAddresses: ToField>, ToPhantom>>> - private constructor(typeArgs: [], fields: PerTypeListFields, ) { this.$fullTypeName = composeSuiType( PerTypeList.$typeName, ...typeArgs ) as "0x2::deny_list::PerTypeList"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: PerTypeListFields, ) { this.$fullTypeName = composeSuiType( PerTypeList.$typeName, ...typeArgs ) as `${typeof PKG_V25}::deny_list::PerTypeList`; this.$typeArgs = typeArgs; this.id = fields.id;; this.deniedCount = fields.deniedCount;; this.deniedAddresses = fields.deniedAddresses; } - static reified( ): PerTypeListReified { return { typeName: PerTypeList.$typeName, fullTypeName: composeSuiType( PerTypeList.$typeName, ...[] ) as "0x2::deny_list::PerTypeList", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => PerTypeList.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PerTypeList.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PerTypeList.fromBcs( data, ), bcs: PerTypeList.bcs, fromJSONField: (field: any) => PerTypeList.fromJSONField( field, ), fromJSON: (json: Record) => PerTypeList.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PerTypeList.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PerTypeList.fetch( client, id, ), new: ( fields: PerTypeListFields, ) => { return new PerTypeList( [], fields ) }, kind: "StructClassReified", } } + static reified( ): PerTypeListReified { return { typeName: PerTypeList.$typeName, fullTypeName: composeSuiType( PerTypeList.$typeName, ...[] ) as `${typeof PKG_V25}::deny_list::PerTypeList`, typeArgs: [ ] as [], isPhantom: PerTypeList.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => PerTypeList.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PerTypeList.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PerTypeList.fromBcs( data, ), bcs: PerTypeList.bcs, fromJSONField: (field: any) => PerTypeList.fromJSONField( field, ), fromJSON: (json: Record) => PerTypeList.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PerTypeList.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PerTypeList.fetch( client, id, ), new: ( fields: PerTypeListFields, ) => { return new PerTypeList( [], fields ) }, kind: "StructClassReified", } } static get r() { return PerTypeList.reified() } @@ -134,6 +129,7 @@ export class PerTypeList implements StructClass { static readonly $typeName = "0 static fromSuiParsedData( content: SuiParsedData ): PerTypeList { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPerTypeList(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a PerTypeList object`); } return PerTypeList.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching PerTypeList object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPerTypeList(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a PerTypeList object`); } + return PerTypeList.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/display/structs.ts b/src/codegen/_dependencies/source/0x2/display/structs.ts index e1ce242..7a31cad 100644 --- a/src/codegen/_dependencies/source/0x2/display/structs.ts +++ b/src/codegen/_dependencies/source/0x2/display/structs.ts @@ -1,34 +1,32 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {String} from "../../0x1/string/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; import {VecMap} from "../vec-map/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Display =============================== */ -export function isDisplay(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::display::Display<"); } +export function isDisplay(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::display::Display` + '<'); } export interface DisplayFields { id: ToField; fields: ToField>; version: ToField<"u16"> } export type DisplayReified = Reified< Display, DisplayFields >; -export class Display implements StructClass { static readonly $typeName = "0x2::display::Display"; static readonly $numTypeParams = 1; +export class Display implements StructClass { static readonly $typeName = `${PKG_V25}::display::Display`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Display.$typeName; - - readonly $fullTypeName: `0x2::display::Display<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Display.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::display::Display<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Display.$isPhantom; readonly id: ToField; readonly fields: ToField>; readonly version: ToField<"u16"> - private constructor(typeArgs: [PhantomToTypeStr], fields: DisplayFields, ) { this.$fullTypeName = composeSuiType( Display.$typeName, ...typeArgs ) as `0x2::display::Display<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: DisplayFields, ) { this.$fullTypeName = composeSuiType( Display.$typeName, ...typeArgs ) as `${typeof PKG_V25}::display::Display<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.fields = fields.fields;; this.version = fields.version; } - static reified>( T: T ): DisplayReified> { return { typeName: Display.$typeName, fullTypeName: composeSuiType( Display.$typeName, ...[extractType(T)] ) as `0x2::display::Display<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Display.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Display.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Display.fromBcs( T, data, ), bcs: Display.bcs, fromJSONField: (field: any) => Display.fromJSONField( T, field, ), fromJSON: (json: Record) => Display.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Display.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Display.fetch( client, T, id, ), new: ( fields: DisplayFields>, ) => { return new Display( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): DisplayReified> { return { typeName: Display.$typeName, fullTypeName: composeSuiType( Display.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::display::Display<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Display.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Display.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Display.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Display.fromBcs( T, data, ), bcs: Display.bcs, fromJSONField: (field: any) => Display.fromJSONField( T, field, ), fromJSON: (json: Record) => Display.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Display.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Display.fetch( client, T, id, ), new: ( fields: DisplayFields>, ) => { return new Display( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Display.reified } @@ -67,33 +65,32 @@ export class Display implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Display> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isDisplay(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Display object`); } return Display.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Display object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isDisplay(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Display object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Display.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== DisplayCreated =============================== */ -export function isDisplayCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::display::DisplayCreated<"); } +export function isDisplayCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::display::DisplayCreated` + '<'); } export interface DisplayCreatedFields { id: ToField } export type DisplayCreatedReified = Reified< DisplayCreated, DisplayCreatedFields >; -export class DisplayCreated implements StructClass { static readonly $typeName = "0x2::display::DisplayCreated"; static readonly $numTypeParams = 1; - - readonly $typeName = DisplayCreated.$typeName; - - readonly $fullTypeName: `0x2::display::DisplayCreated<${PhantomToTypeStr}>`; +export class DisplayCreated implements StructClass { static readonly $typeName = `${PKG_V25}::display::DisplayCreated`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = DisplayCreated.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::display::DisplayCreated<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = DisplayCreated.$isPhantom; readonly id: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: DisplayCreatedFields, ) { this.$fullTypeName = composeSuiType( DisplayCreated.$typeName, ...typeArgs ) as `0x2::display::DisplayCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: DisplayCreatedFields, ) { this.$fullTypeName = composeSuiType( DisplayCreated.$typeName, ...typeArgs ) as `${typeof PKG_V25}::display::DisplayCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified>( T: T ): DisplayCreatedReified> { return { typeName: DisplayCreated.$typeName, fullTypeName: composeSuiType( DisplayCreated.$typeName, ...[extractType(T)] ) as `0x2::display::DisplayCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => DisplayCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DisplayCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => DisplayCreated.fromBcs( T, data, ), bcs: DisplayCreated.bcs, fromJSONField: (field: any) => DisplayCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => DisplayCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => DisplayCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => DisplayCreated.fetch( client, T, id, ), new: ( fields: DisplayCreatedFields>, ) => { return new DisplayCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): DisplayCreatedReified> { return { typeName: DisplayCreated.$typeName, fullTypeName: composeSuiType( DisplayCreated.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::display::DisplayCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: DisplayCreated.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => DisplayCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => DisplayCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => DisplayCreated.fromBcs( T, data, ), bcs: DisplayCreated.bcs, fromJSONField: (field: any) => DisplayCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => DisplayCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => DisplayCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => DisplayCreated.fetch( client, T, id, ), new: ( fields: DisplayCreatedFields>, ) => { return new DisplayCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return DisplayCreated.reified } @@ -132,33 +129,32 @@ export class DisplayCreated implements StructClas static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): DisplayCreated> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isDisplayCreated(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a DisplayCreated object`); } return DisplayCreated.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching DisplayCreated object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isDisplayCreated(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a DisplayCreated object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return DisplayCreated.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== VersionUpdated =============================== */ -export function isVersionUpdated(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::display::VersionUpdated<"); } +export function isVersionUpdated(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::display::VersionUpdated` + '<'); } export interface VersionUpdatedFields { id: ToField; version: ToField<"u16">; fields: ToField> } export type VersionUpdatedReified = Reified< VersionUpdated, VersionUpdatedFields >; -export class VersionUpdated implements StructClass { static readonly $typeName = "0x2::display::VersionUpdated"; static readonly $numTypeParams = 1; - - readonly $typeName = VersionUpdated.$typeName; +export class VersionUpdated implements StructClass { static readonly $typeName = `${PKG_V25}::display::VersionUpdated`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::display::VersionUpdated<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = VersionUpdated.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::display::VersionUpdated<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = VersionUpdated.$isPhantom; readonly id: ToField; readonly version: ToField<"u16">; readonly fields: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: VersionUpdatedFields, ) { this.$fullTypeName = composeSuiType( VersionUpdated.$typeName, ...typeArgs ) as `0x2::display::VersionUpdated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: VersionUpdatedFields, ) { this.$fullTypeName = composeSuiType( VersionUpdated.$typeName, ...typeArgs ) as `${typeof PKG_V25}::display::VersionUpdated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.version = fields.version;; this.fields = fields.fields; } - static reified>( T: T ): VersionUpdatedReified> { return { typeName: VersionUpdated.$typeName, fullTypeName: composeSuiType( VersionUpdated.$typeName, ...[extractType(T)] ) as `0x2::display::VersionUpdated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => VersionUpdated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VersionUpdated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => VersionUpdated.fromBcs( T, data, ), bcs: VersionUpdated.bcs, fromJSONField: (field: any) => VersionUpdated.fromJSONField( T, field, ), fromJSON: (json: Record) => VersionUpdated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => VersionUpdated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => VersionUpdated.fetch( client, T, id, ), new: ( fields: VersionUpdatedFields>, ) => { return new VersionUpdated( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): VersionUpdatedReified> { return { typeName: VersionUpdated.$typeName, fullTypeName: composeSuiType( VersionUpdated.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::display::VersionUpdated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: VersionUpdated.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => VersionUpdated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VersionUpdated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => VersionUpdated.fromBcs( T, data, ), bcs: VersionUpdated.bcs, fromJSONField: (field: any) => VersionUpdated.fromJSONField( T, field, ), fromJSON: (json: Record) => VersionUpdated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => VersionUpdated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => VersionUpdated.fetch( client, T, id, ), new: ( fields: VersionUpdatedFields>, ) => { return new VersionUpdated( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return VersionUpdated.reified } @@ -197,6 +193,9 @@ export class VersionUpdated implements StructClas static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): VersionUpdated> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVersionUpdated(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VersionUpdated object`); } return VersionUpdated.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VersionUpdated object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVersionUpdated(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VersionUpdated object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return VersionUpdated.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/dynamic-field/structs.ts b/src/codegen/_dependencies/source/0x2/dynamic-field/structs.ts index a6d57e9..c85e59e 100644 --- a/src/codegen/_dependencies/source/0x2/dynamic-field/structs.ts +++ b/src/codegen/_dependencies/source/0x2/dynamic-field/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Field =============================== */ -export function isField(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::dynamic_field::Field<"); } +export function isField(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::dynamic_field::Field` + '<'); } export interface FieldFields { id: ToField; name: ToField; value: ToField } export type FieldReified = Reified< Field, FieldFields >; -export class Field implements StructClass { static readonly $typeName = "0x2::dynamic_field::Field"; static readonly $numTypeParams = 2; +export class Field implements StructClass { static readonly $typeName = `${PKG_V25}::dynamic_field::Field`; static readonly $numTypeParams = 2; static readonly $isPhantom = [false,false,] as const; - readonly $typeName = Field.$typeName; - - readonly $fullTypeName: `0x2::dynamic_field::Field<${ToTypeStr}, ${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr, ToTypeStr]; + readonly $typeName = Field.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::dynamic_field::Field<${ToTypeStr}, ${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr, ToTypeStr]; readonly $isPhantom = Field.$isPhantom; readonly id: ToField; readonly name: ToField; readonly value: ToField - private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: FieldFields, ) { this.$fullTypeName = composeSuiType( Field.$typeName, ...typeArgs ) as `0x2::dynamic_field::Field<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: FieldFields, ) { this.$fullTypeName = composeSuiType( Field.$typeName, ...typeArgs ) as `${typeof PKG_V25}::dynamic_field::Field<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.name = fields.name;; this.value = fields.value; } - static reified, Value extends Reified>( Name: Name, Value: Value ): FieldReified, ToTypeArgument> { return { typeName: Field.$typeName, fullTypeName: composeSuiType( Field.$typeName, ...[extractType(Name), extractType(Value)] ) as `0x2::dynamic_field::Field<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(Name), extractType(Value) ] as [ToTypeStr>, ToTypeStr>], reifiedTypeArgs: [Name, Value], fromFields: (fields: Record) => Field.fromFields( [Name, Value], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Field.fromFieldsWithTypes( [Name, Value], item, ), fromBcs: (data: Uint8Array) => Field.fromBcs( [Name, Value], data, ), bcs: Field.bcs(toBcs(Name), toBcs(Value)), fromJSONField: (field: any) => Field.fromJSONField( [Name, Value], field, ), fromJSON: (json: Record) => Field.fromJSON( [Name, Value], json, ), fromSuiParsedData: (content: SuiParsedData) => Field.fromSuiParsedData( [Name, Value], content, ), fetch: async (client: SuiClient, id: string) => Field.fetch( client, [Name, Value], id, ), new: ( fields: FieldFields, ToTypeArgument>, ) => { return new Field( [extractType(Name), extractType(Value)], fields ) }, kind: "StructClassReified", } } + static reified, Value extends Reified>( Name: Name, Value: Value ): FieldReified, ToTypeArgument> { return { typeName: Field.$typeName, fullTypeName: composeSuiType( Field.$typeName, ...[extractType(Name), extractType(Value)] ) as `${typeof PKG_V25}::dynamic_field::Field<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(Name), extractType(Value) ] as [ToTypeStr>, ToTypeStr>], isPhantom: Field.$isPhantom, reifiedTypeArgs: [Name, Value], fromFields: (fields: Record) => Field.fromFields( [Name, Value], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Field.fromFieldsWithTypes( [Name, Value], item, ), fromBcs: (data: Uint8Array) => Field.fromBcs( [Name, Value], data, ), bcs: Field.bcs(toBcs(Name), toBcs(Value)), fromJSONField: (field: any) => Field.fromJSONField( [Name, Value], field, ), fromJSON: (json: Record) => Field.fromJSON( [Name, Value], json, ), fromSuiParsedData: (content: SuiParsedData) => Field.fromSuiParsedData( [Name, Value], content, ), fetch: async (client: SuiClient, id: string) => Field.fetch( client, [Name, Value], id, ), new: ( fields: FieldFields, ToTypeArgument>, ) => { return new Field( [extractType(Name), extractType(Value)], fields ) }, kind: "StructClassReified", } } static get r() { return Field.reified } @@ -65,6 +63,9 @@ export class Field implem static fromSuiParsedData, Value extends Reified>( typeArgs: [Name, Value], content: SuiParsedData ): Field, ToTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isField(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Field object`); } return Field.fromFieldsWithTypes( typeArgs, content ); } static async fetch, Value extends Reified>( client: SuiClient, typeArgs: [Name, Value], id: string ): Promise, ToTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Field object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isField(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Field object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return Field.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/dynamic-object-field/structs.ts b/src/codegen/_dependencies/source/0x2/dynamic-object-field/structs.ts index a88c5b1..d932b81 100644 --- a/src/codegen/_dependencies/source/0x2/dynamic-object-field/structs.ts +++ b/src/codegen/_dependencies/source/0x2/dynamic-object-field/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Wrapper =============================== */ -export function isWrapper(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::dynamic_object_field::Wrapper<"); } +export function isWrapper(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::dynamic_object_field::Wrapper` + '<'); } export interface WrapperFields { name: ToField } export type WrapperReified = Reified< Wrapper, WrapperFields >; -export class Wrapper implements StructClass { static readonly $typeName = "0x2::dynamic_object_field::Wrapper"; static readonly $numTypeParams = 1; +export class Wrapper implements StructClass { static readonly $typeName = `${PKG_V25}::dynamic_object_field::Wrapper`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; - readonly $typeName = Wrapper.$typeName; - - readonly $fullTypeName: `0x2::dynamic_object_field::Wrapper<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; + readonly $typeName = Wrapper.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::dynamic_object_field::Wrapper<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = Wrapper.$isPhantom; readonly name: ToField - private constructor(typeArgs: [ToTypeStr], fields: WrapperFields, ) { this.$fullTypeName = composeSuiType( Wrapper.$typeName, ...typeArgs ) as `0x2::dynamic_object_field::Wrapper<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: WrapperFields, ) { this.$fullTypeName = composeSuiType( Wrapper.$typeName, ...typeArgs ) as `${typeof PKG_V25}::dynamic_object_field::Wrapper<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.name = fields.name; } - static reified>( Name: Name ): WrapperReified> { return { typeName: Wrapper.$typeName, fullTypeName: composeSuiType( Wrapper.$typeName, ...[extractType(Name)] ) as `0x2::dynamic_object_field::Wrapper<${ToTypeStr>}>`, typeArgs: [ extractType(Name) ] as [ToTypeStr>], reifiedTypeArgs: [Name], fromFields: (fields: Record) => Wrapper.fromFields( Name, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Wrapper.fromFieldsWithTypes( Name, item, ), fromBcs: (data: Uint8Array) => Wrapper.fromBcs( Name, data, ), bcs: Wrapper.bcs(toBcs(Name)), fromJSONField: (field: any) => Wrapper.fromJSONField( Name, field, ), fromJSON: (json: Record) => Wrapper.fromJSON( Name, json, ), fromSuiParsedData: (content: SuiParsedData) => Wrapper.fromSuiParsedData( Name, content, ), fetch: async (client: SuiClient, id: string) => Wrapper.fetch( client, Name, id, ), new: ( fields: WrapperFields>, ) => { return new Wrapper( [extractType(Name)], fields ) }, kind: "StructClassReified", } } + static reified>( Name: Name ): WrapperReified> { return { typeName: Wrapper.$typeName, fullTypeName: composeSuiType( Wrapper.$typeName, ...[extractType(Name)] ) as `${typeof PKG_V25}::dynamic_object_field::Wrapper<${ToTypeStr>}>`, typeArgs: [ extractType(Name) ] as [ToTypeStr>], isPhantom: Wrapper.$isPhantom, reifiedTypeArgs: [Name], fromFields: (fields: Record) => Wrapper.fromFields( Name, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Wrapper.fromFieldsWithTypes( Name, item, ), fromBcs: (data: Uint8Array) => Wrapper.fromBcs( Name, data, ), bcs: Wrapper.bcs(toBcs(Name)), fromJSONField: (field: any) => Wrapper.fromJSONField( Name, field, ), fromJSON: (json: Record) => Wrapper.fromJSON( Name, json, ), fromSuiParsedData: (content: SuiParsedData) => Wrapper.fromSuiParsedData( Name, content, ), fetch: async (client: SuiClient, id: string) => Wrapper.fetch( client, Name, id, ), new: ( fields: WrapperFields>, ) => { return new Wrapper( [extractType(Name)], fields ) }, kind: "StructClassReified", } } static get r() { return Wrapper.reified } @@ -66,6 +64,9 @@ export class Wrapper implements StructClass { static static fromSuiParsedData>( typeArg: Name, content: SuiParsedData ): Wrapper> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isWrapper(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Wrapper object`); } return Wrapper.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: Name, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Wrapper object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isWrapper(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Wrapper object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Wrapper.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/groth16/structs.ts b/src/codegen/_dependencies/source/0x2/groth16/structs.ts index 130aac5..6a913e7 100644 --- a/src/codegen/_dependencies/source/0x2/groth16/structs.ts +++ b/src/codegen/_dependencies/source/0x2/groth16/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Curve =============================== */ -export function isCurve(type: string): boolean { type = compressSuiType(type); return type === "0x2::groth16::Curve"; } +export function isCurve(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::groth16::Curve`; } export interface CurveFields { id: ToField<"u8"> } export type CurveReified = Reified< Curve, CurveFields >; -export class Curve implements StructClass { static readonly $typeName = "0x2::groth16::Curve"; static readonly $numTypeParams = 0; +export class Curve implements StructClass { static readonly $typeName = `${PKG_V25}::groth16::Curve`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Curve.$typeName; - - readonly $fullTypeName: "0x2::groth16::Curve"; - - readonly $typeArgs: []; + readonly $typeName = Curve.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::groth16::Curve`; readonly $typeArgs: []; readonly $isPhantom = Curve.$isPhantom; readonly id: ToField<"u8"> - private constructor(typeArgs: [], fields: CurveFields, ) { this.$fullTypeName = composeSuiType( Curve.$typeName, ...typeArgs ) as "0x2::groth16::Curve"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: CurveFields, ) { this.$fullTypeName = composeSuiType( Curve.$typeName, ...typeArgs ) as `${typeof PKG_V25}::groth16::Curve`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified( ): CurveReified { return { typeName: Curve.$typeName, fullTypeName: composeSuiType( Curve.$typeName, ...[] ) as "0x2::groth16::Curve", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Curve.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Curve.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Curve.fromBcs( data, ), bcs: Curve.bcs, fromJSONField: (field: any) => Curve.fromJSONField( field, ), fromJSON: (json: Record) => Curve.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Curve.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Curve.fetch( client, id, ), new: ( fields: CurveFields, ) => { return new Curve( [], fields ) }, kind: "StructClassReified", } } + static reified( ): CurveReified { return { typeName: Curve.$typeName, fullTypeName: composeSuiType( Curve.$typeName, ...[] ) as `${typeof PKG_V25}::groth16::Curve`, typeArgs: [ ] as [], isPhantom: Curve.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Curve.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Curve.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Curve.fromBcs( data, ), bcs: Curve.bcs, fromJSONField: (field: any) => Curve.fromJSONField( field, ), fromJSON: (json: Record) => Curve.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Curve.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Curve.fetch( client, id, ), new: ( fields: CurveFields, ) => { return new Curve( [], fields ) }, kind: "StructClassReified", } } static get r() { return Curve.reified() } @@ -65,33 +63,30 @@ export class Curve implements StructClass { static readonly $typeName = "0x2::gr static fromSuiParsedData( content: SuiParsedData ): Curve { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isCurve(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Curve object`); } return Curve.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Curve object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isCurve(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Curve object`); } + return Curve.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== PreparedVerifyingKey =============================== */ -export function isPreparedVerifyingKey(type: string): boolean { type = compressSuiType(type); return type === "0x2::groth16::PreparedVerifyingKey"; } +export function isPreparedVerifyingKey(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::groth16::PreparedVerifyingKey`; } export interface PreparedVerifyingKeyFields { vkGammaAbcG1Bytes: ToField>; alphaG1BetaG2Bytes: ToField>; gammaG2NegPcBytes: ToField>; deltaG2NegPcBytes: ToField> } export type PreparedVerifyingKeyReified = Reified< PreparedVerifyingKey, PreparedVerifyingKeyFields >; -export class PreparedVerifyingKey implements StructClass { static readonly $typeName = "0x2::groth16::PreparedVerifyingKey"; static readonly $numTypeParams = 0; +export class PreparedVerifyingKey implements StructClass { static readonly $typeName = `${PKG_V25}::groth16::PreparedVerifyingKey`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = PreparedVerifyingKey.$typeName; - - readonly $fullTypeName: "0x2::groth16::PreparedVerifyingKey"; - - readonly $typeArgs: []; + readonly $typeName = PreparedVerifyingKey.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::groth16::PreparedVerifyingKey`; readonly $typeArgs: []; readonly $isPhantom = PreparedVerifyingKey.$isPhantom; readonly vkGammaAbcG1Bytes: ToField>; readonly alphaG1BetaG2Bytes: ToField>; readonly gammaG2NegPcBytes: ToField>; readonly deltaG2NegPcBytes: ToField> - private constructor(typeArgs: [], fields: PreparedVerifyingKeyFields, ) { this.$fullTypeName = composeSuiType( PreparedVerifyingKey.$typeName, ...typeArgs ) as "0x2::groth16::PreparedVerifyingKey"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: PreparedVerifyingKeyFields, ) { this.$fullTypeName = composeSuiType( PreparedVerifyingKey.$typeName, ...typeArgs ) as `${typeof PKG_V25}::groth16::PreparedVerifyingKey`; this.$typeArgs = typeArgs; this.vkGammaAbcG1Bytes = fields.vkGammaAbcG1Bytes;; this.alphaG1BetaG2Bytes = fields.alphaG1BetaG2Bytes;; this.gammaG2NegPcBytes = fields.gammaG2NegPcBytes;; this.deltaG2NegPcBytes = fields.deltaG2NegPcBytes; } - static reified( ): PreparedVerifyingKeyReified { return { typeName: PreparedVerifyingKey.$typeName, fullTypeName: composeSuiType( PreparedVerifyingKey.$typeName, ...[] ) as "0x2::groth16::PreparedVerifyingKey", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => PreparedVerifyingKey.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PreparedVerifyingKey.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PreparedVerifyingKey.fromBcs( data, ), bcs: PreparedVerifyingKey.bcs, fromJSONField: (field: any) => PreparedVerifyingKey.fromJSONField( field, ), fromJSON: (json: Record) => PreparedVerifyingKey.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PreparedVerifyingKey.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PreparedVerifyingKey.fetch( client, id, ), new: ( fields: PreparedVerifyingKeyFields, ) => { return new PreparedVerifyingKey( [], fields ) }, kind: "StructClassReified", } } + static reified( ): PreparedVerifyingKeyReified { return { typeName: PreparedVerifyingKey.$typeName, fullTypeName: composeSuiType( PreparedVerifyingKey.$typeName, ...[] ) as `${typeof PKG_V25}::groth16::PreparedVerifyingKey`, typeArgs: [ ] as [], isPhantom: PreparedVerifyingKey.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => PreparedVerifyingKey.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PreparedVerifyingKey.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PreparedVerifyingKey.fromBcs( data, ), bcs: PreparedVerifyingKey.bcs, fromJSONField: (field: any) => PreparedVerifyingKey.fromJSONField( field, ), fromJSON: (json: Record) => PreparedVerifyingKey.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PreparedVerifyingKey.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PreparedVerifyingKey.fetch( client, id, ), new: ( fields: PreparedVerifyingKeyFields, ) => { return new PreparedVerifyingKey( [], fields ) }, kind: "StructClassReified", } } static get r() { return PreparedVerifyingKey.reified() } @@ -130,33 +125,30 @@ export class PreparedVerifyingKey implements StructClass { static readonly $type static fromSuiParsedData( content: SuiParsedData ): PreparedVerifyingKey { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPreparedVerifyingKey(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a PreparedVerifyingKey object`); } return PreparedVerifyingKey.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching PreparedVerifyingKey object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPreparedVerifyingKey(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a PreparedVerifyingKey object`); } + return PreparedVerifyingKey.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ProofPoints =============================== */ -export function isProofPoints(type: string): boolean { type = compressSuiType(type); return type === "0x2::groth16::ProofPoints"; } +export function isProofPoints(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::groth16::ProofPoints`; } export interface ProofPointsFields { bytes: ToField> } export type ProofPointsReified = Reified< ProofPoints, ProofPointsFields >; -export class ProofPoints implements StructClass { static readonly $typeName = "0x2::groth16::ProofPoints"; static readonly $numTypeParams = 0; +export class ProofPoints implements StructClass { static readonly $typeName = `${PKG_V25}::groth16::ProofPoints`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = ProofPoints.$typeName; - - readonly $fullTypeName: "0x2::groth16::ProofPoints"; - - readonly $typeArgs: []; + readonly $typeName = ProofPoints.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::groth16::ProofPoints`; readonly $typeArgs: []; readonly $isPhantom = ProofPoints.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [], fields: ProofPointsFields, ) { this.$fullTypeName = composeSuiType( ProofPoints.$typeName, ...typeArgs ) as "0x2::groth16::ProofPoints"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ProofPointsFields, ) { this.$fullTypeName = composeSuiType( ProofPoints.$typeName, ...typeArgs ) as `${typeof PKG_V25}::groth16::ProofPoints`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): ProofPointsReified { return { typeName: ProofPoints.$typeName, fullTypeName: composeSuiType( ProofPoints.$typeName, ...[] ) as "0x2::groth16::ProofPoints", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => ProofPoints.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ProofPoints.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ProofPoints.fromBcs( data, ), bcs: ProofPoints.bcs, fromJSONField: (field: any) => ProofPoints.fromJSONField( field, ), fromJSON: (json: Record) => ProofPoints.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ProofPoints.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ProofPoints.fetch( client, id, ), new: ( fields: ProofPointsFields, ) => { return new ProofPoints( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ProofPointsReified { return { typeName: ProofPoints.$typeName, fullTypeName: composeSuiType( ProofPoints.$typeName, ...[] ) as `${typeof PKG_V25}::groth16::ProofPoints`, typeArgs: [ ] as [], isPhantom: ProofPoints.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => ProofPoints.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ProofPoints.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ProofPoints.fromBcs( data, ), bcs: ProofPoints.bcs, fromJSONField: (field: any) => ProofPoints.fromJSONField( field, ), fromJSON: (json: Record) => ProofPoints.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ProofPoints.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ProofPoints.fetch( client, id, ), new: ( fields: ProofPointsFields, ) => { return new ProofPoints( [], fields ) }, kind: "StructClassReified", } } static get r() { return ProofPoints.reified() } @@ -195,33 +187,30 @@ export class ProofPoints implements StructClass { static readonly $typeName = "0 static fromSuiParsedData( content: SuiParsedData ): ProofPoints { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isProofPoints(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ProofPoints object`); } return ProofPoints.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ProofPoints object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isProofPoints(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ProofPoints object`); } + return ProofPoints.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== PublicProofInputs =============================== */ -export function isPublicProofInputs(type: string): boolean { type = compressSuiType(type); return type === "0x2::groth16::PublicProofInputs"; } +export function isPublicProofInputs(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::groth16::PublicProofInputs`; } export interface PublicProofInputsFields { bytes: ToField> } export type PublicProofInputsReified = Reified< PublicProofInputs, PublicProofInputsFields >; -export class PublicProofInputs implements StructClass { static readonly $typeName = "0x2::groth16::PublicProofInputs"; static readonly $numTypeParams = 0; +export class PublicProofInputs implements StructClass { static readonly $typeName = `${PKG_V25}::groth16::PublicProofInputs`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = PublicProofInputs.$typeName; - - readonly $fullTypeName: "0x2::groth16::PublicProofInputs"; - - readonly $typeArgs: []; + readonly $typeName = PublicProofInputs.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::groth16::PublicProofInputs`; readonly $typeArgs: []; readonly $isPhantom = PublicProofInputs.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [], fields: PublicProofInputsFields, ) { this.$fullTypeName = composeSuiType( PublicProofInputs.$typeName, ...typeArgs ) as "0x2::groth16::PublicProofInputs"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: PublicProofInputsFields, ) { this.$fullTypeName = composeSuiType( PublicProofInputs.$typeName, ...typeArgs ) as `${typeof PKG_V25}::groth16::PublicProofInputs`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): PublicProofInputsReified { return { typeName: PublicProofInputs.$typeName, fullTypeName: composeSuiType( PublicProofInputs.$typeName, ...[] ) as "0x2::groth16::PublicProofInputs", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => PublicProofInputs.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PublicProofInputs.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PublicProofInputs.fromBcs( data, ), bcs: PublicProofInputs.bcs, fromJSONField: (field: any) => PublicProofInputs.fromJSONField( field, ), fromJSON: (json: Record) => PublicProofInputs.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PublicProofInputs.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PublicProofInputs.fetch( client, id, ), new: ( fields: PublicProofInputsFields, ) => { return new PublicProofInputs( [], fields ) }, kind: "StructClassReified", } } + static reified( ): PublicProofInputsReified { return { typeName: PublicProofInputs.$typeName, fullTypeName: composeSuiType( PublicProofInputs.$typeName, ...[] ) as `${typeof PKG_V25}::groth16::PublicProofInputs`, typeArgs: [ ] as [], isPhantom: PublicProofInputs.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => PublicProofInputs.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PublicProofInputs.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => PublicProofInputs.fromBcs( data, ), bcs: PublicProofInputs.bcs, fromJSONField: (field: any) => PublicProofInputs.fromJSONField( field, ), fromJSON: (json: Record) => PublicProofInputs.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => PublicProofInputs.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => PublicProofInputs.fetch( client, id, ), new: ( fields: PublicProofInputsFields, ) => { return new PublicProofInputs( [], fields ) }, kind: "StructClassReified", } } static get r() { return PublicProofInputs.reified() } @@ -260,6 +249,7 @@ export class PublicProofInputs implements StructClass { static readonly $typeNam static fromSuiParsedData( content: SuiParsedData ): PublicProofInputs { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPublicProofInputs(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a PublicProofInputs object`); } return PublicProofInputs.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching PublicProofInputs object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPublicProofInputs(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a PublicProofInputs object`); } + return PublicProofInputs.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/group-ops/structs.ts b/src/codegen/_dependencies/source/0x2/group-ops/structs.ts index 7d188e5..54aea6e 100644 --- a/src/codegen/_dependencies/source/0x2/group-ops/structs.ts +++ b/src/codegen/_dependencies/source/0x2/group-ops/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, Vector, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Element =============================== */ -export function isElement(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::group_ops::Element<"); } +export function isElement(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::group_ops::Element` + '<'); } export interface ElementFields { bytes: ToField> } export type ElementReified = Reified< Element, ElementFields >; -export class Element implements StructClass { static readonly $typeName = "0x2::group_ops::Element"; static readonly $numTypeParams = 1; +export class Element implements StructClass { static readonly $typeName = `${PKG_V25}::group_ops::Element`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Element.$typeName; - - readonly $fullTypeName: `0x2::group_ops::Element<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Element.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::group_ops::Element<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Element.$isPhantom; readonly bytes: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: ElementFields, ) { this.$fullTypeName = composeSuiType( Element.$typeName, ...typeArgs ) as `0x2::group_ops::Element<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ElementFields, ) { this.$fullTypeName = composeSuiType( Element.$typeName, ...typeArgs ) as `${typeof PKG_V25}::group_ops::Element<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified>( T: T ): ElementReified> { return { typeName: Element.$typeName, fullTypeName: composeSuiType( Element.$typeName, ...[extractType(T)] ) as `0x2::group_ops::Element<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Element.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Element.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Element.fromBcs( T, data, ), bcs: Element.bcs, fromJSONField: (field: any) => Element.fromJSONField( T, field, ), fromJSON: (json: Record) => Element.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Element.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Element.fetch( client, T, id, ), new: ( fields: ElementFields>, ) => { return new Element( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ElementReified> { return { typeName: Element.$typeName, fullTypeName: composeSuiType( Element.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::group_ops::Element<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Element.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Element.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Element.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Element.fromBcs( T, data, ), bcs: Element.bcs, fromJSONField: (field: any) => Element.fromJSONField( T, field, ), fromJSON: (json: Record) => Element.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Element.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Element.fetch( client, T, id, ), new: ( fields: ElementFields>, ) => { return new Element( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Element.reified } @@ -65,6 +63,9 @@ export class Element implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Element> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isElement(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Element object`); } return Element.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Element object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isElement(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Element object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Element.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/index.ts b/src/codegen/_dependencies/source/0x2/index.ts index a386324..9d7b09a 100644 --- a/src/codegen/_dependencies/source/0x2/index.ts +++ b/src/codegen/_dependencies/source/0x2/index.ts @@ -1 +1 @@ -export const PACKAGE_ID = "0x2"; export const PUBLISHED_AT = "0x2"; +export const PACKAGE_ID = "0x2"; export const PUBLISHED_AT = "0x2"; export const PKG_V25 = "0x2"; diff --git a/src/codegen/_dependencies/source/0x2/init.ts b/src/codegen/_dependencies/source/0x2/init.ts index 20b3691..d767c64 100644 --- a/src/codegen/_dependencies/source/0x2/init.ts +++ b/src/codegen/_dependencies/source/0x2/init.ts @@ -40,32 +40,20 @@ export function registerClasses(loader: StructClassLoader) { loader.register(gro loader.register(groth16.PreparedVerifyingKey); loader.register(groth16.ProofPoints); loader.register(groth16.PublicProofInputs); -loader.register(url.Url); loader.register(txContext.TxContext); loader.register(object.ID); loader.register(object.UID); loader.register(transfer.Receiving); -loader.register(clock.Clock); -loader.register(balance.Balance); -loader.register(balance.Supply); -loader.register(vecSet.VecSet); loader.register(dynamicField.Field); -loader.register(table.Table); -loader.register(bag.Bag); -loader.register(denyList.DenyList); -loader.register(denyList.PerTypeList); -loader.register(coin.Coin); -loader.register(coin.CoinMetadata); -loader.register(coin.CurrencyCreated); -loader.register(coin.DenyCap); -loader.register(coin.RegulatedCoinMetadata); -loader.register(coin.TreasuryCap); -loader.register(bcs.BCS); loader.register(authenticatorState.ActiveJwk); loader.register(authenticatorState.AuthenticatorState); loader.register(authenticatorState.AuthenticatorStateInner); loader.register(authenticatorState.JWK); loader.register(authenticatorState.JwkId); +loader.register(bag.Bag); +loader.register(balance.Balance); +loader.register(balance.Supply); +loader.register(bcs.BCS); loader.register(groupOps.Element); loader.register(bls12381.G1); loader.register(bls12381.G2); @@ -73,6 +61,18 @@ loader.register(bls12381.GT); loader.register(bls12381.Scalar); loader.register(borrow.Borrow); loader.register(borrow.Referent); +loader.register(clock.Clock); +loader.register(url.Url); +loader.register(vecSet.VecSet); +loader.register(table.Table); +loader.register(denyList.DenyList); +loader.register(denyList.PerTypeList); +loader.register(coin.Coin); +loader.register(coin.CoinMetadata); +loader.register(coin.CurrencyCreated); +loader.register(coin.DenyCap); +loader.register(coin.RegulatedCoinMetadata); +loader.register(coin.TreasuryCap); loader.register(vecMap.Entry); loader.register(vecMap.VecMap); loader.register(package_.Publisher); diff --git a/src/codegen/_dependencies/source/0x2/kiosk-extension/structs.ts b/src/codegen/_dependencies/source/0x2/kiosk-extension/structs.ts index 0965906..46a30a5 100644 --- a/src/codegen/_dependencies/source/0x2/kiosk-extension/structs.ts +++ b/src/codegen/_dependencies/source/0x2/kiosk-extension/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Bag} from "../bag/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Extension =============================== */ -export function isExtension(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk_extension::Extension"; } +export function isExtension(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk_extension::Extension`; } export interface ExtensionFields { storage: ToField; permissions: ToField<"u128">; isEnabled: ToField<"bool"> } export type ExtensionReified = Reified< Extension, ExtensionFields >; -export class Extension implements StructClass { static readonly $typeName = "0x2::kiosk_extension::Extension"; static readonly $numTypeParams = 0; +export class Extension implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk_extension::Extension`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Extension.$typeName; - - readonly $fullTypeName: "0x2::kiosk_extension::Extension"; - - readonly $typeArgs: []; + readonly $typeName = Extension.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk_extension::Extension`; readonly $typeArgs: []; readonly $isPhantom = Extension.$isPhantom; readonly storage: ToField; readonly permissions: ToField<"u128">; readonly isEnabled: ToField<"bool"> - private constructor(typeArgs: [], fields: ExtensionFields, ) { this.$fullTypeName = composeSuiType( Extension.$typeName, ...typeArgs ) as "0x2::kiosk_extension::Extension"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ExtensionFields, ) { this.$fullTypeName = composeSuiType( Extension.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk_extension::Extension`; this.$typeArgs = typeArgs; this.storage = fields.storage;; this.permissions = fields.permissions;; this.isEnabled = fields.isEnabled; } - static reified( ): ExtensionReified { return { typeName: Extension.$typeName, fullTypeName: composeSuiType( Extension.$typeName, ...[] ) as "0x2::kiosk_extension::Extension", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Extension.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Extension.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Extension.fromBcs( data, ), bcs: Extension.bcs, fromJSONField: (field: any) => Extension.fromJSONField( field, ), fromJSON: (json: Record) => Extension.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Extension.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Extension.fetch( client, id, ), new: ( fields: ExtensionFields, ) => { return new Extension( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ExtensionReified { return { typeName: Extension.$typeName, fullTypeName: composeSuiType( Extension.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk_extension::Extension`, typeArgs: [ ] as [], isPhantom: Extension.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Extension.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Extension.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Extension.fromBcs( data, ), bcs: Extension.bcs, fromJSONField: (field: any) => Extension.fromJSONField( field, ), fromJSON: (json: Record) => Extension.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Extension.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Extension.fetch( client, id, ), new: ( fields: ExtensionFields, ) => { return new Extension( [], fields ) }, kind: "StructClassReified", } } static get r() { return Extension.reified() } @@ -65,33 +63,30 @@ export class Extension implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): Extension { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isExtension(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Extension object`); } return Extension.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Extension object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isExtension(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Extension object`); } + return Extension.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ExtensionKey =============================== */ -export function isExtensionKey(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::kiosk_extension::ExtensionKey<"); } +export function isExtensionKey(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::kiosk_extension::ExtensionKey` + '<'); } export interface ExtensionKeyFields { dummyField: ToField<"bool"> } export type ExtensionKeyReified = Reified< ExtensionKey, ExtensionKeyFields >; -export class ExtensionKey implements StructClass { static readonly $typeName = "0x2::kiosk_extension::ExtensionKey"; static readonly $numTypeParams = 1; - - readonly $typeName = ExtensionKey.$typeName; +export class ExtensionKey implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk_extension::ExtensionKey`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::kiosk_extension::ExtensionKey<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = ExtensionKey.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk_extension::ExtensionKey<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = ExtensionKey.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [PhantomToTypeStr], fields: ExtensionKeyFields, ) { this.$fullTypeName = composeSuiType( ExtensionKey.$typeName, ...typeArgs ) as `0x2::kiosk_extension::ExtensionKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ExtensionKeyFields, ) { this.$fullTypeName = composeSuiType( ExtensionKey.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk_extension::ExtensionKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified>( Ext: Ext ): ExtensionKeyReified> { return { typeName: ExtensionKey.$typeName, fullTypeName: composeSuiType( ExtensionKey.$typeName, ...[extractType(Ext)] ) as `0x2::kiosk_extension::ExtensionKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(Ext) ] as [PhantomToTypeStr>], reifiedTypeArgs: [Ext], fromFields: (fields: Record) => ExtensionKey.fromFields( Ext, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ExtensionKey.fromFieldsWithTypes( Ext, item, ), fromBcs: (data: Uint8Array) => ExtensionKey.fromBcs( Ext, data, ), bcs: ExtensionKey.bcs, fromJSONField: (field: any) => ExtensionKey.fromJSONField( Ext, field, ), fromJSON: (json: Record) => ExtensionKey.fromJSON( Ext, json, ), fromSuiParsedData: (content: SuiParsedData) => ExtensionKey.fromSuiParsedData( Ext, content, ), fetch: async (client: SuiClient, id: string) => ExtensionKey.fetch( client, Ext, id, ), new: ( fields: ExtensionKeyFields>, ) => { return new ExtensionKey( [extractType(Ext)], fields ) }, kind: "StructClassReified", } } + static reified>( Ext: Ext ): ExtensionKeyReified> { return { typeName: ExtensionKey.$typeName, fullTypeName: composeSuiType( ExtensionKey.$typeName, ...[extractType(Ext)] ) as `${typeof PKG_V25}::kiosk_extension::ExtensionKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(Ext) ] as [PhantomToTypeStr>], isPhantom: ExtensionKey.$isPhantom, reifiedTypeArgs: [Ext], fromFields: (fields: Record) => ExtensionKey.fromFields( Ext, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ExtensionKey.fromFieldsWithTypes( Ext, item, ), fromBcs: (data: Uint8Array) => ExtensionKey.fromBcs( Ext, data, ), bcs: ExtensionKey.bcs, fromJSONField: (field: any) => ExtensionKey.fromJSONField( Ext, field, ), fromJSON: (json: Record) => ExtensionKey.fromJSON( Ext, json, ), fromSuiParsedData: (content: SuiParsedData) => ExtensionKey.fromSuiParsedData( Ext, content, ), fetch: async (client: SuiClient, id: string) => ExtensionKey.fetch( client, Ext, id, ), new: ( fields: ExtensionKeyFields>, ) => { return new ExtensionKey( [extractType(Ext)], fields ) }, kind: "StructClassReified", } } static get r() { return ExtensionKey.reified } @@ -130,6 +125,9 @@ export class ExtensionKey implements StructClas static fromSuiParsedData>( typeArg: Ext, content: SuiParsedData ): ExtensionKey> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isExtensionKey(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ExtensionKey object`); } return ExtensionKey.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: Ext, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ExtensionKey object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isExtensionKey(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ExtensionKey object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return ExtensionKey.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/kiosk/structs.ts b/src/codegen/_dependencies/source/0x2/kiosk/structs.ts index d6582f7..7f464cf 100644 --- a/src/codegen/_dependencies/source/0x2/kiosk/structs.ts +++ b/src/codegen/_dependencies/source/0x2/kiosk/structs.ts @@ -1,35 +1,33 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, ToTypeStr as ToPhantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Balance} from "../balance/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; import {SUI} from "../sui/structs"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== Borrow =============================== */ -export function isBorrow(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::Borrow"; } +export function isBorrow(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::Borrow`; } export interface BorrowFields { kioskId: ToField; itemId: ToField } export type BorrowReified = Reified< Borrow, BorrowFields >; -export class Borrow implements StructClass { static readonly $typeName = "0x2::kiosk::Borrow"; static readonly $numTypeParams = 0; +export class Borrow implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::Borrow`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Borrow.$typeName; - - readonly $fullTypeName: "0x2::kiosk::Borrow"; - - readonly $typeArgs: []; + readonly $typeName = Borrow.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::Borrow`; readonly $typeArgs: []; readonly $isPhantom = Borrow.$isPhantom; readonly kioskId: ToField; readonly itemId: ToField - private constructor(typeArgs: [], fields: BorrowFields, ) { this.$fullTypeName = composeSuiType( Borrow.$typeName, ...typeArgs ) as "0x2::kiosk::Borrow"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BorrowFields, ) { this.$fullTypeName = composeSuiType( Borrow.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::Borrow`; this.$typeArgs = typeArgs; this.kioskId = fields.kioskId;; this.itemId = fields.itemId; } - static reified( ): BorrowReified { return { typeName: Borrow.$typeName, fullTypeName: composeSuiType( Borrow.$typeName, ...[] ) as "0x2::kiosk::Borrow", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Borrow.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Borrow.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Borrow.fromBcs( data, ), bcs: Borrow.bcs, fromJSONField: (field: any) => Borrow.fromJSONField( field, ), fromJSON: (json: Record) => Borrow.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Borrow.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Borrow.fetch( client, id, ), new: ( fields: BorrowFields, ) => { return new Borrow( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BorrowReified { return { typeName: Borrow.$typeName, fullTypeName: composeSuiType( Borrow.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::Borrow`, typeArgs: [ ] as [], isPhantom: Borrow.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Borrow.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Borrow.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Borrow.fromBcs( data, ), bcs: Borrow.bcs, fromJSONField: (field: any) => Borrow.fromJSONField( field, ), fromJSON: (json: Record) => Borrow.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Borrow.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Borrow.fetch( client, id, ), new: ( fields: BorrowFields, ) => { return new Borrow( [], fields ) }, kind: "StructClassReified", } } static get r() { return Borrow.reified() } @@ -68,33 +66,30 @@ export class Borrow implements StructClass { static readonly $typeName = "0x2::k static fromSuiParsedData( content: SuiParsedData ): Borrow { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBorrow(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Borrow object`); } return Borrow.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Borrow object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBorrow(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Borrow object`); } + return Borrow.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Item =============================== */ -export function isItem(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::Item"; } +export function isItem(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::Item`; } export interface ItemFields { id: ToField } export type ItemReified = Reified< Item, ItemFields >; -export class Item implements StructClass { static readonly $typeName = "0x2::kiosk::Item"; static readonly $numTypeParams = 0; - - readonly $typeName = Item.$typeName; - - readonly $fullTypeName: "0x2::kiosk::Item"; +export class Item implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::Item`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = Item.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::Item`; readonly $typeArgs: []; readonly $isPhantom = Item.$isPhantom; readonly id: ToField - private constructor(typeArgs: [], fields: ItemFields, ) { this.$fullTypeName = composeSuiType( Item.$typeName, ...typeArgs ) as "0x2::kiosk::Item"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ItemFields, ) { this.$fullTypeName = composeSuiType( Item.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::Item`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified( ): ItemReified { return { typeName: Item.$typeName, fullTypeName: composeSuiType( Item.$typeName, ...[] ) as "0x2::kiosk::Item", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Item.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Item.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Item.fromBcs( data, ), bcs: Item.bcs, fromJSONField: (field: any) => Item.fromJSONField( field, ), fromJSON: (json: Record) => Item.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Item.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Item.fetch( client, id, ), new: ( fields: ItemFields, ) => { return new Item( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ItemReified { return { typeName: Item.$typeName, fullTypeName: composeSuiType( Item.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::Item`, typeArgs: [ ] as [], isPhantom: Item.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Item.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Item.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Item.fromBcs( data, ), bcs: Item.bcs, fromJSONField: (field: any) => Item.fromJSONField( field, ), fromJSON: (json: Record) => Item.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Item.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Item.fetch( client, id, ), new: ( fields: ItemFields, ) => { return new Item( [], fields ) }, kind: "StructClassReified", } } static get r() { return Item.reified() } @@ -133,33 +128,30 @@ export class Item implements StructClass { static readonly $typeName = "0x2::kio static fromSuiParsedData( content: SuiParsedData ): Item { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isItem(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Item object`); } return Item.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Item object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isItem(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Item object`); } + return Item.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ItemDelisted =============================== */ -export function isItemDelisted(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::kiosk::ItemDelisted<"); } +export function isItemDelisted(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::kiosk::ItemDelisted` + '<'); } export interface ItemDelistedFields { kiosk: ToField; id: ToField } export type ItemDelistedReified = Reified< ItemDelisted, ItemDelistedFields >; -export class ItemDelisted implements StructClass { static readonly $typeName = "0x2::kiosk::ItemDelisted"; static readonly $numTypeParams = 1; - - readonly $typeName = ItemDelisted.$typeName; +export class ItemDelisted implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::ItemDelisted`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::kiosk::ItemDelisted<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = ItemDelisted.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::ItemDelisted<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = ItemDelisted.$isPhantom; readonly kiosk: ToField; readonly id: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: ItemDelistedFields, ) { this.$fullTypeName = composeSuiType( ItemDelisted.$typeName, ...typeArgs ) as `0x2::kiosk::ItemDelisted<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ItemDelistedFields, ) { this.$fullTypeName = composeSuiType( ItemDelisted.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::ItemDelisted<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.kiosk = fields.kiosk;; this.id = fields.id; } - static reified>( T: T ): ItemDelistedReified> { return { typeName: ItemDelisted.$typeName, fullTypeName: composeSuiType( ItemDelisted.$typeName, ...[extractType(T)] ) as `0x2::kiosk::ItemDelisted<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemDelisted.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemDelisted.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemDelisted.fromBcs( T, data, ), bcs: ItemDelisted.bcs, fromJSONField: (field: any) => ItemDelisted.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemDelisted.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemDelisted.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemDelisted.fetch( client, T, id, ), new: ( fields: ItemDelistedFields>, ) => { return new ItemDelisted( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ItemDelistedReified> { return { typeName: ItemDelisted.$typeName, fullTypeName: composeSuiType( ItemDelisted.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::kiosk::ItemDelisted<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: ItemDelisted.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemDelisted.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemDelisted.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemDelisted.fromBcs( T, data, ), bcs: ItemDelisted.bcs, fromJSONField: (field: any) => ItemDelisted.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemDelisted.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemDelisted.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemDelisted.fetch( client, T, id, ), new: ( fields: ItemDelistedFields>, ) => { return new ItemDelisted( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return ItemDelisted.reified } @@ -198,33 +190,32 @@ export class ItemDelisted implements StructClass static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): ItemDelisted> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isItemDelisted(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ItemDelisted object`); } return ItemDelisted.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ItemDelisted object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isItemDelisted(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ItemDelisted object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return ItemDelisted.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ItemListed =============================== */ -export function isItemListed(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::kiosk::ItemListed<"); } +export function isItemListed(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::kiosk::ItemListed` + '<'); } export interface ItemListedFields { kiosk: ToField; id: ToField; price: ToField<"u64"> } export type ItemListedReified = Reified< ItemListed, ItemListedFields >; -export class ItemListed implements StructClass { static readonly $typeName = "0x2::kiosk::ItemListed"; static readonly $numTypeParams = 1; - - readonly $typeName = ItemListed.$typeName; +export class ItemListed implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::ItemListed`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::kiosk::ItemListed<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = ItemListed.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::ItemListed<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = ItemListed.$isPhantom; readonly kiosk: ToField; readonly id: ToField; readonly price: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: ItemListedFields, ) { this.$fullTypeName = composeSuiType( ItemListed.$typeName, ...typeArgs ) as `0x2::kiosk::ItemListed<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ItemListedFields, ) { this.$fullTypeName = composeSuiType( ItemListed.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::ItemListed<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.kiosk = fields.kiosk;; this.id = fields.id;; this.price = fields.price; } - static reified>( T: T ): ItemListedReified> { return { typeName: ItemListed.$typeName, fullTypeName: composeSuiType( ItemListed.$typeName, ...[extractType(T)] ) as `0x2::kiosk::ItemListed<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemListed.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemListed.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemListed.fromBcs( T, data, ), bcs: ItemListed.bcs, fromJSONField: (field: any) => ItemListed.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemListed.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemListed.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemListed.fetch( client, T, id, ), new: ( fields: ItemListedFields>, ) => { return new ItemListed( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ItemListedReified> { return { typeName: ItemListed.$typeName, fullTypeName: composeSuiType( ItemListed.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::kiosk::ItemListed<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: ItemListed.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemListed.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemListed.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemListed.fromBcs( T, data, ), bcs: ItemListed.bcs, fromJSONField: (field: any) => ItemListed.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemListed.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemListed.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemListed.fetch( client, T, id, ), new: ( fields: ItemListedFields>, ) => { return new ItemListed( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return ItemListed.reified } @@ -263,33 +254,32 @@ export class ItemListed implements StructClass { static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): ItemListed> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isItemListed(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ItemListed object`); } return ItemListed.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ItemListed object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isItemListed(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ItemListed object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return ItemListed.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ItemPurchased =============================== */ -export function isItemPurchased(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::kiosk::ItemPurchased<"); } +export function isItemPurchased(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::kiosk::ItemPurchased` + '<'); } export interface ItemPurchasedFields { kiosk: ToField; id: ToField; price: ToField<"u64"> } export type ItemPurchasedReified = Reified< ItemPurchased, ItemPurchasedFields >; -export class ItemPurchased implements StructClass { static readonly $typeName = "0x2::kiosk::ItemPurchased"; static readonly $numTypeParams = 1; - - readonly $typeName = ItemPurchased.$typeName; +export class ItemPurchased implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::ItemPurchased`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::kiosk::ItemPurchased<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = ItemPurchased.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::ItemPurchased<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = ItemPurchased.$isPhantom; readonly kiosk: ToField; readonly id: ToField; readonly price: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: ItemPurchasedFields, ) { this.$fullTypeName = composeSuiType( ItemPurchased.$typeName, ...typeArgs ) as `0x2::kiosk::ItemPurchased<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ItemPurchasedFields, ) { this.$fullTypeName = composeSuiType( ItemPurchased.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::ItemPurchased<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.kiosk = fields.kiosk;; this.id = fields.id;; this.price = fields.price; } - static reified>( T: T ): ItemPurchasedReified> { return { typeName: ItemPurchased.$typeName, fullTypeName: composeSuiType( ItemPurchased.$typeName, ...[extractType(T)] ) as `0x2::kiosk::ItemPurchased<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemPurchased.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemPurchased.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemPurchased.fromBcs( T, data, ), bcs: ItemPurchased.bcs, fromJSONField: (field: any) => ItemPurchased.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemPurchased.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemPurchased.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemPurchased.fetch( client, T, id, ), new: ( fields: ItemPurchasedFields>, ) => { return new ItemPurchased( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ItemPurchasedReified> { return { typeName: ItemPurchased.$typeName, fullTypeName: composeSuiType( ItemPurchased.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::kiosk::ItemPurchased<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: ItemPurchased.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => ItemPurchased.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ItemPurchased.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ItemPurchased.fromBcs( T, data, ), bcs: ItemPurchased.bcs, fromJSONField: (field: any) => ItemPurchased.fromJSONField( T, field, ), fromJSON: (json: Record) => ItemPurchased.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ItemPurchased.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ItemPurchased.fetch( client, T, id, ), new: ( fields: ItemPurchasedFields>, ) => { return new ItemPurchased( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return ItemPurchased.reified } @@ -328,33 +318,32 @@ export class ItemPurchased implements StructClass static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): ItemPurchased> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isItemPurchased(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ItemPurchased object`); } return ItemPurchased.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ItemPurchased object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isItemPurchased(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ItemPurchased object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return ItemPurchased.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Kiosk =============================== */ -export function isKiosk(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::Kiosk"; } +export function isKiosk(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::Kiosk`; } export interface KioskFields { id: ToField; profits: ToField>>; owner: ToField<"address">; itemCount: ToField<"u32">; allowExtensions: ToField<"bool"> } export type KioskReified = Reified< Kiosk, KioskFields >; -export class Kiosk implements StructClass { static readonly $typeName = "0x2::kiosk::Kiosk"; static readonly $numTypeParams = 0; - - readonly $typeName = Kiosk.$typeName; - - readonly $fullTypeName: "0x2::kiosk::Kiosk"; +export class Kiosk implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::Kiosk`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = Kiosk.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::Kiosk`; readonly $typeArgs: []; readonly $isPhantom = Kiosk.$isPhantom; readonly id: ToField; readonly profits: ToField>>; readonly owner: ToField<"address">; readonly itemCount: ToField<"u32">; readonly allowExtensions: ToField<"bool"> - private constructor(typeArgs: [], fields: KioskFields, ) { this.$fullTypeName = composeSuiType( Kiosk.$typeName, ...typeArgs ) as "0x2::kiosk::Kiosk"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: KioskFields, ) { this.$fullTypeName = composeSuiType( Kiosk.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::Kiosk`; this.$typeArgs = typeArgs; this.id = fields.id;; this.profits = fields.profits;; this.owner = fields.owner;; this.itemCount = fields.itemCount;; this.allowExtensions = fields.allowExtensions; } - static reified( ): KioskReified { return { typeName: Kiosk.$typeName, fullTypeName: composeSuiType( Kiosk.$typeName, ...[] ) as "0x2::kiosk::Kiosk", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Kiosk.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Kiosk.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Kiosk.fromBcs( data, ), bcs: Kiosk.bcs, fromJSONField: (field: any) => Kiosk.fromJSONField( field, ), fromJSON: (json: Record) => Kiosk.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Kiosk.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Kiosk.fetch( client, id, ), new: ( fields: KioskFields, ) => { return new Kiosk( [], fields ) }, kind: "StructClassReified", } } + static reified( ): KioskReified { return { typeName: Kiosk.$typeName, fullTypeName: composeSuiType( Kiosk.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::Kiosk`, typeArgs: [ ] as [], isPhantom: Kiosk.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Kiosk.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Kiosk.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Kiosk.fromBcs( data, ), bcs: Kiosk.bcs, fromJSONField: (field: any) => Kiosk.fromJSONField( field, ), fromJSON: (json: Record) => Kiosk.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Kiosk.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Kiosk.fetch( client, id, ), new: ( fields: KioskFields, ) => { return new Kiosk( [], fields ) }, kind: "StructClassReified", } } static get r() { return Kiosk.reified() } @@ -393,33 +382,30 @@ export class Kiosk implements StructClass { static readonly $typeName = "0x2::ki static fromSuiParsedData( content: SuiParsedData ): Kiosk { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isKiosk(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Kiosk object`); } return Kiosk.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Kiosk object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isKiosk(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Kiosk object`); } + return Kiosk.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== KioskOwnerCap =============================== */ -export function isKioskOwnerCap(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::KioskOwnerCap"; } +export function isKioskOwnerCap(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::KioskOwnerCap`; } export interface KioskOwnerCapFields { id: ToField; for: ToField } export type KioskOwnerCapReified = Reified< KioskOwnerCap, KioskOwnerCapFields >; -export class KioskOwnerCap implements StructClass { static readonly $typeName = "0x2::kiosk::KioskOwnerCap"; static readonly $numTypeParams = 0; - - readonly $typeName = KioskOwnerCap.$typeName; +export class KioskOwnerCap implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::KioskOwnerCap`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $fullTypeName: "0x2::kiosk::KioskOwnerCap"; - - readonly $typeArgs: []; + readonly $typeName = KioskOwnerCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::KioskOwnerCap`; readonly $typeArgs: []; readonly $isPhantom = KioskOwnerCap.$isPhantom; readonly id: ToField; readonly for: ToField - private constructor(typeArgs: [], fields: KioskOwnerCapFields, ) { this.$fullTypeName = composeSuiType( KioskOwnerCap.$typeName, ...typeArgs ) as "0x2::kiosk::KioskOwnerCap"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: KioskOwnerCapFields, ) { this.$fullTypeName = composeSuiType( KioskOwnerCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::KioskOwnerCap`; this.$typeArgs = typeArgs; this.id = fields.id;; this.for = fields.for; } - static reified( ): KioskOwnerCapReified { return { typeName: KioskOwnerCap.$typeName, fullTypeName: composeSuiType( KioskOwnerCap.$typeName, ...[] ) as "0x2::kiosk::KioskOwnerCap", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => KioskOwnerCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => KioskOwnerCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => KioskOwnerCap.fromBcs( data, ), bcs: KioskOwnerCap.bcs, fromJSONField: (field: any) => KioskOwnerCap.fromJSONField( field, ), fromJSON: (json: Record) => KioskOwnerCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => KioskOwnerCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => KioskOwnerCap.fetch( client, id, ), new: ( fields: KioskOwnerCapFields, ) => { return new KioskOwnerCap( [], fields ) }, kind: "StructClassReified", } } + static reified( ): KioskOwnerCapReified { return { typeName: KioskOwnerCap.$typeName, fullTypeName: composeSuiType( KioskOwnerCap.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::KioskOwnerCap`, typeArgs: [ ] as [], isPhantom: KioskOwnerCap.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => KioskOwnerCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => KioskOwnerCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => KioskOwnerCap.fromBcs( data, ), bcs: KioskOwnerCap.bcs, fromJSONField: (field: any) => KioskOwnerCap.fromJSONField( field, ), fromJSON: (json: Record) => KioskOwnerCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => KioskOwnerCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => KioskOwnerCap.fetch( client, id, ), new: ( fields: KioskOwnerCapFields, ) => { return new KioskOwnerCap( [], fields ) }, kind: "StructClassReified", } } static get r() { return KioskOwnerCap.reified() } @@ -458,33 +444,30 @@ export class KioskOwnerCap implements StructClass { static readonly $typeName = static fromSuiParsedData( content: SuiParsedData ): KioskOwnerCap { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isKioskOwnerCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a KioskOwnerCap object`); } return KioskOwnerCap.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching KioskOwnerCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isKioskOwnerCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a KioskOwnerCap object`); } + return KioskOwnerCap.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Listing =============================== */ -export function isListing(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::Listing"; } +export function isListing(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::Listing`; } export interface ListingFields { id: ToField; isExclusive: ToField<"bool"> } export type ListingReified = Reified< Listing, ListingFields >; -export class Listing implements StructClass { static readonly $typeName = "0x2::kiosk::Listing"; static readonly $numTypeParams = 0; - - readonly $typeName = Listing.$typeName; - - readonly $fullTypeName: "0x2::kiosk::Listing"; +export class Listing implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::Listing`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = Listing.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::Listing`; readonly $typeArgs: []; readonly $isPhantom = Listing.$isPhantom; readonly id: ToField; readonly isExclusive: ToField<"bool"> - private constructor(typeArgs: [], fields: ListingFields, ) { this.$fullTypeName = composeSuiType( Listing.$typeName, ...typeArgs ) as "0x2::kiosk::Listing"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ListingFields, ) { this.$fullTypeName = composeSuiType( Listing.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::Listing`; this.$typeArgs = typeArgs; this.id = fields.id;; this.isExclusive = fields.isExclusive; } - static reified( ): ListingReified { return { typeName: Listing.$typeName, fullTypeName: composeSuiType( Listing.$typeName, ...[] ) as "0x2::kiosk::Listing", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Listing.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Listing.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Listing.fromBcs( data, ), bcs: Listing.bcs, fromJSONField: (field: any) => Listing.fromJSONField( field, ), fromJSON: (json: Record) => Listing.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Listing.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Listing.fetch( client, id, ), new: ( fields: ListingFields, ) => { return new Listing( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ListingReified { return { typeName: Listing.$typeName, fullTypeName: composeSuiType( Listing.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::Listing`, typeArgs: [ ] as [], isPhantom: Listing.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Listing.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Listing.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Listing.fromBcs( data, ), bcs: Listing.bcs, fromJSONField: (field: any) => Listing.fromJSONField( field, ), fromJSON: (json: Record) => Listing.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Listing.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Listing.fetch( client, id, ), new: ( fields: ListingFields, ) => { return new Listing( [], fields ) }, kind: "StructClassReified", } } static get r() { return Listing.reified() } @@ -523,33 +506,30 @@ export class Listing implements StructClass { static readonly $typeName = "0x2:: static fromSuiParsedData( content: SuiParsedData ): Listing { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isListing(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Listing object`); } return Listing.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Listing object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isListing(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Listing object`); } + return Listing.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Lock =============================== */ -export function isLock(type: string): boolean { type = compressSuiType(type); return type === "0x2::kiosk::Lock"; } +export function isLock(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::kiosk::Lock`; } export interface LockFields { id: ToField } export type LockReified = Reified< Lock, LockFields >; -export class Lock implements StructClass { static readonly $typeName = "0x2::kiosk::Lock"; static readonly $numTypeParams = 0; - - readonly $typeName = Lock.$typeName; +export class Lock implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::Lock`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $fullTypeName: "0x2::kiosk::Lock"; - - readonly $typeArgs: []; + readonly $typeName = Lock.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::Lock`; readonly $typeArgs: []; readonly $isPhantom = Lock.$isPhantom; readonly id: ToField - private constructor(typeArgs: [], fields: LockFields, ) { this.$fullTypeName = composeSuiType( Lock.$typeName, ...typeArgs ) as "0x2::kiosk::Lock"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: LockFields, ) { this.$fullTypeName = composeSuiType( Lock.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::Lock`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified( ): LockReified { return { typeName: Lock.$typeName, fullTypeName: composeSuiType( Lock.$typeName, ...[] ) as "0x2::kiosk::Lock", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Lock.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Lock.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Lock.fromBcs( data, ), bcs: Lock.bcs, fromJSONField: (field: any) => Lock.fromJSONField( field, ), fromJSON: (json: Record) => Lock.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Lock.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Lock.fetch( client, id, ), new: ( fields: LockFields, ) => { return new Lock( [], fields ) }, kind: "StructClassReified", } } + static reified( ): LockReified { return { typeName: Lock.$typeName, fullTypeName: composeSuiType( Lock.$typeName, ...[] ) as `${typeof PKG_V25}::kiosk::Lock`, typeArgs: [ ] as [], isPhantom: Lock.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Lock.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Lock.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Lock.fromBcs( data, ), bcs: Lock.bcs, fromJSONField: (field: any) => Lock.fromJSONField( field, ), fromJSON: (json: Record) => Lock.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Lock.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Lock.fetch( client, id, ), new: ( fields: LockFields, ) => { return new Lock( [], fields ) }, kind: "StructClassReified", } } static get r() { return Lock.reified() } @@ -588,33 +568,30 @@ export class Lock implements StructClass { static readonly $typeName = "0x2::kio static fromSuiParsedData( content: SuiParsedData ): Lock { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isLock(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Lock object`); } return Lock.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Lock object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isLock(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Lock object`); } + return Lock.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== PurchaseCap =============================== */ -export function isPurchaseCap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::kiosk::PurchaseCap<"); } +export function isPurchaseCap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::kiosk::PurchaseCap` + '<'); } export interface PurchaseCapFields { id: ToField; kioskId: ToField; itemId: ToField; minPrice: ToField<"u64"> } export type PurchaseCapReified = Reified< PurchaseCap, PurchaseCapFields >; -export class PurchaseCap implements StructClass { static readonly $typeName = "0x2::kiosk::PurchaseCap"; static readonly $numTypeParams = 1; +export class PurchaseCap implements StructClass { static readonly $typeName = `${PKG_V25}::kiosk::PurchaseCap`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = PurchaseCap.$typeName; - - readonly $fullTypeName: `0x2::kiosk::PurchaseCap<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = PurchaseCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::kiosk::PurchaseCap<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = PurchaseCap.$isPhantom; readonly id: ToField; readonly kioskId: ToField; readonly itemId: ToField; readonly minPrice: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: PurchaseCapFields, ) { this.$fullTypeName = composeSuiType( PurchaseCap.$typeName, ...typeArgs ) as `0x2::kiosk::PurchaseCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: PurchaseCapFields, ) { this.$fullTypeName = composeSuiType( PurchaseCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::kiosk::PurchaseCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.kioskId = fields.kioskId;; this.itemId = fields.itemId;; this.minPrice = fields.minPrice; } - static reified>( T: T ): PurchaseCapReified> { return { typeName: PurchaseCap.$typeName, fullTypeName: composeSuiType( PurchaseCap.$typeName, ...[extractType(T)] ) as `0x2::kiosk::PurchaseCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => PurchaseCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PurchaseCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => PurchaseCap.fromBcs( T, data, ), bcs: PurchaseCap.bcs, fromJSONField: (field: any) => PurchaseCap.fromJSONField( T, field, ), fromJSON: (json: Record) => PurchaseCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => PurchaseCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => PurchaseCap.fetch( client, T, id, ), new: ( fields: PurchaseCapFields>, ) => { return new PurchaseCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): PurchaseCapReified> { return { typeName: PurchaseCap.$typeName, fullTypeName: composeSuiType( PurchaseCap.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::kiosk::PurchaseCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: PurchaseCap.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => PurchaseCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PurchaseCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => PurchaseCap.fromBcs( T, data, ), bcs: PurchaseCap.bcs, fromJSONField: (field: any) => PurchaseCap.fromJSONField( T, field, ), fromJSON: (json: Record) => PurchaseCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => PurchaseCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => PurchaseCap.fetch( client, T, id, ), new: ( fields: PurchaseCapFields>, ) => { return new PurchaseCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return PurchaseCap.reified } @@ -653,6 +630,9 @@ export class PurchaseCap implements StructClass { static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): PurchaseCap> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPurchaseCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a PurchaseCap object`); } return PurchaseCap.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching PurchaseCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPurchaseCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a PurchaseCap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return PurchaseCap.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/linked-table/structs.ts b/src/codegen/_dependencies/source/0x2/linked-table/structs.ts index 6c3ac67..f3a826c 100644 --- a/src/codegen/_dependencies/source/0x2/linked-table/structs.ts +++ b/src/codegen/_dependencies/source/0x2/linked-table/structs.ts @@ -1,33 +1,31 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeArgument, ToTypeStr, TypeArgument, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Option} from "../../0x1/option/structs"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== LinkedTable =============================== */ -export function isLinkedTable(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::linked_table::LinkedTable<"); } +export function isLinkedTable(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::linked_table::LinkedTable` + '<'); } export interface LinkedTableFields { id: ToField; size: ToField<"u64">; head: ToField>; tail: ToField> } export type LinkedTableReified = Reified< LinkedTable, LinkedTableFields >; -export class LinkedTable implements StructClass { static readonly $typeName = "0x2::linked_table::LinkedTable"; static readonly $numTypeParams = 2; +export class LinkedTable implements StructClass { static readonly $typeName = `${PKG_V25}::linked_table::LinkedTable`; static readonly $numTypeParams = 2; static readonly $isPhantom = [false,true,] as const; - readonly $typeName = LinkedTable.$typeName; - - readonly $fullTypeName: `0x2::linked_table::LinkedTable<${ToTypeStr}, ${PhantomToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr, PhantomToTypeStr]; + readonly $typeName = LinkedTable.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::linked_table::LinkedTable<${ToTypeStr}, ${PhantomToTypeStr}>`; readonly $typeArgs: [ToTypeStr, PhantomToTypeStr]; readonly $isPhantom = LinkedTable.$isPhantom; readonly id: ToField; readonly size: ToField<"u64">; readonly head: ToField>; readonly tail: ToField> - private constructor(typeArgs: [ToTypeStr, PhantomToTypeStr], fields: LinkedTableFields, ) { this.$fullTypeName = composeSuiType( LinkedTable.$typeName, ...typeArgs ) as `0x2::linked_table::LinkedTable<${ToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr, PhantomToTypeStr], fields: LinkedTableFields, ) { this.$fullTypeName = composeSuiType( LinkedTable.$typeName, ...typeArgs ) as `${typeof PKG_V25}::linked_table::LinkedTable<${ToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.size = fields.size;; this.head = fields.head;; this.tail = fields.tail; } - static reified, V extends PhantomReified>( K: K, V: V ): LinkedTableReified, ToPhantomTypeArgument> { return { typeName: LinkedTable.$typeName, fullTypeName: composeSuiType( LinkedTable.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::linked_table::LinkedTable<${ToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, PhantomToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => LinkedTable.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => LinkedTable.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => LinkedTable.fromBcs( [K, V], data, ), bcs: LinkedTable.bcs(toBcs(K)), fromJSONField: (field: any) => LinkedTable.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => LinkedTable.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => LinkedTable.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => LinkedTable.fetch( client, [K, V], id, ), new: ( fields: LinkedTableFields, ToPhantomTypeArgument>, ) => { return new LinkedTable( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends PhantomReified>( K: K, V: V ): LinkedTableReified, ToPhantomTypeArgument> { return { typeName: LinkedTable.$typeName, fullTypeName: composeSuiType( LinkedTable.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::linked_table::LinkedTable<${ToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, PhantomToTypeStr>], isPhantom: LinkedTable.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => LinkedTable.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => LinkedTable.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => LinkedTable.fromBcs( [K, V], data, ), bcs: LinkedTable.bcs(toBcs(K)), fromJSONField: (field: any) => LinkedTable.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => LinkedTable.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => LinkedTable.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => LinkedTable.fetch( client, [K, V], id, ), new: ( fields: LinkedTableFields, ToPhantomTypeArgument>, ) => { return new LinkedTable( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return LinkedTable.reified } @@ -51,7 +49,7 @@ export class LinkedTable toJSONField() { return { - id: this.id,size: this.size.toString(),head: fieldToJSON>(`0x1::option::Option<${this.$typeArgs[0]}>`, this.head),tail: fieldToJSON>(`0x1::option::Option<${this.$typeArgs[0]}>`, this.tail), + id: this.id,size: this.size.toString(),head: fieldToJSON>(`${Option.$typeName}<${this.$typeArgs[0]}>`, this.head),tail: fieldToJSON>(`${Option.$typeName}<${this.$typeArgs[0]}>`, this.tail), } } @@ -66,33 +64,32 @@ export class LinkedTable static fromSuiParsedData, V extends PhantomReified>( typeArgs: [K, V], content: SuiParsedData ): LinkedTable, ToPhantomTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isLinkedTable(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a LinkedTable object`); } return LinkedTable.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends PhantomReified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToPhantomTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching LinkedTable object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isLinkedTable(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a LinkedTable object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return LinkedTable.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Node =============================== */ -export function isNode(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::linked_table::Node<"); } +export function isNode(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::linked_table::Node` + '<'); } export interface NodeFields { prev: ToField>; next: ToField>; value: ToField } export type NodeReified = Reified< Node, NodeFields >; -export class Node implements StructClass { static readonly $typeName = "0x2::linked_table::Node"; static readonly $numTypeParams = 2; +export class Node implements StructClass { static readonly $typeName = `${PKG_V25}::linked_table::Node`; static readonly $numTypeParams = 2; static readonly $isPhantom = [false,false,] as const; - readonly $typeName = Node.$typeName; - - readonly $fullTypeName: `0x2::linked_table::Node<${ToTypeStr}, ${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr, ToTypeStr]; + readonly $typeName = Node.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::linked_table::Node<${ToTypeStr}, ${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr, ToTypeStr]; readonly $isPhantom = Node.$isPhantom; readonly prev: ToField>; readonly next: ToField>; readonly value: ToField - private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: NodeFields, ) { this.$fullTypeName = composeSuiType( Node.$typeName, ...typeArgs ) as `0x2::linked_table::Node<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: NodeFields, ) { this.$fullTypeName = composeSuiType( Node.$typeName, ...typeArgs ) as `${typeof PKG_V25}::linked_table::Node<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; this.prev = fields.prev;; this.next = fields.next;; this.value = fields.value; } - static reified, V extends Reified>( K: K, V: V ): NodeReified, ToTypeArgument> { return { typeName: Node.$typeName, fullTypeName: composeSuiType( Node.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::linked_table::Node<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Node.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Node.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Node.fromBcs( [K, V], data, ), bcs: Node.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => Node.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Node.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Node.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Node.fetch( client, [K, V], id, ), new: ( fields: NodeFields, ToTypeArgument>, ) => { return new Node( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends Reified>( K: K, V: V ): NodeReified, ToTypeArgument> { return { typeName: Node.$typeName, fullTypeName: composeSuiType( Node.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::linked_table::Node<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], isPhantom: Node.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Node.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Node.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Node.fromBcs( [K, V], data, ), bcs: Node.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => Node.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Node.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Node.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Node.fetch( client, [K, V], id, ), new: ( fields: NodeFields, ToTypeArgument>, ) => { return new Node( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return Node.reified } @@ -116,7 +113,7 @@ export class Node implements Str toJSONField() { return { - prev: fieldToJSON>(`0x1::option::Option<${this.$typeArgs[0]}>`, this.prev),next: fieldToJSON>(`0x1::option::Option<${this.$typeArgs[0]}>`, this.next),value: fieldToJSON(this.$typeArgs[1], this.value), + prev: fieldToJSON>(`${Option.$typeName}<${this.$typeArgs[0]}>`, this.prev),next: fieldToJSON>(`${Option.$typeName}<${this.$typeArgs[0]}>`, this.next),value: fieldToJSON(this.$typeArgs[1], this.value), } } @@ -131,6 +128,9 @@ export class Node implements Str static fromSuiParsedData, V extends Reified>( typeArgs: [K, V], content: SuiParsedData ): Node, ToTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isNode(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Node object`); } return Node.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends Reified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Node object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isNode(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Node object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return Node.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/object-bag/structs.ts b/src/codegen/_dependencies/source/0x2/object-bag/structs.ts index b0dbb30..63a4f87 100644 --- a/src/codegen/_dependencies/source/0x2/object-bag/structs.ts +++ b/src/codegen/_dependencies/source/0x2/object-bag/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== ObjectBag =============================== */ -export function isObjectBag(type: string): boolean { type = compressSuiType(type); return type === "0x2::object_bag::ObjectBag"; } +export function isObjectBag(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::object_bag::ObjectBag`; } export interface ObjectBagFields { id: ToField; size: ToField<"u64"> } export type ObjectBagReified = Reified< ObjectBag, ObjectBagFields >; -export class ObjectBag implements StructClass { static readonly $typeName = "0x2::object_bag::ObjectBag"; static readonly $numTypeParams = 0; +export class ObjectBag implements StructClass { static readonly $typeName = `${PKG_V25}::object_bag::ObjectBag`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = ObjectBag.$typeName; - - readonly $fullTypeName: "0x2::object_bag::ObjectBag"; - - readonly $typeArgs: []; + readonly $typeName = ObjectBag.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::object_bag::ObjectBag`; readonly $typeArgs: []; readonly $isPhantom = ObjectBag.$isPhantom; readonly id: ToField; readonly size: ToField<"u64"> - private constructor(typeArgs: [], fields: ObjectBagFields, ) { this.$fullTypeName = composeSuiType( ObjectBag.$typeName, ...typeArgs ) as "0x2::object_bag::ObjectBag"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: ObjectBagFields, ) { this.$fullTypeName = composeSuiType( ObjectBag.$typeName, ...typeArgs ) as `${typeof PKG_V25}::object_bag::ObjectBag`; this.$typeArgs = typeArgs; this.id = fields.id;; this.size = fields.size; } - static reified( ): ObjectBagReified { return { typeName: ObjectBag.$typeName, fullTypeName: composeSuiType( ObjectBag.$typeName, ...[] ) as "0x2::object_bag::ObjectBag", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => ObjectBag.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ObjectBag.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ObjectBag.fromBcs( data, ), bcs: ObjectBag.bcs, fromJSONField: (field: any) => ObjectBag.fromJSONField( field, ), fromJSON: (json: Record) => ObjectBag.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ObjectBag.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ObjectBag.fetch( client, id, ), new: ( fields: ObjectBagFields, ) => { return new ObjectBag( [], fields ) }, kind: "StructClassReified", } } + static reified( ): ObjectBagReified { return { typeName: ObjectBag.$typeName, fullTypeName: composeSuiType( ObjectBag.$typeName, ...[] ) as `${typeof PKG_V25}::object_bag::ObjectBag`, typeArgs: [ ] as [], isPhantom: ObjectBag.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => ObjectBag.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ObjectBag.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ObjectBag.fromBcs( data, ), bcs: ObjectBag.bcs, fromJSONField: (field: any) => ObjectBag.fromJSONField( field, ), fromJSON: (json: Record) => ObjectBag.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ObjectBag.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ObjectBag.fetch( client, id, ), new: ( fields: ObjectBagFields, ) => { return new ObjectBag( [], fields ) }, kind: "StructClassReified", } } static get r() { return ObjectBag.reified() } @@ -65,6 +63,7 @@ export class ObjectBag implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): ObjectBag { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isObjectBag(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ObjectBag object`); } return ObjectBag.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ObjectBag object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isObjectBag(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ObjectBag object`); } + return ObjectBag.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/object-table/structs.ts b/src/codegen/_dependencies/source/0x2/object-table/structs.ts index 6bd157a..bf38862 100644 --- a/src/codegen/_dependencies/source/0x2/object-table/structs.ts +++ b/src/codegen/_dependencies/source/0x2/object-table/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== ObjectTable =============================== */ -export function isObjectTable(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::object_table::ObjectTable<"); } +export function isObjectTable(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::object_table::ObjectTable` + '<'); } export interface ObjectTableFields { id: ToField; size: ToField<"u64"> } export type ObjectTableReified = Reified< ObjectTable, ObjectTableFields >; -export class ObjectTable implements StructClass { static readonly $typeName = "0x2::object_table::ObjectTable"; static readonly $numTypeParams = 2; +export class ObjectTable implements StructClass { static readonly $typeName = `${PKG_V25}::object_table::ObjectTable`; static readonly $numTypeParams = 2; static readonly $isPhantom = [true,true,] as const; - readonly $typeName = ObjectTable.$typeName; - - readonly $fullTypeName: `0x2::object_table::ObjectTable<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr, PhantomToTypeStr]; + readonly $typeName = ObjectTable.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::object_table::ObjectTable<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr, PhantomToTypeStr]; readonly $isPhantom = ObjectTable.$isPhantom; readonly id: ToField; readonly size: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr, PhantomToTypeStr], fields: ObjectTableFields, ) { this.$fullTypeName = composeSuiType( ObjectTable.$typeName, ...typeArgs ) as `0x2::object_table::ObjectTable<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr, PhantomToTypeStr], fields: ObjectTableFields, ) { this.$fullTypeName = composeSuiType( ObjectTable.$typeName, ...typeArgs ) as `${typeof PKG_V25}::object_table::ObjectTable<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.size = fields.size; } - static reified, V extends PhantomReified>( K: K, V: V ): ObjectTableReified, ToPhantomTypeArgument> { return { typeName: ObjectTable.$typeName, fullTypeName: composeSuiType( ObjectTable.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::object_table::ObjectTable<${PhantomToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [PhantomToTypeStr>, PhantomToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => ObjectTable.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ObjectTable.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => ObjectTable.fromBcs( [K, V], data, ), bcs: ObjectTable.bcs, fromJSONField: (field: any) => ObjectTable.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => ObjectTable.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => ObjectTable.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => ObjectTable.fetch( client, [K, V], id, ), new: ( fields: ObjectTableFields, ToPhantomTypeArgument>, ) => { return new ObjectTable( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends PhantomReified>( K: K, V: V ): ObjectTableReified, ToPhantomTypeArgument> { return { typeName: ObjectTable.$typeName, fullTypeName: composeSuiType( ObjectTable.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::object_table::ObjectTable<${PhantomToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [PhantomToTypeStr>, PhantomToTypeStr>], isPhantom: ObjectTable.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => ObjectTable.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ObjectTable.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => ObjectTable.fromBcs( [K, V], data, ), bcs: ObjectTable.bcs, fromJSONField: (field: any) => ObjectTable.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => ObjectTable.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => ObjectTable.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => ObjectTable.fetch( client, [K, V], id, ), new: ( fields: ObjectTableFields, ToPhantomTypeArgument>, ) => { return new ObjectTable( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return ObjectTable.reified } @@ -65,6 +63,9 @@ export class ObjectTable, V extends PhantomReified>( typeArgs: [K, V], content: SuiParsedData ): ObjectTable, ToPhantomTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isObjectTable(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ObjectTable object`); } return ObjectTable.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends PhantomReified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToPhantomTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ObjectTable object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isObjectTable(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ObjectTable object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return ObjectTable.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/object/structs.ts b/src/codegen/_dependencies/source/0x2/object/structs.ts index d37c1bf..16a0d88 100644 --- a/src/codegen/_dependencies/source/0x2/object/structs.ts +++ b/src/codegen/_dependencies/source/0x2/object/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== ID =============================== */ -export function isID(type: string): boolean { type = compressSuiType(type); return type === "0x2::object::ID"; } +export function isID(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::object::ID`; } export interface IDFields { bytes: ToField<"address"> } export type IDReified = Reified< ID, IDFields >; -export class ID implements StructClass { static readonly $typeName = "0x2::object::ID"; static readonly $numTypeParams = 0; +export class ID implements StructClass { static readonly $typeName = `${PKG_V25}::object::ID`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = ID.$typeName; - - readonly $fullTypeName: "0x2::object::ID"; - - readonly $typeArgs: []; + readonly $typeName = ID.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::object::ID`; readonly $typeArgs: []; readonly $isPhantom = ID.$isPhantom; readonly bytes: ToField<"address"> - private constructor(typeArgs: [], fields: IDFields, ) { this.$fullTypeName = composeSuiType( ID.$typeName, ...typeArgs ) as "0x2::object::ID"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: IDFields, ) { this.$fullTypeName = composeSuiType( ID.$typeName, ...typeArgs ) as `${typeof PKG_V25}::object::ID`; this.$typeArgs = typeArgs; this.bytes = fields.bytes; } - static reified( ): IDReified { return { typeName: ID.$typeName, fullTypeName: composeSuiType( ID.$typeName, ...[] ) as "0x2::object::ID", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => ID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ID.fromBcs( data, ), bcs: ID.bcs, fromJSONField: (field: any) => ID.fromJSONField( field, ), fromJSON: (json: Record) => ID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ID.fetch( client, id, ), new: ( fields: IDFields, ) => { return new ID( [], fields ) }, kind: "StructClassReified", } } + static reified( ): IDReified { return { typeName: ID.$typeName, fullTypeName: composeSuiType( ID.$typeName, ...[] ) as `${typeof PKG_V25}::object::ID`, typeArgs: [ ] as [], isPhantom: ID.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => ID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => ID.fromBcs( data, ), bcs: ID.bcs, fromJSONField: (field: any) => ID.fromJSONField( field, ), fromJSON: (json: Record) => ID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => ID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => ID.fetch( client, id, ), new: ( fields: IDFields, ) => { return new ID( [], fields ) }, kind: "StructClassReified", } } static get r() { return ID.reified() } @@ -64,33 +62,30 @@ export class ID implements StructClass { static readonly $typeName = "0x2::objec static fromSuiParsedData( content: SuiParsedData ): ID { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isID(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ID object`); } return ID.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ID object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isID(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ID object`); } + return ID.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== UID =============================== */ -export function isUID(type: string): boolean { type = compressSuiType(type); return type === "0x2::object::UID"; } +export function isUID(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::object::UID`; } export interface UIDFields { id: ToField } export type UIDReified = Reified< UID, UIDFields >; -export class UID implements StructClass { static readonly $typeName = "0x2::object::UID"; static readonly $numTypeParams = 0; +export class UID implements StructClass { static readonly $typeName = `${PKG_V25}::object::UID`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = UID.$typeName; - - readonly $fullTypeName: "0x2::object::UID"; - - readonly $typeArgs: []; + readonly $typeName = UID.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::object::UID`; readonly $typeArgs: []; readonly $isPhantom = UID.$isPhantom; readonly id: ToField - private constructor(typeArgs: [], fields: UIDFields, ) { this.$fullTypeName = composeSuiType( UID.$typeName, ...typeArgs ) as "0x2::object::UID"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: UIDFields, ) { this.$fullTypeName = composeSuiType( UID.$typeName, ...typeArgs ) as `${typeof PKG_V25}::object::UID`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified( ): UIDReified { return { typeName: UID.$typeName, fullTypeName: composeSuiType( UID.$typeName, ...[] ) as "0x2::object::UID", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => UID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UID.fromBcs( data, ), bcs: UID.bcs, fromJSONField: (field: any) => UID.fromJSONField( field, ), fromJSON: (json: Record) => UID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UID.fetch( client, id, ), new: ( fields: UIDFields, ) => { return new UID( [], fields ) }, kind: "StructClassReified", } } + static reified( ): UIDReified { return { typeName: UID.$typeName, fullTypeName: composeSuiType( UID.$typeName, ...[] ) as `${typeof PKG_V25}::object::UID`, typeArgs: [ ] as [], isPhantom: UID.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => UID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UID.fromBcs( data, ), bcs: UID.bcs, fromJSONField: (field: any) => UID.fromJSONField( field, ), fromJSON: (json: Record) => UID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UID.fetch( client, id, ), new: ( fields: UIDFields, ) => { return new UID( [], fields ) }, kind: "StructClassReified", } } static get r() { return UID.reified() } @@ -129,6 +124,7 @@ export class UID implements StructClass { static readonly $typeName = "0x2::obje static fromSuiParsedData( content: SuiParsedData ): UID { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isUID(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a UID object`); } return UID.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching UID object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isUID(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a UID object`); } + return UID.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/package/structs.ts b/src/codegen/_dependencies/source/0x2/package/structs.ts index 7852863..16be9a8 100644 --- a/src/codegen/_dependencies/source/0x2/package/structs.ts +++ b/src/codegen/_dependencies/source/0x2/package/structs.ts @@ -2,33 +2,31 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../../0x1/ascii/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Publisher =============================== */ -export function isPublisher(type: string): boolean { type = compressSuiType(type); return type === "0x2::package::Publisher"; } +export function isPublisher(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::package::Publisher`; } export interface PublisherFields { id: ToField; package: ToField; moduleName: ToField } export type PublisherReified = Reified< Publisher, PublisherFields >; -export class Publisher implements StructClass { static readonly $typeName = "0x2::package::Publisher"; static readonly $numTypeParams = 0; +export class Publisher implements StructClass { static readonly $typeName = `${PKG_V25}::package::Publisher`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Publisher.$typeName; - - readonly $fullTypeName: "0x2::package::Publisher"; - - readonly $typeArgs: []; + readonly $typeName = Publisher.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::package::Publisher`; readonly $typeArgs: []; readonly $isPhantom = Publisher.$isPhantom; readonly id: ToField; readonly package: ToField; readonly moduleName: ToField - private constructor(typeArgs: [], fields: PublisherFields, ) { this.$fullTypeName = composeSuiType( Publisher.$typeName, ...typeArgs ) as "0x2::package::Publisher"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: PublisherFields, ) { this.$fullTypeName = composeSuiType( Publisher.$typeName, ...typeArgs ) as `${typeof PKG_V25}::package::Publisher`; this.$typeArgs = typeArgs; this.id = fields.id;; this.package = fields.package;; this.moduleName = fields.moduleName; } - static reified( ): PublisherReified { return { typeName: Publisher.$typeName, fullTypeName: composeSuiType( Publisher.$typeName, ...[] ) as "0x2::package::Publisher", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Publisher.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Publisher.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Publisher.fromBcs( data, ), bcs: Publisher.bcs, fromJSONField: (field: any) => Publisher.fromJSONField( field, ), fromJSON: (json: Record) => Publisher.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Publisher.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Publisher.fetch( client, id, ), new: ( fields: PublisherFields, ) => { return new Publisher( [], fields ) }, kind: "StructClassReified", } } + static reified( ): PublisherReified { return { typeName: Publisher.$typeName, fullTypeName: composeSuiType( Publisher.$typeName, ...[] ) as `${typeof PKG_V25}::package::Publisher`, typeArgs: [ ] as [], isPhantom: Publisher.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Publisher.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Publisher.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Publisher.fromBcs( data, ), bcs: Publisher.bcs, fromJSONField: (field: any) => Publisher.fromJSONField( field, ), fromJSON: (json: Record) => Publisher.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Publisher.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Publisher.fetch( client, id, ), new: ( fields: PublisherFields, ) => { return new Publisher( [], fields ) }, kind: "StructClassReified", } } static get r() { return Publisher.reified() } @@ -67,33 +65,30 @@ export class Publisher implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): Publisher { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPublisher(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Publisher object`); } return Publisher.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Publisher object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPublisher(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Publisher object`); } + return Publisher.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== UpgradeCap =============================== */ -export function isUpgradeCap(type: string): boolean { type = compressSuiType(type); return type === "0x2::package::UpgradeCap"; } +export function isUpgradeCap(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::package::UpgradeCap`; } export interface UpgradeCapFields { id: ToField; package: ToField; version: ToField<"u64">; policy: ToField<"u8"> } export type UpgradeCapReified = Reified< UpgradeCap, UpgradeCapFields >; -export class UpgradeCap implements StructClass { static readonly $typeName = "0x2::package::UpgradeCap"; static readonly $numTypeParams = 0; +export class UpgradeCap implements StructClass { static readonly $typeName = `${PKG_V25}::package::UpgradeCap`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = UpgradeCap.$typeName; - - readonly $fullTypeName: "0x2::package::UpgradeCap"; - - readonly $typeArgs: []; + readonly $typeName = UpgradeCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::package::UpgradeCap`; readonly $typeArgs: []; readonly $isPhantom = UpgradeCap.$isPhantom; readonly id: ToField; readonly package: ToField; readonly version: ToField<"u64">; readonly policy: ToField<"u8"> - private constructor(typeArgs: [], fields: UpgradeCapFields, ) { this.$fullTypeName = composeSuiType( UpgradeCap.$typeName, ...typeArgs ) as "0x2::package::UpgradeCap"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: UpgradeCapFields, ) { this.$fullTypeName = composeSuiType( UpgradeCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::package::UpgradeCap`; this.$typeArgs = typeArgs; this.id = fields.id;; this.package = fields.package;; this.version = fields.version;; this.policy = fields.policy; } - static reified( ): UpgradeCapReified { return { typeName: UpgradeCap.$typeName, fullTypeName: composeSuiType( UpgradeCap.$typeName, ...[] ) as "0x2::package::UpgradeCap", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeCap.fromBcs( data, ), bcs: UpgradeCap.bcs, fromJSONField: (field: any) => UpgradeCap.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeCap.fetch( client, id, ), new: ( fields: UpgradeCapFields, ) => { return new UpgradeCap( [], fields ) }, kind: "StructClassReified", } } + static reified( ): UpgradeCapReified { return { typeName: UpgradeCap.$typeName, fullTypeName: composeSuiType( UpgradeCap.$typeName, ...[] ) as `${typeof PKG_V25}::package::UpgradeCap`, typeArgs: [ ] as [], isPhantom: UpgradeCap.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeCap.fromBcs( data, ), bcs: UpgradeCap.bcs, fromJSONField: (field: any) => UpgradeCap.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeCap.fetch( client, id, ), new: ( fields: UpgradeCapFields, ) => { return new UpgradeCap( [], fields ) }, kind: "StructClassReified", } } static get r() { return UpgradeCap.reified() } @@ -132,33 +127,30 @@ export class UpgradeCap implements StructClass { static readonly $typeName = "0x static fromSuiParsedData( content: SuiParsedData ): UpgradeCap { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isUpgradeCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a UpgradeCap object`); } return UpgradeCap.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching UpgradeCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isUpgradeCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a UpgradeCap object`); } + return UpgradeCap.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== UpgradeReceipt =============================== */ -export function isUpgradeReceipt(type: string): boolean { type = compressSuiType(type); return type === "0x2::package::UpgradeReceipt"; } +export function isUpgradeReceipt(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::package::UpgradeReceipt`; } export interface UpgradeReceiptFields { cap: ToField; package: ToField } export type UpgradeReceiptReified = Reified< UpgradeReceipt, UpgradeReceiptFields >; -export class UpgradeReceipt implements StructClass { static readonly $typeName = "0x2::package::UpgradeReceipt"; static readonly $numTypeParams = 0; +export class UpgradeReceipt implements StructClass { static readonly $typeName = `${PKG_V25}::package::UpgradeReceipt`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = UpgradeReceipt.$typeName; - - readonly $fullTypeName: "0x2::package::UpgradeReceipt"; - - readonly $typeArgs: []; + readonly $typeName = UpgradeReceipt.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::package::UpgradeReceipt`; readonly $typeArgs: []; readonly $isPhantom = UpgradeReceipt.$isPhantom; readonly cap: ToField; readonly package: ToField - private constructor(typeArgs: [], fields: UpgradeReceiptFields, ) { this.$fullTypeName = composeSuiType( UpgradeReceipt.$typeName, ...typeArgs ) as "0x2::package::UpgradeReceipt"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: UpgradeReceiptFields, ) { this.$fullTypeName = composeSuiType( UpgradeReceipt.$typeName, ...typeArgs ) as `${typeof PKG_V25}::package::UpgradeReceipt`; this.$typeArgs = typeArgs; this.cap = fields.cap;; this.package = fields.package; } - static reified( ): UpgradeReceiptReified { return { typeName: UpgradeReceipt.$typeName, fullTypeName: composeSuiType( UpgradeReceipt.$typeName, ...[] ) as "0x2::package::UpgradeReceipt", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeReceipt.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeReceipt.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeReceipt.fromBcs( data, ), bcs: UpgradeReceipt.bcs, fromJSONField: (field: any) => UpgradeReceipt.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeReceipt.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeReceipt.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeReceipt.fetch( client, id, ), new: ( fields: UpgradeReceiptFields, ) => { return new UpgradeReceipt( [], fields ) }, kind: "StructClassReified", } } + static reified( ): UpgradeReceiptReified { return { typeName: UpgradeReceipt.$typeName, fullTypeName: composeSuiType( UpgradeReceipt.$typeName, ...[] ) as `${typeof PKG_V25}::package::UpgradeReceipt`, typeArgs: [ ] as [], isPhantom: UpgradeReceipt.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeReceipt.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeReceipt.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeReceipt.fromBcs( data, ), bcs: UpgradeReceipt.bcs, fromJSONField: (field: any) => UpgradeReceipt.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeReceipt.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeReceipt.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeReceipt.fetch( client, id, ), new: ( fields: UpgradeReceiptFields, ) => { return new UpgradeReceipt( [], fields ) }, kind: "StructClassReified", } } static get r() { return UpgradeReceipt.reified() } @@ -197,33 +189,30 @@ export class UpgradeReceipt implements StructClass { static readonly $typeName = static fromSuiParsedData( content: SuiParsedData ): UpgradeReceipt { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isUpgradeReceipt(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a UpgradeReceipt object`); } return UpgradeReceipt.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching UpgradeReceipt object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isUpgradeReceipt(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a UpgradeReceipt object`); } + return UpgradeReceipt.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== UpgradeTicket =============================== */ -export function isUpgradeTicket(type: string): boolean { type = compressSuiType(type); return type === "0x2::package::UpgradeTicket"; } +export function isUpgradeTicket(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::package::UpgradeTicket`; } export interface UpgradeTicketFields { cap: ToField; package: ToField; policy: ToField<"u8">; digest: ToField> } export type UpgradeTicketReified = Reified< UpgradeTicket, UpgradeTicketFields >; -export class UpgradeTicket implements StructClass { static readonly $typeName = "0x2::package::UpgradeTicket"; static readonly $numTypeParams = 0; +export class UpgradeTicket implements StructClass { static readonly $typeName = `${PKG_V25}::package::UpgradeTicket`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = UpgradeTicket.$typeName; - - readonly $fullTypeName: "0x2::package::UpgradeTicket"; - - readonly $typeArgs: []; + readonly $typeName = UpgradeTicket.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::package::UpgradeTicket`; readonly $typeArgs: []; readonly $isPhantom = UpgradeTicket.$isPhantom; readonly cap: ToField; readonly package: ToField; readonly policy: ToField<"u8">; readonly digest: ToField> - private constructor(typeArgs: [], fields: UpgradeTicketFields, ) { this.$fullTypeName = composeSuiType( UpgradeTicket.$typeName, ...typeArgs ) as "0x2::package::UpgradeTicket"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: UpgradeTicketFields, ) { this.$fullTypeName = composeSuiType( UpgradeTicket.$typeName, ...typeArgs ) as `${typeof PKG_V25}::package::UpgradeTicket`; this.$typeArgs = typeArgs; this.cap = fields.cap;; this.package = fields.package;; this.policy = fields.policy;; this.digest = fields.digest; } - static reified( ): UpgradeTicketReified { return { typeName: UpgradeTicket.$typeName, fullTypeName: composeSuiType( UpgradeTicket.$typeName, ...[] ) as "0x2::package::UpgradeTicket", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeTicket.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeTicket.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeTicket.fromBcs( data, ), bcs: UpgradeTicket.bcs, fromJSONField: (field: any) => UpgradeTicket.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeTicket.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeTicket.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeTicket.fetch( client, id, ), new: ( fields: UpgradeTicketFields, ) => { return new UpgradeTicket( [], fields ) }, kind: "StructClassReified", } } + static reified( ): UpgradeTicketReified { return { typeName: UpgradeTicket.$typeName, fullTypeName: composeSuiType( UpgradeTicket.$typeName, ...[] ) as `${typeof PKG_V25}::package::UpgradeTicket`, typeArgs: [ ] as [], isPhantom: UpgradeTicket.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => UpgradeTicket.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => UpgradeTicket.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => UpgradeTicket.fromBcs( data, ), bcs: UpgradeTicket.bcs, fromJSONField: (field: any) => UpgradeTicket.fromJSONField( field, ), fromJSON: (json: Record) => UpgradeTicket.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => UpgradeTicket.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => UpgradeTicket.fetch( client, id, ), new: ( fields: UpgradeTicketFields, ) => { return new UpgradeTicket( [], fields ) }, kind: "StructClassReified", } } static get r() { return UpgradeTicket.reified() } @@ -262,6 +251,7 @@ export class UpgradeTicket implements StructClass { static readonly $typeName = static fromSuiParsedData( content: SuiParsedData ): UpgradeTicket { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isUpgradeTicket(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a UpgradeTicket object`); } return UpgradeTicket.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching UpgradeTicket object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isUpgradeTicket(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a UpgradeTicket object`); } + return UpgradeTicket.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/priority-queue/structs.ts b/src/codegen/_dependencies/source/0x2/priority-queue/structs.ts index 04ab58f..73808c0 100644 --- a/src/codegen/_dependencies/source/0x2/priority-queue/structs.ts +++ b/src/codegen/_dependencies/source/0x2/priority-queue/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, Vector, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Entry =============================== */ -export function isEntry(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::priority_queue::Entry<"); } +export function isEntry(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::priority_queue::Entry` + '<'); } export interface EntryFields { priority: ToField<"u64">; value: ToField } export type EntryReified = Reified< Entry, EntryFields >; -export class Entry implements StructClass { static readonly $typeName = "0x2::priority_queue::Entry"; static readonly $numTypeParams = 1; +export class Entry implements StructClass { static readonly $typeName = `${PKG_V25}::priority_queue::Entry`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; - readonly $typeName = Entry.$typeName; - - readonly $fullTypeName: `0x2::priority_queue::Entry<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; + readonly $typeName = Entry.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::priority_queue::Entry<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = Entry.$isPhantom; readonly priority: ToField<"u64">; readonly value: ToField - private constructor(typeArgs: [ToTypeStr], fields: EntryFields, ) { this.$fullTypeName = composeSuiType( Entry.$typeName, ...typeArgs ) as `0x2::priority_queue::Entry<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: EntryFields, ) { this.$fullTypeName = composeSuiType( Entry.$typeName, ...typeArgs ) as `${typeof PKG_V25}::priority_queue::Entry<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.priority = fields.priority;; this.value = fields.value; } - static reified>( T: T ): EntryReified> { return { typeName: Entry.$typeName, fullTypeName: composeSuiType( Entry.$typeName, ...[extractType(T)] ) as `0x2::priority_queue::Entry<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Entry.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Entry.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Entry.fromBcs( T, data, ), bcs: Entry.bcs(toBcs(T)), fromJSONField: (field: any) => Entry.fromJSONField( T, field, ), fromJSON: (json: Record) => Entry.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Entry.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Entry.fetch( client, T, id, ), new: ( fields: EntryFields>, ) => { return new Entry( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): EntryReified> { return { typeName: Entry.$typeName, fullTypeName: composeSuiType( Entry.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::priority_queue::Entry<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], isPhantom: Entry.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Entry.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Entry.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Entry.fromBcs( T, data, ), bcs: Entry.bcs(toBcs(T)), fromJSONField: (field: any) => Entry.fromJSONField( T, field, ), fromJSON: (json: Record) => Entry.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Entry.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Entry.fetch( client, T, id, ), new: ( fields: EntryFields>, ) => { return new Entry( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Entry.reified } @@ -67,33 +65,32 @@ export class Entry implements StructClass { static reado static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Entry> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isEntry(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Entry object`); } return Entry.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Entry object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isEntry(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Entry object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Entry.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== PriorityQueue =============================== */ -export function isPriorityQueue(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::priority_queue::PriorityQueue<"); } +export function isPriorityQueue(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::priority_queue::PriorityQueue` + '<'); } export interface PriorityQueueFields { entries: ToField>> } export type PriorityQueueReified = Reified< PriorityQueue, PriorityQueueFields >; -export class PriorityQueue implements StructClass { static readonly $typeName = "0x2::priority_queue::PriorityQueue"; static readonly $numTypeParams = 1; +export class PriorityQueue implements StructClass { static readonly $typeName = `${PKG_V25}::priority_queue::PriorityQueue`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; - readonly $typeName = PriorityQueue.$typeName; - - readonly $fullTypeName: `0x2::priority_queue::PriorityQueue<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; + readonly $typeName = PriorityQueue.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::priority_queue::PriorityQueue<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = PriorityQueue.$isPhantom; readonly entries: ToField>> - private constructor(typeArgs: [ToTypeStr], fields: PriorityQueueFields, ) { this.$fullTypeName = composeSuiType( PriorityQueue.$typeName, ...typeArgs ) as `0x2::priority_queue::PriorityQueue<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: PriorityQueueFields, ) { this.$fullTypeName = composeSuiType( PriorityQueue.$typeName, ...typeArgs ) as `${typeof PKG_V25}::priority_queue::PriorityQueue<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.entries = fields.entries; } - static reified>( T: T ): PriorityQueueReified> { return { typeName: PriorityQueue.$typeName, fullTypeName: composeSuiType( PriorityQueue.$typeName, ...[extractType(T)] ) as `0x2::priority_queue::PriorityQueue<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => PriorityQueue.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PriorityQueue.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => PriorityQueue.fromBcs( T, data, ), bcs: PriorityQueue.bcs(toBcs(T)), fromJSONField: (field: any) => PriorityQueue.fromJSONField( T, field, ), fromJSON: (json: Record) => PriorityQueue.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => PriorityQueue.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => PriorityQueue.fetch( client, T, id, ), new: ( fields: PriorityQueueFields>, ) => { return new PriorityQueue( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): PriorityQueueReified> { return { typeName: PriorityQueue.$typeName, fullTypeName: composeSuiType( PriorityQueue.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::priority_queue::PriorityQueue<${ToTypeStr>}>`, typeArgs: [ extractType(T) ] as [ToTypeStr>], isPhantom: PriorityQueue.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => PriorityQueue.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => PriorityQueue.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => PriorityQueue.fromBcs( T, data, ), bcs: PriorityQueue.bcs(toBcs(T)), fromJSONField: (field: any) => PriorityQueue.fromJSONField( T, field, ), fromJSON: (json: Record) => PriorityQueue.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => PriorityQueue.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => PriorityQueue.fetch( client, T, id, ), new: ( fields: PriorityQueueFields>, ) => { return new PriorityQueue( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return PriorityQueue.reified } @@ -119,7 +116,7 @@ export class PriorityQueue implements StructClass { stat toJSONField() { return { - entries: fieldToJSON>>(`vector<0x2::priority_queue::Entry<${this.$typeArgs[0]}>>`, this.entries), + entries: fieldToJSON>>(`vector<${Entry.$typeName}<${this.$typeArgs[0]}>>`, this.entries), } } @@ -134,6 +131,9 @@ export class PriorityQueue implements StructClass { stat static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): PriorityQueue> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isPriorityQueue(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a PriorityQueue object`); } return PriorityQueue.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching PriorityQueue object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isPriorityQueue(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a PriorityQueue object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return PriorityQueue.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/random/structs.ts b/src/codegen/_dependencies/source/0x2/random/structs.ts index 0c4cc5e..1708f23 100644 --- a/src/codegen/_dependencies/source/0x2/random/structs.ts +++ b/src/codegen/_dependencies/source/0x2/random/structs.ts @@ -1,34 +1,32 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; import {Versioned} from "../versioned/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Random =============================== */ -export function isRandom(type: string): boolean { type = compressSuiType(type); return type === "0x2::random::Random"; } +export function isRandom(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::random::Random`; } export interface RandomFields { id: ToField; inner: ToField } export type RandomReified = Reified< Random, RandomFields >; -export class Random implements StructClass { static readonly $typeName = "0x2::random::Random"; static readonly $numTypeParams = 0; +export class Random implements StructClass { static readonly $typeName = `${PKG_V25}::random::Random`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Random.$typeName; - - readonly $fullTypeName: "0x2::random::Random"; - - readonly $typeArgs: []; + readonly $typeName = Random.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::random::Random`; readonly $typeArgs: []; readonly $isPhantom = Random.$isPhantom; readonly id: ToField; readonly inner: ToField - private constructor(typeArgs: [], fields: RandomFields, ) { this.$fullTypeName = composeSuiType( Random.$typeName, ...typeArgs ) as "0x2::random::Random"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: RandomFields, ) { this.$fullTypeName = composeSuiType( Random.$typeName, ...typeArgs ) as `${typeof PKG_V25}::random::Random`; this.$typeArgs = typeArgs; this.id = fields.id;; this.inner = fields.inner; } - static reified( ): RandomReified { return { typeName: Random.$typeName, fullTypeName: composeSuiType( Random.$typeName, ...[] ) as "0x2::random::Random", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Random.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Random.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Random.fromBcs( data, ), bcs: Random.bcs, fromJSONField: (field: any) => Random.fromJSONField( field, ), fromJSON: (json: Record) => Random.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Random.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Random.fetch( client, id, ), new: ( fields: RandomFields, ) => { return new Random( [], fields ) }, kind: "StructClassReified", } } + static reified( ): RandomReified { return { typeName: Random.$typeName, fullTypeName: composeSuiType( Random.$typeName, ...[] ) as `${typeof PKG_V25}::random::Random`, typeArgs: [ ] as [], isPhantom: Random.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Random.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Random.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Random.fromBcs( data, ), bcs: Random.bcs, fromJSONField: (field: any) => Random.fromJSONField( field, ), fromJSON: (json: Record) => Random.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Random.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Random.fetch( client, id, ), new: ( fields: RandomFields, ) => { return new Random( [], fields ) }, kind: "StructClassReified", } } static get r() { return Random.reified() } @@ -67,33 +65,30 @@ export class Random implements StructClass { static readonly $typeName = "0x2::r static fromSuiParsedData( content: SuiParsedData ): Random { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRandom(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Random object`); } return Random.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Random object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRandom(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Random object`); } + return Random.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== RandomGenerator =============================== */ -export function isRandomGenerator(type: string): boolean { type = compressSuiType(type); return type === "0x2::random::RandomGenerator"; } +export function isRandomGenerator(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::random::RandomGenerator`; } export interface RandomGeneratorFields { seed: ToField>; counter: ToField<"u16">; buffer: ToField> } export type RandomGeneratorReified = Reified< RandomGenerator, RandomGeneratorFields >; -export class RandomGenerator implements StructClass { static readonly $typeName = "0x2::random::RandomGenerator"; static readonly $numTypeParams = 0; - - readonly $typeName = RandomGenerator.$typeName; - - readonly $fullTypeName: "0x2::random::RandomGenerator"; +export class RandomGenerator implements StructClass { static readonly $typeName = `${PKG_V25}::random::RandomGenerator`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = RandomGenerator.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::random::RandomGenerator`; readonly $typeArgs: []; readonly $isPhantom = RandomGenerator.$isPhantom; readonly seed: ToField>; readonly counter: ToField<"u16">; readonly buffer: ToField> - private constructor(typeArgs: [], fields: RandomGeneratorFields, ) { this.$fullTypeName = composeSuiType( RandomGenerator.$typeName, ...typeArgs ) as "0x2::random::RandomGenerator"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: RandomGeneratorFields, ) { this.$fullTypeName = composeSuiType( RandomGenerator.$typeName, ...typeArgs ) as `${typeof PKG_V25}::random::RandomGenerator`; this.$typeArgs = typeArgs; this.seed = fields.seed;; this.counter = fields.counter;; this.buffer = fields.buffer; } - static reified( ): RandomGeneratorReified { return { typeName: RandomGenerator.$typeName, fullTypeName: composeSuiType( RandomGenerator.$typeName, ...[] ) as "0x2::random::RandomGenerator", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => RandomGenerator.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RandomGenerator.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => RandomGenerator.fromBcs( data, ), bcs: RandomGenerator.bcs, fromJSONField: (field: any) => RandomGenerator.fromJSONField( field, ), fromJSON: (json: Record) => RandomGenerator.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => RandomGenerator.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => RandomGenerator.fetch( client, id, ), new: ( fields: RandomGeneratorFields, ) => { return new RandomGenerator( [], fields ) }, kind: "StructClassReified", } } + static reified( ): RandomGeneratorReified { return { typeName: RandomGenerator.$typeName, fullTypeName: composeSuiType( RandomGenerator.$typeName, ...[] ) as `${typeof PKG_V25}::random::RandomGenerator`, typeArgs: [ ] as [], isPhantom: RandomGenerator.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => RandomGenerator.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RandomGenerator.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => RandomGenerator.fromBcs( data, ), bcs: RandomGenerator.bcs, fromJSONField: (field: any) => RandomGenerator.fromJSONField( field, ), fromJSON: (json: Record) => RandomGenerator.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => RandomGenerator.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => RandomGenerator.fetch( client, id, ), new: ( fields: RandomGeneratorFields, ) => { return new RandomGenerator( [], fields ) }, kind: "StructClassReified", } } static get r() { return RandomGenerator.reified() } @@ -132,33 +127,30 @@ export class RandomGenerator implements StructClass { static readonly $typeName static fromSuiParsedData( content: SuiParsedData ): RandomGenerator { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRandomGenerator(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a RandomGenerator object`); } return RandomGenerator.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching RandomGenerator object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRandomGenerator(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a RandomGenerator object`); } + return RandomGenerator.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== RandomInner =============================== */ -export function isRandomInner(type: string): boolean { type = compressSuiType(type); return type === "0x2::random::RandomInner"; } +export function isRandomInner(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::random::RandomInner`; } export interface RandomInnerFields { version: ToField<"u64">; epoch: ToField<"u64">; randomnessRound: ToField<"u64">; randomBytes: ToField> } export type RandomInnerReified = Reified< RandomInner, RandomInnerFields >; -export class RandomInner implements StructClass { static readonly $typeName = "0x2::random::RandomInner"; static readonly $numTypeParams = 0; - - readonly $typeName = RandomInner.$typeName; +export class RandomInner implements StructClass { static readonly $typeName = `${PKG_V25}::random::RandomInner`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $fullTypeName: "0x2::random::RandomInner"; - - readonly $typeArgs: []; + readonly $typeName = RandomInner.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::random::RandomInner`; readonly $typeArgs: []; readonly $isPhantom = RandomInner.$isPhantom; readonly version: ToField<"u64">; readonly epoch: ToField<"u64">; readonly randomnessRound: ToField<"u64">; readonly randomBytes: ToField> - private constructor(typeArgs: [], fields: RandomInnerFields, ) { this.$fullTypeName = composeSuiType( RandomInner.$typeName, ...typeArgs ) as "0x2::random::RandomInner"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: RandomInnerFields, ) { this.$fullTypeName = composeSuiType( RandomInner.$typeName, ...typeArgs ) as `${typeof PKG_V25}::random::RandomInner`; this.$typeArgs = typeArgs; this.version = fields.version;; this.epoch = fields.epoch;; this.randomnessRound = fields.randomnessRound;; this.randomBytes = fields.randomBytes; } - static reified( ): RandomInnerReified { return { typeName: RandomInner.$typeName, fullTypeName: composeSuiType( RandomInner.$typeName, ...[] ) as "0x2::random::RandomInner", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => RandomInner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RandomInner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => RandomInner.fromBcs( data, ), bcs: RandomInner.bcs, fromJSONField: (field: any) => RandomInner.fromJSONField( field, ), fromJSON: (json: Record) => RandomInner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => RandomInner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => RandomInner.fetch( client, id, ), new: ( fields: RandomInnerFields, ) => { return new RandomInner( [], fields ) }, kind: "StructClassReified", } } + static reified( ): RandomInnerReified { return { typeName: RandomInner.$typeName, fullTypeName: composeSuiType( RandomInner.$typeName, ...[] ) as `${typeof PKG_V25}::random::RandomInner`, typeArgs: [ ] as [], isPhantom: RandomInner.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => RandomInner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RandomInner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => RandomInner.fromBcs( data, ), bcs: RandomInner.bcs, fromJSONField: (field: any) => RandomInner.fromJSONField( field, ), fromJSON: (json: Record) => RandomInner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => RandomInner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => RandomInner.fetch( client, id, ), new: ( fields: RandomInnerFields, ) => { return new RandomInner( [], fields ) }, kind: "StructClassReified", } } static get r() { return RandomInner.reified() } @@ -197,6 +189,7 @@ export class RandomInner implements StructClass { static readonly $typeName = "0 static fromSuiParsedData( content: SuiParsedData ): RandomInner { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRandomInner(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a RandomInner object`); } return RandomInner.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching RandomInner object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRandomInner(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a RandomInner object`); } + return RandomInner.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/sui/structs.ts b/src/codegen/_dependencies/source/0x2/sui/structs.ts index 5bd8dcd..ecf668d 100644 --- a/src/codegen/_dependencies/source/0x2/sui/structs.ts +++ b/src/codegen/_dependencies/source/0x2/sui/structs.ts @@ -1,31 +1,29 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== SUI =============================== */ -export function isSUI(type: string): boolean { type = compressSuiType(type); return type === "0x2::sui::SUI"; } +export function isSUI(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::sui::SUI`; } export interface SUIFields { dummyField: ToField<"bool"> } export type SUIReified = Reified< SUI, SUIFields >; -export class SUI implements StructClass { static readonly $typeName = "0x2::sui::SUI"; static readonly $numTypeParams = 0; +export class SUI implements StructClass { static readonly $typeName = `${PKG_V25}::sui::SUI`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = SUI.$typeName; - - readonly $fullTypeName: "0x2::sui::SUI"; - - readonly $typeArgs: []; + readonly $typeName = SUI.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::sui::SUI`; readonly $typeArgs: []; readonly $isPhantom = SUI.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: SUIFields, ) { this.$fullTypeName = composeSuiType( SUI.$typeName, ...typeArgs ) as "0x2::sui::SUI"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: SUIFields, ) { this.$fullTypeName = composeSuiType( SUI.$typeName, ...typeArgs ) as `${typeof PKG_V25}::sui::SUI`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): SUIReified { return { typeName: SUI.$typeName, fullTypeName: composeSuiType( SUI.$typeName, ...[] ) as "0x2::sui::SUI", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => SUI.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => SUI.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => SUI.fromBcs( data, ), bcs: SUI.bcs, fromJSONField: (field: any) => SUI.fromJSONField( field, ), fromJSON: (json: Record) => SUI.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => SUI.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => SUI.fetch( client, id, ), new: ( fields: SUIFields, ) => { return new SUI( [], fields ) }, kind: "StructClassReified", } } + static reified( ): SUIReified { return { typeName: SUI.$typeName, fullTypeName: composeSuiType( SUI.$typeName, ...[] ) as `${typeof PKG_V25}::sui::SUI`, typeArgs: [ ] as [], isPhantom: SUI.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => SUI.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => SUI.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => SUI.fromBcs( data, ), bcs: SUI.bcs, fromJSONField: (field: any) => SUI.fromJSONField( field, ), fromJSON: (json: Record) => SUI.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => SUI.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => SUI.fetch( client, id, ), new: ( fields: SUIFields, ) => { return new SUI( [], fields ) }, kind: "StructClassReified", } } static get r() { return SUI.reified() } @@ -64,6 +62,7 @@ export class SUI implements StructClass { static readonly $typeName = "0x2::sui: static fromSuiParsedData( content: SuiParsedData ): SUI { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isSUI(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a SUI object`); } return SUI.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching SUI object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isSUI(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a SUI object`); } + return SUI.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/table-vec/structs.ts b/src/codegen/_dependencies/source/0x2/table-vec/structs.ts index 833cd10..2664c17 100644 --- a/src/codegen/_dependencies/source/0x2/table-vec/structs.ts +++ b/src/codegen/_dependencies/source/0x2/table-vec/structs.ts @@ -1,33 +1,31 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {Table} from "../table/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== TableVec =============================== */ -export function isTableVec(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::table_vec::TableVec<"); } +export function isTableVec(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::table_vec::TableVec` + '<'); } export interface TableVecFields { contents: ToField> } export type TableVecReified = Reified< TableVec, TableVecFields >; -export class TableVec implements StructClass { static readonly $typeName = "0x2::table_vec::TableVec"; static readonly $numTypeParams = 1; +export class TableVec implements StructClass { static readonly $typeName = `${PKG_V25}::table_vec::TableVec`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = TableVec.$typeName; - - readonly $fullTypeName: `0x2::table_vec::TableVec<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TableVec.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::table_vec::TableVec<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TableVec.$isPhantom; readonly contents: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: TableVecFields, ) { this.$fullTypeName = composeSuiType( TableVec.$typeName, ...typeArgs ) as `0x2::table_vec::TableVec<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TableVecFields, ) { this.$fullTypeName = composeSuiType( TableVec.$typeName, ...typeArgs ) as `${typeof PKG_V25}::table_vec::TableVec<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.contents = fields.contents; } - static reified>( Element: Element ): TableVecReified> { return { typeName: TableVec.$typeName, fullTypeName: composeSuiType( TableVec.$typeName, ...[extractType(Element)] ) as `0x2::table_vec::TableVec<${PhantomToTypeStr>}>`, typeArgs: [ extractType(Element) ] as [PhantomToTypeStr>], reifiedTypeArgs: [Element], fromFields: (fields: Record) => TableVec.fromFields( Element, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TableVec.fromFieldsWithTypes( Element, item, ), fromBcs: (data: Uint8Array) => TableVec.fromBcs( Element, data, ), bcs: TableVec.bcs, fromJSONField: (field: any) => TableVec.fromJSONField( Element, field, ), fromJSON: (json: Record) => TableVec.fromJSON( Element, json, ), fromSuiParsedData: (content: SuiParsedData) => TableVec.fromSuiParsedData( Element, content, ), fetch: async (client: SuiClient, id: string) => TableVec.fetch( client, Element, id, ), new: ( fields: TableVecFields>, ) => { return new TableVec( [extractType(Element)], fields ) }, kind: "StructClassReified", } } + static reified>( Element: Element ): TableVecReified> { return { typeName: TableVec.$typeName, fullTypeName: composeSuiType( TableVec.$typeName, ...[extractType(Element)] ) as `${typeof PKG_V25}::table_vec::TableVec<${PhantomToTypeStr>}>`, typeArgs: [ extractType(Element) ] as [PhantomToTypeStr>], isPhantom: TableVec.$isPhantom, reifiedTypeArgs: [Element], fromFields: (fields: Record) => TableVec.fromFields( Element, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TableVec.fromFieldsWithTypes( Element, item, ), fromBcs: (data: Uint8Array) => TableVec.fromBcs( Element, data, ), bcs: TableVec.bcs, fromJSONField: (field: any) => TableVec.fromJSONField( Element, field, ), fromJSON: (json: Record) => TableVec.fromJSON( Element, json, ), fromSuiParsedData: (content: SuiParsedData) => TableVec.fromSuiParsedData( Element, content, ), fetch: async (client: SuiClient, id: string) => TableVec.fetch( client, Element, id, ), new: ( fields: TableVecFields>, ) => { return new TableVec( [extractType(Element)], fields ) }, kind: "StructClassReified", } } static get r() { return TableVec.reified } @@ -66,6 +64,9 @@ export class TableVec implements StructClas static fromSuiParsedData>( typeArg: Element, content: SuiParsedData ): TableVec> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTableVec(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TableVec object`); } return TableVec.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: Element, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TableVec object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTableVec(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TableVec object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TableVec.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/table/structs.ts b/src/codegen/_dependencies/source/0x2/table/structs.ts index 38189ca..eb137a7 100644 --- a/src/codegen/_dependencies/source/0x2/table/structs.ts +++ b/src/codegen/_dependencies/source/0x2/table/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Table =============================== */ -export function isTable(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::table::Table<"); } +export function isTable(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::table::Table` + '<'); } export interface TableFields { id: ToField; size: ToField<"u64"> } export type TableReified = Reified< Table, TableFields >; -export class Table implements StructClass { static readonly $typeName = "0x2::table::Table"; static readonly $numTypeParams = 2; +export class Table implements StructClass { static readonly $typeName = `${PKG_V25}::table::Table`; static readonly $numTypeParams = 2; static readonly $isPhantom = [true,true,] as const; - readonly $typeName = Table.$typeName; - - readonly $fullTypeName: `0x2::table::Table<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr, PhantomToTypeStr]; + readonly $typeName = Table.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::table::Table<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr, PhantomToTypeStr]; readonly $isPhantom = Table.$isPhantom; readonly id: ToField; readonly size: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr, PhantomToTypeStr], fields: TableFields, ) { this.$fullTypeName = composeSuiType( Table.$typeName, ...typeArgs ) as `0x2::table::Table<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr, PhantomToTypeStr], fields: TableFields, ) { this.$fullTypeName = composeSuiType( Table.$typeName, ...typeArgs ) as `${typeof PKG_V25}::table::Table<${PhantomToTypeStr}, ${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.size = fields.size; } - static reified, V extends PhantomReified>( K: K, V: V ): TableReified, ToPhantomTypeArgument> { return { typeName: Table.$typeName, fullTypeName: composeSuiType( Table.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::table::Table<${PhantomToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [PhantomToTypeStr>, PhantomToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Table.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Table.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Table.fromBcs( [K, V], data, ), bcs: Table.bcs, fromJSONField: (field: any) => Table.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Table.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Table.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Table.fetch( client, [K, V], id, ), new: ( fields: TableFields, ToPhantomTypeArgument>, ) => { return new Table( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends PhantomReified>( K: K, V: V ): TableReified, ToPhantomTypeArgument> { return { typeName: Table.$typeName, fullTypeName: composeSuiType( Table.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::table::Table<${PhantomToTypeStr>}, ${PhantomToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [PhantomToTypeStr>, PhantomToTypeStr>], isPhantom: Table.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Table.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Table.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Table.fromBcs( [K, V], data, ), bcs: Table.bcs, fromJSONField: (field: any) => Table.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Table.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Table.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Table.fetch( client, [K, V], id, ), new: ( fields: TableFields, ToPhantomTypeArgument>, ) => { return new Table( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return Table.reified } @@ -65,6 +63,9 @@ export class Table static fromSuiParsedData, V extends PhantomReified>( typeArgs: [K, V], content: SuiParsedData ): Table, ToPhantomTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTable(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Table object`); } return Table.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends PhantomReified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToPhantomTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Table object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTable(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Table object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return Table.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/token/structs.ts b/src/codegen/_dependencies/source/0x2/token/structs.ts index 3191a14..f0a3e09 100644 --- a/src/codegen/_dependencies/source/0x2/token/structs.ts +++ b/src/codegen/_dependencies/source/0x2/token/structs.ts @@ -1,38 +1,36 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Option} from "../../0x1/option/structs"; import {String} from "../../0x1/string/structs"; import {TypeName} from "../../0x1/type-name/structs"; import {Balance} from "../balance/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; import {VecMap} from "../vec-map/structs"; import {VecSet} from "../vec-set/structs"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== RuleKey =============================== */ -export function isRuleKey(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::RuleKey<"); } +export function isRuleKey(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::RuleKey` + '<'); } export interface RuleKeyFields { isProtected: ToField<"bool"> } export type RuleKeyReified = Reified< RuleKey, RuleKeyFields >; -export class RuleKey implements StructClass { static readonly $typeName = "0x2::token::RuleKey"; static readonly $numTypeParams = 1; +export class RuleKey implements StructClass { static readonly $typeName = `${PKG_V25}::token::RuleKey`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = RuleKey.$typeName; - - readonly $fullTypeName: `0x2::token::RuleKey<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = RuleKey.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::RuleKey<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = RuleKey.$isPhantom; readonly isProtected: ToField<"bool"> - private constructor(typeArgs: [PhantomToTypeStr], fields: RuleKeyFields, ) { this.$fullTypeName = composeSuiType( RuleKey.$typeName, ...typeArgs ) as `0x2::token::RuleKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: RuleKeyFields, ) { this.$fullTypeName = composeSuiType( RuleKey.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::RuleKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.isProtected = fields.isProtected; } - static reified>( T: T ): RuleKeyReified> { return { typeName: RuleKey.$typeName, fullTypeName: composeSuiType( RuleKey.$typeName, ...[extractType(T)] ) as `0x2::token::RuleKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => RuleKey.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RuleKey.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RuleKey.fromBcs( T, data, ), bcs: RuleKey.bcs, fromJSONField: (field: any) => RuleKey.fromJSONField( T, field, ), fromJSON: (json: Record) => RuleKey.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RuleKey.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RuleKey.fetch( client, T, id, ), new: ( fields: RuleKeyFields>, ) => { return new RuleKey( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): RuleKeyReified> { return { typeName: RuleKey.$typeName, fullTypeName: composeSuiType( RuleKey.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::RuleKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: RuleKey.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => RuleKey.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RuleKey.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RuleKey.fromBcs( T, data, ), bcs: RuleKey.bcs, fromJSONField: (field: any) => RuleKey.fromJSONField( T, field, ), fromJSON: (json: Record) => RuleKey.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RuleKey.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RuleKey.fetch( client, T, id, ), new: ( fields: RuleKeyFields>, ) => { return new RuleKey( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return RuleKey.reified } @@ -71,33 +69,32 @@ export class RuleKey implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): RuleKey> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRuleKey(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a RuleKey object`); } return RuleKey.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching RuleKey object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRuleKey(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a RuleKey object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return RuleKey.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== ActionRequest =============================== */ -export function isActionRequest(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::ActionRequest<"); } +export function isActionRequest(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::ActionRequest` + '<'); } export interface ActionRequestFields { name: ToField; amount: ToField<"u64">; sender: ToField<"address">; recipient: ToField>; spentBalance: ToField>>; approvals: ToField> } export type ActionRequestReified = Reified< ActionRequest, ActionRequestFields >; -export class ActionRequest implements StructClass { static readonly $typeName = "0x2::token::ActionRequest"; static readonly $numTypeParams = 1; - - readonly $typeName = ActionRequest.$typeName; - - readonly $fullTypeName: `0x2::token::ActionRequest<${PhantomToTypeStr}>`; +export class ActionRequest implements StructClass { static readonly $typeName = `${PKG_V25}::token::ActionRequest`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = ActionRequest.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::ActionRequest<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = ActionRequest.$isPhantom; readonly name: ToField; readonly amount: ToField<"u64">; readonly sender: ToField<"address">; readonly recipient: ToField>; readonly spentBalance: ToField>>; readonly approvals: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: ActionRequestFields, ) { this.$fullTypeName = composeSuiType( ActionRequest.$typeName, ...typeArgs ) as `0x2::token::ActionRequest<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ActionRequestFields, ) { this.$fullTypeName = composeSuiType( ActionRequest.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::ActionRequest<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.name = fields.name;; this.amount = fields.amount;; this.sender = fields.sender;; this.recipient = fields.recipient;; this.spentBalance = fields.spentBalance;; this.approvals = fields.approvals; } - static reified>( T: T ): ActionRequestReified> { return { typeName: ActionRequest.$typeName, fullTypeName: composeSuiType( ActionRequest.$typeName, ...[extractType(T)] ) as `0x2::token::ActionRequest<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => ActionRequest.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ActionRequest.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ActionRequest.fromBcs( T, data, ), bcs: ActionRequest.bcs, fromJSONField: (field: any) => ActionRequest.fromJSONField( T, field, ), fromJSON: (json: Record) => ActionRequest.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ActionRequest.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ActionRequest.fetch( client, T, id, ), new: ( fields: ActionRequestFields>, ) => { return new ActionRequest( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ActionRequestReified> { return { typeName: ActionRequest.$typeName, fullTypeName: composeSuiType( ActionRequest.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::ActionRequest<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: ActionRequest.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => ActionRequest.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => ActionRequest.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => ActionRequest.fromBcs( T, data, ), bcs: ActionRequest.bcs, fromJSONField: (field: any) => ActionRequest.fromJSONField( T, field, ), fromJSON: (json: Record) => ActionRequest.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => ActionRequest.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => ActionRequest.fetch( client, T, id, ), new: ( fields: ActionRequestFields>, ) => { return new ActionRequest( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return ActionRequest.reified } @@ -121,7 +118,7 @@ export class ActionRequest implements StructClass toJSONField() { return { - name: this.name,amount: this.amount.toString(),sender: this.sender,recipient: fieldToJSON>(`0x1::option::Option
`, this.recipient),spentBalance: fieldToJSON>>(`0x1::option::Option<0x2::balance::Balance<${this.$typeArgs[0]}>>`, this.spentBalance),approvals: this.approvals.toJSONField(), + name: this.name,amount: this.amount.toString(),sender: this.sender,recipient: fieldToJSON>(`${Option.$typeName}
`, this.recipient),spentBalance: fieldToJSON>>(`${Option.$typeName}<${Balance.$typeName}<${this.$typeArgs[0]}>>`, this.spentBalance),approvals: this.approvals.toJSONField(), } } @@ -136,33 +133,32 @@ export class ActionRequest implements StructClass static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): ActionRequest> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isActionRequest(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a ActionRequest object`); } return ActionRequest.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching ActionRequest object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isActionRequest(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a ActionRequest object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return ActionRequest.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Token =============================== */ -export function isToken(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::Token<"); } +export function isToken(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::Token` + '<'); } export interface TokenFields { id: ToField; balance: ToField> } export type TokenReified = Reified< Token, TokenFields >; -export class Token implements StructClass { static readonly $typeName = "0x2::token::Token"; static readonly $numTypeParams = 1; - - readonly $typeName = Token.$typeName; +export class Token implements StructClass { static readonly $typeName = `${PKG_V25}::token::Token`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::token::Token<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Token.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::Token<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Token.$isPhantom; readonly id: ToField; readonly balance: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: TokenFields, ) { this.$fullTypeName = composeSuiType( Token.$typeName, ...typeArgs ) as `0x2::token::Token<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TokenFields, ) { this.$fullTypeName = composeSuiType( Token.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::Token<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.balance = fields.balance; } - static reified>( T: T ): TokenReified> { return { typeName: Token.$typeName, fullTypeName: composeSuiType( Token.$typeName, ...[extractType(T)] ) as `0x2::token::Token<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Token.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Token.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Token.fromBcs( T, data, ), bcs: Token.bcs, fromJSONField: (field: any) => Token.fromJSONField( T, field, ), fromJSON: (json: Record) => Token.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Token.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Token.fetch( client, T, id, ), new: ( fields: TokenFields>, ) => { return new Token( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TokenReified> { return { typeName: Token.$typeName, fullTypeName: composeSuiType( Token.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::Token<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Token.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Token.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Token.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Token.fromBcs( T, data, ), bcs: Token.bcs, fromJSONField: (field: any) => Token.fromJSONField( T, field, ), fromJSON: (json: Record) => Token.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Token.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Token.fetch( client, T, id, ), new: ( fields: TokenFields>, ) => { return new Token( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Token.reified } @@ -201,33 +197,32 @@ export class Token implements StructClass { stati static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Token> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isToken(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Token object`); } return Token.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Token object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isToken(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Token object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Token.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TokenPolicy =============================== */ -export function isTokenPolicy(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::TokenPolicy<"); } +export function isTokenPolicy(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::TokenPolicy` + '<'); } export interface TokenPolicyFields { id: ToField; spentBalance: ToField>; rules: ToField>> } export type TokenPolicyReified = Reified< TokenPolicy, TokenPolicyFields >; -export class TokenPolicy implements StructClass { static readonly $typeName = "0x2::token::TokenPolicy"; static readonly $numTypeParams = 1; +export class TokenPolicy implements StructClass { static readonly $typeName = `${PKG_V25}::token::TokenPolicy`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = TokenPolicy.$typeName; - - readonly $fullTypeName: `0x2::token::TokenPolicy<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TokenPolicy.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::TokenPolicy<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TokenPolicy.$isPhantom; readonly id: ToField; readonly spentBalance: ToField>; readonly rules: ToField>> - private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyFields, ) { this.$fullTypeName = composeSuiType( TokenPolicy.$typeName, ...typeArgs ) as `0x2::token::TokenPolicy<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyFields, ) { this.$fullTypeName = composeSuiType( TokenPolicy.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::TokenPolicy<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.spentBalance = fields.spentBalance;; this.rules = fields.rules; } - static reified>( T: T ): TokenPolicyReified> { return { typeName: TokenPolicy.$typeName, fullTypeName: composeSuiType( TokenPolicy.$typeName, ...[extractType(T)] ) as `0x2::token::TokenPolicy<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicy.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicy.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicy.fromBcs( T, data, ), bcs: TokenPolicy.bcs, fromJSONField: (field: any) => TokenPolicy.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicy.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicy.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicy.fetch( client, T, id, ), new: ( fields: TokenPolicyFields>, ) => { return new TokenPolicy( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TokenPolicyReified> { return { typeName: TokenPolicy.$typeName, fullTypeName: composeSuiType( TokenPolicy.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::TokenPolicy<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TokenPolicy.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicy.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicy.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicy.fromBcs( T, data, ), bcs: TokenPolicy.bcs, fromJSONField: (field: any) => TokenPolicy.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicy.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicy.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicy.fetch( client, T, id, ), new: ( fields: TokenPolicyFields>, ) => { return new TokenPolicy( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TokenPolicy.reified } @@ -266,33 +261,32 @@ export class TokenPolicy implements StructClass { static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TokenPolicy> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTokenPolicy(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TokenPolicy object`); } return TokenPolicy.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TokenPolicy object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTokenPolicy(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TokenPolicy object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TokenPolicy.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TokenPolicyCap =============================== */ -export function isTokenPolicyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::TokenPolicyCap<"); } +export function isTokenPolicyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::TokenPolicyCap` + '<'); } export interface TokenPolicyCapFields { id: ToField; for: ToField } export type TokenPolicyCapReified = Reified< TokenPolicyCap, TokenPolicyCapFields >; -export class TokenPolicyCap implements StructClass { static readonly $typeName = "0x2::token::TokenPolicyCap"; static readonly $numTypeParams = 1; - - readonly $typeName = TokenPolicyCap.$typeName; - - readonly $fullTypeName: `0x2::token::TokenPolicyCap<${PhantomToTypeStr}>`; +export class TokenPolicyCap implements StructClass { static readonly $typeName = `${PKG_V25}::token::TokenPolicyCap`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TokenPolicyCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::TokenPolicyCap<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TokenPolicyCap.$isPhantom; readonly id: ToField; readonly for: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyCapFields, ) { this.$fullTypeName = composeSuiType( TokenPolicyCap.$typeName, ...typeArgs ) as `0x2::token::TokenPolicyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyCapFields, ) { this.$fullTypeName = composeSuiType( TokenPolicyCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::TokenPolicyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.for = fields.for; } - static reified>( T: T ): TokenPolicyCapReified> { return { typeName: TokenPolicyCap.$typeName, fullTypeName: composeSuiType( TokenPolicyCap.$typeName, ...[extractType(T)] ) as `0x2::token::TokenPolicyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicyCap.fromBcs( T, data, ), bcs: TokenPolicyCap.bcs, fromJSONField: (field: any) => TokenPolicyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicyCap.fetch( client, T, id, ), new: ( fields: TokenPolicyCapFields>, ) => { return new TokenPolicyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TokenPolicyCapReified> { return { typeName: TokenPolicyCap.$typeName, fullTypeName: composeSuiType( TokenPolicyCap.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::TokenPolicyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TokenPolicyCap.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicyCap.fromBcs( T, data, ), bcs: TokenPolicyCap.bcs, fromJSONField: (field: any) => TokenPolicyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicyCap.fetch( client, T, id, ), new: ( fields: TokenPolicyCapFields>, ) => { return new TokenPolicyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TokenPolicyCap.reified } @@ -331,33 +325,32 @@ export class TokenPolicyCap implements StructClas static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TokenPolicyCap> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTokenPolicyCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TokenPolicyCap object`); } return TokenPolicyCap.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TokenPolicyCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTokenPolicyCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TokenPolicyCap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TokenPolicyCap.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TokenPolicyCreated =============================== */ -export function isTokenPolicyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::token::TokenPolicyCreated<"); } +export function isTokenPolicyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::token::TokenPolicyCreated` + '<'); } export interface TokenPolicyCreatedFields { id: ToField; isMutable: ToField<"bool"> } export type TokenPolicyCreatedReified = Reified< TokenPolicyCreated, TokenPolicyCreatedFields >; -export class TokenPolicyCreated implements StructClass { static readonly $typeName = "0x2::token::TokenPolicyCreated"; static readonly $numTypeParams = 1; - - readonly $typeName = TokenPolicyCreated.$typeName; +export class TokenPolicyCreated implements StructClass { static readonly $typeName = `${PKG_V25}::token::TokenPolicyCreated`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::token::TokenPolicyCreated<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TokenPolicyCreated.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::token::TokenPolicyCreated<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TokenPolicyCreated.$isPhantom; readonly id: ToField; readonly isMutable: ToField<"bool"> - private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyCreatedFields, ) { this.$fullTypeName = composeSuiType( TokenPolicyCreated.$typeName, ...typeArgs ) as `0x2::token::TokenPolicyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TokenPolicyCreatedFields, ) { this.$fullTypeName = composeSuiType( TokenPolicyCreated.$typeName, ...typeArgs ) as `${typeof PKG_V25}::token::TokenPolicyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.isMutable = fields.isMutable; } - static reified>( T: T ): TokenPolicyCreatedReified> { return { typeName: TokenPolicyCreated.$typeName, fullTypeName: composeSuiType( TokenPolicyCreated.$typeName, ...[extractType(T)] ) as `0x2::token::TokenPolicyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicyCreated.fromBcs( T, data, ), bcs: TokenPolicyCreated.bcs, fromJSONField: (field: any) => TokenPolicyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicyCreated.fetch( client, T, id, ), new: ( fields: TokenPolicyCreatedFields>, ) => { return new TokenPolicyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TokenPolicyCreatedReified> { return { typeName: TokenPolicyCreated.$typeName, fullTypeName: composeSuiType( TokenPolicyCreated.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::token::TokenPolicyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TokenPolicyCreated.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TokenPolicyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TokenPolicyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TokenPolicyCreated.fromBcs( T, data, ), bcs: TokenPolicyCreated.bcs, fromJSONField: (field: any) => TokenPolicyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => TokenPolicyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TokenPolicyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TokenPolicyCreated.fetch( client, T, id, ), new: ( fields: TokenPolicyCreatedFields>, ) => { return new TokenPolicyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TokenPolicyCreated.reified } @@ -396,6 +389,9 @@ export class TokenPolicyCreated implements Struct static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TokenPolicyCreated> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTokenPolicyCreated(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TokenPolicyCreated object`); } return TokenPolicyCreated.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TokenPolicyCreated object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTokenPolicyCreated(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TokenPolicyCreated object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TokenPolicyCreated.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/transfer-policy/structs.ts b/src/codegen/_dependencies/source/0x2/transfer-policy/structs.ts index 3feb38a..e8e1ff6 100644 --- a/src/codegen/_dependencies/source/0x2/transfer-policy/structs.ts +++ b/src/codegen/_dependencies/source/0x2/transfer-policy/structs.ts @@ -1,37 +1,35 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom, ToTypeStr as ToPhantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {TypeName} from "../../0x1/type-name/structs"; import {Balance} from "../balance/structs"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; import {SUI} from "../sui/structs"; import {VecSet} from "../vec-set/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== RuleKey =============================== */ -export function isRuleKey(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::RuleKey<"); } +export function isRuleKey(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::RuleKey` + '<'); } export interface RuleKeyFields { dummyField: ToField<"bool"> } export type RuleKeyReified = Reified< RuleKey, RuleKeyFields >; -export class RuleKey implements StructClass { static readonly $typeName = "0x2::transfer_policy::RuleKey"; static readonly $numTypeParams = 1; +export class RuleKey implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::RuleKey`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = RuleKey.$typeName; - - readonly $fullTypeName: `0x2::transfer_policy::RuleKey<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = RuleKey.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::RuleKey<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = RuleKey.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [PhantomToTypeStr], fields: RuleKeyFields, ) { this.$fullTypeName = composeSuiType( RuleKey.$typeName, ...typeArgs ) as `0x2::transfer_policy::RuleKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: RuleKeyFields, ) { this.$fullTypeName = composeSuiType( RuleKey.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::RuleKey<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified>( T: T ): RuleKeyReified> { return { typeName: RuleKey.$typeName, fullTypeName: composeSuiType( RuleKey.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::RuleKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => RuleKey.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RuleKey.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RuleKey.fromBcs( T, data, ), bcs: RuleKey.bcs, fromJSONField: (field: any) => RuleKey.fromJSONField( T, field, ), fromJSON: (json: Record) => RuleKey.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RuleKey.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RuleKey.fetch( client, T, id, ), new: ( fields: RuleKeyFields>, ) => { return new RuleKey( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): RuleKeyReified> { return { typeName: RuleKey.$typeName, fullTypeName: composeSuiType( RuleKey.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::RuleKey<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: RuleKey.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => RuleKey.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => RuleKey.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => RuleKey.fromBcs( T, data, ), bcs: RuleKey.bcs, fromJSONField: (field: any) => RuleKey.fromJSONField( T, field, ), fromJSON: (json: Record) => RuleKey.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => RuleKey.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => RuleKey.fetch( client, T, id, ), new: ( fields: RuleKeyFields>, ) => { return new RuleKey( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return RuleKey.reified } @@ -70,33 +68,32 @@ export class RuleKey implements StructClass { sta static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): RuleKey> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isRuleKey(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a RuleKey object`); } return RuleKey.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching RuleKey object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isRuleKey(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a RuleKey object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return RuleKey.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TransferPolicy =============================== */ -export function isTransferPolicy(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::TransferPolicy<"); } +export function isTransferPolicy(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::TransferPolicy` + '<'); } export interface TransferPolicyFields { id: ToField; balance: ToField>>; rules: ToField> } export type TransferPolicyReified = Reified< TransferPolicy, TransferPolicyFields >; -export class TransferPolicy implements StructClass { static readonly $typeName = "0x2::transfer_policy::TransferPolicy"; static readonly $numTypeParams = 1; - - readonly $typeName = TransferPolicy.$typeName; - - readonly $fullTypeName: `0x2::transfer_policy::TransferPolicy<${PhantomToTypeStr}>`; +export class TransferPolicy implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::TransferPolicy`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TransferPolicy.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::TransferPolicy<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TransferPolicy.$isPhantom; readonly id: ToField; readonly balance: ToField>>; readonly rules: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyFields, ) { this.$fullTypeName = composeSuiType( TransferPolicy.$typeName, ...typeArgs ) as `0x2::transfer_policy::TransferPolicy<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyFields, ) { this.$fullTypeName = composeSuiType( TransferPolicy.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::TransferPolicy<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.balance = fields.balance;; this.rules = fields.rules; } - static reified>( T: T ): TransferPolicyReified> { return { typeName: TransferPolicy.$typeName, fullTypeName: composeSuiType( TransferPolicy.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::TransferPolicy<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicy.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicy.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicy.fromBcs( T, data, ), bcs: TransferPolicy.bcs, fromJSONField: (field: any) => TransferPolicy.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicy.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicy.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicy.fetch( client, T, id, ), new: ( fields: TransferPolicyFields>, ) => { return new TransferPolicy( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TransferPolicyReified> { return { typeName: TransferPolicy.$typeName, fullTypeName: composeSuiType( TransferPolicy.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::TransferPolicy<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TransferPolicy.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicy.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicy.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicy.fromBcs( T, data, ), bcs: TransferPolicy.bcs, fromJSONField: (field: any) => TransferPolicy.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicy.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicy.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicy.fetch( client, T, id, ), new: ( fields: TransferPolicyFields>, ) => { return new TransferPolicy( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TransferPolicy.reified } @@ -135,33 +132,32 @@ export class TransferPolicy implements StructClas static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TransferPolicy> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTransferPolicy(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TransferPolicy object`); } return TransferPolicy.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TransferPolicy object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTransferPolicy(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TransferPolicy object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TransferPolicy.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TransferPolicyCap =============================== */ -export function isTransferPolicyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::TransferPolicyCap<"); } +export function isTransferPolicyCap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::TransferPolicyCap` + '<'); } export interface TransferPolicyCapFields { id: ToField; policyId: ToField } export type TransferPolicyCapReified = Reified< TransferPolicyCap, TransferPolicyCapFields >; -export class TransferPolicyCap implements StructClass { static readonly $typeName = "0x2::transfer_policy::TransferPolicyCap"; static readonly $numTypeParams = 1; - - readonly $typeName = TransferPolicyCap.$typeName; +export class TransferPolicyCap implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::TransferPolicyCap`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::transfer_policy::TransferPolicyCap<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TransferPolicyCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::TransferPolicyCap<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TransferPolicyCap.$isPhantom; readonly id: ToField; readonly policyId: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyCapFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyCap.$typeName, ...typeArgs ) as `0x2::transfer_policy::TransferPolicyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyCapFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyCap<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.policyId = fields.policyId; } - static reified>( T: T ): TransferPolicyCapReified> { return { typeName: TransferPolicyCap.$typeName, fullTypeName: composeSuiType( TransferPolicyCap.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::TransferPolicyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyCap.fromBcs( T, data, ), bcs: TransferPolicyCap.bcs, fromJSONField: (field: any) => TransferPolicyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyCap.fetch( client, T, id, ), new: ( fields: TransferPolicyCapFields>, ) => { return new TransferPolicyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TransferPolicyCapReified> { return { typeName: TransferPolicyCap.$typeName, fullTypeName: composeSuiType( TransferPolicyCap.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyCap<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TransferPolicyCap.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyCap.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyCap.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyCap.fromBcs( T, data, ), bcs: TransferPolicyCap.bcs, fromJSONField: (field: any) => TransferPolicyCap.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyCap.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyCap.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyCap.fetch( client, T, id, ), new: ( fields: TransferPolicyCapFields>, ) => { return new TransferPolicyCap( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TransferPolicyCap.reified } @@ -200,33 +196,32 @@ export class TransferPolicyCap implements StructC static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TransferPolicyCap> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTransferPolicyCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TransferPolicyCap object`); } return TransferPolicyCap.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TransferPolicyCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTransferPolicyCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TransferPolicyCap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TransferPolicyCap.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TransferPolicyCreated =============================== */ -export function isTransferPolicyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::TransferPolicyCreated<"); } +export function isTransferPolicyCreated(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::TransferPolicyCreated` + '<'); } export interface TransferPolicyCreatedFields { id: ToField } export type TransferPolicyCreatedReified = Reified< TransferPolicyCreated, TransferPolicyCreatedFields >; -export class TransferPolicyCreated implements StructClass { static readonly $typeName = "0x2::transfer_policy::TransferPolicyCreated"; static readonly $numTypeParams = 1; +export class TransferPolicyCreated implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::TransferPolicyCreated`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = TransferPolicyCreated.$typeName; - - readonly $fullTypeName: `0x2::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TransferPolicyCreated.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TransferPolicyCreated.$isPhantom; readonly id: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyCreatedFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyCreated.$typeName, ...typeArgs ) as `0x2::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyCreatedFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyCreated.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified>( T: T ): TransferPolicyCreatedReified> { return { typeName: TransferPolicyCreated.$typeName, fullTypeName: composeSuiType( TransferPolicyCreated.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyCreated.fromBcs( T, data, ), bcs: TransferPolicyCreated.bcs, fromJSONField: (field: any) => TransferPolicyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyCreated.fetch( client, T, id, ), new: ( fields: TransferPolicyCreatedFields>, ) => { return new TransferPolicyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TransferPolicyCreatedReified> { return { typeName: TransferPolicyCreated.$typeName, fullTypeName: composeSuiType( TransferPolicyCreated.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyCreated<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TransferPolicyCreated.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyCreated.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyCreated.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyCreated.fromBcs( T, data, ), bcs: TransferPolicyCreated.bcs, fromJSONField: (field: any) => TransferPolicyCreated.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyCreated.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyCreated.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyCreated.fetch( client, T, id, ), new: ( fields: TransferPolicyCreatedFields>, ) => { return new TransferPolicyCreated( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TransferPolicyCreated.reified } @@ -265,33 +260,32 @@ export class TransferPolicyCreated implements Str static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TransferPolicyCreated> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTransferPolicyCreated(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TransferPolicyCreated object`); } return TransferPolicyCreated.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TransferPolicyCreated object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTransferPolicyCreated(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TransferPolicyCreated object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TransferPolicyCreated.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TransferPolicyDestroyed =============================== */ -export function isTransferPolicyDestroyed(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::TransferPolicyDestroyed<"); } +export function isTransferPolicyDestroyed(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::TransferPolicyDestroyed` + '<'); } export interface TransferPolicyDestroyedFields { id: ToField } export type TransferPolicyDestroyedReified = Reified< TransferPolicyDestroyed, TransferPolicyDestroyedFields >; -export class TransferPolicyDestroyed implements StructClass { static readonly $typeName = "0x2::transfer_policy::TransferPolicyDestroyed"; static readonly $numTypeParams = 1; - - readonly $typeName = TransferPolicyDestroyed.$typeName; - - readonly $fullTypeName: `0x2::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr}>`; +export class TransferPolicyDestroyed implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::TransferPolicyDestroyed`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TransferPolicyDestroyed.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TransferPolicyDestroyed.$isPhantom; readonly id: ToField - private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyDestroyedFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyDestroyed.$typeName, ...typeArgs ) as `0x2::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TransferPolicyDestroyedFields, ) { this.$fullTypeName = composeSuiType( TransferPolicyDestroyed.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified>( T: T ): TransferPolicyDestroyedReified> { return { typeName: TransferPolicyDestroyed.$typeName, fullTypeName: composeSuiType( TransferPolicyDestroyed.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyDestroyed.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyDestroyed.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyDestroyed.fromBcs( T, data, ), bcs: TransferPolicyDestroyed.bcs, fromJSONField: (field: any) => TransferPolicyDestroyed.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyDestroyed.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyDestroyed.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyDestroyed.fetch( client, T, id, ), new: ( fields: TransferPolicyDestroyedFields>, ) => { return new TransferPolicyDestroyed( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TransferPolicyDestroyedReified> { return { typeName: TransferPolicyDestroyed.$typeName, fullTypeName: composeSuiType( TransferPolicyDestroyed.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::TransferPolicyDestroyed<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TransferPolicyDestroyed.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferPolicyDestroyed.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferPolicyDestroyed.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferPolicyDestroyed.fromBcs( T, data, ), bcs: TransferPolicyDestroyed.bcs, fromJSONField: (field: any) => TransferPolicyDestroyed.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferPolicyDestroyed.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferPolicyDestroyed.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferPolicyDestroyed.fetch( client, T, id, ), new: ( fields: TransferPolicyDestroyedFields>, ) => { return new TransferPolicyDestroyed( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TransferPolicyDestroyed.reified } @@ -330,33 +324,32 @@ export class TransferPolicyDestroyed implements S static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TransferPolicyDestroyed> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTransferPolicyDestroyed(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TransferPolicyDestroyed object`); } return TransferPolicyDestroyed.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TransferPolicyDestroyed object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTransferPolicyDestroyed(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TransferPolicyDestroyed object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TransferPolicyDestroyed.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== TransferRequest =============================== */ -export function isTransferRequest(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer_policy::TransferRequest<"); } +export function isTransferRequest(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer_policy::TransferRequest` + '<'); } export interface TransferRequestFields { item: ToField; paid: ToField<"u64">; from: ToField; receipts: ToField> } export type TransferRequestReified = Reified< TransferRequest, TransferRequestFields >; -export class TransferRequest implements StructClass { static readonly $typeName = "0x2::transfer_policy::TransferRequest"; static readonly $numTypeParams = 1; - - readonly $typeName = TransferRequest.$typeName; +export class TransferRequest implements StructClass { static readonly $typeName = `${PKG_V25}::transfer_policy::TransferRequest`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $fullTypeName: `0x2::transfer_policy::TransferRequest<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TransferRequest.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer_policy::TransferRequest<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TransferRequest.$isPhantom; readonly item: ToField; readonly paid: ToField<"u64">; readonly from: ToField; readonly receipts: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: TransferRequestFields, ) { this.$fullTypeName = composeSuiType( TransferRequest.$typeName, ...typeArgs ) as `0x2::transfer_policy::TransferRequest<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TransferRequestFields, ) { this.$fullTypeName = composeSuiType( TransferRequest.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer_policy::TransferRequest<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.item = fields.item;; this.paid = fields.paid;; this.from = fields.from;; this.receipts = fields.receipts; } - static reified>( T: T ): TransferRequestReified> { return { typeName: TransferRequest.$typeName, fullTypeName: composeSuiType( TransferRequest.$typeName, ...[extractType(T)] ) as `0x2::transfer_policy::TransferRequest<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferRequest.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferRequest.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferRequest.fromBcs( T, data, ), bcs: TransferRequest.bcs, fromJSONField: (field: any) => TransferRequest.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferRequest.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferRequest.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferRequest.fetch( client, T, id, ), new: ( fields: TransferRequestFields>, ) => { return new TransferRequest( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TransferRequestReified> { return { typeName: TransferRequest.$typeName, fullTypeName: composeSuiType( TransferRequest.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer_policy::TransferRequest<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TransferRequest.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TransferRequest.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TransferRequest.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TransferRequest.fromBcs( T, data, ), bcs: TransferRequest.bcs, fromJSONField: (field: any) => TransferRequest.fromJSONField( T, field, ), fromJSON: (json: Record) => TransferRequest.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TransferRequest.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TransferRequest.fetch( client, T, id, ), new: ( fields: TransferRequestFields>, ) => { return new TransferRequest( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TransferRequest.reified } @@ -395,6 +388,9 @@ export class TransferRequest implements StructCla static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TransferRequest> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTransferRequest(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TransferRequest object`); } return TransferRequest.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TransferRequest object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTransferRequest(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TransferRequest object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TransferRequest.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/transfer/structs.ts b/src/codegen/_dependencies/source/0x2/transfer/structs.ts index 8267a75..bfa464a 100644 --- a/src/codegen/_dependencies/source/0x2/transfer/structs.ts +++ b/src/codegen/_dependencies/source/0x2/transfer/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {ID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Receiving =============================== */ -export function isReceiving(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::transfer::Receiving<"); } +export function isReceiving(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::transfer::Receiving` + '<'); } export interface ReceivingFields { id: ToField; version: ToField<"u64"> } export type ReceivingReified = Reified< Receiving, ReceivingFields >; -export class Receiving implements StructClass { static readonly $typeName = "0x2::transfer::Receiving"; static readonly $numTypeParams = 1; +export class Receiving implements StructClass { static readonly $typeName = `${PKG_V25}::transfer::Receiving`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Receiving.$typeName; - - readonly $fullTypeName: `0x2::transfer::Receiving<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Receiving.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::transfer::Receiving<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Receiving.$isPhantom; readonly id: ToField; readonly version: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: ReceivingFields, ) { this.$fullTypeName = composeSuiType( Receiving.$typeName, ...typeArgs ) as `0x2::transfer::Receiving<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: ReceivingFields, ) { this.$fullTypeName = composeSuiType( Receiving.$typeName, ...typeArgs ) as `${typeof PKG_V25}::transfer::Receiving<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.id = fields.id;; this.version = fields.version; } - static reified>( T: T ): ReceivingReified> { return { typeName: Receiving.$typeName, fullTypeName: composeSuiType( Receiving.$typeName, ...[extractType(T)] ) as `0x2::transfer::Receiving<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Receiving.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Receiving.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Receiving.fromBcs( T, data, ), bcs: Receiving.bcs, fromJSONField: (field: any) => Receiving.fromJSONField( T, field, ), fromJSON: (json: Record) => Receiving.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Receiving.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Receiving.fetch( client, T, id, ), new: ( fields: ReceivingFields>, ) => { return new Receiving( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): ReceivingReified> { return { typeName: Receiving.$typeName, fullTypeName: composeSuiType( Receiving.$typeName, ...[extractType(T)] ) as `${typeof PKG_V25}::transfer::Receiving<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Receiving.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Receiving.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Receiving.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Receiving.fromBcs( T, data, ), bcs: Receiving.bcs, fromJSONField: (field: any) => Receiving.fromJSONField( T, field, ), fromJSON: (json: Record) => Receiving.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Receiving.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Receiving.fetch( client, T, id, ), new: ( fields: ReceivingFields>, ) => { return new Receiving( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Receiving.reified } @@ -65,6 +63,9 @@ export class Receiving implements StructClass { s static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Receiving> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isReceiving(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Receiving object`); } return Receiving.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Receiving object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isReceiving(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Receiving object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Receiving.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/tx-context/structs.ts b/src/codegen/_dependencies/source/0x2/tx-context/structs.ts index 87698ef..09eca3e 100644 --- a/src/codegen/_dependencies/source/0x2/tx-context/structs.ts +++ b/src/codegen/_dependencies/source/0x2/tx-context/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== TxContext =============================== */ -export function isTxContext(type: string): boolean { type = compressSuiType(type); return type === "0x2::tx_context::TxContext"; } +export function isTxContext(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::tx_context::TxContext`; } export interface TxContextFields { sender: ToField<"address">; txHash: ToField>; epoch: ToField<"u64">; epochTimestampMs: ToField<"u64">; idsCreated: ToField<"u64"> } export type TxContextReified = Reified< TxContext, TxContextFields >; -export class TxContext implements StructClass { static readonly $typeName = "0x2::tx_context::TxContext"; static readonly $numTypeParams = 0; +export class TxContext implements StructClass { static readonly $typeName = `${PKG_V25}::tx_context::TxContext`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = TxContext.$typeName; - - readonly $fullTypeName: "0x2::tx_context::TxContext"; - - readonly $typeArgs: []; + readonly $typeName = TxContext.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::tx_context::TxContext`; readonly $typeArgs: []; readonly $isPhantom = TxContext.$isPhantom; readonly sender: ToField<"address">; readonly txHash: ToField>; readonly epoch: ToField<"u64">; readonly epochTimestampMs: ToField<"u64">; readonly idsCreated: ToField<"u64"> - private constructor(typeArgs: [], fields: TxContextFields, ) { this.$fullTypeName = composeSuiType( TxContext.$typeName, ...typeArgs ) as "0x2::tx_context::TxContext"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: TxContextFields, ) { this.$fullTypeName = composeSuiType( TxContext.$typeName, ...typeArgs ) as `${typeof PKG_V25}::tx_context::TxContext`; this.$typeArgs = typeArgs; this.sender = fields.sender;; this.txHash = fields.txHash;; this.epoch = fields.epoch;; this.epochTimestampMs = fields.epochTimestampMs;; this.idsCreated = fields.idsCreated; } - static reified( ): TxContextReified { return { typeName: TxContext.$typeName, fullTypeName: composeSuiType( TxContext.$typeName, ...[] ) as "0x2::tx_context::TxContext", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => TxContext.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TxContext.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => TxContext.fromBcs( data, ), bcs: TxContext.bcs, fromJSONField: (field: any) => TxContext.fromJSONField( field, ), fromJSON: (json: Record) => TxContext.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => TxContext.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => TxContext.fetch( client, id, ), new: ( fields: TxContextFields, ) => { return new TxContext( [], fields ) }, kind: "StructClassReified", } } + static reified( ): TxContextReified { return { typeName: TxContext.$typeName, fullTypeName: composeSuiType( TxContext.$typeName, ...[] ) as `${typeof PKG_V25}::tx_context::TxContext`, typeArgs: [ ] as [], isPhantom: TxContext.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => TxContext.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TxContext.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => TxContext.fromBcs( data, ), bcs: TxContext.bcs, fromJSONField: (field: any) => TxContext.fromJSONField( field, ), fromJSON: (json: Record) => TxContext.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => TxContext.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => TxContext.fetch( client, id, ), new: ( fields: TxContextFields, ) => { return new TxContext( [], fields ) }, kind: "StructClassReified", } } static get r() { return TxContext.reified() } @@ -65,6 +63,7 @@ export class TxContext implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): TxContext { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTxContext(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TxContext object`); } return TxContext.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TxContext object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTxContext(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TxContext object`); } + return TxContext.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/url/structs.ts b/src/codegen/_dependencies/source/0x2/url/structs.ts index 9feec9b..3234363 100644 --- a/src/codegen/_dependencies/source/0x2/url/structs.ts +++ b/src/codegen/_dependencies/source/0x2/url/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../../0x1/ascii/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V25} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Url =============================== */ -export function isUrl(type: string): boolean { type = compressSuiType(type); return type === "0x2::url::Url"; } +export function isUrl(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::url::Url`; } export interface UrlFields { url: ToField } export type UrlReified = Reified< Url, UrlFields >; -export class Url implements StructClass { static readonly $typeName = "0x2::url::Url"; static readonly $numTypeParams = 0; +export class Url implements StructClass { static readonly $typeName = `${PKG_V25}::url::Url`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Url.$typeName; - - readonly $fullTypeName: "0x2::url::Url"; - - readonly $typeArgs: []; + readonly $typeName = Url.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::url::Url`; readonly $typeArgs: []; readonly $isPhantom = Url.$isPhantom; readonly url: ToField - private constructor(typeArgs: [], fields: UrlFields, ) { this.$fullTypeName = composeSuiType( Url.$typeName, ...typeArgs ) as "0x2::url::Url"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: UrlFields, ) { this.$fullTypeName = composeSuiType( Url.$typeName, ...typeArgs ) as `${typeof PKG_V25}::url::Url`; this.$typeArgs = typeArgs; this.url = fields.url; } - static reified( ): UrlReified { return { typeName: Url.$typeName, fullTypeName: composeSuiType( Url.$typeName, ...[] ) as "0x2::url::Url", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Url.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Url.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Url.fromBcs( data, ), bcs: Url.bcs, fromJSONField: (field: any) => Url.fromJSONField( field, ), fromJSON: (json: Record) => Url.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Url.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Url.fetch( client, id, ), new: ( fields: UrlFields, ) => { return new Url( [], fields ) }, kind: "StructClassReified", } } + static reified( ): UrlReified { return { typeName: Url.$typeName, fullTypeName: composeSuiType( Url.$typeName, ...[] ) as `${typeof PKG_V25}::url::Url`, typeArgs: [ ] as [], isPhantom: Url.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Url.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Url.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Url.fromBcs( data, ), bcs: Url.bcs, fromJSONField: (field: any) => Url.fromJSONField( field, ), fromJSON: (json: Record) => Url.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Url.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Url.fetch( client, id, ), new: ( fields: UrlFields, ) => { return new Url( [], fields ) }, kind: "StructClassReified", } } static get r() { return Url.reified() } @@ -65,6 +63,7 @@ export class Url implements StructClass { static readonly $typeName = "0x2::url: static fromSuiParsedData( content: SuiParsedData ): Url { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isUrl(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Url object`); } return Url.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Url object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isUrl(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Url object`); } + return Url.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/vec-map/structs.ts b/src/codegen/_dependencies/source/0x2/vec-map/structs.ts index 0efb6b9..b9f976c 100644 --- a/src/codegen/_dependencies/source/0x2/vec-map/structs.ts +++ b/src/codegen/_dependencies/source/0x2/vec-map/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, Vector, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Entry =============================== */ -export function isEntry(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::vec_map::Entry<"); } +export function isEntry(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::vec_map::Entry` + '<'); } export interface EntryFields { key: ToField; value: ToField } export type EntryReified = Reified< Entry, EntryFields >; -export class Entry implements StructClass { static readonly $typeName = "0x2::vec_map::Entry"; static readonly $numTypeParams = 2; +export class Entry implements StructClass { static readonly $typeName = `${PKG_V25}::vec_map::Entry`; static readonly $numTypeParams = 2; static readonly $isPhantom = [false,false,] as const; - readonly $typeName = Entry.$typeName; - - readonly $fullTypeName: `0x2::vec_map::Entry<${ToTypeStr}, ${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr, ToTypeStr]; + readonly $typeName = Entry.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::vec_map::Entry<${ToTypeStr}, ${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr, ToTypeStr]; readonly $isPhantom = Entry.$isPhantom; readonly key: ToField; readonly value: ToField - private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: EntryFields, ) { this.$fullTypeName = composeSuiType( Entry.$typeName, ...typeArgs ) as `0x2::vec_map::Entry<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: EntryFields, ) { this.$fullTypeName = composeSuiType( Entry.$typeName, ...typeArgs ) as `${typeof PKG_V25}::vec_map::Entry<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; this.key = fields.key;; this.value = fields.value; } - static reified, V extends Reified>( K: K, V: V ): EntryReified, ToTypeArgument> { return { typeName: Entry.$typeName, fullTypeName: composeSuiType( Entry.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::vec_map::Entry<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Entry.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Entry.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Entry.fromBcs( [K, V], data, ), bcs: Entry.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => Entry.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Entry.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Entry.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Entry.fetch( client, [K, V], id, ), new: ( fields: EntryFields, ToTypeArgument>, ) => { return new Entry( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends Reified>( K: K, V: V ): EntryReified, ToTypeArgument> { return { typeName: Entry.$typeName, fullTypeName: composeSuiType( Entry.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::vec_map::Entry<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], isPhantom: Entry.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => Entry.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Entry.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => Entry.fromBcs( [K, V], data, ), bcs: Entry.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => Entry.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => Entry.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => Entry.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => Entry.fetch( client, [K, V], id, ), new: ( fields: EntryFields, ToTypeArgument>, ) => { return new Entry( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return Entry.reified } @@ -65,33 +63,32 @@ export class Entry implements St static fromSuiParsedData, V extends Reified>( typeArgs: [K, V], content: SuiParsedData ): Entry, ToTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isEntry(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Entry object`); } return Entry.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends Reified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Entry object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isEntry(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Entry object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return Entry.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== VecMap =============================== */ -export function isVecMap(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::vec_map::VecMap<"); } +export function isVecMap(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::vec_map::VecMap` + '<'); } export interface VecMapFields { contents: ToField>> } export type VecMapReified = Reified< VecMap, VecMapFields >; -export class VecMap implements StructClass { static readonly $typeName = "0x2::vec_map::VecMap"; static readonly $numTypeParams = 2; +export class VecMap implements StructClass { static readonly $typeName = `${PKG_V25}::vec_map::VecMap`; static readonly $numTypeParams = 2; static readonly $isPhantom = [false,false,] as const; - readonly $typeName = VecMap.$typeName; - - readonly $fullTypeName: `0x2::vec_map::VecMap<${ToTypeStr}, ${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr, ToTypeStr]; + readonly $typeName = VecMap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::vec_map::VecMap<${ToTypeStr}, ${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr, ToTypeStr]; readonly $isPhantom = VecMap.$isPhantom; readonly contents: ToField>> - private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: VecMapFields, ) { this.$fullTypeName = composeSuiType( VecMap.$typeName, ...typeArgs ) as `0x2::vec_map::VecMap<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr, ToTypeStr], fields: VecMapFields, ) { this.$fullTypeName = composeSuiType( VecMap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::vec_map::VecMap<${ToTypeStr}, ${ToTypeStr}>`; this.$typeArgs = typeArgs; this.contents = fields.contents; } - static reified, V extends Reified>( K: K, V: V ): VecMapReified, ToTypeArgument> { return { typeName: VecMap.$typeName, fullTypeName: composeSuiType( VecMap.$typeName, ...[extractType(K), extractType(V)] ) as `0x2::vec_map::VecMap<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], reifiedTypeArgs: [K, V], fromFields: (fields: Record) => VecMap.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VecMap.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => VecMap.fromBcs( [K, V], data, ), bcs: VecMap.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => VecMap.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => VecMap.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => VecMap.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => VecMap.fetch( client, [K, V], id, ), new: ( fields: VecMapFields, ToTypeArgument>, ) => { return new VecMap( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } + static reified, V extends Reified>( K: K, V: V ): VecMapReified, ToTypeArgument> { return { typeName: VecMap.$typeName, fullTypeName: composeSuiType( VecMap.$typeName, ...[extractType(K), extractType(V)] ) as `${typeof PKG_V25}::vec_map::VecMap<${ToTypeStr>}, ${ToTypeStr>}>`, typeArgs: [ extractType(K), extractType(V) ] as [ToTypeStr>, ToTypeStr>], isPhantom: VecMap.$isPhantom, reifiedTypeArgs: [K, V], fromFields: (fields: Record) => VecMap.fromFields( [K, V], fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VecMap.fromFieldsWithTypes( [K, V], item, ), fromBcs: (data: Uint8Array) => VecMap.fromBcs( [K, V], data, ), bcs: VecMap.bcs(toBcs(K), toBcs(V)), fromJSONField: (field: any) => VecMap.fromJSONField( [K, V], field, ), fromJSON: (json: Record) => VecMap.fromJSON( [K, V], json, ), fromSuiParsedData: (content: SuiParsedData) => VecMap.fromSuiParsedData( [K, V], content, ), fetch: async (client: SuiClient, id: string) => VecMap.fetch( client, [K, V], id, ), new: ( fields: VecMapFields, ToTypeArgument>, ) => { return new VecMap( [extractType(K), extractType(V)], fields ) }, kind: "StructClassReified", } } static get r() { return VecMap.reified } @@ -115,7 +112,7 @@ export class VecMap implements S toJSONField() { return { - contents: fieldToJSON>>(`vector<0x2::vec_map::Entry<${this.$typeArgs[0]}, ${this.$typeArgs[1]}>>`, this.contents), + contents: fieldToJSON>>(`vector<${Entry.$typeName}<${this.$typeArgs[0]}, ${this.$typeArgs[1]}>>`, this.contents), } } @@ -130,6 +127,9 @@ export class VecMap implements S static fromSuiParsedData, V extends Reified>( typeArgs: [K, V], content: SuiParsedData ): VecMap, ToTypeArgument> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVecMap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VecMap object`); } return VecMap.fromFieldsWithTypes( typeArgs, content ); } static async fetch, V extends Reified>( client: SuiClient, typeArgs: [K, V], id: string ): Promise, ToTypeArgument>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VecMap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVecMap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VecMap object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 2) { throw new Error(`type argument mismatch: expected 2 type arguments but got ${gotTypeArgs.length}`); }; for (let i = 0; i < 2; i++) { const gotTypeArg = compressSuiType(gotTypeArgs[i]); const expectedTypeArg = compressSuiType(extractType(typeArgs[i])); if (gotTypeArg !== expectedTypeArg) { throw new Error(`type argument mismatch at position ${i}: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); } }; + return VecMap.fromBcs( typeArgs, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/vec-set/structs.ts b/src/codegen/_dependencies/source/0x2/vec-set/structs.ts index b57626f..a8e499e 100644 --- a/src/codegen/_dependencies/source/0x2/vec-set/structs.ts +++ b/src/codegen/_dependencies/source/0x2/vec-set/structs.ts @@ -1,32 +1,30 @@ import * as reified from "../../../../_framework/reified"; import {PhantomReified, Reified, StructClass, ToField, ToTypeArgument, ToTypeStr, TypeArgument, Vector, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, fieldToJSON, phantom, toBcs} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; -import {BcsType, bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; +import {BcsType, bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== VecSet =============================== */ -export function isVecSet(type: string): boolean { type = compressSuiType(type); return type.startsWith("0x2::vec_set::VecSet<"); } +export function isVecSet(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V25}::vec_set::VecSet` + '<'); } export interface VecSetFields { contents: ToField> } export type VecSetReified = Reified< VecSet, VecSetFields >; -export class VecSet implements StructClass { static readonly $typeName = "0x2::vec_set::VecSet"; static readonly $numTypeParams = 1; +export class VecSet implements StructClass { static readonly $typeName = `${PKG_V25}::vec_set::VecSet`; static readonly $numTypeParams = 1; static readonly $isPhantom = [false,] as const; - readonly $typeName = VecSet.$typeName; - - readonly $fullTypeName: `0x2::vec_set::VecSet<${ToTypeStr}>`; - - readonly $typeArgs: [ToTypeStr]; + readonly $typeName = VecSet.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::vec_set::VecSet<${ToTypeStr}>`; readonly $typeArgs: [ToTypeStr]; readonly $isPhantom = VecSet.$isPhantom; readonly contents: ToField> - private constructor(typeArgs: [ToTypeStr], fields: VecSetFields, ) { this.$fullTypeName = composeSuiType( VecSet.$typeName, ...typeArgs ) as `0x2::vec_set::VecSet<${ToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [ToTypeStr], fields: VecSetFields, ) { this.$fullTypeName = composeSuiType( VecSet.$typeName, ...typeArgs ) as `${typeof PKG_V25}::vec_set::VecSet<${ToTypeStr}>`; this.$typeArgs = typeArgs; this.contents = fields.contents; } - static reified>( K: K ): VecSetReified> { return { typeName: VecSet.$typeName, fullTypeName: composeSuiType( VecSet.$typeName, ...[extractType(K)] ) as `0x2::vec_set::VecSet<${ToTypeStr>}>`, typeArgs: [ extractType(K) ] as [ToTypeStr>], reifiedTypeArgs: [K], fromFields: (fields: Record) => VecSet.fromFields( K, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VecSet.fromFieldsWithTypes( K, item, ), fromBcs: (data: Uint8Array) => VecSet.fromBcs( K, data, ), bcs: VecSet.bcs(toBcs(K)), fromJSONField: (field: any) => VecSet.fromJSONField( K, field, ), fromJSON: (json: Record) => VecSet.fromJSON( K, json, ), fromSuiParsedData: (content: SuiParsedData) => VecSet.fromSuiParsedData( K, content, ), fetch: async (client: SuiClient, id: string) => VecSet.fetch( client, K, id, ), new: ( fields: VecSetFields>, ) => { return new VecSet( [extractType(K)], fields ) }, kind: "StructClassReified", } } + static reified>( K: K ): VecSetReified> { return { typeName: VecSet.$typeName, fullTypeName: composeSuiType( VecSet.$typeName, ...[extractType(K)] ) as `${typeof PKG_V25}::vec_set::VecSet<${ToTypeStr>}>`, typeArgs: [ extractType(K) ] as [ToTypeStr>], isPhantom: VecSet.$isPhantom, reifiedTypeArgs: [K], fromFields: (fields: Record) => VecSet.fromFields( K, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VecSet.fromFieldsWithTypes( K, item, ), fromBcs: (data: Uint8Array) => VecSet.fromBcs( K, data, ), bcs: VecSet.bcs(toBcs(K)), fromJSONField: (field: any) => VecSet.fromJSONField( K, field, ), fromJSON: (json: Record) => VecSet.fromJSON( K, json, ), fromSuiParsedData: (content: SuiParsedData) => VecSet.fromSuiParsedData( K, content, ), fetch: async (client: SuiClient, id: string) => VecSet.fetch( client, K, id, ), new: ( fields: VecSetFields>, ) => { return new VecSet( [extractType(K)], fields ) }, kind: "StructClassReified", } } static get r() { return VecSet.reified } @@ -67,6 +65,9 @@ export class VecSet implements StructClass { static read static fromSuiParsedData>( typeArg: K, content: SuiParsedData ): VecSet> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVecSet(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VecSet object`); } return VecSet.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: K, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VecSet object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVecSet(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VecSet object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return VecSet.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/versioned/structs.ts b/src/codegen/_dependencies/source/0x2/versioned/structs.ts index 7a600fa..c5cdc49 100644 --- a/src/codegen/_dependencies/source/0x2/versioned/structs.ts +++ b/src/codegen/_dependencies/source/0x2/versioned/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {PKG_V25} from "../index"; import {ID, UID} from "../object/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== VersionChangeCap =============================== */ -export function isVersionChangeCap(type: string): boolean { type = compressSuiType(type); return type === "0x2::versioned::VersionChangeCap"; } +export function isVersionChangeCap(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::versioned::VersionChangeCap`; } export interface VersionChangeCapFields { versionedId: ToField; oldVersion: ToField<"u64"> } export type VersionChangeCapReified = Reified< VersionChangeCap, VersionChangeCapFields >; -export class VersionChangeCap implements StructClass { static readonly $typeName = "0x2::versioned::VersionChangeCap"; static readonly $numTypeParams = 0; +export class VersionChangeCap implements StructClass { static readonly $typeName = `${PKG_V25}::versioned::VersionChangeCap`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = VersionChangeCap.$typeName; - - readonly $fullTypeName: "0x2::versioned::VersionChangeCap"; - - readonly $typeArgs: []; + readonly $typeName = VersionChangeCap.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::versioned::VersionChangeCap`; readonly $typeArgs: []; readonly $isPhantom = VersionChangeCap.$isPhantom; readonly versionedId: ToField; readonly oldVersion: ToField<"u64"> - private constructor(typeArgs: [], fields: VersionChangeCapFields, ) { this.$fullTypeName = composeSuiType( VersionChangeCap.$typeName, ...typeArgs ) as "0x2::versioned::VersionChangeCap"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: VersionChangeCapFields, ) { this.$fullTypeName = composeSuiType( VersionChangeCap.$typeName, ...typeArgs ) as `${typeof PKG_V25}::versioned::VersionChangeCap`; this.$typeArgs = typeArgs; this.versionedId = fields.versionedId;; this.oldVersion = fields.oldVersion; } - static reified( ): VersionChangeCapReified { return { typeName: VersionChangeCap.$typeName, fullTypeName: composeSuiType( VersionChangeCap.$typeName, ...[] ) as "0x2::versioned::VersionChangeCap", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => VersionChangeCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VersionChangeCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VersionChangeCap.fromBcs( data, ), bcs: VersionChangeCap.bcs, fromJSONField: (field: any) => VersionChangeCap.fromJSONField( field, ), fromJSON: (json: Record) => VersionChangeCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VersionChangeCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VersionChangeCap.fetch( client, id, ), new: ( fields: VersionChangeCapFields, ) => { return new VersionChangeCap( [], fields ) }, kind: "StructClassReified", } } + static reified( ): VersionChangeCapReified { return { typeName: VersionChangeCap.$typeName, fullTypeName: composeSuiType( VersionChangeCap.$typeName, ...[] ) as `${typeof PKG_V25}::versioned::VersionChangeCap`, typeArgs: [ ] as [], isPhantom: VersionChangeCap.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => VersionChangeCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VersionChangeCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VersionChangeCap.fromBcs( data, ), bcs: VersionChangeCap.bcs, fromJSONField: (field: any) => VersionChangeCap.fromJSONField( field, ), fromJSON: (json: Record) => VersionChangeCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VersionChangeCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VersionChangeCap.fetch( client, id, ), new: ( fields: VersionChangeCapFields, ) => { return new VersionChangeCap( [], fields ) }, kind: "StructClassReified", } } static get r() { return VersionChangeCap.reified() } @@ -65,33 +63,30 @@ export class VersionChangeCap implements StructClass { static readonly $typeName static fromSuiParsedData( content: SuiParsedData ): VersionChangeCap { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVersionChangeCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VersionChangeCap object`); } return VersionChangeCap.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VersionChangeCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVersionChangeCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VersionChangeCap object`); } + return VersionChangeCap.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Versioned =============================== */ -export function isVersioned(type: string): boolean { type = compressSuiType(type); return type === "0x2::versioned::Versioned"; } +export function isVersioned(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::versioned::Versioned`; } export interface VersionedFields { id: ToField; version: ToField<"u64"> } export type VersionedReified = Reified< Versioned, VersionedFields >; -export class Versioned implements StructClass { static readonly $typeName = "0x2::versioned::Versioned"; static readonly $numTypeParams = 0; +export class Versioned implements StructClass { static readonly $typeName = `${PKG_V25}::versioned::Versioned`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Versioned.$typeName; - - readonly $fullTypeName: "0x2::versioned::Versioned"; - - readonly $typeArgs: []; + readonly $typeName = Versioned.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::versioned::Versioned`; readonly $typeArgs: []; readonly $isPhantom = Versioned.$isPhantom; readonly id: ToField; readonly version: ToField<"u64"> - private constructor(typeArgs: [], fields: VersionedFields, ) { this.$fullTypeName = composeSuiType( Versioned.$typeName, ...typeArgs ) as "0x2::versioned::Versioned"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: VersionedFields, ) { this.$fullTypeName = composeSuiType( Versioned.$typeName, ...typeArgs ) as `${typeof PKG_V25}::versioned::Versioned`; this.$typeArgs = typeArgs; this.id = fields.id;; this.version = fields.version; } - static reified( ): VersionedReified { return { typeName: Versioned.$typeName, fullTypeName: composeSuiType( Versioned.$typeName, ...[] ) as "0x2::versioned::Versioned", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Versioned.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Versioned.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Versioned.fromBcs( data, ), bcs: Versioned.bcs, fromJSONField: (field: any) => Versioned.fromJSONField( field, ), fromJSON: (json: Record) => Versioned.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Versioned.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Versioned.fetch( client, id, ), new: ( fields: VersionedFields, ) => { return new Versioned( [], fields ) }, kind: "StructClassReified", } } + static reified( ): VersionedReified { return { typeName: Versioned.$typeName, fullTypeName: composeSuiType( Versioned.$typeName, ...[] ) as `${typeof PKG_V25}::versioned::Versioned`, typeArgs: [ ] as [], isPhantom: Versioned.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Versioned.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Versioned.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Versioned.fromBcs( data, ), bcs: Versioned.bcs, fromJSONField: (field: any) => Versioned.fromJSONField( field, ), fromJSON: (json: Record) => Versioned.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Versioned.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Versioned.fetch( client, id, ), new: ( fields: VersionedFields, ) => { return new Versioned( [], fields ) }, kind: "StructClassReified", } } static get r() { return Versioned.reified() } @@ -130,6 +125,7 @@ export class Versioned implements StructClass { static readonly $typeName = "0x2 static fromSuiParsedData( content: SuiParsedData ): Versioned { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVersioned(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Versioned object`); } return Versioned.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Versioned object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVersioned(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Versioned object`); } + return Versioned.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/zklogin-verified-id/structs.ts b/src/codegen/_dependencies/source/0x2/zklogin-verified-id/structs.ts index 1efdad6..326d897 100644 --- a/src/codegen/_dependencies/source/0x2/zklogin-verified-id/structs.ts +++ b/src/codegen/_dependencies/source/0x2/zklogin-verified-id/structs.ts @@ -1,33 +1,31 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../../0x1/string/structs"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== VerifiedID =============================== */ -export function isVerifiedID(type: string): boolean { type = compressSuiType(type); return type === "0x2::zklogin_verified_id::VerifiedID"; } +export function isVerifiedID(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::zklogin_verified_id::VerifiedID`; } export interface VerifiedIDFields { id: ToField; owner: ToField<"address">; keyClaimName: ToField; keyClaimValue: ToField; issuer: ToField; audience: ToField } export type VerifiedIDReified = Reified< VerifiedID, VerifiedIDFields >; -export class VerifiedID implements StructClass { static readonly $typeName = "0x2::zklogin_verified_id::VerifiedID"; static readonly $numTypeParams = 0; +export class VerifiedID implements StructClass { static readonly $typeName = `${PKG_V25}::zklogin_verified_id::VerifiedID`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = VerifiedID.$typeName; - - readonly $fullTypeName: "0x2::zklogin_verified_id::VerifiedID"; - - readonly $typeArgs: []; + readonly $typeName = VerifiedID.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::zklogin_verified_id::VerifiedID`; readonly $typeArgs: []; readonly $isPhantom = VerifiedID.$isPhantom; readonly id: ToField; readonly owner: ToField<"address">; readonly keyClaimName: ToField; readonly keyClaimValue: ToField; readonly issuer: ToField; readonly audience: ToField - private constructor(typeArgs: [], fields: VerifiedIDFields, ) { this.$fullTypeName = composeSuiType( VerifiedID.$typeName, ...typeArgs ) as "0x2::zklogin_verified_id::VerifiedID"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: VerifiedIDFields, ) { this.$fullTypeName = composeSuiType( VerifiedID.$typeName, ...typeArgs ) as `${typeof PKG_V25}::zklogin_verified_id::VerifiedID`; this.$typeArgs = typeArgs; this.id = fields.id;; this.owner = fields.owner;; this.keyClaimName = fields.keyClaimName;; this.keyClaimValue = fields.keyClaimValue;; this.issuer = fields.issuer;; this.audience = fields.audience; } - static reified( ): VerifiedIDReified { return { typeName: VerifiedID.$typeName, fullTypeName: composeSuiType( VerifiedID.$typeName, ...[] ) as "0x2::zklogin_verified_id::VerifiedID", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => VerifiedID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VerifiedID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VerifiedID.fromBcs( data, ), bcs: VerifiedID.bcs, fromJSONField: (field: any) => VerifiedID.fromJSONField( field, ), fromJSON: (json: Record) => VerifiedID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VerifiedID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VerifiedID.fetch( client, id, ), new: ( fields: VerifiedIDFields, ) => { return new VerifiedID( [], fields ) }, kind: "StructClassReified", } } + static reified( ): VerifiedIDReified { return { typeName: VerifiedID.$typeName, fullTypeName: composeSuiType( VerifiedID.$typeName, ...[] ) as `${typeof PKG_V25}::zklogin_verified_id::VerifiedID`, typeArgs: [ ] as [], isPhantom: VerifiedID.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => VerifiedID.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VerifiedID.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VerifiedID.fromBcs( data, ), bcs: VerifiedID.bcs, fromJSONField: (field: any) => VerifiedID.fromJSONField( field, ), fromJSON: (json: Record) => VerifiedID.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VerifiedID.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VerifiedID.fetch( client, id, ), new: ( fields: VerifiedIDFields, ) => { return new VerifiedID( [], fields ) }, kind: "StructClassReified", } } static get r() { return VerifiedID.reified() } @@ -66,6 +64,7 @@ export class VerifiedID implements StructClass { static readonly $typeName = "0x static fromSuiParsedData( content: SuiParsedData ): VerifiedID { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVerifiedID(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VerifiedID object`); } return VerifiedID.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VerifiedID object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVerifiedID(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VerifiedID object`); } + return VerifiedID.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0x2/zklogin-verified-issuer/structs.ts b/src/codegen/_dependencies/source/0x2/zklogin-verified-issuer/structs.ts index 6ecf54d..a35fab8 100644 --- a/src/codegen/_dependencies/source/0x2/zklogin-verified-issuer/structs.ts +++ b/src/codegen/_dependencies/source/0x2/zklogin-verified-issuer/structs.ts @@ -1,33 +1,31 @@ import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom} from "../../../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; import {String} from "../../0x1/string/structs"; +import {PKG_V25} from "../index"; import {UID} from "../object/structs"; -import {bcs, fromB64, fromHEX, toHEX} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64, fromHEX, toHEX} from "@mysten/sui/utils"; /* ============================== VerifiedIssuer =============================== */ -export function isVerifiedIssuer(type: string): boolean { type = compressSuiType(type); return type === "0x2::zklogin_verified_issuer::VerifiedIssuer"; } +export function isVerifiedIssuer(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V25}::zklogin_verified_issuer::VerifiedIssuer`; } export interface VerifiedIssuerFields { id: ToField; owner: ToField<"address">; issuer: ToField } export type VerifiedIssuerReified = Reified< VerifiedIssuer, VerifiedIssuerFields >; -export class VerifiedIssuer implements StructClass { static readonly $typeName = "0x2::zklogin_verified_issuer::VerifiedIssuer"; static readonly $numTypeParams = 0; +export class VerifiedIssuer implements StructClass { static readonly $typeName = `${PKG_V25}::zklogin_verified_issuer::VerifiedIssuer`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = VerifiedIssuer.$typeName; - - readonly $fullTypeName: "0x2::zklogin_verified_issuer::VerifiedIssuer"; - - readonly $typeArgs: []; + readonly $typeName = VerifiedIssuer.$typeName; readonly $fullTypeName: `${typeof PKG_V25}::zklogin_verified_issuer::VerifiedIssuer`; readonly $typeArgs: []; readonly $isPhantom = VerifiedIssuer.$isPhantom; readonly id: ToField; readonly owner: ToField<"address">; readonly issuer: ToField - private constructor(typeArgs: [], fields: VerifiedIssuerFields, ) { this.$fullTypeName = composeSuiType( VerifiedIssuer.$typeName, ...typeArgs ) as "0x2::zklogin_verified_issuer::VerifiedIssuer"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: VerifiedIssuerFields, ) { this.$fullTypeName = composeSuiType( VerifiedIssuer.$typeName, ...typeArgs ) as `${typeof PKG_V25}::zklogin_verified_issuer::VerifiedIssuer`; this.$typeArgs = typeArgs; this.id = fields.id;; this.owner = fields.owner;; this.issuer = fields.issuer; } - static reified( ): VerifiedIssuerReified { return { typeName: VerifiedIssuer.$typeName, fullTypeName: composeSuiType( VerifiedIssuer.$typeName, ...[] ) as "0x2::zklogin_verified_issuer::VerifiedIssuer", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => VerifiedIssuer.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VerifiedIssuer.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VerifiedIssuer.fromBcs( data, ), bcs: VerifiedIssuer.bcs, fromJSONField: (field: any) => VerifiedIssuer.fromJSONField( field, ), fromJSON: (json: Record) => VerifiedIssuer.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VerifiedIssuer.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VerifiedIssuer.fetch( client, id, ), new: ( fields: VerifiedIssuerFields, ) => { return new VerifiedIssuer( [], fields ) }, kind: "StructClassReified", } } + static reified( ): VerifiedIssuerReified { return { typeName: VerifiedIssuer.$typeName, fullTypeName: composeSuiType( VerifiedIssuer.$typeName, ...[] ) as `${typeof PKG_V25}::zklogin_verified_issuer::VerifiedIssuer`, typeArgs: [ ] as [], isPhantom: VerifiedIssuer.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => VerifiedIssuer.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => VerifiedIssuer.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => VerifiedIssuer.fromBcs( data, ), bcs: VerifiedIssuer.bcs, fromJSONField: (field: any) => VerifiedIssuer.fromJSONField( field, ), fromJSON: (json: Record) => VerifiedIssuer.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => VerifiedIssuer.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => VerifiedIssuer.fetch( client, id, ), new: ( fields: VerifiedIssuerFields, ) => { return new VerifiedIssuer( [], fields ) }, kind: "StructClassReified", } } static get r() { return VerifiedIssuer.reified() } @@ -66,6 +64,7 @@ export class VerifiedIssuer implements StructClass { static readonly $typeName = static fromSuiParsedData( content: SuiParsedData ): VerifiedIssuer { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isVerifiedIssuer(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a VerifiedIssuer object`); } return VerifiedIssuer.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching VerifiedIssuer object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isVerifiedIssuer(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a VerifiedIssuer object`); } + return VerifiedIssuer.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/index.ts b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/index.ts index 5ebbad7..de6ab5a 100644 --- a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/index.ts +++ b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/index.ts @@ -1 +1 @@ -export const PACKAGE_ID = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca"; export const PUBLISHED_AT = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca"; +export const PACKAGE_ID = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca"; export const PUBLISHED_AT = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca"; export const PKG_V1 = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca"; diff --git a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/locker/structs.ts b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/locker/structs.ts index 7afad12..90e47f3 100644 --- a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/locker/structs.ts +++ b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/locker/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; +import {PKG_V1} from "../index"; import {TimeLockedBalance} from "../time-locked-balance/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Locker =============================== */ -export function isLocker(type: string): boolean { type = compressSuiType(type); return type.startsWith("0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::locker::Locker<"); } +export function isLocker(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V1}::locker::Locker` + '<'); } export interface LockerFields { balance: ToField> } export type LockerReified = Reified< Locker, LockerFields >; -export class Locker implements StructClass { static readonly $typeName = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::locker::Locker"; static readonly $numTypeParams = 1; +export class Locker implements StructClass { static readonly $typeName = `${PKG_V1}::locker::Locker`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = Locker.$typeName; - - readonly $fullTypeName: `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::locker::Locker<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = Locker.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::locker::Locker<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = Locker.$isPhantom; readonly balance: ToField> - private constructor(typeArgs: [PhantomToTypeStr], fields: LockerFields, ) { this.$fullTypeName = composeSuiType( Locker.$typeName, ...typeArgs ) as `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::locker::Locker<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: LockerFields, ) { this.$fullTypeName = composeSuiType( Locker.$typeName, ...typeArgs ) as `${typeof PKG_V1}::locker::Locker<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.balance = fields.balance; } - static reified>( T: T ): LockerReified> { return { typeName: Locker.$typeName, fullTypeName: composeSuiType( Locker.$typeName, ...[extractType(T)] ) as `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::locker::Locker<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => Locker.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Locker.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Locker.fromBcs( T, data, ), bcs: Locker.bcs, fromJSONField: (field: any) => Locker.fromJSONField( T, field, ), fromJSON: (json: Record) => Locker.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Locker.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Locker.fetch( client, T, id, ), new: ( fields: LockerFields>, ) => { return new Locker( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): LockerReified> { return { typeName: Locker.$typeName, fullTypeName: composeSuiType( Locker.$typeName, ...[extractType(T)] ) as `${typeof PKG_V1}::locker::Locker<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: Locker.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => Locker.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Locker.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => Locker.fromBcs( T, data, ), bcs: Locker.bcs, fromJSONField: (field: any) => Locker.fromJSONField( T, field, ), fromJSON: (json: Record) => Locker.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => Locker.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => Locker.fetch( client, T, id, ), new: ( fields: LockerFields>, ) => { return new Locker( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return Locker.reified } @@ -65,6 +63,9 @@ export class Locker implements StructClass { stat static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): Locker> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isLocker(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Locker object`); } return Locker.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Locker object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isLocker(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Locker object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return Locker.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/time-locked-balance/structs.ts b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/time-locked-balance/structs.ts index f6420ea..b899ed2 100644 --- a/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/time-locked-balance/structs.ts +++ b/src/codegen/_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/time-locked-balance/structs.ts @@ -1,32 +1,30 @@ import {PhantomReified, PhantomToTypeStr, PhantomTypeArgument, Reified, StructClass, ToField, ToPhantomTypeArgument, ToTypeStr, assertFieldsWithTypesArgsMatch, assertReifiedTypeArgsMatch, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, extractType, phantom} from "../../../../_framework/reified"; -import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util"; +import {FieldsWithTypes, composeSuiType, compressSuiType, parseTypeName} from "../../../../_framework/util"; import {Balance} from "../../0x2/balance/structs"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V1} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== TimeLockedBalance =============================== */ -export function isTimeLockedBalance(type: string): boolean { type = compressSuiType(type); return type.startsWith("0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::time_locked_balance::TimeLockedBalance<"); } +export function isTimeLockedBalance(type: string): boolean { type = compressSuiType(type); return type.startsWith(`${PKG_V1}::time_locked_balance::TimeLockedBalance` + '<'); } export interface TimeLockedBalanceFields { lockedBalance: ToField>; unlockStartTsSec: ToField<"u64">; unlockPerSecond: ToField<"u64">; unlockedBalance: ToField>; finalUnlockTsSec: ToField<"u64">; previousUnlockAt: ToField<"u64"> } export type TimeLockedBalanceReified = Reified< TimeLockedBalance, TimeLockedBalanceFields >; -export class TimeLockedBalance implements StructClass { static readonly $typeName = "0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::time_locked_balance::TimeLockedBalance"; static readonly $numTypeParams = 1; +export class TimeLockedBalance implements StructClass { static readonly $typeName = `${PKG_V1}::time_locked_balance::TimeLockedBalance`; static readonly $numTypeParams = 1; static readonly $isPhantom = [true,] as const; - readonly $typeName = TimeLockedBalance.$typeName; - - readonly $fullTypeName: `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr}>`; - - readonly $typeArgs: [PhantomToTypeStr]; + readonly $typeName = TimeLockedBalance.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr}>`; readonly $typeArgs: [PhantomToTypeStr]; readonly $isPhantom = TimeLockedBalance.$isPhantom; readonly lockedBalance: ToField>; readonly unlockStartTsSec: ToField<"u64">; readonly unlockPerSecond: ToField<"u64">; readonly unlockedBalance: ToField>; readonly finalUnlockTsSec: ToField<"u64">; readonly previousUnlockAt: ToField<"u64"> - private constructor(typeArgs: [PhantomToTypeStr], fields: TimeLockedBalanceFields, ) { this.$fullTypeName = composeSuiType( TimeLockedBalance.$typeName, ...typeArgs ) as `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; + private constructor(typeArgs: [PhantomToTypeStr], fields: TimeLockedBalanceFields, ) { this.$fullTypeName = composeSuiType( TimeLockedBalance.$typeName, ...typeArgs ) as `${typeof PKG_V1}::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr}>`; this.$typeArgs = typeArgs; this.lockedBalance = fields.lockedBalance;; this.unlockStartTsSec = fields.unlockStartTsSec;; this.unlockPerSecond = fields.unlockPerSecond;; this.unlockedBalance = fields.unlockedBalance;; this.finalUnlockTsSec = fields.finalUnlockTsSec;; this.previousUnlockAt = fields.previousUnlockAt; } - static reified>( T: T ): TimeLockedBalanceReified> { return { typeName: TimeLockedBalance.$typeName, fullTypeName: composeSuiType( TimeLockedBalance.$typeName, ...[extractType(T)] ) as `0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], reifiedTypeArgs: [T], fromFields: (fields: Record) => TimeLockedBalance.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TimeLockedBalance.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TimeLockedBalance.fromBcs( T, data, ), bcs: TimeLockedBalance.bcs, fromJSONField: (field: any) => TimeLockedBalance.fromJSONField( T, field, ), fromJSON: (json: Record) => TimeLockedBalance.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TimeLockedBalance.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TimeLockedBalance.fetch( client, T, id, ), new: ( fields: TimeLockedBalanceFields>, ) => { return new TimeLockedBalance( [extractType(T)], fields ) }, kind: "StructClassReified", } } + static reified>( T: T ): TimeLockedBalanceReified> { return { typeName: TimeLockedBalance.$typeName, fullTypeName: composeSuiType( TimeLockedBalance.$typeName, ...[extractType(T)] ) as `${typeof PKG_V1}::time_locked_balance::TimeLockedBalance<${PhantomToTypeStr>}>`, typeArgs: [ extractType(T) ] as [PhantomToTypeStr>], isPhantom: TimeLockedBalance.$isPhantom, reifiedTypeArgs: [T], fromFields: (fields: Record) => TimeLockedBalance.fromFields( T, fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => TimeLockedBalance.fromFieldsWithTypes( T, item, ), fromBcs: (data: Uint8Array) => TimeLockedBalance.fromBcs( T, data, ), bcs: TimeLockedBalance.bcs, fromJSONField: (field: any) => TimeLockedBalance.fromJSONField( T, field, ), fromJSON: (json: Record) => TimeLockedBalance.fromJSON( T, json, ), fromSuiParsedData: (content: SuiParsedData) => TimeLockedBalance.fromSuiParsedData( T, content, ), fetch: async (client: SuiClient, id: string) => TimeLockedBalance.fetch( client, T, id, ), new: ( fields: TimeLockedBalanceFields>, ) => { return new TimeLockedBalance( [extractType(T)], fields ) }, kind: "StructClassReified", } } static get r() { return TimeLockedBalance.reified } @@ -65,6 +63,9 @@ export class TimeLockedBalance implements StructC static fromSuiParsedData>( typeArg: T, content: SuiParsedData ): TimeLockedBalance> { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isTimeLockedBalance(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a TimeLockedBalance object`); } return TimeLockedBalance.fromFieldsWithTypes( typeArg, content ); } static async fetch>( client: SuiClient, typeArg: T, id: string ): Promise>> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching TimeLockedBalance object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isTimeLockedBalance(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a TimeLockedBalance object`); } + + const gotTypeArgs = parseTypeName(res.data.bcs.type).typeArgs; if (gotTypeArgs.length !== 1) { throw new Error(`type argument mismatch: expected 1 type argument but got '${gotTypeArgs.length}'`); }; const gotTypeArg = compressSuiType(gotTypeArgs[0]); const expectedTypeArg = compressSuiType(extractType(typeArg)); if (gotTypeArg !== compressSuiType(extractType(typeArg))) { throw new Error(`type argument mismatch: expected '${expectedTypeArg}' but got '${gotTypeArg}'`); }; + return TimeLockedBalance.fromBcs( typeArg, fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/_framework/init-loader.ts b/src/codegen/_framework/init-loader.ts new file mode 100644 index 0000000..9608c31 --- /dev/null +++ b/src/codegen/_framework/init-loader.ts @@ -0,0 +1,13 @@ +import * as package_source_1 from "../_dependencies/source/0x1/init"; +import * as package_source_2 from "../_dependencies/source/0x2/init"; +import * as package_source_bafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca from "../_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/init"; +import * as package_source_9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049 from "../mineral/init"; +import {StructClassLoader} from "./loader"; + +function registerClassesSource(loader: StructClassLoader) { package_source_1.registerClasses(loader); +package_source_2.registerClasses(loader); +package_source_9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049.registerClasses(loader); +package_source_bafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca.registerClasses(loader); + } + +export function registerClasses(loader: StructClassLoader) { registerClassesSource(loader); } diff --git a/src/codegen/_framework/init-source.ts b/src/codegen/_framework/init-source.ts deleted file mode 100644 index a74025b..0000000 --- a/src/codegen/_framework/init-source.ts +++ /dev/null @@ -1,11 +0,0 @@ -import * as package_1 from "../_dependencies/source/0x1/init"; -import * as package_2 from "../_dependencies/source/0x2/init"; -import * as package_bafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca from "../_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/init"; -import * as package_0 from "../mineral/init"; -import {structClassLoaderSource as structClassLoader} from "./loader"; - -let initialized = false; export function initLoaderIfNeeded() { if (initialized) { return }; initialized = true; package_0.registerClasses(structClassLoader); -package_1.registerClasses(structClassLoader); -package_2.registerClasses(structClassLoader); -package_bafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca.registerClasses(structClassLoader); - } diff --git a/src/codegen/_framework/loader.ts b/src/codegen/_framework/loader.ts index a140017..7520f5f 100644 --- a/src/codegen/_framework/loader.ts +++ b/src/codegen/_framework/loader.ts @@ -10,14 +10,17 @@ import { TypeArgument, VectorClass, VectorClassReified, + phantom, vector, } from './reified' +import { registerClasses } from './init-loader' export type PrimitiveValue = string | number | boolean | bigint interface _StructClass { $typeName: string $numTypeParams: number + $isPhantom: readonly boolean[] reified( ...Ts: Array | PhantomReified> ): StructClassReified @@ -68,10 +71,20 @@ export class StructClassLoader { ) } - return cls.reified(...typeArgs.map(t => this.reified(t))) + const reifiedTypeArgs: Array | PhantomReified> = + [] + for (let i = 0; i < typeArgs.length; i++) { + if (cls.$isPhantom[i]) { + reifiedTypeArgs.push(phantom(typeArgs[i])) + } else { + reifiedTypeArgs.push(this.reified(typeArgs[i])) + } + } + + return cls.reified(...reifiedTypeArgs) } } -export const structClassLoaderSource = new StructClassLoader() -export const structClassLoaderOnchain = new StructClassLoader() +export const loader = new StructClassLoader() +registerClasses(loader) diff --git a/src/codegen/_framework/reified.ts b/src/codegen/_framework/reified.ts index e3a09d0..3b21049 100644 --- a/src/codegen/_framework/reified.ts +++ b/src/codegen/_framework/reified.ts @@ -1,12 +1,14 @@ -import { BcsType, bcs, fromHEX, toHEX } from '@mysten/bcs' +import { bcs, BcsType } from '@mysten/sui/bcs' +import { fromHEX, toHEX } from '@mysten/sui/utils' import { FieldsWithTypes, compressSuiType, parseTypeName } from './util' -import { SuiClient, SuiParsedData } from '@mysten/sui.js/client' +import { SuiClient, SuiParsedData } from '@mysten/sui/client' export interface StructClass { - $typeName: string - $fullTypeName: string - $typeArgs: string[] + readonly $typeName: string + readonly $fullTypeName: string + readonly $typeArgs: string[] + readonly $isPhantom: readonly boolean[] toJSONField(): Record toJSON(): Record } @@ -43,6 +45,7 @@ export interface StructClassReified { typeName: T['$typeName'] // e.g., '0x2::balance::Balance', without type arguments fullTypeName: ToTypeStr // e.g., '0x2::balance::Balance<0x2::sui:SUI>' typeArgs: T['$typeArgs'] // e.g., ['0x2::sui:SUI'] + isPhantom: T['$isPhantom'] // e.g., [true, false] reifiedTypeArgs: Array | PhantomReified> bcs: BcsType fromFields(fields: Record): T diff --git a/src/codegen/_framework/util.ts b/src/codegen/_framework/util.ts index 6c4d037..b5d9db4 100644 --- a/src/codegen/_framework/util.ts +++ b/src/codegen/_framework/util.ts @@ -1,24 +1,19 @@ +import { bcs, BcsType } from '@mysten/sui/bcs' import { + Transaction, TransactionArgument, - TransactionBlock, TransactionObjectArgument, -} from '@mysten/sui.js/transactions' -import { bcs, ObjectArg as SuiObjectArg } from '@mysten/sui.js/bcs' -import { BcsType } from '@mysten/bcs' + TransactionObjectInput, +} from '@mysten/sui/transactions' export interface FieldsWithTypes { - /* eslint-disable @typescript-eslint/no-explicit-any */ fields: Record type: string } export type ObjectId = string -export type ObjectCallArg = { Object: SuiObjectArg } - -export type ObjectArg = string | ObjectCallArg | TransactionArgument - export type PureArg = | bigint | string @@ -27,40 +22,87 @@ export type PureArg = | null | TransactionArgument | Array -export type GenericArg = ObjectArg | PureArg | Array | Array | Array +export type GenericArg = + | TransactionObjectInput + | PureArg + | Array + | Array + | Array -export function parseTypeName(name: string): { typeName: string; typeArgs: string[] } { - const parsed = bcs.parseTypeName(name) - return { typeName: parsed.name, typeArgs: parsed.params as string[] } -} +export function splitGenericParameters( + str: string, + genericSeparators: [string, string] = ['<', '>'] +) { + const [left, right] = genericSeparators + const tok = [] + let word = '' + let nestedAngleBrackets = 0 -export function isTransactionArgument(arg: GenericArg): arg is TransactionArgument { - if (!arg || typeof arg !== 'object' || Array.isArray(arg)) { - return false + for (let i = 0; i < str.length; i++) { + const char = str[i] + if (char === left) { + nestedAngleBrackets++ + } + if (char === right) { + nestedAngleBrackets-- + } + if (nestedAngleBrackets === 0 && char === ',') { + tok.push(word.trim()) + word = '' + continue + } + word += char } - return 'kind' in arg + tok.push(word.trim()) + + return tok } -export function isTransactionObjectArgument(arg: GenericArg): arg is TransactionObjectArgument { - if (!isTransactionArgument(arg)) { - return false +export function parseTypeName(name: string): { typeName: string; typeArgs: string[] } { + if (typeof name !== 'string') { + throw new Error(`Illegal type passed as a name of the type: ${name}`) + } + + const [left, right] = ['<', '>'] + + const l_bound = name.indexOf(left) + const r_bound = Array.from(name).reverse().indexOf(right) + + // if there are no generics - exit gracefully. + if (l_bound === -1 && r_bound === -1) { + return { typeName: name, typeArgs: [] } + } + + // if one of the bounds is not defined - throw an Error. + if (l_bound === -1 || r_bound === -1) { + throw new Error(`Unclosed generic in name '${name}'`) } - if (arg.kind === 'Input' && arg.type === 'pure') { + const typeName = name.slice(0, l_bound) + const typeArgs = splitGenericParameters(name.slice(l_bound + 1, name.length - r_bound - 1), [ + left, + right, + ]) + + return { typeName, typeArgs } +} + +export function isTransactionArgument(arg: GenericArg): arg is TransactionArgument { + if (!arg || typeof arg !== 'object' || Array.isArray(arg)) { return false } - return true + return 'GasCoin' in arg || 'Input' in arg || 'Result' in arg || 'NestedResult' in arg } -export function obj(txb: TransactionBlock, arg: ObjectArg) { - return isTransactionArgument(arg) ? arg : txb.object(arg) +export function obj(tx: Transaction, arg: TransactionObjectInput) { + return isTransactionArgument(arg) ? arg : tx.object(arg) } -export function pure(txb: TransactionBlock, arg: PureArg, type: string) { +export function pure(tx: Transaction, arg: PureArg, type: string): TransactionArgument { if (isTransactionArgument(arg)) { - return obj(txb, arg) + return obj(tx, arg) } function getBcsForType(type: string): BcsType { @@ -96,11 +138,61 @@ export function pure(txb: TransactionBlock, arg: PureArg, type: string) { } } - function isOrHasNestedTransactionArgument(arg: PureArg): boolean { - if (Array.isArray(arg)) { - return arg.some(item => isOrHasNestedTransactionArgument(item)) + function hasUndefinedOrNull(items: PureArg[]) { + for (const item of items) { + if (typeof item === 'undefined' || item === null) { + return true + } + + if (Array.isArray(item)) { + return hasUndefinedOrNull(item) + } + } + + return false + } + + function consistsOnlyOfPrimitiveValues(items: PureArg[]) { + for (const item of items) { + if (!Array.isArray(item)) { + if (item === null) { + continue + } + switch (typeof item) { + case 'string': + case 'number': + case 'bigint': + case 'boolean': + continue + default: + return false + } + } + + return consistsOnlyOfPrimitiveValues(item) + } + + return true + } + + function hasPrimitiveValues(items: PureArg[]) { + for (const item of items) { + if (!Array.isArray(item)) { + switch (typeof item) { + case 'string': + case 'number': + case 'bigint': + case 'boolean': + return true + default: + continue + } + } + + return hasPrimitiveValues(item) } - return isTransactionArgument(arg) + + return false } // handle some cases when TransactionArgument is nested within a vector or option @@ -108,104 +200,121 @@ export function pure(txb: TransactionBlock, arg: PureArg, type: string) { switch (typeName) { case '0x1::option::Option': if (arg === null) { - return txb.pure(bcs.option(bcs.Bool).serialize(null)) // bcs.Bool is arbitrary + return tx.pure.option('bool', null) // 'bool' is arbitrary } - if (isOrHasNestedTransactionArgument(arg)) { - throw new Error('nesting TransactionArgument is not supported') + if (consistsOnlyOfPrimitiveValues([arg])) { + return tx.pure(getBcsForType(type).serialize(arg)) } - break + if (hasPrimitiveValues([arg])) { + throw new Error('mixing primitive and TransactionArgument values is not supported') + } + + // wrap it with some + return tx.moveCall({ + target: `0x1::option::some`, + typeArguments: [typeArgs[0]], + arguments: [pure(tx, arg, typeArgs[0])], + }) case 'vector': if (!Array.isArray(arg)) { throw new Error('expected an array for vector type') } if (arg.length === 0) { - return txb.pure(bcs.vector(bcs.Bool).serialize([])) // bcs.Bool is arbitrary + return tx.pure(bcs.vector(bcs.Bool).serialize([])) // bcs.Bool is arbitrary } - if (arg.some(arg => Array.isArray(arg) && isOrHasNestedTransactionArgument(arg))) { - throw new Error('nesting TransactionArgument is not supported') + if (hasUndefinedOrNull(arg)) { + throw new Error('the provided array contains undefined or null values') } - if ( - isTransactionArgument(arg[0]) && - arg.filter(arg => !isTransactionArgument(arg)).length > 0 - ) { - throw new Error('mixing TransactionArgument with other types is not supported') + if (consistsOnlyOfPrimitiveValues(arg)) { + return tx.pure(getBcsForType(type).serialize(arg)) } - if (isTransactionObjectArgument(arg[0])) { - return txb.makeMoveVec({ - objects: arg as Array, - type: typeArgs[0], - }) + if (hasPrimitiveValues(arg)) { + throw new Error('mixing primitive and TransactionArgument values is not supported') } - } - return txb.pure(getBcsForType(type).serialize(arg)) + return tx.makeMoveVec({ + type: typeArgs[0], + elements: arg as Array, + }) + default: + return tx.pure(getBcsForType(type).serialize(arg)) + } } -export function option(txb: TransactionBlock, type: string, arg: GenericArg | null) { +export function option(tx: Transaction, type: string, arg: GenericArg | null) { if (isTransactionArgument(arg)) { return arg } + if (typeArgIsPure(type)) { - return pure(txb, arg as PureArg | TransactionArgument, `0x1::option::Option<${type}>`) + return pure(tx, arg as PureArg | TransactionArgument, `0x1::option::Option<${type}>`) } + if (arg === null) { - return txb.moveCall({ + return tx.moveCall({ target: `0x1::option::none`, typeArguments: [type], arguments: [], }) } + // wrap it with some - const val = generic(txb, type, arg) - return txb.moveCall({ + const val = generic(tx, type, arg) + return tx.moveCall({ target: `0x1::option::some`, typeArguments: [type], arguments: [val], }) } -export function generic(txb: TransactionBlock, type: string, arg: GenericArg) { +export function generic(tx: Transaction, type: string, arg: GenericArg) { if (typeArgIsPure(type)) { - return pure(txb, arg as PureArg | TransactionArgument, type) + return pure(tx, arg as PureArg | TransactionArgument, type) } else { const { typeName, typeArgs } = parseTypeName(type) if (typeName === 'vector' && Array.isArray(arg)) { const itemType = typeArgs[0] - return txb.makeMoveVec({ - objects: arg.map(item => obj(txb, item as ObjectArg)) as Array, + return tx.makeMoveVec({ type: itemType, + elements: arg.map(item => + obj(tx, item as TransactionObjectInput) + ) as Array, }) } else { - return obj(txb, arg as ObjectArg) + return obj(tx, arg as TransactionObjectInput) } } } export function vector( - txb: TransactionBlock, + tx: Transaction, itemType: string, items: Array | TransactionArgument ) { + if (typeof items === 'function') { + throw new Error('Transaction plugins are not supported') + } + if (typeArgIsPure(itemType)) { - return pure(txb, items as PureArg, `vector<${itemType}>`) + return pure(tx, items as PureArg, `vector<${itemType}>`) } else if (isTransactionArgument(items)) { return items } else { const { typeName: itemTypeName, typeArgs: itemTypeArgs } = parseTypeName(itemType) if (itemTypeName === '0x1::option::Option') { - const objects = items.map(item => - option(txb, itemTypeArgs[0], item) + const elements = items.map(item => + option(tx, itemTypeArgs[0], item) ) as Array - return txb.makeMoveVec({ - objects, + return tx.makeMoveVec({ type: itemType, + elements, }) } - return txb.makeMoveVec({ - objects: items as Array, + return tx.makeMoveVec({ type: itemType, + elements: items as Array, }) } } diff --git a/src/codegen/mineral/icon/functions.ts b/src/codegen/mineral/icon/functions.ts index 98105f0..99af31b 100644 --- a/src/codegen/mineral/icon/functions.ts +++ b/src/codegen/mineral/icon/functions.ts @@ -1,4 +1,4 @@ import {PUBLISHED_AT} from ".."; -import {TransactionBlock} from "@mysten/sui.js/transactions"; +import {Transaction} from "@mysten/sui/transactions"; -export function getIconUrl( txb: TransactionBlock, ) { return txb.moveCall({ target: `${PUBLISHED_AT}::icon::get_icon_url`, arguments: [ ], }) } +export function getIconUrl( tx: Transaction, ) { return tx.moveCall({ target: `${PUBLISHED_AT}::icon::get_icon_url`, arguments: [ ], }) } diff --git a/src/codegen/mineral/index.ts b/src/codegen/mineral/index.ts index e329f2e..d8d7ae2 100644 --- a/src/codegen/mineral/index.ts +++ b/src/codegen/mineral/index.ts @@ -1 +1 @@ -export const PACKAGE_ID = "0x0"; export const PUBLISHED_AT = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049"; +export const PACKAGE_ID = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049"; export const PUBLISHED_AT = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049"; export const PKG_V1 = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049"; diff --git a/src/codegen/mineral/init.ts b/src/codegen/mineral/init.ts index d922ff2..2f7b984 100644 --- a/src/codegen/mineral/init.ts +++ b/src/codegen/mineral/init.ts @@ -3,8 +3,8 @@ import * as miner from "./miner/structs"; import {StructClassLoader} from "../_framework/loader"; export function registerClasses(loader: StructClassLoader) { loader.register(miner.Miner); +loader.register(mine.Config); loader.register(mine.AdminCap); loader.register(mine.Bus); -loader.register(mine.Config); loader.register(mine.MINE); } diff --git a/src/codegen/mineral/mine/functions.ts b/src/codegen/mineral/mine/functions.ts index bd1628e..675e9c5 100644 --- a/src/codegen/mineral/mine/functions.ts +++ b/src/codegen/mineral/mine/functions.ts @@ -1,41 +1,42 @@ import {PUBLISHED_AT} from ".."; -import {ObjectArg, obj, pure, vector} from "../../_framework/util"; -import {TransactionArgument, TransactionBlock} from "@mysten/sui.js/transactions"; +import {obj, pure, vector} from "../../_framework/util"; +import {Bus} from "./structs"; +import {Transaction, TransactionArgument, TransactionObjectInput} from "@mysten/sui/transactions"; -export function treasury( txb: TransactionBlock, config: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::treasury`, arguments: [ obj(txb, config) ], }) } +export function treasury( tx: Transaction, config: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::treasury`, arguments: [ obj(tx, config) ], }) } -export function totalHashes( txb: TransactionBlock, config: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::total_hashes`, arguments: [ obj(txb, config) ], }) } +export function totalHashes( tx: Transaction, config: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::total_hashes`, arguments: [ obj(tx, config) ], }) } -export function totalRewards( txb: TransactionBlock, config: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::total_rewards`, arguments: [ obj(txb, config) ], }) } +export function totalRewards( tx: Transaction, config: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::total_rewards`, arguments: [ obj(tx, config) ], }) } -export interface MineArgs { nonce: bigint | TransactionArgument; bus: ObjectArg; miner: ObjectArg; clock: ObjectArg } +export interface MineArgs { nonce: bigint | TransactionArgument; bus: TransactionObjectInput; miner: TransactionObjectInput; clock: TransactionObjectInput } -export function mine( txb: TransactionBlock, args: MineArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::mine`, arguments: [ pure(txb, args.nonce, `u64`), obj(txb, args.bus), obj(txb, args.miner), obj(txb, args.clock) ], }) } +export function mine( tx: Transaction, args: MineArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::mine`, arguments: [ pure(tx, args.nonce, `u64`), obj(tx, args.bus), obj(tx, args.miner), obj(tx, args.clock) ], }) } -export function calculateDifficulty( txb: TransactionBlock, totalHashes: bigint | TransactionArgument ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::calculate_difficulty`, arguments: [ pure(txb, totalHashes, `u64`) ], }) } +export function calculateDifficulty( tx: Transaction, totalHashes: bigint | TransactionArgument ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::calculate_difficulty`, arguments: [ pure(tx, totalHashes, `u64`) ], }) } export interface CalculateNewRewardRateArgs { currentRate: bigint | TransactionArgument; epochRewards: bigint | TransactionArgument; maxReward: bigint | TransactionArgument } -export function calculateNewRewardRate( txb: TransactionBlock, args: CalculateNewRewardRateArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::calculate_new_reward_rate`, arguments: [ pure(txb, args.currentRate, `u64`), pure(txb, args.epochRewards, `u64`), pure(txb, args.maxReward, `u64`) ], }) } +export function calculateNewRewardRate( tx: Transaction, args: CalculateNewRewardRateArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::calculate_new_reward_rate`, arguments: [ pure(tx, args.currentRate, `u64`), pure(tx, args.epochRewards, `u64`), pure(tx, args.maxReward, `u64`) ], }) } -export function difficulty( txb: TransactionBlock, bus: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::difficulty`, arguments: [ obj(txb, bus) ], }) } +export function difficulty( tx: Transaction, bus: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::difficulty`, arguments: [ obj(tx, bus) ], }) } -export interface EpochResetArgs { config: ObjectArg; buses: Array | TransactionArgument; clock: ObjectArg } +export interface EpochResetArgs { config: TransactionObjectInput; buses: Array | TransactionArgument; clock: TransactionObjectInput } -export function epochReset( txb: TransactionBlock, args: EpochResetArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::epoch_reset`, arguments: [ obj(txb, args.config), vector(txb, `0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus`, args.buses), obj(txb, args.clock) ], }) } +export function epochReset( tx: Transaction, args: EpochResetArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::epoch_reset`, arguments: [ obj(tx, args.config), vector(tx, `${Bus.$typeName}`, args.buses), obj(tx, args.clock) ], }) } export interface GenerateProofArgs { currentHash: Array | TransactionArgument; sender: string | TransactionArgument; nonce: bigint | TransactionArgument } -export function generateProof( txb: TransactionBlock, args: GenerateProofArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::generate_proof`, arguments: [ pure(txb, args.currentHash, `vector`), pure(txb, args.sender, `address`), pure(txb, args.nonce, `u64`) ], }) } +export function generateProof( tx: Transaction, args: GenerateProofArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::generate_proof`, arguments: [ pure(tx, args.currentHash, `vector`), pure(tx, args.sender, `address`), pure(tx, args.nonce, `u64`) ], }) } -export function init( txb: TransactionBlock, witness: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::init`, arguments: [ obj(txb, witness) ], }) } +export function init( tx: Transaction, witness: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::init`, arguments: [ obj(tx, witness) ], }) } -export function live( txb: TransactionBlock, bus: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::live`, arguments: [ obj(txb, bus) ], }) } +export function live( tx: Transaction, bus: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::live`, arguments: [ obj(tx, bus) ], }) } -export function rewardRate( txb: TransactionBlock, bus: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::reward_rate`, arguments: [ obj(txb, bus) ], }) } +export function rewardRate( tx: Transaction, bus: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::reward_rate`, arguments: [ obj(tx, bus) ], }) } -export function rewards( txb: TransactionBlock, bus: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::rewards`, arguments: [ obj(txb, bus) ], }) } +export function rewards( tx: Transaction, bus: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::rewards`, arguments: [ obj(tx, bus) ], }) } export interface ValidateProofArgs { proof: Array | TransactionArgument; difficulty: number | TransactionArgument } -export function validateProof( txb: TransactionBlock, args: ValidateProofArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::mine::validate_proof`, arguments: [ pure(txb, args.proof, `vector`), pure(txb, args.difficulty, `u8`) ], }) } +export function validateProof( tx: Transaction, args: ValidateProofArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::mine::validate_proof`, arguments: [ pure(tx, args.proof, `vector`), pure(tx, args.difficulty, `u8`) ], }) } diff --git a/src/codegen/mineral/mine/structs.ts b/src/codegen/mineral/mine/structs.ts index 3317bbb..3abfcfa 100644 --- a/src/codegen/mineral/mine/structs.ts +++ b/src/codegen/mineral/mine/structs.ts @@ -4,32 +4,92 @@ import {UID} from "../../_dependencies/source/0x2/object/structs"; import {Locker} from "../../_dependencies/source/0xbafd431cc9362367d02dc2752216782a265216af069d70a7679de5f38c0d62ca/locker/structs"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, phantom, ToTypeStr as ToPhantom} from "../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V1} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; + +/* ============================== Config =============================== */ + +export function isConfig(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V1}::mine::Config`; } + +export interface ConfigFields { id: ToField; version: ToField<"u8">; busCount: ToField<"u64">; treasury: ToField>>; lastDifficultyAdjustment: ToField<"u64">; totalRewards: ToField<"u64">; totalHashes: ToField<"u64"> } + +export type ConfigReified = Reified< Config, ConfigFields >; + +export class Config implements StructClass { static readonly $typeName = `${PKG_V1}::mine::Config`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; + + readonly $typeName = Config.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::mine::Config`; readonly $typeArgs: []; readonly $isPhantom = Config.$isPhantom; + + readonly id: ToField; readonly version: ToField<"u8">; readonly busCount: ToField<"u64">; readonly treasury: ToField>>; readonly lastDifficultyAdjustment: ToField<"u64">; readonly totalRewards: ToField<"u64">; readonly totalHashes: ToField<"u64"> + + private constructor(typeArgs: [], fields: ConfigFields, ) { this.$fullTypeName = composeSuiType( Config.$typeName, ...typeArgs ) as `${typeof PKG_V1}::mine::Config`; this.$typeArgs = typeArgs; + + this.id = fields.id;; this.version = fields.version;; this.busCount = fields.busCount;; this.treasury = fields.treasury;; this.lastDifficultyAdjustment = fields.lastDifficultyAdjustment;; this.totalRewards = fields.totalRewards;; this.totalHashes = fields.totalHashes; } + + static reified( ): ConfigReified { return { typeName: Config.$typeName, fullTypeName: composeSuiType( Config.$typeName, ...[] ) as `${typeof PKG_V1}::mine::Config`, typeArgs: [ ] as [], isPhantom: Config.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Config.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Config.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Config.fromBcs( data, ), bcs: Config.bcs, fromJSONField: (field: any) => Config.fromJSONField( field, ), fromJSON: (json: Record) => Config.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Config.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Config.fetch( client, id, ), new: ( fields: ConfigFields, ) => { return new Config( [], fields ) }, kind: "StructClassReified", } } + + static get r() { return Config.reified() } + + static phantom( ): PhantomReified> { return phantom(Config.reified( )); } static get p() { return Config.phantom() } + + static get bcs() { return bcs.struct("Config", { + + id: UID.bcs, version: bcs.u8(), bus_count: bcs.u64(), treasury: Locker.bcs, last_difficulty_adjustment: bcs.u64(), total_rewards: bcs.u64(), total_hashes: bcs.u64() + +}) }; + + static fromFields( fields: Record ): Config { return Config.reified( ).new( { id: decodeFromFields(UID.reified(), fields.id), version: decodeFromFields("u8", fields.version), busCount: decodeFromFields("u64", fields.bus_count), treasury: decodeFromFields(Locker.reified(reified.phantom(MINE.reified())), fields.treasury), lastDifficultyAdjustment: decodeFromFields("u64", fields.last_difficulty_adjustment), totalRewards: decodeFromFields("u64", fields.total_rewards), totalHashes: decodeFromFields("u64", fields.total_hashes) } ) } + + static fromFieldsWithTypes( item: FieldsWithTypes ): Config { if (!isConfig(item.type)) { throw new Error("not a Config type"); + + } + + return Config.reified( ).new( { id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id), version: decodeFromFieldsWithTypes("u8", item.fields.version), busCount: decodeFromFieldsWithTypes("u64", item.fields.bus_count), treasury: decodeFromFieldsWithTypes(Locker.reified(reified.phantom(MINE.reified())), item.fields.treasury), lastDifficultyAdjustment: decodeFromFieldsWithTypes("u64", item.fields.last_difficulty_adjustment), totalRewards: decodeFromFieldsWithTypes("u64", item.fields.total_rewards), totalHashes: decodeFromFieldsWithTypes("u64", item.fields.total_hashes) } ) } + + static fromBcs( data: Uint8Array ): Config { return Config.fromFields( Config.bcs.parse(data) ) } + + toJSONField() { return { + + id: this.id,version: this.version,busCount: this.busCount.toString(),treasury: this.treasury.toJSONField(),lastDifficultyAdjustment: this.lastDifficultyAdjustment.toString(),totalRewards: this.totalRewards.toString(),totalHashes: this.totalHashes.toString(), + +} } + + toJSON() { return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() } } + + static fromJSONField( field: any ): Config { return Config.reified( ).new( { id: decodeFromJSONField(UID.reified(), field.id), version: decodeFromJSONField("u8", field.version), busCount: decodeFromJSONField("u64", field.busCount), treasury: decodeFromJSONField(Locker.reified(reified.phantom(MINE.reified())), field.treasury), lastDifficultyAdjustment: decodeFromJSONField("u64", field.lastDifficultyAdjustment), totalRewards: decodeFromJSONField("u64", field.totalRewards), totalHashes: decodeFromJSONField("u64", field.totalHashes) } ) } + + static fromJSON( json: Record ): Config { if (json.$typeName !== Config.$typeName) { throw new Error("not a WithTwoGenerics json object") }; + + return Config.fromJSONField( json, ) } + + static fromSuiParsedData( content: SuiParsedData ): Config { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isConfig(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Config object`); } return Config.fromFieldsWithTypes( content ); } + + static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Config object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isConfig(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Config object`); } + + return Config.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } + + } /* ============================== AdminCap =============================== */ -export function isAdminCap(type: string): boolean { type = compressSuiType(type); return type === "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::AdminCap"; } +export function isAdminCap(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V1}::mine::AdminCap`; } export interface AdminCapFields { id: ToField } export type AdminCapReified = Reified< AdminCap, AdminCapFields >; -export class AdminCap implements StructClass { static readonly $typeName = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::AdminCap"; static readonly $numTypeParams = 0; - - readonly $typeName = AdminCap.$typeName; - - readonly $fullTypeName: "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::AdminCap"; +export class AdminCap implements StructClass { static readonly $typeName = `${PKG_V1}::mine::AdminCap`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = AdminCap.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::mine::AdminCap`; readonly $typeArgs: []; readonly $isPhantom = AdminCap.$isPhantom; readonly id: ToField - private constructor(typeArgs: [], fields: AdminCapFields, ) { this.$fullTypeName = composeSuiType( AdminCap.$typeName, ...typeArgs ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::AdminCap"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: AdminCapFields, ) { this.$fullTypeName = composeSuiType( AdminCap.$typeName, ...typeArgs ) as `${typeof PKG_V1}::mine::AdminCap`; this.$typeArgs = typeArgs; this.id = fields.id; } - static reified( ): AdminCapReified { return { typeName: AdminCap.$typeName, fullTypeName: composeSuiType( AdminCap.$typeName, ...[] ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::AdminCap", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => AdminCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AdminCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AdminCap.fromBcs( data, ), bcs: AdminCap.bcs, fromJSONField: (field: any) => AdminCap.fromJSONField( field, ), fromJSON: (json: Record) => AdminCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AdminCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AdminCap.fetch( client, id, ), new: ( fields: AdminCapFields, ) => { return new AdminCap( [], fields ) }, kind: "StructClassReified", } } + static reified( ): AdminCapReified { return { typeName: AdminCap.$typeName, fullTypeName: composeSuiType( AdminCap.$typeName, ...[] ) as `${typeof PKG_V1}::mine::AdminCap`, typeArgs: [ ] as [], isPhantom: AdminCap.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => AdminCap.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => AdminCap.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => AdminCap.fromBcs( data, ), bcs: AdminCap.bcs, fromJSONField: (field: any) => AdminCap.fromJSONField( field, ), fromJSON: (json: Record) => AdminCap.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => AdminCap.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => AdminCap.fetch( client, id, ), new: ( fields: AdminCapFields, ) => { return new AdminCap( [], fields ) }, kind: "StructClassReified", } } static get r() { return AdminCap.reified() } @@ -68,33 +128,30 @@ export class AdminCap implements StructClass { static readonly $typeName = "0x9c static fromSuiParsedData( content: SuiParsedData ): AdminCap { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isAdminCap(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a AdminCap object`); } return AdminCap.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching AdminCap object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isAdminCap(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a AdminCap object`); } + return AdminCap.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== Bus =============================== */ -export function isBus(type: string): boolean { type = compressSuiType(type); return type === "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus"; } +export function isBus(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V1}::mine::Bus`; } export interface BusFields { id: ToField; version: ToField<"u8">; live: ToField<"bool">; difficulty: ToField<"u8">; rewardRate: ToField<"u64">; lastReset: ToField<"u64">; rewards: ToField>>; epochHashes: ToField<"u64"> } export type BusReified = Reified< Bus, BusFields >; -export class Bus implements StructClass { static readonly $typeName = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus"; static readonly $numTypeParams = 0; - - readonly $typeName = Bus.$typeName; - - readonly $fullTypeName: "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus"; +export class Bus implements StructClass { static readonly $typeName = `${PKG_V1}::mine::Bus`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeArgs: []; + readonly $typeName = Bus.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::mine::Bus`; readonly $typeArgs: []; readonly $isPhantom = Bus.$isPhantom; readonly id: ToField; readonly version: ToField<"u8">; readonly live: ToField<"bool">; readonly difficulty: ToField<"u8">; readonly rewardRate: ToField<"u64">; readonly lastReset: ToField<"u64">; readonly rewards: ToField>>; readonly epochHashes: ToField<"u64"> - private constructor(typeArgs: [], fields: BusFields, ) { this.$fullTypeName = composeSuiType( Bus.$typeName, ...typeArgs ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: BusFields, ) { this.$fullTypeName = composeSuiType( Bus.$typeName, ...typeArgs ) as `${typeof PKG_V1}::mine::Bus`; this.$typeArgs = typeArgs; this.id = fields.id;; this.version = fields.version;; this.live = fields.live;; this.difficulty = fields.difficulty;; this.rewardRate = fields.rewardRate;; this.lastReset = fields.lastReset;; this.rewards = fields.rewards;; this.epochHashes = fields.epochHashes; } - static reified( ): BusReified { return { typeName: Bus.$typeName, fullTypeName: composeSuiType( Bus.$typeName, ...[] ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Bus", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Bus.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Bus.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Bus.fromBcs( data, ), bcs: Bus.bcs, fromJSONField: (field: any) => Bus.fromJSONField( field, ), fromJSON: (json: Record) => Bus.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Bus.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Bus.fetch( client, id, ), new: ( fields: BusFields, ) => { return new Bus( [], fields ) }, kind: "StructClassReified", } } + static reified( ): BusReified { return { typeName: Bus.$typeName, fullTypeName: composeSuiType( Bus.$typeName, ...[] ) as `${typeof PKG_V1}::mine::Bus`, typeArgs: [ ] as [], isPhantom: Bus.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Bus.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Bus.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Bus.fromBcs( data, ), bcs: Bus.bcs, fromJSONField: (field: any) => Bus.fromJSONField( field, ), fromJSON: (json: Record) => Bus.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Bus.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Bus.fetch( client, id, ), new: ( fields: BusFields, ) => { return new Bus( [], fields ) }, kind: "StructClassReified", } } static get r() { return Bus.reified() } @@ -133,98 +190,30 @@ export class Bus implements StructClass { static readonly $typeName = "0x9cde6fd static fromSuiParsedData( content: SuiParsedData ): Bus { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBus(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Bus object`); } return Bus.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Bus object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBus(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Bus object`); } - return Bus.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } - - } - -/* ============================== Config =============================== */ - -export function isConfig(type: string): boolean { type = compressSuiType(type); return type === "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Config"; } - -export interface ConfigFields { id: ToField; version: ToField<"u8">; busCount: ToField<"u64">; treasury: ToField>>; lastDifficultyAdjustment: ToField<"u64">; totalRewards: ToField<"u64">; totalHashes: ToField<"u64"> } - -export type ConfigReified = Reified< Config, ConfigFields >; - -export class Config implements StructClass { static readonly $typeName = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Config"; static readonly $numTypeParams = 0; - - readonly $typeName = Config.$typeName; - - readonly $fullTypeName: "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Config"; - - readonly $typeArgs: []; - - readonly id: ToField; readonly version: ToField<"u8">; readonly busCount: ToField<"u64">; readonly treasury: ToField>>; readonly lastDifficultyAdjustment: ToField<"u64">; readonly totalRewards: ToField<"u64">; readonly totalHashes: ToField<"u64"> - - private constructor(typeArgs: [], fields: ConfigFields, ) { this.$fullTypeName = composeSuiType( Config.$typeName, ...typeArgs ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Config"; this.$typeArgs = typeArgs; - - this.id = fields.id;; this.version = fields.version;; this.busCount = fields.busCount;; this.treasury = fields.treasury;; this.lastDifficultyAdjustment = fields.lastDifficultyAdjustment;; this.totalRewards = fields.totalRewards;; this.totalHashes = fields.totalHashes; } - - static reified( ): ConfigReified { return { typeName: Config.$typeName, fullTypeName: composeSuiType( Config.$typeName, ...[] ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::Config", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Config.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Config.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Config.fromBcs( data, ), bcs: Config.bcs, fromJSONField: (field: any) => Config.fromJSONField( field, ), fromJSON: (json: Record) => Config.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Config.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Config.fetch( client, id, ), new: ( fields: ConfigFields, ) => { return new Config( [], fields ) }, kind: "StructClassReified", } } - - static get r() { return Config.reified() } - - static phantom( ): PhantomReified> { return phantom(Config.reified( )); } static get p() { return Config.phantom() } - - static get bcs() { return bcs.struct("Config", { - - id: UID.bcs, version: bcs.u8(), bus_count: bcs.u64(), treasury: Locker.bcs, last_difficulty_adjustment: bcs.u64(), total_rewards: bcs.u64(), total_hashes: bcs.u64() - -}) }; - - static fromFields( fields: Record ): Config { return Config.reified( ).new( { id: decodeFromFields(UID.reified(), fields.id), version: decodeFromFields("u8", fields.version), busCount: decodeFromFields("u64", fields.bus_count), treasury: decodeFromFields(Locker.reified(reified.phantom(MINE.reified())), fields.treasury), lastDifficultyAdjustment: decodeFromFields("u64", fields.last_difficulty_adjustment), totalRewards: decodeFromFields("u64", fields.total_rewards), totalHashes: decodeFromFields("u64", fields.total_hashes) } ) } - - static fromFieldsWithTypes( item: FieldsWithTypes ): Config { if (!isConfig(item.type)) { throw new Error("not a Config type"); - - } - - return Config.reified( ).new( { id: decodeFromFieldsWithTypes(UID.reified(), item.fields.id), version: decodeFromFieldsWithTypes("u8", item.fields.version), busCount: decodeFromFieldsWithTypes("u64", item.fields.bus_count), treasury: decodeFromFieldsWithTypes(Locker.reified(reified.phantom(MINE.reified())), item.fields.treasury), lastDifficultyAdjustment: decodeFromFieldsWithTypes("u64", item.fields.last_difficulty_adjustment), totalRewards: decodeFromFieldsWithTypes("u64", item.fields.total_rewards), totalHashes: decodeFromFieldsWithTypes("u64", item.fields.total_hashes) } ) } - - static fromBcs( data: Uint8Array ): Config { return Config.fromFields( Config.bcs.parse(data) ) } - - toJSONField() { return { - - id: this.id,version: this.version,busCount: this.busCount.toString(),treasury: this.treasury.toJSONField(),lastDifficultyAdjustment: this.lastDifficultyAdjustment.toString(),totalRewards: this.totalRewards.toString(),totalHashes: this.totalHashes.toString(), - -} } - toJSON() { return { $typeName: this.$typeName, $typeArgs: this.$typeArgs, ...this.toJSONField() } } - - static fromJSONField( field: any ): Config { return Config.reified( ).new( { id: decodeFromJSONField(UID.reified(), field.id), version: decodeFromJSONField("u8", field.version), busCount: decodeFromJSONField("u64", field.busCount), treasury: decodeFromJSONField(Locker.reified(reified.phantom(MINE.reified())), field.treasury), lastDifficultyAdjustment: decodeFromJSONField("u64", field.lastDifficultyAdjustment), totalRewards: decodeFromJSONField("u64", field.totalRewards), totalHashes: decodeFromJSONField("u64", field.totalHashes) } ) } - - static fromJSON( json: Record ): Config { if (json.$typeName !== Config.$typeName) { throw new Error("not a WithTwoGenerics json object") }; - - return Config.fromJSONField( json, ) } - - static fromSuiParsedData( content: SuiParsedData ): Config { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isConfig(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Config object`); } return Config.fromFieldsWithTypes( content ); } - - static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Config object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isConfig(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Config object`); } - return Config.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } + return Bus.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } /* ============================== MINE =============================== */ -export function isMINE(type: string): boolean { type = compressSuiType(type); return type === "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::MINE"; } +export function isMINE(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V1}::mine::MINE`; } export interface MINEFields { dummyField: ToField<"bool"> } export type MINEReified = Reified< MINE, MINEFields >; -export class MINE implements StructClass { static readonly $typeName = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::MINE"; static readonly $numTypeParams = 0; +export class MINE implements StructClass { static readonly $typeName = `${PKG_V1}::mine::MINE`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = MINE.$typeName; - - readonly $fullTypeName: "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::MINE"; - - readonly $typeArgs: []; + readonly $typeName = MINE.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::mine::MINE`; readonly $typeArgs: []; readonly $isPhantom = MINE.$isPhantom; readonly dummyField: ToField<"bool"> - private constructor(typeArgs: [], fields: MINEFields, ) { this.$fullTypeName = composeSuiType( MINE.$typeName, ...typeArgs ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::MINE"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: MINEFields, ) { this.$fullTypeName = composeSuiType( MINE.$typeName, ...typeArgs ) as `${typeof PKG_V1}::mine::MINE`; this.$typeArgs = typeArgs; this.dummyField = fields.dummyField; } - static reified( ): MINEReified { return { typeName: MINE.$typeName, fullTypeName: composeSuiType( MINE.$typeName, ...[] ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::mine::MINE", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => MINE.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => MINE.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => MINE.fromBcs( data, ), bcs: MINE.bcs, fromJSONField: (field: any) => MINE.fromJSONField( field, ), fromJSON: (json: Record) => MINE.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => MINE.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => MINE.fetch( client, id, ), new: ( fields: MINEFields, ) => { return new MINE( [], fields ) }, kind: "StructClassReified", } } + static reified( ): MINEReified { return { typeName: MINE.$typeName, fullTypeName: composeSuiType( MINE.$typeName, ...[] ) as `${typeof PKG_V1}::mine::MINE`, typeArgs: [ ] as [], isPhantom: MINE.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => MINE.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => MINE.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => MINE.fromBcs( data, ), bcs: MINE.bcs, fromJSONField: (field: any) => MINE.fromJSONField( field, ), fromJSON: (json: Record) => MINE.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => MINE.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => MINE.fetch( client, id, ), new: ( fields: MINEFields, ) => { return new MINE( [], fields ) }, kind: "StructClassReified", } } static get r() { return MINE.reified() } @@ -263,6 +252,7 @@ export class MINE implements StructClass { static readonly $typeName = "0x9cde6f static fromSuiParsedData( content: SuiParsedData ): MINE { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isMINE(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a MINE object`); } return MINE.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching MINE object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isMINE(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a MINE object`); } + return MINE.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/codegen/mineral/miner/functions.ts b/src/codegen/mineral/miner/functions.ts index a71d6f3..97228ba 100644 --- a/src/codegen/mineral/miner/functions.ts +++ b/src/codegen/mineral/miner/functions.ts @@ -1,23 +1,23 @@ import {PUBLISHED_AT} from ".."; -import {ObjectArg, obj, pure} from "../../_framework/util"; -import {TransactionArgument, TransactionBlock} from "@mysten/sui.js/transactions"; +import {obj, pure} from "../../_framework/util"; +import {Transaction, TransactionArgument, TransactionObjectInput} from "@mysten/sui/transactions"; -export function new_( txb: TransactionBlock, ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::new`, arguments: [ ], }) } +export function new_( tx: Transaction, ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::new`, arguments: [ ], }) } -export function currentHash( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::current_hash`, arguments: [ obj(txb, self) ], }) } +export function destroy( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::destroy`, arguments: [ obj(tx, self) ], }) } -export function currentHashMut( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::current_hash_mut`, arguments: [ obj(txb, self) ], }) } +export function currentHash( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::current_hash`, arguments: [ obj(tx, self) ], }) } -export function destroy( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::destroy`, arguments: [ obj(txb, self) ], }) } +export function currentHashMut( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::current_hash_mut`, arguments: [ obj(tx, self) ], }) } -export function recordHash( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::record_hash`, arguments: [ obj(txb, self) ], }) } +export function recordHash( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::record_hash`, arguments: [ obj(tx, self) ], }) } -export interface RecordRewardsArgs { self: ObjectArg; amount: bigint | TransactionArgument } +export interface RecordRewardsArgs { self: TransactionObjectInput; amount: bigint | TransactionArgument } -export function recordRewards( txb: TransactionBlock, args: RecordRewardsArgs ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::record_rewards`, arguments: [ obj(txb, args.self), pure(txb, args.amount, `u64`) ], }) } +export function recordRewards( tx: Transaction, args: RecordRewardsArgs ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::record_rewards`, arguments: [ obj(tx, args.self), pure(tx, args.amount, `u64`) ], }) } -export function register( txb: TransactionBlock, ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::register`, arguments: [ ], }) } +export function register( tx: Transaction, ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::register`, arguments: [ ], }) } -export function totalHashes( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::total_hashes`, arguments: [ obj(txb, self) ], }) } +export function totalHashes( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::total_hashes`, arguments: [ obj(tx, self) ], }) } -export function totalRewards( txb: TransactionBlock, self: ObjectArg ) { return txb.moveCall({ target: `${PUBLISHED_AT}::miner::total_rewards`, arguments: [ obj(txb, self) ], }) } +export function totalRewards( tx: Transaction, self: TransactionObjectInput ) { return tx.moveCall({ target: `${PUBLISHED_AT}::miner::total_rewards`, arguments: [ obj(tx, self) ], }) } diff --git a/src/codegen/mineral/miner/structs.ts b/src/codegen/mineral/miner/structs.ts index 9f13f89..50925c9 100644 --- a/src/codegen/mineral/miner/structs.ts +++ b/src/codegen/mineral/miner/structs.ts @@ -2,32 +2,30 @@ import * as reified from "../../_framework/reified"; import {UID} from "../../_dependencies/source/0x2/object/structs"; import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../_framework/reified"; import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../_framework/util"; -import {bcs, fromB64} from "@mysten/bcs"; -import {SuiClient, SuiParsedData} from "@mysten/sui.js/client"; +import {PKG_V1} from "../index"; +import {bcs} from "@mysten/sui/bcs"; +import {SuiClient, SuiParsedData} from "@mysten/sui/client"; +import {fromB64} from "@mysten/sui/utils"; /* ============================== Miner =============================== */ -export function isMiner(type: string): boolean { type = compressSuiType(type); return type === "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::miner::Miner"; } +export function isMiner(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V1}::miner::Miner`; } export interface MinerFields { id: ToField; currentHash: ToField>; totalRewards: ToField<"u64">; totalHashes: ToField<"u64"> } export type MinerReified = Reified< Miner, MinerFields >; -export class Miner implements StructClass { static readonly $typeName = "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::miner::Miner"; static readonly $numTypeParams = 0; +export class Miner implements StructClass { static readonly $typeName = `${PKG_V1}::miner::Miner`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const; - readonly $typeName = Miner.$typeName; - - readonly $fullTypeName: "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::miner::Miner"; - - readonly $typeArgs: []; + readonly $typeName = Miner.$typeName; readonly $fullTypeName: `${typeof PKG_V1}::miner::Miner`; readonly $typeArgs: []; readonly $isPhantom = Miner.$isPhantom; readonly id: ToField; readonly currentHash: ToField>; readonly totalRewards: ToField<"u64">; readonly totalHashes: ToField<"u64"> - private constructor(typeArgs: [], fields: MinerFields, ) { this.$fullTypeName = composeSuiType( Miner.$typeName, ...typeArgs ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::miner::Miner"; this.$typeArgs = typeArgs; + private constructor(typeArgs: [], fields: MinerFields, ) { this.$fullTypeName = composeSuiType( Miner.$typeName, ...typeArgs ) as `${typeof PKG_V1}::miner::Miner`; this.$typeArgs = typeArgs; this.id = fields.id;; this.currentHash = fields.currentHash;; this.totalRewards = fields.totalRewards;; this.totalHashes = fields.totalHashes; } - static reified( ): MinerReified { return { typeName: Miner.$typeName, fullTypeName: composeSuiType( Miner.$typeName, ...[] ) as "0x9cde6fd22c9518820644dd1350ac1595bb23751033d247465ff3c7572d9a7049::miner::Miner", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record) => Miner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Miner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Miner.fromBcs( data, ), bcs: Miner.bcs, fromJSONField: (field: any) => Miner.fromJSONField( field, ), fromJSON: (json: Record) => Miner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Miner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Miner.fetch( client, id, ), new: ( fields: MinerFields, ) => { return new Miner( [], fields ) }, kind: "StructClassReified", } } + static reified( ): MinerReified { return { typeName: Miner.$typeName, fullTypeName: composeSuiType( Miner.$typeName, ...[] ) as `${typeof PKG_V1}::miner::Miner`, typeArgs: [ ] as [], isPhantom: Miner.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record) => Miner.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Miner.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Miner.fromBcs( data, ), bcs: Miner.bcs, fromJSONField: (field: any) => Miner.fromJSONField( field, ), fromJSON: (json: Record) => Miner.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Miner.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Miner.fetch( client, id, ), new: ( fields: MinerFields, ) => { return new Miner( [], fields ) }, kind: "StructClassReified", } } static get r() { return Miner.reified() } @@ -66,6 +64,7 @@ export class Miner implements StructClass { static readonly $typeName = "0x9cde6 static fromSuiParsedData( content: SuiParsedData ): Miner { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isMiner(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Miner object`); } return Miner.fromFieldsWithTypes( content ); } static async fetch( client: SuiClient, id: string ): Promise { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Miner object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isMiner(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Miner object`); } + return Miner.fromBcs( fromB64(res.data.bcs.bcsBytes) ); } } diff --git a/src/common.ts b/src/common.ts index 0170aac..94bb1e0 100644 --- a/src/common.ts +++ b/src/common.ts @@ -1,23 +1,25 @@ /* eslint-disable fp/no-loops, fp/no-mutation, fp/no-mutating-methods, fp/no-let, no-constant-condition */ import { keccak_256 } from "@noble/hashes/sha3"; -import { mine } from "./codegen/mineral/mine/functions"; -import { register } from "./codegen/mineral/miner/functions"; -import { SUI_CLOCK_OBJECT_ID, MIST_PER_SUI } from "@mysten/sui.js/utils"; -import { ProofData } from "./ports"; -import * as constants from "./constants"; +import { SignatureWithBytes } from "@mysten/sui/cryptography"; +import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; +import { SUI_CLOCK_OBJECT_ID, MIST_PER_SUI } from "@mysten/sui/utils"; +import { Transaction } from "@mysten/sui/transactions"; import { TransactionEffects, ExecutionStatus, SuiClient, SuiTransactionBlockResponse, -} from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { Ed25519Keypair } from "@mysten/sui.js/dist/cjs/keypairs/ed25519"; +} from "@mysten/sui/client"; +import { TurbosSdk } from "turbos-clmm-sdk"; + +import { ProofData } from "./ports"; +import * as constants from "./constants"; + +import { mine } from "./codegen/mineral/mine/functions"; +import { register } from "./codegen/mineral/miner/functions"; import { Bus } from "./codegen/mineral/mine/structs"; import { Miner } from "./codegen/mineral/miner/structs"; -import { SignatureWithBytes } from "@mysten/sui.js/dist/cjs/cryptography"; -import { TurbosSdk } from "turbos-clmm-sdk"; export const getClient = () => { return new SuiClient({ @@ -92,7 +94,7 @@ export async function fetchBuses(client: SuiClient): Promise { } export async function estimateGasAndSubmit( - txb: TransactionBlock, + txb: Transaction, client: SuiClient, wallet: Ed25519Keypair ): Promise { @@ -127,7 +129,7 @@ export async function estimateGasAndSubmit( } export function signTx( - txb: TransactionBlock, + txb: Transaction, client: SuiClient, wallet: Ed25519Keypair, gas: number | null @@ -162,7 +164,7 @@ export function handleMineralError(effects: TransactionEffects) { } export async function launch( - txb: TransactionBlock, + txb: Transaction, client: SuiClient, wallet: Ed25519Keypair, gas: number @@ -182,8 +184,8 @@ export function buildMineTx( proofData: ProofData, busId: string, payer: string -): TransactionBlock { - const txb = new TransactionBlock(); +): Transaction { + const txb = new Transaction(); const [createdObj] = mine(txb, { nonce: BigInt(proofData.proof.nonce), bus: txb.sharedObjectRef({ @@ -256,7 +258,7 @@ export async function getOrCreateMiner( return proof; } - const txb = new TransactionBlock(); + const txb = new Transaction(); register(txb); const _res = await estimateGasAndSubmit(txb, client, wallet); diff --git a/src/index.ts b/src/index.ts index 09171c7..2051c06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,13 +15,13 @@ import { } from "./common"; import { CONFIG } from "./constants"; import { Network, TurbosSdk } from "turbos-clmm-sdk"; -import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519"; -import { bcs } from "@mysten/sui.js/bcs"; +import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"; +import { bcs } from "@mysten/sui/bcs"; import { Stats, ElmApp, Balances } from "./ports"; -import { decodeSuiPrivateKey } from "@mysten/sui.js/cryptography"; -import { SuiClient } from "@mysten/sui.js/client"; -import { TransactionBlock } from "@mysten/sui.js/transactions"; -import { SUI_TYPE_ARG } from "@mysten/sui.js/utils"; +import { decodeSuiPrivateKey } from "@mysten/sui/cryptography"; +import { SuiClient } from "@mysten/sui/client"; +import { Transaction } from "@mysten/sui/transactions"; +import { SUI_TYPE_ARG } from "@mysten/sui/utils"; import { MINE, Config } from "./codegen/mineral/mine/structs"; import { Miner } from "./codegen/mineral/miner/structs"; @@ -127,7 +127,7 @@ let worker: Worker | null = null; if (wallet) { const coins = await fetchMineral(provider, wallet.toSuiAddress()); - const txb = new TransactionBlock(); + const txb = new Transaction(); txb.mergeCoins( coins[0].coinObjectId, coins.slice(1).map((coin) => coin.coinObjectId)