Use optional config in waku_new

This commit is contained in:
Daniel Sanchez Quiros 2022-09-29 18:50:22 +02:00
parent 710db3aa07
commit 03187ccb6c
2 changed files with 4 additions and 3 deletions

View File

@ -5,7 +5,7 @@ use multiaddr::Multiaddr;
use serde::{Deserialize, Serialize};
// internal
#[derive(Serialize, Deserialize, Default)]
#[derive(Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NodeConfig {
host: Option<std::net::IpAddr>,

View File

@ -8,8 +8,9 @@ use crate::general::{JsonResponse, Result};
/// Instantiates a Waku node
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_newchar-jsonconfig)
pub fn waku_new(config: &NodeConfig) -> Result<bool> {
let s_config = serde_json::to_string(config)
pub fn waku_new(config: Option<NodeConfig>) -> Result<bool> {
let config = config.unwrap_or_default();
let s_config = serde_json::to_string(&config)
.expect("Serialization from properly built NodeConfig should never fail");
let result: &str = unsafe {
CStr::from_ptr(waku_sys::waku_new(