Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(init): fund existing accounts; update contractsDir #13

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
17 changes: 9 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,7 @@ function exe(command) {
}

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

function removeFiles(pattern) {
Expand All @@ -52,7 +53,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 +61,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 +90,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