bm_staking.sh

Overview

bm_staking.sh is a Bash script designed to automate interactions with a blockchain smart contract system related to block manager staking and rewards. It primarily manages the lifecycle of a Block Manager Node Wallet by initializing it, fetching its details, starting the block manager process, and periodically requesting rewards.

The script communicates with smart contracts using the tvm-cli tool, which interacts with TON Virtual Machine (TVM) contracts through their ABI (Application Binary Interface) JSON files. It requires a private key file for authentication and uses an address root constant to locate the relevant contract root.

Key contract artifacts used:

File Constants and Initial Setup

Command-Line Parameters

Parameter Validation

Core Functional Steps

Getting the Block Manager Node Wallet Address

Fetching Wallet Details

Starting the Block Manager Process

Reward Processing Function

process_bm () {
  tvm-cli -j callx --abi $BM_ABI --addr $BM_WALLET --keys $BM_KEY -m getReward
}

Infinite Reward Loop

Commented Code: Contract Data Decoding

Implementation Details and Algorithms

Interaction with Other System Components

Usage Example

./bm_staking.sh -p 60 /path/to/block_manager_private_key.json

Mermaid Diagram: Flowchart of Main Functionality

flowchart TD
Start --> ParseOpts["Parse -p option"]
ParseOpts --> ValidateKey["Validate BM_KEY file"]
ValidateKey --> ExtractPubKey["Extract public key from BM_KEY"]
ExtractPubKey --> GetWalletAddr["Get BM Wallet Address via getAckiNackiBlockManagerNodeWalletAddress"]
GetWalletAddr --> GetWalletDetails["Get wallet details via getDetails"]
GetWalletDetails --> StartBM["Call startBM method"]
StartBM --> Sleep10s["Sleep 10 seconds"]
Sleep10s --> Loop["Enter infinite loop"]
Loop --> ProcessBM["Call getReward method"]
ProcessBM --> SleepInterval["Sleep SLEEP_TIME seconds"]
SleepInterval --> Loop

This flowchart represents the sequential steps of the script from initialization, contract calls, to the continuous reward claiming loop.