-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
228 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const config = { separateCompilables: true }; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Config } from './Config'; | ||
import { BLUEPRINT_CONFIG } from '../paths'; | ||
|
||
let config: Config | undefined; | ||
|
||
export async function getConfig(): Promise<Config | undefined> { | ||
if (config) { | ||
return config; | ||
} | ||
|
||
try { | ||
const configModule = await import(BLUEPRINT_CONFIG); | ||
if (!('config' in configModule) || typeof configModule.config !== 'object') { | ||
return undefined; | ||
} | ||
config = configModule.config; | ||
|
||
return config; | ||
} catch { | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
src/templates/func/not-separated-common/wrappers/compile.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{name}}.compile.ts | ||
import { CompilerConfig } from '@ton/blueprint'; | ||
|
||
export const compile: CompilerConfig = { | ||
lang: 'func', | ||
targets: ['{{contractPath}}'], | ||
}; |
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
src/templates/tact/not-separated-common/wrappers/compile.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{name}}.compile.ts | ||
import { CompilerConfig } from '@ton/blueprint'; | ||
|
||
export const compile: CompilerConfig = { | ||
lang: 'tact', | ||
target: '{{contractPath}}', | ||
options: { | ||
debug: true, | ||
}, | ||
}; |
2 changes: 2 additions & 0 deletions
2
src/templates/tact/not-separated-common/wrappers/wrapper.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{name}}.ts | ||
export * from '../build/{{name}}/tact_{{name}}'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './object.utils'; | ||
export * from './timer.utils'; | ||
export * from './ton.utils'; | ||
export * from './selection.utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export function oneOrZeroOf<T extends { [k: string]: boolean | undefined }>(options: T): keyof T | undefined { | ||
let opt: keyof T | undefined = undefined; | ||
for (const k in options) { | ||
if (options[k]) { | ||
if (opt === undefined) { | ||
opt = k; | ||
} else { | ||
throw new Error(`Please pick only one of the options: ${Object.keys(options).join(', ')}`); | ||
} | ||
} | ||
} | ||
return opt; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import path from 'path'; | ||
import fs from 'fs/promises'; | ||
import { UIProvider } from '../ui/UIProvider'; | ||
import { SCRIPTS_DIR } from '../paths'; | ||
import { COMPILE_END, getCompilablesDirectory } from '../compile/compile'; | ||
import { File } from '../types/file'; | ||
|
||
export const findCompiles = async (directory?: string): Promise<File[]> => { | ||
directory ??= await getCompilablesDirectory(); | ||
const files = await fs.readdir(directory); | ||
const compilables = files.filter((file) => file.endsWith(COMPILE_END)); | ||
return compilables.map((file) => ({ | ||
path: path.join(directory, file), | ||
name: file.slice(0, file.length - COMPILE_END.length), | ||
})); | ||
}; | ||
|
||
export const findScripts = async (): Promise<File[]> => { | ||
const dirents = await fs.readdir(SCRIPTS_DIR, { recursive: true, withFileTypes: true }); | ||
const scripts = dirents.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.ts')); | ||
|
||
return scripts | ||
.map((script) => ({ | ||
name: path.join(script.path.slice(SCRIPTS_DIR.length), script.name), | ||
path: path.join(SCRIPTS_DIR, script.path, script.name), | ||
})) | ||
.sort((a, b) => (a.name >= b.name ? 1 : -1)); | ||
}; | ||
|
||
export async function selectOption( | ||
options: { name: string; value: string }[], | ||
opts: { | ||
ui: UIProvider; | ||
msg: string; | ||
hint?: string; | ||
}, | ||
) { | ||
if (opts.hint) { | ||
const found = options.find((o) => o.value === opts.hint); | ||
if (found === undefined) { | ||
throw new Error(`Could not find option '${opts.hint}'`); | ||
} | ||
return found; | ||
} else { | ||
return await opts.ui.choose(opts.msg, options, (o) => o.name); | ||
} | ||
} | ||
|
||
export async function selectFile( | ||
files: File[], | ||
opts: { | ||
ui: UIProvider; | ||
hint?: string; | ||
import?: boolean; | ||
}, | ||
) { | ||
let selected: File; | ||
|
||
if (opts.hint) { | ||
const found = files.find((f) => f.name.toLowerCase() === opts.hint?.toLowerCase()); | ||
if (found === undefined) { | ||
throw new Error(`Could not find file with name '${opts.hint}'`); | ||
} | ||
selected = found; | ||
opts.ui.write(`Using file: ${selected.name}`); | ||
} else { | ||
if (files.length === 1) { | ||
selected = files[0]; | ||
opts.ui.write(`Using file: ${selected.name}`); | ||
} else { | ||
selected = await opts.ui.choose('Choose file to use', files, (f) => f.name); | ||
} | ||
} | ||
|
||
return { | ||
...selected, | ||
module: opts.import !== false ? await import(selected.path) : undefined, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function sleep(ms: number) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Address, Cell } from '@ton/core'; | ||
|
||
export const tonDeepLink = (address: Address, amount: bigint, body?: Cell, stateInit?: Cell) => | ||
`ton://transfer/${address.toString({ | ||
urlSafe: true, | ||
bounceable: true, | ||
})}?amount=${amount.toString()}${body ? '&bin=' + body.toBoc().toString('base64url') : ''}${ | ||
stateInit ? '&init=' + stateInit.toBoc().toString('base64url') : '' | ||
}`; | ||
|
||
export function getExplorerLink(address: string, network: string, explorer: string) { | ||
const networkPrefix = network === 'testnet' ? 'testnet.' : ''; | ||
|
||
switch (explorer) { | ||
case 'tonscan': | ||
return `https://${networkPrefix}tonscan.org/address/${address}`; | ||
|
||
case 'tonviewer': | ||
return `https://${networkPrefix}tonviewer.com/${address}`; | ||
|
||
case 'toncx': | ||
return `https://${networkPrefix}ton.cx/address/${address}`; | ||
|
||
case 'dton': | ||
return `https://${networkPrefix}dton.io/a/${address}`; | ||
|
||
default: | ||
return `https://${networkPrefix}tonscan.org/address/${address}`; | ||
} | ||
} |