Skip to content
Snippets Groups Projects
Select Git revision
  • c5993f8b5e58952aae533872700b6876e9b96bc9
  • master default protected
  • chrome-manifest-v3
  • feature/migrate-cordova-13
  • feat/improve-network-scan
  • feat/force-migration-check
  • develop
  • feature/encrypted_comment
  • feature/android_api_19
  • gitlab_migration_1
  • rml8
  • v1.7.15-rc1
  • v1.7.14
  • v1.7.13
  • v1.7.12
  • v1.7.11
  • v1.7.10
  • v1.7.9
  • v1.7.8
  • v1.7.7
  • v1.7.6
  • v1.7.5
  • v1.7.4
  • v1.7.3
  • v1.7.2
  • v1.7.1
  • v1.7.0
  • v1.7.0-rc2
  • v1.7.0-rc1
  • v1.6.12
  • v1.6.11
31 results

wallet-controllers.js

Blame
  • docker-entrypoint 3.56 KiB
    #!/bin/bash
    
    # Custom startup if a first argument is present and is equal to '--'
    # then we just run duniter with the provided arguments (but the '--')
    # without applying all the automated configuration below
    if [ "$1" = -- ]; then
      shift
      exec duniter "$@"
    fi
    
    # Normal startup
    function boolean () {
      echo "$1" | sed -E 's/^(true|yes|1)$/true/i'
    }
    
    function ternary () {
      if [ $(boolean "$1") = true ]; then
        echo "$2"
      else
        echo "$3"
      fi
    }
    
    # Define chain name at the beginning
    # with #274 we could have default given in network branch
    DUNITER_CHAIN_NAME="${DUNITER_CHAIN_NAME:-dev}"
    case "$DUNITER_CHAIN_NAME" in
      dev)
        chain=(--dev)
        ;;
      *)
        chain=(--chain "$DUNITER_CHAIN_NAME")
        ;;
    esac
    
    # Node name will appear on network
    DUNITER_NODE_NAME="${DUNITER_NODE_NAME:-$DUNITER_INSTANCE_NAME}"
    if [ -n "$DUNITER_NODE_NAME" ]; then
      set -- "$@" --name "$DUNITER_NODE_NAME"
    fi
    
    # Path of key file. Should be generated below if not present before starting Duniter
    _DUNITER_KEY_FILE=/var/lib/duniter/node.key
    set -- "$@" --node-key-file "$_DUNITER_KEY_FILE"
    
    # Generate node.key if not existing (chain name is required)
    if [ ! -f "$_DUNITER_KEY_FILE" ]; then
      echo "Generating node key file '$_DUNITER_KEY_FILE'..."
      duniter key generate-node-key --file "$_DUNITER_KEY_FILE" "${chain[@]}"
    else
      echo "Node key file '$_DUNITER_KEY_FILE' exists."
    fi
    # Log peer ID
    _DUNITER_PEER_ID="$(duniter key inspect-node-key --file "$_DUNITER_KEY_FILE")"
    echo "Node peer ID is '$_DUNITER_PEER_ID'."
    
    # Define public address (with dns, correct port and protocol for instance)
    if [ -n "$DUNITER_PUBLIC_ADDR" ]; then
      set -- "$@" --public-addr "$DUNITER_PUBLIC_ADDR"
    fi
    
    # Define public RPC endpoint (gossiped on the network)
    if [ -n "$DUNITER_PUBLIC_RPC" ]; then
      set -- "$@" --public-rpc "$DUNITER_PUBLIC_RPC"
    fi
    
    # Define public Squid endpoint (gossiped on the network)  
    if [ -n "$DUNITER_PUBLIC_SQUID" ]; then
      set -- "$@" --public-squid "$DUNITER_PUBLIC_SQUID"
    fi
    
    # Define public endpoints from JSON file (gossiped on the network)
    if [ -n "$DUNITER_PUBLIC_ENDPOINTS" ]; then
      set -- "$@" --public-endpoints "$DUNITER_PUBLIC_ENDPOINTS"
    fi
    
    # Define listen address (inside docker)
    if [ -n "$DUNITER_LISTEN_ADDR" ]; then
      set -- "$@" --listen-addr "$DUNITER_LISTEN_ADDR"
    fi
    
    DUNITER_RPC_CORS="${DUNITER_RPC_CORS:-all}"
    set -- "$@" --rpc-cors "$DUNITER_RPC_CORS"
    
    # In case of validator, unsafe rpc methods are needed (like rotate_key) and should not be exposed publicly
    DUNITER_VALIDATOR=$(boolean "${DUNITER_VALIDATOR:-false}")
    if [ "$DUNITER_VALIDATOR" = true ]; then
      set -- "$@" --rpc-methods Unsafe --validator
    fi
    
    DUNITER_DISABLE_PROMETHEUS=$(boolean "${DUNITER_DISABLE_PROMETHEUS:-false}")
    if [ "$DUNITER_DISABLE_PROMETHEUS" = true ]; then
      set -- "$@" --no-prometheus
    fi
    
    DUNITER_DISABLE_TELEMETRY=$(boolean "${DUNITER_DISABLE_TELEMETRY:-false}")
    if [ "$DUNITER_DISABLE_TELEMETRY" = true ]; then
      set -- "$@" --no-telemetry
    fi
    
    # Set pruning profile
    DUNITER_PRUNING_PROFILE="${DUNITER_PRUNING_PROFILE:-default}"
    case "$DUNITER_PRUNING_PROFILE" in
      default)
        ;;
      archive)
        set -- "$@" --state-pruning archive --blocks-pruning archive
        ;;
      light)
        set -- "$@" --blocks-pruning 14400
        ;;
      *)
        echo "ERROR: ignoring unknown DUNITER_PRUNING_PROFILE value '$DUNITER_PRUNING_PROFILE'" >&2
        ;;
    esac
    
    # Set main command
    # Since we are inside docker, we can bind to all interfaces.
    # User will bind port to host interface or set reverse proxy when needed.
    set -- "$@" \
      "${chain[@]}" \
      -d /var/lib/duniter --unsafe-rpc-external
    
    echo "Starting duniter with parameters:" "$@"
    exec duniter "$@"