Skip to content

Commit

Permalink
fix(init): fund existing accounts; update contractsDir
Browse files Browse the repository at this point in the history
- if accounts already exist,
  - don't panic (that's the `| true`)
  - fund them
- use `.stellar` directory, not `.soroban` (and extract to a variable)
- rm unused `id` var
- build contracts after binding
  • Loading branch information
chadoh committed Dec 9, 2024
1 parent 68bd0a8 commit a10a0c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ console.log('###################### Initializing ########################');
// Get dirname (equivalent to the Bash version)
const __filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(__filename);
const contractsDir = `${dirname}/.stellar/contract-ids`;

// variable for later setting pinned version of soroban in "$(dirname/target/bin/soroban)"
const cli = 'stellar';
Expand All @@ -29,7 +30,8 @@ function exe(command) {
}

function fundAll() {
exe(`${cli} keys generate ${process.env.SOROBAN_ACCOUNT}`);
exe(`${cli} keys generate ${process.env.SOROBAN_ACCOUNT} | true`);
exe(`${cli} keys fund ${process.env.SOROBAN_ACCOUNT}`);
}

function removeFiles(pattern) {
Expand All @@ -52,7 +54,6 @@ function deploy(wasm) {
}

function deployAll() {
const contractsDir = `${dirname}/.soroban/contract-ids`;
mkdirSync(contractsDir, { recursive: true });

const wasmFiles = glob(`${dirname}/target/wasm32-unknown-unknown/release/*.wasm`);
Expand All @@ -61,7 +62,7 @@ function deployAll() {
}

function contracts() {
const contractFiles = glob(`${dirname}/.soroban/contract-ids/*.json`);
const contractFiles = glob(`${contractsDir}/*.json`);

return contractFiles
.map(path => ({
Expand All @@ -74,13 +75,14 @@ function contracts() {

function bind({alias, id}) {
exe(`${cli} contract bindings typescript --contract-id ${id} --output-dir ${dirname}/packages/${alias} --overwrite`);
exe(`(cd ${dirname}/packages/${alias} && npm i && npm run build)`);
}

function bindAll() {
contracts().forEach(bind);
}

function importContract({id, alias}) {
function importContract({alias}) {
const outputDir = `${dirname}/src/contracts/`;

mkdirSync(outputDir, { recursive: true });
Expand Down

0 comments on commit a10a0c1

Please sign in to comment.