forked from hyperledger-solang/solang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
69 lines (49 loc) · 1.96 KB
/
setup.js
File metadata and controls
69 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import 'dotenv/config';
import { mkdirSync, readdirSync} from 'fs';
import { execSync } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
console.log("###################### Initializing ########################");
// Get dirname (equivalent to the Bash version)
const __filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(__filename);
// variable for later setting pinned version of soroban in "$(dirname/target/bin/soroban)"
const soroban = "soroban"
// Function to execute and log shell commands
function exe(command) {
console.log(command);
execSync(command, { stdio: 'inherit' });
}
function generate_alice() {
exe(`${soroban} keys generate alice --network testnet --overwrite`);
// get the secret key of alice and put it in alice.txt
exe(`${soroban} keys show alice > alice.txt`);
}
function filenameNoExtension(filename) {
return path.basename(filename, path.extname(filename));
}
function deploy(wasm) {
let contractId = path.join(dirname, '.soroban', 'contract-ids', filenameNoExtension(wasm) + '.txt');
exe(`(${soroban} contract deploy --wasm ${wasm} --ignore-checks --source-account alice --network testnet) > ${contractId}`);
}
function deploy_all() {
const contractsDir = path.join(dirname, '.soroban', 'contract-ids');
mkdirSync(contractsDir, { recursive: true });
let wasmFiles = readdirSync(`${dirname}`).filter(file => file.endsWith('.wasm'));
console.log(dirname);
let rust_wasm = path.join('rust','target','wasm32-unknown-unknown', 'release-with-logs', 'hello_world.wasm');
// add rust wasm file to the list of wasm files
wasmFiles.push(rust_wasm);
wasmFiles.forEach(wasmFile => {
deploy(path.join(dirname, wasmFile));
});
}
function add_testnet() {
exe(`${soroban} network add \
--global testnet \
--rpc-url https://soroban-testnet.stellar.org:443 \
--network-passphrase "Test SDF Network ; September 2015"`);
}
add_testnet();
generate_alice();
deploy_all();