Loading...
Loading...
Compare original and translation side by side
flowchart LR
subgraph Clients
DApp["dApp / wallet"]
Explorer["Block explorer"]
Svc["Backend service"]
end
subgraph Node["Midnight node"]
RPC["JSON-RPC layer"]
RT["Runtime / pallet-midnight"]
Store["State storage"]
end
DApp -->|HTTP / WSS| RPC
Explorer --> RPC
Svc --> RPC
RPC --> RT
RT --> Storeflowchart LR
subgraph Clients
DApp["dApp / wallet"]
Explorer["Block explorer"]
Svc["Backend service"]
end
subgraph Node["Midnight node"]
RPC["JSON-RPC layer"]
RT["Runtime / pallet-midnight"]
Store["State storage"]
end
DApp -->|HTTP / WSS| RPC
Explorer --> RPC
Svc --> RPC
RPC --> RT
RT --> Store| Method | Purpose |
|---|---|
| JSON-encoded smart contract state |
| Raw binary-encoded contract state at a block |
| Unclaimed tokens/rewards for a beneficiary |
| ZSwap chain state for a contract |
| Supported RPC API versions (tooling compatibility) |
| Ledger version at a block |
| 方法 | 用途 |
|---|---|
| JSON格式编码的智能合约状态 |
| 指定区块下原始二进制编码的合约状态 |
| 受益人未领取的代币/奖励 |
| 合约对应的ZSwap链状态 |
| 支持的RPC API版本(工具兼容性) |
| 指定区块下的账本版本 |
#[method(name = "midnight_jsonContractState")]
fn get_json_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_contractState")]
fn get_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_unclaimedAmount")]
fn get_unclaimed_amount(
&self,
beneficiary: String,
at: Option<BlockHash>,
) -> Result<u128, StateRpcError>;
#[method(name = "midnight_zswapChainState")]
fn get_zswap_chain_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_apiVersions")]
fn get_supported_api_versions(&self) -> RpcResult<Vec<u32>>;
#[method(name = "midnight_ledgerVersion")]
fn get_ledger_version(&self, at: Option<BlockHash>) -> Result<String, BlockRpcError>;atflowchart TB
Q["Client query"] --> M{"Method type"}
M -->|Contract| CS["midnight_contractState / jsonContractState"]
M -->|ZSwap| ZS["midnight_zswapChainState"]
M -->|Rewards| UA["midnight_unclaimedAmount"]
M -->|Meta| LV["midnight_ledgerVersion / apiVersions"]
CS --> Block["Resolve at block hash or latest"]
ZS --> Block
UA --> Block
LV --> Block#[method(name = "midnight_jsonContractState")]
fn get_json_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_contractState")]
fn get_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_unclaimedAmount")]
fn get_unclaimed_amount(
&self,
beneficiary: String,
at: Option<BlockHash>,
) -> Result<u128, StateRpcError>;
#[method(name = "midnight_zswapChainState")]
fn get_zswap_chain_state(
&self,
contract_address: String,
at: Option<BlockHash>,
) -> Result<String, StateRpcError>;
#[method(name = "midnight_apiVersions")]
fn get_supported_api_versions(&self) -> RpcResult<Vec<u32>>;
#[method(name = "midnight_ledgerVersion")]
fn get_ledger_version(&self, at: Option<BlockHash>) -> Result<String, BlockRpcError>;atflowchart TB
Q["Client query"] --> M{"Method type"}
M -->|Contract| CS["midnight_contractState / jsonContractState"]
M -->|ZSwap| ZS["midnight_zswapChainState"]
M -->|Rewards| UA["midnight_unclaimedAmount"]
M -->|Meta| LV["midnight_ledgerVersion / apiVersions"]
CS --> Block["Resolve at block hash or latest"]
ZS --> Block
UA --> Block
LV --> Block| Method | Purpose |
|---|---|
| Node health status |
| Fetch block by hash |
| Read storage at a key |
| List all supported RPC endpoints |
rpc_methodsNote: Some Midnight RPC methods may not appear in Polkadot JS Apps. See Polkadot SDK RPC docs for overlap; support varies by node version and configuration.
midnight-indexer/| 方法 | 用途 |
|---|---|
| 节点健康状态 |
| 通过哈希获取区块 |
| 通过键读取存储数据 |
| 列出所有支持的RPC端点 |
rpc_methods**注意:**部分Midnight RPC方法可能不会在Polkadot JS Apps中显示。有关重叠方法,请查看Polkadot SDK RPC文档;支持情况因节点版本和配置而异。
midnight-indexer/Warning: Not all RPC methods are safe to expose on public or production nodes.
| Risk | Mitigation |
|---|---|
| Sensitive data leakage | Use |
| External attack surface | Avoid |
| Performance abuse | Limit exposed endpoints to your operational role |
flowchart TD
Role{"Node role?"}
Role -->|Validator / block producer| Safe["--rpc-methods Safe<br/>No --rpc-external"]
Role -->|Observer / archive| Review["Review threat model<br/>May expose read-only RPC"]
Safe --> Audit["Audit rpc_methods list"]
Review --> Audit**警告:**并非所有RPC方法都适合在公共节点或生产节点上暴露。
| 风险 | 缓解措施 |
|---|---|
| 敏感数据泄露 | 使用 |
| 外部攻击面扩大 | 除非必要,否则避免使用 |
| 性能滥用 | 根据你的操作角色限制暴露的端点 |
flowchart TD
Role{"Node role?"}
Role -->|Validator / block producer| Safe["--rpc-methods Safe<br/>No --rpc-external"]
Role -->|Observer / archive| Review["Review threat model<br/>May expose read-only RPC"]
Safe --> Audit["Audit rpc_methods list"]
Review --> Auditmidnight-onchain-logic/midnight-indexer/midnight-transactions/midnight-onchain-logic/midnight-indexer/midnight-transactions/