Page cover image

fetchall

Published: March 2025 | Last updated: March 2025

Overview

The fetchall RPC method allows you to retrieve multiple files from the Lynx blockchain in reverse chronological order (newest first). This command is useful for backing up or migrating data, as it can download either a specific number of the most recent files or all files stored on the blockchain for the authenticated tenant. Authentication is required to execute this function.

Syntax

fetchall <count> <path>

Description

When you invoke the fetchall method, the Lynx daemon searches the blockchain for the most recent files and downloads them to your designated location. The files are retrieved in reverse chronological order, meaning the newest files are fetched first. This method requires authentication and is designed for bulk retrieval operations.

Parameters

Parameter
Type
Required
Description

count

string/integer

Yes

The number of most recent assets to fetch. Enter 0 to retrieve all assets stored on the blockchain.

path

string

Yes

The full filesystem path where the retrieved files should be stored (e.g., /home/username/downloads). This path must exist before calling the method.

Returns

The method returns an array containing a single object with the following fields:

Field
Type
Description

result

string

Indicates whether the operation succeeded (success) or failed (failure).

message

string

Provides additional information about the result. For successful operations, shows the number of assets fetched (e.g., Number of assets fetched: 5). For failures, indicates the reason (e.g., Invalid path: /path/to/directory., Not authenticated., Invalid count: abc.).

Authentication Requirements

The fetchall command requires authentication:

  • You must authenticate using the auth command before using fetchall

  • If not authenticated, the method will return a "Not authenticated" error

Examples

Retrieve the 5 most recent files

lynx-cli fetchall 5 /home/username/downloads

Output:

[
  {
    "result": "success",
    "message": "Number of assets fetched: 5"
  }
]

Retrieve all files stored on the blockchain

lynx-cli fetchall 0 /home/username/downloads

Using JSON-RPC:

curl --user username --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "fetchall", "params": ["5", "/home/username/downloads"]}' -H 'content-type: text/plain;' http://127.0.0.1:9332/

Error Handling

The method will return a failure result in the following scenarios:

  • The user is not authenticated

  • The specified path doesn't exist on the filesystem

  • The count parameter is not a valid integer

Implementation Notes

  • There is a 2-second pause between each file retrieval to prevent overwhelming the system

  • The count parameter is converted to an integer with input validation to prevent errors

Last updated