|
| 1 | +# Lumera Client |
| 2 | + |
| 3 | +A Go client for interacting with the Lumera blockchain. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Connect to Lumera nodes via gRPC |
| 8 | +- Interact with all Lumera modules: |
| 9 | + - Action module - manage and query action data |
| 10 | + - SuperNode module - interact with supernodes |
| 11 | + - Transaction module - broadcast and query transactions |
| 12 | + - Node module - query node status and blockchain info |
| 13 | +- Configurable connection options |
| 14 | +- Clean, modular API design with clear separation of interfaces and implementations |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +go get github.com/LumeraProtocol/lumera-client |
| 20 | +``` |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +```go |
| 25 | +package main |
| 26 | + |
| 27 | +import ( |
| 28 | + "context" |
| 29 | + "fmt" |
| 30 | + "log" |
| 31 | + |
| 32 | + "github.com/LumeraProtocol/lumera-client/client" |
| 33 | +) |
| 34 | + |
| 35 | +func main() { |
| 36 | + // Create a context |
| 37 | + ctx := context.Background() |
| 38 | + |
| 39 | + // Initialize the client with options |
| 40 | + lumeraClient, err := client.NewClient( |
| 41 | + ctx, |
| 42 | + client.WithGRPCAddr("localhost:9090"), |
| 43 | + client.WithChainID("lumera-mainnet"), |
| 44 | + client.WithTimeout(30), |
| 45 | + ) |
| 46 | + if err != nil { |
| 47 | + log.Fatalf("Failed to create Lumera client: %v", err) |
| 48 | + } |
| 49 | + defer lumeraClient.Close() |
| 50 | + |
| 51 | + // Get the latest block height |
| 52 | + latestBlock, err := lumeraClient.Node().GetLatestBlock(ctx) |
| 53 | + if err != nil { |
| 54 | + log.Fatalf("Failed to get latest block: %v", err) |
| 55 | + } |
| 56 | + |
| 57 | + fmt.Printf("Latest block height: %d\n", latestBlock.Block.Header.Height) |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Examples |
| 62 | + |
| 63 | +The repository includes example applications demonstrating how to use the client: |
| 64 | + |
| 65 | +- **Basic Example**: Shows simple queries and interactions with the Lumera blockchain |
| 66 | +- **Advanced Example**: Demonstrates a complete transaction flow with error handling and retries |
| 67 | + |
| 68 | +To run the examples: |
| 69 | + |
| 70 | +```bash |
| 71 | +# Build and run the basic example |
| 72 | +make run-basic |
| 73 | + |
| 74 | +# Build and run the advanced example |
| 75 | +make run-advanced |
| 76 | +``` |
| 77 | + |
| 78 | +## Project Structure |
| 79 | + |
| 80 | +``` |
| 81 | +lumera-client/ |
| 82 | +│ # Core client package |
| 83 | +│ interface.go # Client interface definitions |
| 84 | +│ client.go # Client implementation |
| 85 | +│ config.go # Configuration types |
| 86 | +│ options.go # Option functions |
| 87 | +│ connection.go # Connection handling |
| 88 | +├── modules/ # Module-specific packages |
| 89 | +│ ├── action/ # Action module |
| 90 | +│ ├── node/ # Node module |
| 91 | +│ ├── supernode/ # SuperNode module |
| 92 | +│ └── tx/ # Transaction module |
| 93 | +└── examples/ # Example applications |
| 94 | + └── main.go # Basic usage example |
| 95 | +
|
| 96 | +``` |
| 97 | + |
| 98 | +## Module Documentation |
| 99 | + |
| 100 | +### Action Module |
| 101 | + |
| 102 | +The Action module allows you to interact with Lumera actions, which are the core data processing units in the Lumera blockchain. |
| 103 | + |
| 104 | +```go |
| 105 | +// Get action by ID |
| 106 | +action, err := client.Action().GetAction(ctx, "action-id-123") |
| 107 | + |
| 108 | +// Calculate fee for action with specific data size |
| 109 | +fee, err := client.Action().GetActionFee(ctx, "1024") // 1KB data |
| 110 | +``` |
| 111 | + |
| 112 | +### Node Module |
| 113 | + |
| 114 | +The Node module provides information about the blockchain and node status. |
| 115 | + |
| 116 | +```go |
| 117 | +// Get latest block |
| 118 | +block, err := client.Node().GetLatestBlock(ctx) |
| 119 | + |
| 120 | +// Get specific block by height |
| 121 | +block, err := client.Node().GetBlockByHeight(ctx, 1000) |
| 122 | + |
| 123 | +// Get node information |
| 124 | +nodeInfo, err := client.Node().GetNodeInfo(ctx) |
| 125 | +``` |
| 126 | + |
| 127 | +### SuperNode Module |
| 128 | + |
| 129 | +The SuperNode module allows you to interact with Lumera supernodes. |
| 130 | + |
| 131 | +```go |
| 132 | +// Get top supernodes for a specific block |
| 133 | +topNodes, err := client.SuperNode().GetTopSuperNodesForBlock(ctx, 1000) |
| 134 | + |
| 135 | +// Get specific supernode by address |
| 136 | +node, err := client.SuperNode().GetSuperNode(ctx, "validator-address") |
| 137 | +``` |
| 138 | + |
| 139 | +### Transaction Module |
| 140 | + |
| 141 | +The Transaction module handles transaction broadcasting and querying. |
| 142 | + |
| 143 | +```go |
| 144 | +// Broadcast a signed transaction |
| 145 | +resp, err := client.Tx().BroadcastTx(ctx, txBytes, sdktx.BroadcastMode_BROADCAST_MODE_SYNC) |
| 146 | + |
| 147 | +// Simulate a transaction |
| 148 | +sim, err := client.Tx().SimulateTx(ctx, txBytes) |
| 149 | + |
| 150 | +// Get transaction by hash |
| 151 | +tx, err := client.Tx().GetTx(ctx, "tx-hash") |
| 152 | +``` |
| 153 | + |
0 commit comments