create-dubhe 0.0.10 ā 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/template/101/aptos-template/package.json +1 -1
- package/template/101/initia-template/package.json +1 -1
- package/template/101/movement-template/package.json +1 -1
- package/template/101/rooch-template/package.json +1 -1
- package/template/101/rooch-template/src/pages/home/index.tsx +3 -1
- package/template/101/sui-template/package.json +8 -11
- package/template/101/sui-template/src/pages/home/index.tsx +9 -4
- package/template/cocos/sui-template/assets/lib/dubhe.js +12 -2
- package/template/cocos/sui-template/package.json +3 -3
- package/template/contract/sui-template/contracts/counter/sources/codegen/errors/counter_error_invalid_increment.move +28 -0
- package/template/contract/sui-template/contracts/counter/sources/codegen/events/counter_event_increment.move +28 -0
- package/template/contract/sui-template/contracts/counter/sources/systems/counter.move +11 -2
- package/template/contract/sui-template/dubhe.config.ts +15 -1
- package/template/contract/sui-template/package.json +7 -10
- package/template/nextjs/sui-template/package.json +8 -11
- package/template/nextjs/sui-template/src/pages/home/index.tsx +9 -4
- package/template/101/sui-template/docker-compose.yaml +0 -29
- package/template/101/sui-template/scripts/checkBalance.ts +0 -40
- package/template/101/sui-template/scripts/generateAccount.ts +0 -55
- package/template/101/sui-template/scripts/storeConfig.ts +0 -61
- package/template/101/sui-template/scripts/waitNode.ts +0 -9
- package/template/contract/sui-template/scripts/checkBalance.ts +0 -40
- package/template/contract/sui-template/scripts/generateAccount.ts +0 -37
- package/template/nextjs/sui-template/docker-compose.yaml +0 -29
- package/template/nextjs/sui-template/scripts/checkBalance.ts +0 -40
- package/template/nextjs/sui-template/scripts/generateAccount.ts +0 -55
- package/template/nextjs/sui-template/scripts/storeConfig.ts +0 -61
- package/template/nextjs/sui-template/scripts/waitNode.ts +0 -9
package/dist/index.mjs
CHANGED
|
@@ -97,6 +97,6 @@ Filtered results for: ${this.inputValue?this.inputValue:t.gray("Enter something
|
|
|
97
97
|
`),this.close()}_(s,c){return s.toLowerCase()==="y"?(this.value=!0,this.submit()):s.toLowerCase()==="n"?(this.value=!1,this.submit()):this.bell()}render(){this.closed||(this.firstRender?this.out.write(v.hide):this.out.write(e(this.outputText,this.out.columns)),super.render(),this.outputText=[d.symbol(this.done,this.aborted),t.bold(this.msg),d.delimiter(this.done),this.done?this.value?this.yesMsg:this.noMsg:t.gray(this.initialValue?this.yesOption:this.noOption)].join(" "),this.out.write(l.line+v.to(0)+this.outputText))}}return se=r,se}var ne,Mi;function Pr(){return Mi||(Mi=1,ne={TextPrompt:ur(),SelectPrompt:ar(),TogglePrompt:cr(),DatePrompt:xr(),NumberPrompt:Sr(),MultiselectPrompt:wi(),AutocompletePrompt:$r(),AutocompleteMultiselectPrompt:Mr(),ConfirmPrompt:Tr()}),ne}var Ti;function Or(){return Ti||(Ti=1,function(t){const n=t,d=Pr(),e=r=>r;function l(r,g,s={}){return new Promise((c,i)=>{const f=new d[r](g),p=s.onAbort||e,o=s.onSubmit||e,h=s.onExit||e;f.on("state",g.onState||e),f.on("submit",y=>c(o(y))),f.on("exit",y=>c(h(y))),f.on("abort",y=>i(p(y)))})}n.text=r=>l("TextPrompt",r),n.password=r=>(r.style="password",n.text(r)),n.invisible=r=>(r.style="invisible",n.text(r)),n.number=r=>l("NumberPrompt",r),n.date=r=>l("DatePrompt",r),n.confirm=r=>l("ConfirmPrompt",r),n.list=r=>{const g=r.separator||",";return l("TextPrompt",r,{onSubmit:s=>s.split(g).map(c=>c.trim())})},n.toggle=r=>l("TogglePrompt",r),n.select=r=>l("SelectPrompt",r),n.multiselect=r=>{r.choices=[].concat(r.choices||[]);const g=s=>s.filter(c=>c.selected).map(c=>c.value);return l("MultiselectPrompt",r,{onAbort:g,onSubmit:g})},n.autocompleteMultiselect=r=>{r.choices=[].concat(r.choices||[]);const g=s=>s.filter(c=>c.selected).map(c=>c.value);return l("AutocompleteMultiselectPrompt",r,{onAbort:g,onSubmit:g})};const v=(r,g)=>Promise.resolve(g.filter(s=>s.title.slice(0,r.length).toLowerCase()===r.toLowerCase()));n.autocomplete=r=>(r.suggest=r.suggest||v,r.choices=[].concat(r.choices||[]),l("AutocompletePrompt",r))}(qt)),qt}var oe,Pi;function qr(){if(Pi)return oe;Pi=1;const t=Or(),n=["suggest","format","onState","validate","onRender","type"],d=()=>{};async function e(g=[],{onSubmit:s=d,onCancel:c=d}={}){const i={},f=e._override||{};g=[].concat(g);let p,o,h,y,m,u;const a=async(b,x,w=!1)=>{if(!(!w&&b.validate&&b.validate(x)!==!0))return b.format?await b.format(x,i):x};for(o of g)if({name:y,type:m}=o,typeof m=="function"&&(m=await m(p,{...i},o),o.type=m),!!m){for(let b in o){if(n.includes(b))continue;let x=o[b];o[b]=typeof x=="function"?await x(p,{...i},u):x}if(u=o,typeof o.message!="string")throw new Error("prompt message is required");if({name:y,type:m}=o,t[m]===void 0)throw new Error(`prompt type (${m}) is not defined`);if(f[o.name]!==void 0&&(p=await a(o,f[o.name]),p!==void 0)){i[y]=p;continue}try{p=e._injected?l(e._injected,o.initial):await t[m](o),i[y]=p=await a(o,p,!0),h=await s(o,p,i)}catch{h=!await c(o,i)}if(h)return i}return i}function l(g,s){const c=g.shift();if(c instanceof Error)throw c;return c===void 0?s:c}function v(g){e._injected=(e._injected||[]).concat(g)}function r(g){e._override=Object.assign({},g)}return oe=Object.assign(e,{prompt:e,prompts:t,inject:v,override:r}),oe}function Cr(t){t=(Array.isArray(t)?t:t.split(".")).map(Number);let n=0,d=process.versions.node.split(".").map(Number);for(;n<t.length;n++){if(d[n]>t[n])return!1;if(t[n]>d[n])return!0}return!1}var Dr=Cr("8.6.0")?ir():qr();const Rr=Di(Dr),E={QUICK_START:{title:"101",description:"Quick start",value:"101",path:"template/101/{chain}-template"},WEB:{title:"Web",description:"Web template",value:"web",path:"template/nextjs/{chain}-template"},CONTRACT:{title:"Contract",description:"Contract template",value:"contract",path:"template/contract/{chain}-template"},COCOS:{title:"Cocos",description:"Cocos Creator",value:"cocos",path:"template/cocos/{chain}-template"}},G=[{title:"sui",description:"Sui",value:"sui",supportedTemplates:[E.QUICK_START,E.WEB,E.CONTRACT,E.COCOS]},{title:"aptos",description:"Aptos",value:"aptos",supportedTemplates:[E.QUICK_START,E.WEB,E.CONTRACT,E.COCOS]},{title:"rooch",description:"Rooch",value:"rooch",supportedTemplates:[E.QUICK_START]},{title:"initia",description:"Initia",value:"initia",supportedTemplates:[E.QUICK_START]},{title:"movement",description:"Movement",value:"movement",supportedTemplates:[E.QUICK_START]}],he=process.cwd(),_r={_gitignore:".gitignore"},Oi="dubhe-template-project",Ir=async()=>{const t=await Rr([{type:"text",name:"projectName",message:"Input your projectName.",initial:Oi},{type:"select",name:"chain",message:"Pick your chain.",choices:G.map(({title:u,description:a,value:b})=>({title:u,description:a,value:b})),initial:0},{type:(u,a)=>G.find(b=>b.value===a.chain)?.supportedTemplates.length===1?null:"select",name:"platform",message:"Pick your platform.",choices:(u,a)=>G.find(b=>b.value===a.chain)?.supportedTemplates.map(({title:b,description:x,value:w})=>({title:b,description:x,value:w}))||[],initial:0}]),{projectName:n,chain:d,platform:e}=t,l=G.find(u=>u.value===d);let v=l?.supportedTemplates.find(u=>u.value===e);v||(v=l?.supportedTemplates[0]);const r=v?.path.replace("{chain}",d)||"";let g=n||Oi;const s=V.join(he,g);k.existsSync(s)||k.mkdirSync(s,{recursive:!0});const c=Er(process.env.npm_config_user_agent),i=c?c.name:"npm",f=V.resolve(Ci(import.meta.url),"../..",r);k.existsSync(f)||(console.error(`Template directory not found: ${f}`),process.exit(1));const p=(u,a)=>{const b=V.join(s,_r[u]??u);if(a)k.writeFileSync(b,a);else try{qi(V.join(f,u),b)}catch(x){console.error(`Error copying file ${u}:`,x),process.exit(1)}},o=k.readdirSync(f);for(const u of o.filter(a=>a!=="package.json"&&a!=="node_modules"))p(u);const h=JSON.parse(k.readFileSync(V.join(f,"package.json"),"utf-8"));h.name=n,p("package.json",JSON.stringify(h,null,2)+`
|
|
98
98
|
`);const y=V.relative(he,s),m={success:"\x1B[32m%s\x1B[0m",info:"\x1B[36m%s\x1B[0m",command:"\x1B[33m%s\x1B[0m",separator:"\x1B[90m%s\x1B[0m"};switch(console.log(`
|
|
99
99
|
`+"=".repeat(60)),console.log(m.success,"\u{1F389} Project creation successful!"),console.log(m.info,`\u{1F4C1} Project location: ${s}`),console.log(m.separator,"-".repeat(60)),console.log(m.info,`Next steps:
|
|
100
|
-
`),s!==he&&console.log(m.command,` cd ${y.includes(" ")?`"${y}"`:y}`),
|
|
100
|
+
`),s!==he&&console.log(m.command,` cd ${y.includes(" ")?`"${y}"`:y}`),v?.value||"101"){case"101":case"web":console.log(m.command,` ${i} install`),console.log(m.command,` ${i} run start:localnet`),console.log(m.command,` ${i} run dev`);break;case"contract":console.log(m.command,` ${i} install`);break;case"cocos":console.log(m.command," import project by cocos create ide"),console.log(m.command,` ${i} install`),console.log(m.command,` ${i} run dev`),console.log(m.command," start your cocos project");break}console.log(m.separator,`
|
|
101
101
|
`+"=".repeat(60)+`
|
|
102
102
|
`)};function qi(t,n){k.statSync(t).isDirectory()?Ar(t,n):k.copyFileSync(t,n)}function Ar(t,n){k.mkdirSync(n,{recursive:!0});for(const d of k.readdirSync(t)){const e=V.resolve(t,d),l=V.resolve(n,d);qi(e,l)}}function Er(t){if(!t)return;const n=t.split(" ")[0].split("/");return{name:n[0],version:n[1]}}Ir().catch(t=>{console.error(t)});
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prod:testnet": "pnpm config:store testnet && pnpm next"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@0xobelisk/initia-client": "^0.0.
|
|
30
|
+
"@0xobelisk/initia-client": "^0.0.5",
|
|
31
31
|
"@0xobelisk/initia-cli": "^0.0.3",
|
|
32
32
|
"@0xobelisk/sui-common": "^0.5.21",
|
|
33
33
|
"clsx": "^1.2.1",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"prod:testnet": "pnpm config:store testnet && pnpm next"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@0xobelisk/rooch-client": "^0.0.
|
|
29
|
+
"@0xobelisk/rooch-client": "^0.0.5",
|
|
30
30
|
"@0xobelisk/rooch-cli": "^0.0.3",
|
|
31
31
|
"@0xobelisk/sui-common": "^0.5.21",
|
|
32
32
|
"clsx": "^1.2.1",
|
|
@@ -39,7 +39,9 @@ const Home = () => {
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
const tx = new Transaction();
|
|
42
|
-
const response = await dubhe.tx.counter.increase(
|
|
42
|
+
const response = await dubhe.tx.counter.increase({
|
|
43
|
+
tx,
|
|
44
|
+
});
|
|
43
45
|
console.log(response.execution_info.tx_hash, response.execution_info.status.type);
|
|
44
46
|
if (response.execution_info.status.type == 'executed') {
|
|
45
47
|
setTimeout(async () => {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dubhe-101-template",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Simple starter template",
|
|
5
|
-
"author": "team@0xobelisk.com",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"scripts": {
|
|
8
6
|
"// Utility Commands": "----------------",
|
|
9
7
|
"start:localnet": "pnpm dubhe node",
|
|
@@ -11,15 +9,14 @@
|
|
|
11
9
|
"deploy": "pnpm dubhe publish --network",
|
|
12
10
|
"upgrade": "pnpm dubhe upgrade --network",
|
|
13
11
|
"schema:gen": "pnpm dubhe schemagen",
|
|
14
|
-
"account:gen": "
|
|
15
|
-
"check-balance": "
|
|
16
|
-
"config:store": "ts-
|
|
17
|
-
"deploy:framework": "pnpm dubhe publish --network localnet --contract-name dubhe-framework",
|
|
12
|
+
"account:gen": "pnpm dubhe generate-key --output-ts-path ./src/chain/key.ts",
|
|
13
|
+
"check-balance": "pnpm dubhe check-balance --network",
|
|
14
|
+
"config:store": "pnpm dubhe config-store --output-ts-path ./src/chain/config.ts --network",
|
|
18
15
|
"// Development Environment": "----------------",
|
|
19
16
|
"dev": "pnpm dev:localnet",
|
|
20
17
|
"dev:localnet": "pnpm setup:localnet && pnpm next",
|
|
21
18
|
"dev:testnet": "pnpm setup:testnet && pnpm next",
|
|
22
|
-
"setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm
|
|
19
|
+
"setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm run deploy localnet && pnpm run config:store localnet",
|
|
23
20
|
"setup:testnet": "pnpm account:gen && pnpm check-balance testnet && pnpm run deploy testnet && pnpm run config:store testnet",
|
|
24
21
|
"build": "next build",
|
|
25
22
|
"start": "next start",
|
|
@@ -28,9 +25,9 @@
|
|
|
28
25
|
"prod:testnet": "pnpm config:store testnet && pnpm next"
|
|
29
26
|
},
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@0xobelisk/sui-cli": "^0.5.
|
|
32
|
-
"@0xobelisk/sui-client": "
|
|
33
|
-
"@0xobelisk/sui-common": "^0.5.
|
|
28
|
+
"@0xobelisk/sui-cli": "^0.5.34",
|
|
29
|
+
"@0xobelisk/sui-client": "^0.5.30",
|
|
30
|
+
"@0xobelisk/sui-common": "^0.5.23",
|
|
34
31
|
"@mysten/sui": "1.7.0",
|
|
35
32
|
"clsx": "^1.2.1",
|
|
36
33
|
"dotenv": "^16.4.5",
|
|
@@ -40,9 +40,10 @@ const Home = () => {
|
|
|
40
40
|
metadata: metadata,
|
|
41
41
|
});
|
|
42
42
|
const tx = new Transaction();
|
|
43
|
-
const query_value = (await dubhe.query.counter_schema.get_value(
|
|
44
|
-
tx
|
|
45
|
-
|
|
43
|
+
const query_value = (await dubhe.query.counter_schema.get_value({
|
|
44
|
+
tx,
|
|
45
|
+
params: [tx.object(Counter_Object_Id)],
|
|
46
|
+
})) as DevInspectResults;
|
|
46
47
|
console.log('Counter value:', dubhe.view(query_value)[0]);
|
|
47
48
|
setValue(dubhe.view(query_value)[0]);
|
|
48
49
|
};
|
|
@@ -58,7 +59,11 @@ const Home = () => {
|
|
|
58
59
|
secretKey: PRIVATEKEY,
|
|
59
60
|
});
|
|
60
61
|
const tx = new Transaction();
|
|
61
|
-
(await dubhe.tx.counter_system.inc(
|
|
62
|
+
(await dubhe.tx.counter_system.inc({
|
|
63
|
+
tx,
|
|
64
|
+
params: [tx.object(Counter_Object_Id)],
|
|
65
|
+
isRaw: true,
|
|
66
|
+
})) as TransactionResult;
|
|
62
67
|
const response = await dubhe.signAndSendTxn(tx);
|
|
63
68
|
if (response.effects.status.status == 'success') {
|
|
64
69
|
setTimeout(async () => {
|
|
@@ -4590,13 +4590,23 @@ function withMeta(meta, creator) {
|
|
|
4590
4590
|
return creator;
|
|
4591
4591
|
}
|
|
4592
4592
|
function createQuery(meta, fn) {
|
|
4593
|
-
return withMeta(meta, async (
|
|
4593
|
+
return withMeta(meta, async ({
|
|
4594
|
+
tx,
|
|
4595
|
+
params,
|
|
4596
|
+
typeArguments,
|
|
4597
|
+
isRaw
|
|
4598
|
+
}) => {
|
|
4594
4599
|
const result = await fn(tx, params, typeArguments, isRaw);
|
|
4595
4600
|
return result;
|
|
4596
4601
|
});
|
|
4597
4602
|
}
|
|
4598
4603
|
function createTx(meta, fn) {
|
|
4599
|
-
return withMeta(meta, async (
|
|
4604
|
+
return withMeta(meta, async ({
|
|
4605
|
+
tx,
|
|
4606
|
+
params,
|
|
4607
|
+
typeArguments,
|
|
4608
|
+
isRaw
|
|
4609
|
+
}) => {
|
|
4600
4610
|
return await fn(tx, params, typeArguments, isRaw);
|
|
4601
4611
|
});
|
|
4602
4612
|
}
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"generateAccount": "ts-node scripts/generateAccount.ts"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@0xobelisk/sui-cli": "^0.5.
|
|
19
|
-
"@0xobelisk/sui-client": "
|
|
20
|
-
"@0xobelisk/sui-common": "^0.5.
|
|
18
|
+
"@0xobelisk/sui-cli": "^0.5.34",
|
|
19
|
+
"@0xobelisk/sui-client": "^0.5.30",
|
|
20
|
+
"@0xobelisk/sui-common": "^0.5.23"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "18.16.16",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::counter_error_invalid_increment {
|
|
8
|
+
|
|
9
|
+
const InvalidIncrement: u64 = 0;
|
|
10
|
+
|
|
11
|
+
/// Get the error code.
|
|
12
|
+
|
|
13
|
+
public fun code(): u64 {
|
|
14
|
+
InvalidIncrement
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/// Abort execution with the given error code.
|
|
18
|
+
|
|
19
|
+
public fun emit() {
|
|
20
|
+
abort InvalidIncrement
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Require that the given condition is true, otherwise abort with the given error code.
|
|
24
|
+
|
|
25
|
+
public fun require(condition: bool) {
|
|
26
|
+
if (!condition) { emit() }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright (c) Obelisk Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
#[allow(unused_use)]
|
|
4
|
+
|
|
5
|
+
/* Autogenerated file. Do not edit manually. */
|
|
6
|
+
|
|
7
|
+
module counter::counter_event_increment {
|
|
8
|
+
|
|
9
|
+
use sui::event;
|
|
10
|
+
|
|
11
|
+
use std::ascii::String;
|
|
12
|
+
|
|
13
|
+
public struct IncrementEvent has copy, drop {
|
|
14
|
+
value: u32,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public fun new(value: u32): IncrementEvent {
|
|
18
|
+
IncrementEvent {
|
|
19
|
+
value
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public fun emit(value: u32) {
|
|
24
|
+
event::emit(IncrementEvent {
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
module counter::counter_system {
|
|
2
2
|
use counter::counter_schema::Counter;
|
|
3
|
+
use counter::counter_event_increment;
|
|
4
|
+
use counter::counter_error_invalid_increment;
|
|
3
5
|
|
|
4
|
-
public entry fun inc(counter: &mut Counter) {
|
|
5
|
-
|
|
6
|
+
public entry fun inc(counter: &mut Counter, number: u32) {
|
|
7
|
+
// Check if the increment value is valid.
|
|
8
|
+
counter_error_invalid_increment::require(number > 0);
|
|
9
|
+
counter.borrow_mut_value().mutate!(|value| {
|
|
10
|
+
// Increment the counter value.
|
|
11
|
+
*value = *value + number;
|
|
12
|
+
// Emit an event to notify the increment.
|
|
13
|
+
counter_event_increment::emit(number);
|
|
14
|
+
});
|
|
6
15
|
}
|
|
7
16
|
|
|
8
17
|
public fun get(counter: &Counter): u32 {
|
|
@@ -3,12 +3,26 @@ import { DubheConfig } from '@0xobelisk/sui-common';
|
|
|
3
3
|
export const dubheConfig = {
|
|
4
4
|
name: 'counter',
|
|
5
5
|
description: 'counter contract',
|
|
6
|
-
systems: ['counter'],
|
|
7
6
|
schemas: {
|
|
8
7
|
counter: {
|
|
9
8
|
structure: {
|
|
10
9
|
value: 'StorageValue<u32>',
|
|
11
10
|
},
|
|
11
|
+
events: [
|
|
12
|
+
{
|
|
13
|
+
name: 'Increment',
|
|
14
|
+
fields: {
|
|
15
|
+
value: 'u32',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
errors: [
|
|
20
|
+
{
|
|
21
|
+
name: 'InvalidIncrement',
|
|
22
|
+
code: 0,
|
|
23
|
+
description: 'Increment must be greater than zero',
|
|
24
|
+
},
|
|
25
|
+
]
|
|
12
26
|
},
|
|
13
27
|
},
|
|
14
28
|
} as DubheConfig;
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dubhe-contract-template",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Simple starter template",
|
|
5
|
-
"author": "team@0xobelisk.com",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"scripts": {
|
|
8
6
|
"// Utility Commands": "----------------",
|
|
9
|
-
"start": "pnpm dubhe node",
|
|
7
|
+
"start:localnet": "pnpm dubhe node",
|
|
10
8
|
"faucet": "pnpm dubhe faucet --network",
|
|
11
9
|
"deploy": "pnpm dubhe publish --network",
|
|
12
10
|
"upgrade": "pnpm dubhe upgrade --network",
|
|
13
11
|
"schema:gen": "pnpm dubhe schemagen",
|
|
14
|
-
"account:gen": "
|
|
15
|
-
"check-balance": "
|
|
16
|
-
"deploy:framework": "pnpm dubhe publish --network localnet --contract-name dubhe-framework"
|
|
12
|
+
"account:gen": "pnpm dubhe generate-key",
|
|
13
|
+
"check-balance": "pnpm dubhe check-balance --network"
|
|
17
14
|
},
|
|
18
15
|
"dependencies": {
|
|
19
|
-
"@0xobelisk/sui-cli": "^0.5.
|
|
20
|
-
"@0xobelisk/sui-client": "^0.5.
|
|
21
|
-
"@0xobelisk/sui-common": "^0.5.
|
|
16
|
+
"@0xobelisk/sui-cli": "^0.5.34",
|
|
17
|
+
"@0xobelisk/sui-client": "^0.5.30",
|
|
18
|
+
"@0xobelisk/sui-common": "^0.5.23",
|
|
22
19
|
"dotenv": "^16.4.5",
|
|
23
20
|
"chalk": "^4.1.2"
|
|
24
21
|
},
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dubhe-nextjs-template",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Simple starter template",
|
|
5
|
-
"author": "team@0xobelisk.com",
|
|
6
|
-
"license": "MIT",
|
|
7
5
|
"scripts": {
|
|
8
6
|
"// Utility Commands": "----------------",
|
|
9
7
|
"start:localnet": "pnpm dubhe node",
|
|
@@ -11,15 +9,14 @@
|
|
|
11
9
|
"deploy": "pnpm dubhe publish --network",
|
|
12
10
|
"upgrade": "pnpm dubhe upgrade --network",
|
|
13
11
|
"schema:gen": "pnpm dubhe schemagen",
|
|
14
|
-
"account:gen": "
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"deploy:framework": "pnpm dubhe publish --network localnet --contract-name dubhe-framework",
|
|
12
|
+
"account:gen": "pnpm dubhe generate-key --output-ts-path ./src/chain/key.ts",
|
|
13
|
+
"check-balance": "pnpm dubhe check-balance --network",
|
|
14
|
+
"config:store": "pnpm dubhe config-store --output-ts-path ./src/chain/config.ts --network",
|
|
18
15
|
"// Development Environment": "----------------",
|
|
19
16
|
"dev": "pnpm dev:localnet",
|
|
20
17
|
"dev:localnet": "pnpm setup:localnet && pnpm next",
|
|
21
18
|
"dev:testnet": "pnpm setup:testnet && pnpm next",
|
|
22
|
-
"setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm
|
|
19
|
+
"setup:localnet": "pnpm account:gen && pnpm faucet localnet && pnpm run deploy localnet && pnpm run config:store localnet",
|
|
23
20
|
"setup:testnet": "pnpm account:gen && pnpm check-balance testnet && pnpm run deploy testnet && pnpm run config:store testnet",
|
|
24
21
|
"build": "next build",
|
|
25
22
|
"start": "next start",
|
|
@@ -28,9 +25,9 @@
|
|
|
28
25
|
"prod:testnet": "pnpm config:store testnet && pnpm next"
|
|
29
26
|
},
|
|
30
27
|
"dependencies": {
|
|
31
|
-
"@0xobelisk/sui-cli": "^0.5.
|
|
32
|
-
"@0xobelisk/sui-client": "
|
|
33
|
-
"@0xobelisk/sui-common": "^0.5.
|
|
28
|
+
"@0xobelisk/sui-cli": "^0.5.34",
|
|
29
|
+
"@0xobelisk/sui-client": "^0.5.30",
|
|
30
|
+
"@0xobelisk/sui-common": "^0.5.23",
|
|
34
31
|
"@mysten/dapp-kit": "0.14.9",
|
|
35
32
|
"@mysten/sui": "1.7.0",
|
|
36
33
|
"dotenv": "^16.4.5",
|
|
@@ -45,9 +45,10 @@ const Home: React.FC = () => {
|
|
|
45
45
|
metadata: metadata,
|
|
46
46
|
});
|
|
47
47
|
const tx = new Transaction();
|
|
48
|
-
const queryValue = (await dubhe.query.counter_schema.get_value(
|
|
49
|
-
tx
|
|
50
|
-
|
|
48
|
+
const queryValue = (await dubhe.query.counter_schema.get_value({
|
|
49
|
+
tx,
|
|
50
|
+
params: [tx.object(Counter_Object_Id)],
|
|
51
|
+
})) as DevInspectResults;
|
|
51
52
|
console.log('Counter value:', dubhe.view(queryValue)[0]);
|
|
52
53
|
setValue(dubhe.view(queryValue)[0]);
|
|
53
54
|
} catch (error) {
|
|
@@ -82,7 +83,11 @@ const Home: React.FC = () => {
|
|
|
82
83
|
metadata: metadata,
|
|
83
84
|
});
|
|
84
85
|
const tx = new Transaction();
|
|
85
|
-
await dubhe.tx.counter_system.inc(
|
|
86
|
+
await dubhe.tx.counter_system.inc({
|
|
87
|
+
tx,
|
|
88
|
+
params: [tx.object(Counter_Object_Id)],
|
|
89
|
+
isRaw: true,
|
|
90
|
+
});
|
|
86
91
|
await signAndExecuteTransaction(
|
|
87
92
|
{
|
|
88
93
|
transaction: tx.serialize(),
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
version: "3"
|
|
3
|
-
|
|
4
|
-
services:
|
|
5
|
-
sui-test-validator-node:
|
|
6
|
-
image: vladilenaksana/sui-test-validator:v0.0.3
|
|
7
|
-
restart: always
|
|
8
|
-
volumes:
|
|
9
|
-
- ./:/app
|
|
10
|
-
ports:
|
|
11
|
-
- 9000:9000
|
|
12
|
-
- 9123:9123
|
|
13
|
-
command: ["/opt/sui/bin/sui-test-validator", "--fullnode-rpc-addr", "0.0.0.0:9000", "--faucet-addr", "0.0.0.0:9123"]
|
|
14
|
-
healthcheck:
|
|
15
|
-
test: ["CMD", "curl", "-f", "http://sui-test-validator-node:9123"]
|
|
16
|
-
interval: 3s
|
|
17
|
-
timeout: 5s
|
|
18
|
-
retries: 10
|
|
19
|
-
|
|
20
|
-
# webapp:
|
|
21
|
-
# build:
|
|
22
|
-
# context: .
|
|
23
|
-
# dockerfile: ./Dockerfile
|
|
24
|
-
# ports:
|
|
25
|
-
# - 3000:3000
|
|
26
|
-
# depends_on:
|
|
27
|
-
# "sui-test-validator-node":
|
|
28
|
-
# condition: service_healthy
|
|
29
|
-
# restart: always
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Dubhe, NetworkType } from '@0xobelisk/sui-client';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
dotenv.config();
|
|
5
|
-
|
|
6
|
-
async function checkBalance(network: string) {
|
|
7
|
-
try {
|
|
8
|
-
if (!process.env.PRIVATE_KEY) {
|
|
9
|
-
console.error(chalk.red('Please set the PRIVATE_KEY environment variable'));
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!network) {
|
|
14
|
-
console.error(chalk.red('Network parameter is missing'));
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dubhe = new Dubhe({
|
|
19
|
-
secretKey: process.env.PRIVATE_KEY,
|
|
20
|
-
networkType: network as NetworkType,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const balance = await dubhe.getBalance();
|
|
24
|
-
|
|
25
|
-
if (balance.totalBalance === '0') {
|
|
26
|
-
console.log(chalk.yellow(`Account balance is 0, need to get ${network} coins`));
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log(
|
|
31
|
-
chalk.green(`Current account balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`),
|
|
32
|
-
);
|
|
33
|
-
process.exit(0);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(chalk.red('Failed to check balance:', error));
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
checkBalance(process.argv[2] as NetworkType);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
|
|
4
|
-
async function generateAccount() {
|
|
5
|
-
const path = process.cwd();
|
|
6
|
-
|
|
7
|
-
// Check if .env file exists and has content
|
|
8
|
-
let privateKey: string;
|
|
9
|
-
try {
|
|
10
|
-
const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
|
|
11
|
-
const match = envContent.match(/PRIVATE_KEY=(.+)/);
|
|
12
|
-
if (match && match[1]) {
|
|
13
|
-
privateKey = match[1];
|
|
14
|
-
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
15
|
-
const keypair = dubhe.getKeypair();
|
|
16
|
-
|
|
17
|
-
// Only update key.ts file
|
|
18
|
-
const chainFolderPath = `${path}/src/chain`;
|
|
19
|
-
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
20
|
-
|
|
21
|
-
fs.writeFileSync(
|
|
22
|
-
`${path}/src/chain/key.ts`,
|
|
23
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
24
|
-
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
25
|
-
`,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
console.log(`Using existing Account: ${keypair.toSuiAddress()}`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
// .env file doesn't exist or failed to read, continue to generate new account
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// If no existing private key, generate new account
|
|
36
|
-
const dubhe = new Dubhe();
|
|
37
|
-
const keypair = dubhe.getKeypair();
|
|
38
|
-
privateKey = keypair.getSecretKey();
|
|
39
|
-
|
|
40
|
-
const chainFolderPath = `${path}/src/chain`;
|
|
41
|
-
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
44
|
-
|
|
45
|
-
fs.writeFileSync(
|
|
46
|
-
`${path}/src/chain/key.ts`,
|
|
47
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
48
|
-
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
49
|
-
`,
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
console.log(`Generate new Account: ${keypair.toSuiAddress()}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
generateAccount();
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as fsAsync from 'fs/promises';
|
|
2
|
-
import { mkdirSync, writeFileSync } from 'fs';
|
|
3
|
-
import { exit } from 'process';
|
|
4
|
-
import { dubheConfig } from '../dubhe.config';
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
|
|
7
|
-
export type schema = {
|
|
8
|
-
name: string;
|
|
9
|
-
objectId: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type DeploymentJsonType = {
|
|
13
|
-
projectName: string;
|
|
14
|
-
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
15
|
-
packageId: string;
|
|
16
|
-
schemas: schema[];
|
|
17
|
-
upgradeCap: string;
|
|
18
|
-
version: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
async function getDeploymentJson(projectPath: string, network: string) {
|
|
22
|
-
try {
|
|
23
|
-
const data = await fsAsync.readFile(`${projectPath}/.history/sui_${network}/latest.json`, 'utf8');
|
|
24
|
-
return JSON.parse(data) as DeploymentJsonType;
|
|
25
|
-
} catch {
|
|
26
|
-
console.log('store config failed.');
|
|
27
|
-
exit;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function storeConfig(network: string, packageId: string, schemas: schema[]) {
|
|
32
|
-
let code = `type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
33
|
-
|
|
34
|
-
export const NETWORK: NetworkType = '${network}';
|
|
35
|
-
|
|
36
|
-
export const PACKAGE_ID = '${packageId}'
|
|
37
|
-
|
|
38
|
-
${schemas.map(schema => `export const ${schema.name.split('::')[2]}_Object_Id = '${schema.objectId}'`).join('\n')}
|
|
39
|
-
`;
|
|
40
|
-
const path = process.cwd();
|
|
41
|
-
writeOutput(code, `${path}/src/chain/config.ts`, 'storeConfig');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function writeOutput(output: string, fullOutputPath: string, logPrefix?: string): Promise<void> {
|
|
45
|
-
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
46
|
-
|
|
47
|
-
writeFileSync(fullOutputPath, output);
|
|
48
|
-
if (logPrefix !== undefined) {
|
|
49
|
-
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function main() {
|
|
54
|
-
const path = process.cwd();
|
|
55
|
-
const network = process.argv[2];
|
|
56
|
-
const contractPath = `${path}/contracts/${dubheConfig.name}`;
|
|
57
|
-
const deployment = await getDeploymentJson(contractPath, network);
|
|
58
|
-
storeConfig(deployment.network, deployment.packageId, deployment.schemas);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
main();
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Dubhe, NetworkType } from '@0xobelisk/sui-client';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
dotenv.config();
|
|
5
|
-
|
|
6
|
-
async function checkBalance(network: string) {
|
|
7
|
-
try {
|
|
8
|
-
if (!process.env.PRIVATE_KEY) {
|
|
9
|
-
console.error(chalk.red('Please set the PRIVATE_KEY environment variable'));
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!network) {
|
|
14
|
-
console.error(chalk.red('Network parameter is missing'));
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dubhe = new Dubhe({
|
|
19
|
-
secretKey: process.env.PRIVATE_KEY,
|
|
20
|
-
networkType: network as NetworkType,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const balance = await dubhe.getBalance();
|
|
24
|
-
|
|
25
|
-
if (balance.totalBalance === '0') {
|
|
26
|
-
console.log(chalk.yellow(`Account balance is 0, need to get ${network} coins`));
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log(
|
|
31
|
-
chalk.green(`Current account balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`),
|
|
32
|
-
);
|
|
33
|
-
process.exit(0);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(chalk.red('Failed to check balance:', error));
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
checkBalance(process.argv[2] as NetworkType);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
|
|
4
|
-
async function generateAccount() {
|
|
5
|
-
const path = process.cwd();
|
|
6
|
-
|
|
7
|
-
// Check if .env file exists and has content
|
|
8
|
-
let privateKey: string;
|
|
9
|
-
try {
|
|
10
|
-
const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
|
|
11
|
-
const match = envContent.match(/PRIVATE_KEY=(.+)/);
|
|
12
|
-
if (match && match[1]) {
|
|
13
|
-
privateKey = match[1];
|
|
14
|
-
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
15
|
-
const keypair = dubhe.getKeypair();
|
|
16
|
-
|
|
17
|
-
console.log(`Using existing Account: ${keypair.toSuiAddress()}`);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
// .env file doesn't exist or failed to read, continue to generate new account
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// If no existing private key, generate new account
|
|
25
|
-
const dubhe = new Dubhe();
|
|
26
|
-
const keypair = dubhe.getKeypair();
|
|
27
|
-
privateKey = keypair.getSecretKey();
|
|
28
|
-
|
|
29
|
-
const chainFolderPath = `${path}/src/chain`;
|
|
30
|
-
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
31
|
-
|
|
32
|
-
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
33
|
-
|
|
34
|
-
console.log(`Generate new Account: ${keypair.toSuiAddress()}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
generateAccount();
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
version: "3"
|
|
3
|
-
|
|
4
|
-
services:
|
|
5
|
-
sui-test-validator-node:
|
|
6
|
-
image: vladilenaksana/sui-test-validator:v0.0.3
|
|
7
|
-
restart: always
|
|
8
|
-
volumes:
|
|
9
|
-
- ./:/app
|
|
10
|
-
ports:
|
|
11
|
-
- 9000:9000
|
|
12
|
-
- 9123:9123
|
|
13
|
-
command: ["/opt/sui/bin/sui-test-validator", "--fullnode-rpc-addr", "0.0.0.0:9000", "--faucet-addr", "0.0.0.0:9123"]
|
|
14
|
-
healthcheck:
|
|
15
|
-
test: ["CMD", "curl", "-f", "http://sui-test-validator-node:9123"]
|
|
16
|
-
interval: 3s
|
|
17
|
-
timeout: 5s
|
|
18
|
-
retries: 10
|
|
19
|
-
|
|
20
|
-
# webapp:
|
|
21
|
-
# build:
|
|
22
|
-
# context: .
|
|
23
|
-
# dockerfile: ./Dockerfile
|
|
24
|
-
# ports:
|
|
25
|
-
# - 3000:3000
|
|
26
|
-
# depends_on:
|
|
27
|
-
# "sui-test-validator-node":
|
|
28
|
-
# condition: service_healthy
|
|
29
|
-
# restart: always
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Dubhe, NetworkType } from '@0xobelisk/sui-client';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import dotenv from 'dotenv';
|
|
4
|
-
dotenv.config();
|
|
5
|
-
|
|
6
|
-
async function checkBalance(network: string) {
|
|
7
|
-
try {
|
|
8
|
-
if (!process.env.PRIVATE_KEY) {
|
|
9
|
-
console.error(chalk.red('Please set the PRIVATE_KEY environment variable'));
|
|
10
|
-
process.exit(1);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (!network) {
|
|
14
|
-
console.error(chalk.red('Network parameter is missing'));
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const dubhe = new Dubhe({
|
|
19
|
-
secretKey: process.env.PRIVATE_KEY,
|
|
20
|
-
networkType: network as NetworkType,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const balance = await dubhe.getBalance();
|
|
24
|
-
|
|
25
|
-
if (balance.totalBalance === '0') {
|
|
26
|
-
console.log(chalk.yellow(`Account balance is 0, need to get ${network} coins`));
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
console.log(
|
|
31
|
-
chalk.green(`Current account balance: ${(Number(balance.totalBalance) / 1_000_000_000).toFixed(4)} SUI`),
|
|
32
|
-
);
|
|
33
|
-
process.exit(0);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error(chalk.red('Failed to check balance:', error));
|
|
36
|
-
process.exit(1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
checkBalance(process.argv[2] as NetworkType);
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { Dubhe } from '@0xobelisk/sui-client';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
|
|
4
|
-
async function generateAccount() {
|
|
5
|
-
const path = process.cwd();
|
|
6
|
-
|
|
7
|
-
// Check if .env file exists and has content
|
|
8
|
-
let privateKey: string;
|
|
9
|
-
try {
|
|
10
|
-
const envContent = fs.readFileSync(`${path}/.env`, 'utf8');
|
|
11
|
-
const match = envContent.match(/PRIVATE_KEY=(.+)/);
|
|
12
|
-
if (match && match[1]) {
|
|
13
|
-
privateKey = match[1];
|
|
14
|
-
const dubhe = new Dubhe({ secretKey: privateKey });
|
|
15
|
-
const keypair = dubhe.getKeypair();
|
|
16
|
-
|
|
17
|
-
// Only update key.ts file
|
|
18
|
-
const chainFolderPath = `${path}/src/chain`;
|
|
19
|
-
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
20
|
-
|
|
21
|
-
fs.writeFileSync(
|
|
22
|
-
`${path}/src/chain/key.ts`,
|
|
23
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
24
|
-
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
25
|
-
`,
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
console.log(`Using existing Account: ${keypair.toSuiAddress()}`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
} catch (error) {
|
|
32
|
-
// .env file doesn't exist or failed to read, continue to generate new account
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// If no existing private key, generate new account
|
|
36
|
-
const dubhe = new Dubhe();
|
|
37
|
-
const keypair = dubhe.getKeypair();
|
|
38
|
-
privateKey = keypair.getSecretKey();
|
|
39
|
-
|
|
40
|
-
const chainFolderPath = `${path}/src/chain`;
|
|
41
|
-
fs.mkdirSync(chainFolderPath, { recursive: true });
|
|
42
|
-
|
|
43
|
-
fs.writeFileSync(`${path}/.env`, `PRIVATE_KEY=${privateKey}`);
|
|
44
|
-
|
|
45
|
-
fs.writeFileSync(
|
|
46
|
-
`${path}/src/chain/key.ts`,
|
|
47
|
-
`export const PRIVATEKEY = '${privateKey}';
|
|
48
|
-
export const ACCOUNT = '${keypair.toSuiAddress()}';
|
|
49
|
-
`,
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
console.log(`Generate new Account: ${keypair.toSuiAddress()}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
generateAccount();
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as fsAsync from 'fs/promises';
|
|
2
|
-
import { mkdirSync, writeFileSync } from 'fs';
|
|
3
|
-
import { exit } from 'process';
|
|
4
|
-
import { dubheConfig } from '../dubhe.config';
|
|
5
|
-
import { dirname } from 'path';
|
|
6
|
-
|
|
7
|
-
export type schema = {
|
|
8
|
-
name: string;
|
|
9
|
-
objectId: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type DeploymentJsonType = {
|
|
13
|
-
projectName: string;
|
|
14
|
-
network: 'mainnet' | 'testnet' | 'devnet' | 'localnet';
|
|
15
|
-
packageId: string;
|
|
16
|
-
schemas: schema[];
|
|
17
|
-
upgradeCap: string;
|
|
18
|
-
version: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
async function getDeploymentJson(projectPath: string, network: string) {
|
|
22
|
-
try {
|
|
23
|
-
const data = await fsAsync.readFile(`${projectPath}/.history/sui_${network}/latest.json`, 'utf8');
|
|
24
|
-
return JSON.parse(data) as DeploymentJsonType;
|
|
25
|
-
} catch {
|
|
26
|
-
console.log('store config failed.');
|
|
27
|
-
exit;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function storeConfig(network: string, packageId: string, schemas: schema[]) {
|
|
32
|
-
let code = `type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
33
|
-
|
|
34
|
-
export const NETWORK: NetworkType = '${network}';
|
|
35
|
-
|
|
36
|
-
export const PACKAGE_ID = '${packageId}'
|
|
37
|
-
|
|
38
|
-
${schemas.map(schema => `export const ${schema.name.split('::')[2]}_Object_Id = '${schema.objectId}'`).join('\n')}
|
|
39
|
-
`;
|
|
40
|
-
const path = process.cwd();
|
|
41
|
-
writeOutput(code, `${path}/src/chain/config.ts`, 'storeConfig');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function writeOutput(output: string, fullOutputPath: string, logPrefix?: string): Promise<void> {
|
|
45
|
-
mkdirSync(dirname(fullOutputPath), { recursive: true });
|
|
46
|
-
|
|
47
|
-
writeFileSync(fullOutputPath, output);
|
|
48
|
-
if (logPrefix !== undefined) {
|
|
49
|
-
console.log(`${logPrefix}: ${fullOutputPath}`);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
async function main() {
|
|
54
|
-
const path = process.cwd();
|
|
55
|
-
const network = process.argv[2];
|
|
56
|
-
const contractPath = `${path}/contracts/${dubheConfig.name}`;
|
|
57
|
-
const deployment = await getDeploymentJson(contractPath, network);
|
|
58
|
-
storeConfig(deployment.network, deployment.packageId, deployment.schemas);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
main();
|