# Hyperledger Cacti Integration

## Overview

Hyperledger Cacti is integrated into the Besu network for cross-chain interoperability. Cacti provides connectors for multiple blockchains and enables cross-chain transactions.

## Architecture

### Components

1. **Cactus API Server**: Main Cacti API service
2. **Besu Connector**: Connects Cacti to Besu network
3. **Plugins**: Various blockchain plugins

### Network Integration

- **Chain ID**: 138 (DeFi Oracle Meta Mainnet)
- **RPC Endpoint**: Besu RPC nodes
- **WebSocket Endpoint**: Besu WebSocket nodes

## Deployment

### Prerequisites

- Kubernetes cluster (AKS)
- Besu network deployed
- RPC endpoints accessible

### Deploy Cacti

```bash
# Deploy Cacti
./scripts/deployment/deploy-cacti.sh

# Or manually
kubectl apply -f k8s/cacti/
```

### Verify Deployment

```bash
# Check Cacti status
kubectl get pods -n cacti

# Check Cacti API
curl http://cactus-api.cacti.svc.cluster.local:4000/api/v1/api-server/healthcheck
```

## Configuration

### Cacti Configuration

Cacti is configured via ConfigMap (`k8s/cacti/configmap.yaml`):

- **Node ID**: cactus-node-1
- **API Port**: 4000
- **WebSocket Port**: 4001
- **Besu RPC**: Besu RPC endpoints
- **Chain ID**: 138

### Environment Variables

- `CACTUS_NODE_ID`: cactus-node-1
- `CACTUS_LOG_LEVEL`: info
- `HTTP_PORT`: 4000
- `WS_PORT`: 4001
- `BESU_RPC_HTTP`: Besu RPC URL
- `BESU_RPC_WS`: Besu WebSocket URL
- `BESU_CHAIN_ID`: 138

## Usage

### Register Besu Ledger

```bash
curl -X POST http://cactus-api.cacti.svc.cluster.local:4000/api/v1/plugins/ledger-connector/besu \
  -H "Content-Type: application/json" \
  -d '{
    "ledgerId": "besu-chain-138",
    "chainId": 138,
    "rpc": {
      "http": "http://besu-rpc-service:8545",
      "ws": "ws://besu-rpc-service:8546"
    }
  }'
```

### Deploy Contract

```bash
curl -X POST http://cactus-api.cacti.svc.cluster.local:4000/api/v1/plugins/ledger-connector/besu/deploy-contract \
  -H "Content-Type: application/json" \
  -d '{
    "ledgerId": "besu-chain-138",
    "abi": [...],
    "bytecode": "0x...",
    "constructorArgs": []
  }'
```

### Invoke Contract

```bash
curl -X POST http://cactus-api.cacti.svc.cluster.local:4000/api/v1/plugins/ledger-connector/besu/invoke-contract \
  -H "Content-Type: application/json" \
  -d '{
    "ledgerId": "besu-chain-138",
    "contractAddress": "0x...",
    "abi": [...],
    "method": "transfer",
    "args": ["0x...", "1000"]
  }'
```

## Integration with Besu

Cacti connects to Besu via:

1. **Besu Connector Plugin**: Connects to Besu RPC
2. **Chain ID**: 138
3. **RPC Endpoints**: Besu RPC and WebSocket

### Besu-Cacti Connector

The Besu-Cacti connector (`connectors/besu-cacti/connector.py`) provides:

- Ledger registration
- Contract deployment
- Contract invocation
- Status monitoring

## Cross-Chain Interoperability

Cacti enables:

- **Cross-chain transfers**: Transfer assets between chains
- **Cross-chain contracts**: Deploy contracts on multiple chains
- **Cross-chain bridges**: Bridge assets between chains

## References

- [Cacti Documentation](https://hyperledger.github.io/cacti/)
- [Cacti API](https://hyperledger.github.io/cacti/api/)
- [Besu Connector](https://hyperledger.github.io/cacti/plugins/ledger-connector-besu/)

