Skip to content

Commit 7c82e53

Browse files
committed
feat(grid_client): add node_call + create_node_contract low-level helpers
- node_call<T,R>(node_twin_id, command, payload): generic RMB escape hatch for zos RPCs with no dedicated typed helper (e.g. zos.deployment.get/transfer/prepare, zos.statistics.get). Signs + routes exactly like the built-in deployment helpers. - create_node_contract(node_id, deployment_data, deployment_hash_hex, public_ips): submit a node contract for a deployment that already carries the given md5 hash — used when relocating an existing deployment to another node (contract id is excluded from the hash, so the source signature stays valid). Returns the new contract id via grid-proxy lookup. Both are needed by the within-farm VM migration control plane (my_migrator).
1 parent 0fc9fa9 commit 7c82e53

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

‎src/grid_client/mod.rs‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,61 @@ impl GridClient {
18471847
}
18481848
}
18491849

1850+
/// Create a node contract on-chain for a deployment that already carries the given
1851+
/// md5 hash and metadata — e.g. an existing deployment being **relocated** to a new
1852+
/// node (the contract id is excluded from the deployment hash, so the source
1853+
/// signature stays valid). Submits the `create_node_contract` extrinsic and returns
1854+
/// the new contract id (looked up via grid-proxy once the contract is on-chain).
1855+
/// Low-level companion to [`GridClient::node_call`] for migration/relocation.
1856+
pub async fn create_node_contract(
1857+
&self,
1858+
node_id: u32,
1859+
deployment_data: &str,
1860+
deployment_hash_hex: &str,
1861+
public_ips: u32,
1862+
) -> Result<u64, GridError> {
1863+
submit_create_node_contract(
1864+
&self.chain,
1865+
&self.signer,
1866+
node_id,
1867+
deployment_data,
1868+
deployment_hash_hex,
1869+
public_ips,
1870+
)
1871+
.await?;
1872+
self.wait_for_contract(node_id, deployment_hash_hex).await
1873+
}
1874+
1875+
/// Invoke an arbitrary node RMB command — a low-level escape hatch for zos RPCs
1876+
/// that have no dedicated typed helper on [`GridClient`].
1877+
///
1878+
/// `command` is a zos method name such as `"zos.deployment.get"`; `payload` is
1879+
/// JSON-serialized as the request body and the JSON reply is deserialized into
1880+
/// `R` (use [`serde_json::Value`] for dynamic/empty replies). The call is signed
1881+
/// with this client's identity and routed through the configured relay, exactly
1882+
/// like the built-in deployment helpers.
1883+
///
1884+
/// ```no_run
1885+
/// # async fn demo(client: &zos_sdk_rust::GridClient) -> Result<(), zos_sdk_rust::GridError> {
1886+
/// let deployment: serde_json::Value = client
1887+
/// .node_call(node_twin_id, "zos.deployment.get", &serde_json::json!({ "contract_id": 42u64 }))
1888+
/// .await?;
1889+
/// # let node_twin_id = 0u32; let _ = deployment; Ok(())
1890+
/// # }
1891+
/// ```
1892+
pub async fn node_call<T, R>(
1893+
&self,
1894+
node_twin_id: u32,
1895+
command: &str,
1896+
payload: &T,
1897+
) -> Result<R, GridError>
1898+
where
1899+
T: Serialize,
1900+
R: for<'de> Deserialize<'de> + 'static,
1901+
{
1902+
self.rmb_call(node_twin_id, command, payload, None).await
1903+
}
1904+
18501905
async fn rmb_call<T, R>(
18511906
&self,
18521907
destination_twin_id: u32,

0 commit comments

Comments
 (0)