-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use zx for creating vaults
- Loading branch information
1 parent
5ce73f8
commit f0734e1
Showing
4 changed files
with
92 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { $ } from 'zx'; | ||
|
||
/** | ||
* Creates a vault by executing a command in a Docker container. | ||
* | ||
* @param {string} containerName - The name of the Docker container where the command will be executed. | ||
* @param {string} agoricNet - The network configuration for the Agoric CLI. | ||
* @param {string} commandTimeout - The maximum time in seconds for the command to complete. | ||
* @param {string} wantMinted - The amount of ISTs to be minted by the vault. | ||
* @param {string} giveCollateral - The amount of ATOMs to secure the minted currency. | ||
*/ | ||
const createVault = async (containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral) => { | ||
console.log('Starting the vault creation process...'); | ||
const agops = '/usr/src/agoric-sdk/packages/agoric-cli/bin/agops'; | ||
|
||
const createVaultCommand = `timeout ${commandTimeout} ${agops} vaults open --wantMinted ${wantMinted} --giveCollateral ${giveCollateral} > /tmp/want-ist.json`; | ||
const executeCreateVaultCommand = `docker exec ${containerName} /bin/bash -c "env AGORIC_NET=${agoricNet} ${createVaultCommand}"`; | ||
|
||
try { | ||
await $`${executeCreateVaultCommand}`; | ||
console.log('Vault created successfully. Executing broadcast command...'); | ||
|
||
const broadcastCommand = `timeout ${commandTimeout} ${agops} perf satisfaction --executeOffer /tmp/want-ist.json --from ${userKey} --keyring-backend=test`; | ||
const executeBroadcastCommand = `docker exec ${containerName} /bin/bash -c "env AGORIC_NET=${agoricNet} ${broadcastCommand}"`; | ||
|
||
await $`${executeBroadcastCommand}`; | ||
console.log('Offer broadcast successfully.'); | ||
} catch (error) { | ||
console.error('Error during vault creation:', error); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
const containerName = process.env.INPUT_CONTAINERNAME; | ||
const agoricNet = process.env.INPUT_AGORICNET; | ||
const commandTimeout = process.env.INPUT_COMMANDTIMEOUT; | ||
const userKey = process.env.INPUT_USERKEY; | ||
const wantMinted = process.env.INPUT_WANTMINTED; | ||
const giveCollateral = process.env.INPUT_GIVECOLLATERAL; | ||
|
||
console.log('ARGS:', { containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral }); | ||
createVault(containerName, agoricNet, commandTimeout, userKey, wantMinted, giveCollateral); |
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