diff --git a/pkgs/cctl/default.nix b/pkgs/cctl/default.nix index 31c0952..e7d11ef 100644 --- a/pkgs/cctl/default.nix +++ b/pkgs/cctl/default.nix @@ -1,15 +1,17 @@ -{ stdenv -, lib -, fetchFromGitHub +{ fetchFromGitHub , casper-client-rs , casper-node , casper-node-launcher , casper-node-contracts -, binutils +, coreutils , python3 +, writeShellScriptBin , symlinkJoin +, findutils +, less }: let + python = python3.withPackages (ps: with ps; [ supervisor tomlkit toml ]); cspr-bins = symlinkJoin { name = "cspr-bins"; paths = [ @@ -19,42 +21,78 @@ let casper-node-contracts ]; }; - python = python3.withPackages (ps: with ps; [ supervisor tomlkit toml ]); -in -stdenv.mkDerivation { - pname = "cctl"; - version = "1.0.0"; - src = fetchFromGitHub { owner = "casper-network"; repo = "cctl"; rev = "69af101815a6e43f91159d096319de4912f3f2c8"; sha256 = "sha256-bkZ4DF0DCqIE0NJrluenIAsS79WIjeCOsGlzKTWz74E="; }; + mkCctlCommand = commandName: commandPath: writeShellScriptBin "cctl-${commandName}" '' + export CCTL=${src} + export CCTL_ASSETS=''${CCTL_ASSETS:-./assets} + export CSPR_PATH_TO_RESOURCES=${casper-node.src}/resources + export CSPR_PATH_TO_BIN=${cspr-bins}/bin + ${builtins.readFile "${src}/cmds/${commandPath}.sh"} + ''; +in +symlinkJoin { + name = "cctl"; + paths = [ + coreutils + python + findutils + less + (mkCctlCommand "infra-net-setup" "infra/net/setup") + (mkCctlCommand "infra-net-start" "infra/net/start") + (mkCctlCommand "infra-net-stop" "infra/net/stop") + (mkCctlCommand "infra-net-teardown" "infra/net/teardown") + (mkCctlCommand "infra-net-status" "infra/net/status") - buildPhase = '' - mkdir $out - echo $src - shopt -s globstar # Enable recursive globbing - for file in "$src"/**/*.sh; do - if [ -f "$file" ]; then - relative_path="''${file#$src/}" - target_path="$out/$relative_path" - mkdir -p "$(dirname "$target_path")" - cp $file $target_path - chmod +x $target_path - fi - done - cp -r $src/resources $out/resources + (mkCctlCommand "infra-node-clean" "infra/node/clean") + (mkCctlCommand "infra-node-stop" "infra/node/stop") + (mkCctlCommand "infra-node-restart" "infra/node/restart") + (mkCctlCommand "infra-node-view-config" "infra/node/view_config") + (mkCctlCommand "infra-node-view-error-log" "infra/node/view_log_stderr") + (mkCctlCommand "infra-node-view-log" "infra/node/view_log_stdout") + (mkCctlCommand "infra-node-view-metrics" "infra/node/view_metrics") + (mkCctlCommand "infra-node-view-peers" "infra/node/view_peers") + (mkCctlCommand "infra-node-view-peer-count" "infra/node/view_peer_count") + (mkCctlCommand "infra-node-view-ports" "infra/node/view_ports") + (mkCctlCommand "infra-node-view-rpc-endpoint" "infra/node/view_rpc_endpoint") + (mkCctlCommand "infra-node-view-rpc-schema" "infra/node/view_rpc_schema") + (mkCctlCommand "infra-node-view-status" "infra/node/view_status") + (mkCctlCommand "infra-node-view-storage" "infra/node/view_storage") + (mkCctlCommand "infra-node-write-rpc-schema" "infra/node/write_rpc_schema") - echo "export CCTL=$out" >> $out/activate - echo "export CCTL_ASSETS=./assets" >> $out/activate - echo "export CSPR_PATH_TO_RESOURCES=${casper-node.src}/resources" >> $out/activate - echo "export CSPR_PATH_TO_BIN=${cspr-bins}/bin" >> $out/activate - echo "export PATH=\$PATH:${lib.makeBinPath [ binutils python ] }" >> $out/activate - cp "$src"/activate "$out"/.activate-wrapped - chmod +x "$out"/.activate-wrapped - echo "source $out/.activate-wrapped" >> $out/activate - ''; + (mkCctlCommand "chain-await-n-blocks" "chain/await/n_blocks") + (mkCctlCommand "chain-await-n-eras" "chain/await/n_eras") + (mkCctlCommand "chain-await-until-block-n" "chain/await/until_block_n") + (mkCctlCommand "chain-await-until-era-n" "chain/await/until_era_n") + + (mkCctlCommand "chain-view-account" "chain/query/view_account") + (mkCctlCommand "chain-view-account-balance" "chain/query/view_account_balance") + (mkCctlCommand "chain-view-account-balances" "chain/query/view_account_balances") + (mkCctlCommand "chain-view-account-of-faucet" "chain/query/view_account_of_faucet") + (mkCctlCommand "chain-view-account-of-user" "chain/query/view_account_of_user") + (mkCctlCommand "chain-view-account-of-validator" "chain/query/view_account_of_validator") + (mkCctlCommand "chain-view-auction-info" "chain/query/view_auction_info") + (mkCctlCommand "chain-view-block" "chain/query/view_block") + (mkCctlCommand "chain-view-deploy" "chain/query/view_deploy") + (mkCctlCommand "chain-view-era" "chain/query/view_era") + (mkCctlCommand "chain-view-era-summary" "chain/query/view_era_summary") + (mkCctlCommand "chain-view-genesis-accounts" "chain/query/view_genesis_accounts") + (mkCctlCommand "chain-view-genesis-chainspec" "chain/query/view_genesis_chainspec") + (mkCctlCommand "chain-view-height" "chain/query/view_height") + (mkCctlCommand "chain-view-last-finalized-block" "chain/query/view_last_finalized_block") + (mkCctlCommand "chain-view-state-root-hash" "chain/query/view_state_root_hash") + (mkCctlCommand "chain-view-view-tip-info" "chain/query/view_tip_info") + + (mkCctlCommand "tx-dispatch-native-transfer" "chain/tx/dispatch_transfer_native") + (mkCctlCommand "tx-dispatch-native-transfer-batch" "chain/tx/dispatch_transfer_native_batch") + (mkCctlCommand "tx-dispatch-wasm-transfer" "chain/tx/dispatch_transfer_native_batch") + (mkCctlCommand "tx-dispatch-wasm-transfer-batch" "chain/tx/dispatch_transfer_wasm_batch") + (mkCctlCommand "tx-prepare-native-transfer-batch" "chain/tx/prepare_transfer_native_batch") + (mkCctlCommand "tx-prepare-wasm-transfer-batch" "chain/tx/prepare_transfer_wasm_batch") + ]; }