Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rusk: Introduce JSON-RPC Endpoints #3353

Open
4 tasks
HDauven opened this issue Jan 13, 2025 · 1 comment
Open
4 tasks

rusk: Introduce JSON-RPC Endpoints #3353

HDauven opened this issue Jan 13, 2025 · 1 comment
Assignees
Labels
module:rusk Issues related to rusk module need:feedback Call for participation: feedback is requested to fix this issue type:feature implementing a new feature

Comments

@HDauven
Copy link
Member

HDauven commented Jan 13, 2025

Summary

This issue proposes the addition of new JSON-RPC endpoints to be compatible with existing 3rd party tooling. These endpoints will use the ledger_ prefix to distinguish core blockchain operations from other subsystems.

Proposed Endpoints

ledger_getBalance

  • Description: Returns the balance of a specified public (Moonlight) account.
  • Parameters: ["oCqYsUMRqpRn2kSabH52Gt6FQCwH5JXj5MtRdYVtjMSJ73AFvdbPf98p3gz98fQwNy9ZBiDem6m9BivzURKFSKLYWP3N9JahSPZs9PnZ996P18rTGAjQTNFsxtbrKx79yWu"]
  • Response:
{
  "jsonrpc": "2.0",
  "result": 150000, // Balance in LUX
  "id": 1
}

ledger_getBlock

  • Description: Retrieves a block by height or hash.
  • Parameters:
    • For block height: [101]
    • For block hash: ["ce50a4bb5727a530f38f0cfd9ae6eb4ceeb7538c12619aee1d747cb1f98160a0"]
  • Response:
{
  "jsonrpc": "2.0",
  "result": {
    "hash": "ce50a4bb...",
    "height": 54321,
    "transactions": [...],
    ...
  },
  "id": 1
}

ledger_getBlockHeight

  • Description: Returns the current block height.
  • Parameters: []
  • Response:
{
  "jsonrpc": "2.0",
  "result": 54321, // Block height as an integer
  "id": 1
}

ledger_getTransaction

  • Description: Fetches details of a transaction by its hash.
  • Parameters: ["74f5cca0894765a2c5309c3ed6e29c52ea1f26f8dd418c7c6ad62c49931f3169"]
  • Response:
{
  "jsonrpc": "2.0",
  "result": {
    "hash": "74f5cca08...",
    "type": "phoenix/moonlight",
    ...
  },
  "id": 1
}

Mapping to Internal Functions

JSON-RPC Endpoint Internal Database Function
ledger_getBalance fn get_account(&self, pk: &str) -> anyhow::Result
ledger_getBlock block_by_height(&self, height: u64) -> Result<Option<Block>>
block(&self, hash: &[u8]) -> Result<Option<Block>>
ledger_getBlockHeight block_hash_by_height(&self, height: u64) -> Result<Option<[u8; 32]>>
ledger_getTransaction ledger_tx(&self, tx_id: &[u8]) -> Result<Option<SpentTransaction>>

Rationale for Prefixes

The use of prefixes in JSON-RPC are common to explicitly identify subsystems in RPC calls. This allows us to introduce id_ for Citadel/SSI in the future, stake_ for RPC calls to the staking contract, and potentially other future subsystems. Both SUI and Ethereum use these. Solana does not make use of this.

Tasks

  • Implement ledger_getBalance
  • Implement ledger_getBlock
  • Implement ledger_getBlockHeight
  • Implement ledger_getTransaction
@HDauven HDauven added type:feature implementing a new feature need:feedback Call for participation: feedback is requested to fix this issue module:rusk Issues related to rusk module labels Jan 13, 2025
@welf welf self-assigned this Jan 16, 2025
@welf
Copy link
Contributor

welf commented Jan 16, 2025

Why do we need to prefix endpoints with the ledger_? Why not to create a /ledger endpoint and get a function/method name from the JSON payload as per the JSON-RPC specification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:rusk Issues related to rusk module need:feedback Call for participation: feedback is requested to fix this issue type:feature implementing a new feature
Projects
None yet
Development

No branches or pull requests

2 participants