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
- switch to `STELLAR_*` env vars, rather than obsolete `SOROBAN_*`
  • Loading branch information
chadoh committed Dec 11, 2024
1 parent 68bd0a8 commit 97813da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Prefix with "PUBLIC_" to make available in Astro frontend files
PUBLIC_SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
PUBLIC_SOROBAN_RPC_URL="http://localhost:8000/soroban/rpc"
PUBLIC_STELLAR_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
PUBLIC_STELLAR_RPC_URL="http://localhost:8000/soroban/rpc"

SOROBAN_ACCOUNT="alice"
SOROBAN_NETWORK="standalone"
STELLAR_ACCOUNT="alice"
STELLAR_NETWORK="standalone"
18 changes: 10 additions & 8 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.STELLAR_ACCOUNT} | true`);
exe(`${cli} keys fund ${process.env.STELLAR_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,26 +62,27 @@ function deployAll() {
}

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

return contractFiles
.map(path => ({
alias: filenameNoExtension(path),
...JSON.parse(readFileSync(path))
}))
.filter(data => data.ids[process.env.SOROBAN_NETWORK_PASSPHRASE])
.map(data => ({alias: data.alias, id: data.ids[process.env.SOROBAN_NETWORK_PASSPHRASE]}));
.filter(data => data.ids[process.env.STELLAR_NETWORK_PASSPHRASE])
.map(data => ({alias: data.alias, id: data.ids[process.env.STELLAR_NETWORK_PASSPHRASE]}));
}

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 All @@ -89,10 +91,10 @@ function importContract({id, alias}) {
`import * as Client from '${alias}';\n` +
`import { rpcUrl } from './util';\n\n` +
`export default new Client.Client({\n` +
` ...Client.networks.${process.env.SOROBAN_NETWORK},\n` +
` ...Client.networks.${process.env.STELLAR_NETWORK},\n` +
` rpcUrl,\n` +
`${
process.env.SOROBAN_NETWORK === "local" || "standalone"
process.env.STELLAR_NETWORK === "local" || "standalone"
? ` allowHttp: true,\n`
: null
}` +
Expand Down

0 comments on commit 97813da

Please sign in to comment.