create_block_manager_wallet.sh

Overview

This script automates the deployment of a Block Manager wallet in a blockchain system. It handles key generation, configuration of the TVM (TON Virtual Machine) CLI endpoint, and invokes contract calls to deploy and verify the wallet. The script also validates license numbers associated with the wallet and retrieves addresses for each license. It is intended for use by developers or operators who are managing multisig wallets and licenses within the system.


Detailed Explanation

Script Purpose

Environment Variables & Constants

Variable Name

Description

BM_OWNER_KEY_FILE_OUTPUT_PATH

Path to the file containing the Block Manager owner's key or where the key will be created.

BM_SIGNING_KEY_FILE_OUTPUT_PATH

Path to the file containing the signing key or where the key will be created.

LICENSE_NUMBERS

Comma-separated string of license numbers to associate with the wallet.

TVM_ENDPOINT

URL endpoint for the TVM CLI to send contract calls.

MAX_LICENSES_PER_WALLET

Maximum allowed licenses per wallet (hardcoded to 20).

ABI

Path to the Block Manager contract root ABI JSON file.

WALLET_ABI

Path to the Block Manager wallet ABI JSON file.

ROOT

Root address constant (not actively used in script).

LICENSE_ROOT_ABI

Path to the LicenseRoot contract ABI JSON file.

LICENSE_ROOT_ADDR

Address of the LicenseRoot contract.

LICENSE_ABI

Path to the License contract ABI JSON file.

BMSYSTEM_ROOT

Address of the Block Manager System root contract.


Functions

gen_key

gen_key () {
  if [ ! -e $1 ]; then
    echo File $1 not found. Generating block manager keys...
    tvm-cli -j genphrase --dump $1 > $1.phrase
  fi
}
gen_key "./owner_key.json"

read_key

read_key () {
  local BM_OWNER_PUB_KEY_JSON=$(jq -r .public $BM_OWNER_KEY_FILE_OUTPUT_PATH)
  local BM_SIGNING_PUB_KEY_JSON=$(jq -r .public $BM_SIGNING_KEY_FILE_OUTPUT_PATH)
  local WHITELISTPARAMS=$(echo "$LICENSE_NUMBERS" | jq -R 'split(",") | map({(.): true}) | add')
  
  [ "$(echo $WHITELISTPARAMS | jq -r '. | length')" -gt $MAX_LICENSES_PER_WALLET ] && { echo "License numbers couldn't be greater than $MAX_LICENSES_PER_WALLET" ; exit 1 ; }

  BM_OWNER_PUB_KEY=$(echo '{"pubkey": "0x{public}"}' | sed -e "s/{public}/$BM_OWNER_PUB_KEY_JSON/g")  
  BM_OWNER_PUB_KEY_PARAMS=$(echo "{\"pubkey\": \"0x{public}\", \"signerPubkey\": \"0x{signer_public}\", \"whiteListLicense\": $WHITELISTPARAMS}" | sed -e "s/{public}/$BM_OWNER_PUB_KEY_JSON/g" | sed -e "s/{signer_public}/$BM_SIGNING_PUB_KEY_JSON/g")
}
read_key
echo "$BM_OWNER_PUB_KEY_PARAMS"

Main Execution Flow

  1. Dependency Check: Verifies tvm-cli is installed and available in the environment.

  2. Argument Parsing: Accepts four arguments:

    • Block Manager owner key file path

    • Signing key file path

    • Comma-separated license numbers

    • TVM endpoint URL

  3. TVM CLI Configuration: Sets the TVM CLI endpoint URL using tvm-cli config.

  4. Key Generation: Calls gen_key for owner and signing keys if files do not exist.

  5. Reading Keys and Preparing Parameters: Calls read_key.

  6. Deployment:

    • Calls the deployAckiNackiBlockManagerNodeWallet method on the Block Manager System root contract with the prepared parameters.

    • Waits 3 seconds to allow deployment to complete.

  7. Wallet Address Retrieval: Queries the deployed wallet address using getAckiNackiBlockManagerNodeWalletAddress.

  8. License Address Retrieval:

    • Iterates over each license number.

    • Calls getLicenseBMAddress on the LicenseRoot contract to get the license address.

  9. Wallet Details Check: Retrieves and prints wallet details using getDetails method on the deployed wallet contract.


Important Implementation Details


Interaction with Other System Components


Usage Example

./create_block_manager_wallet.sh ./owner_key.json ./signing_key.json "101,102,103" "https://tvm.example.com"

Mermaid Flowchart

flowchart TD
A[tvm-cli dependency check] --> B[Parse script arguments]
B --> C[Configure TVM CLI endpoint]
C --> D[Generate owner key if missing]
C --> E[Generate signing key if missing]
D --> F[Read keys and prepare JSON params]
E --> F
F --> G[Deploy Block Manager wallet contract]
G --> H["Wait for deployment (sleep 3s)"]
H --> I[Retrieve deployed wallet address]
I --> J[For each license number]
J --> K[Get license address from LicenseRoot contract]
J --> L[Print license addresses]
I --> M[Query wallet details]
M --> N[Print wallet details]

This file is a critical utility for deploying and managing Block Manager wallets and their associated licenses, bridging key management, contract deployment, and license validation workflows. It relies on contract ABIs and blockchain interaction through tvm-cli and integrates with license contracts to maintain wallet-license relationships. For related concepts, see the topics on Smart Contract Deployment and Key Management.