From 5c0141c3fe9fda55c093aeb0f2ca0d01422d5b41 Mon Sep 17 00:00:00 2001 From: Matthew Maxwell <44885822+maxwellmattryan@users.noreply.github.com> Date: Tue, 10 Jan 2023 04:47:13 -0600 Subject: [PATCH] chore: update NodeJS bindings for participation method (#1717) * chore: update NodeJS bindings * fix: add missing match statement * fix: adjust argument types * chore: rename variable * chore: format code * Bump client rev * Fix import Co-authored-by: Thibault Martinez --- Cargo.toml | 2 +- bindings/nodejs/lib/AccountManager.ts | 27 +++++++++++++------ .../nodejs/types/bridge/accountManager.ts | 9 ++++++- bindings/nodejs/types/bridge/index.ts | 2 ++ src/message_interface/message.rs | 12 ++++++++- src/message_interface/message_handler.rs | 8 ++++++ src/message_interface/response.rs | 8 +++++- 7 files changed, 56 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0823d6201..f2abc5561 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ backtrace = { version = "0.3.67", default-features = false, features = [ "std" ] futures = { version = "0.3.25", default-features = false } getset = { version = "0.1.2", default-features = false } # iota-client = { version = "2.0.1-rc.5", default-features = false, features = [ "message_interface", "tls" ] } -iota-client = { git = "https://github.com/iotaledger/iota.rs", rev = "22d70a94750f5800975b5767ef60d002dca0a12e", default-features = false, features = [ "message_interface", "tls" ] } +iota-client = { git = "https://github.com/iotaledger/iota.rs", rev = "b2c1b27e76f748518fe878c2caeed2d5b3b5f610", default-features = false, features = [ "message_interface", "tls" ] } iota-crypto = { version = "0.15.3", default-features = false, features = [ "std", "chacha", "blake2b", "ed25519", "random", "slip10", "bip39", "bip39-en" ] } log = { version = "0.4.17", default-features = false } packable = { version = "0.7.0", default-features = false, features = [ "serde", "primitive-types" ] } diff --git a/bindings/nodejs/lib/AccountManager.ts b/bindings/nodejs/lib/AccountManager.ts index 8b3cb0e94..3ac790a89 100644 --- a/bindings/nodejs/lib/AccountManager.ts +++ b/bindings/nodejs/lib/AccountManager.ts @@ -6,20 +6,21 @@ import { Account } from './Account'; import type { AccountId, - Auth, - EventType, AccountManagerOptions, - CreateAccountPayload, - NodeInfoWrapper, - ClientOptions, AccountSyncOptions, - WalletEvent, - LedgerNanoStatus, + Auth, + ClientOptions, + CreateAccountPayload, Event, EventId, - Node, EventStatus, + EventType, GenerateAddressOptions, + LedgerNanoStatus, + Node, + NodeInfoWrapper, + ParticipationEventType, + WalletEvent, } from '../types'; /** The AccountManager class. */ @@ -226,6 +227,16 @@ export class AccountManager { return JSON.parse(response).payload; } + async getParticipationEventIds(eventType?: ParticipationEventType): Promise { + const response = await this.messageHandler.sendMessage({ + cmd: 'getParticipationEventIds', + payload: { + eventType, + }, + }); + return JSON.parse(response).payload; + } + async getParticipationEvents(): Promise { const response = await this.messageHandler.sendMessage({ cmd: 'getParticipationEvents', diff --git a/bindings/nodejs/types/bridge/accountManager.ts b/bindings/nodejs/types/bridge/accountManager.ts index 664eb1202..065625ae7 100644 --- a/bindings/nodejs/types/bridge/accountManager.ts +++ b/bindings/nodejs/types/bridge/accountManager.ts @@ -6,7 +6,7 @@ import type { import type { GenerateAddressOptions } from '../address'; import type { WalletEvent } from '../event'; import type { Auth, ClientOptions, Node } from '../network'; -import type { EventId } from '../participation'; +import type { EventId, ParticipationEventType } from '../participation'; export type __BackupMessage__ = { cmd: 'backup'; @@ -97,6 +97,13 @@ export type __GetParticipationEventMessage__ = { }; }; +export type __GetParticipationEventIdsMessage__ = { + cmd: 'getParticipationEventIds'; + payload: { + eventType?: ParticipationEventType; + }; +}; + export type __GetParticipationEventsMessage__ = { cmd: 'getParticipationEvents'; }; diff --git a/bindings/nodejs/types/bridge/index.ts b/bindings/nodejs/types/bridge/index.ts index 741972a08..d839439d4 100644 --- a/bindings/nodejs/types/bridge/index.ts +++ b/bindings/nodejs/types/bridge/index.ts @@ -82,6 +82,7 @@ import type { __GetParticipationEventMessage__, __GetParticipationEventsMessage__, __GetParticipationEventStatusMessage__, + __GetParticipationEventIdsMessage__, } from './accountManager'; export type __AccountMethod__ = @@ -161,6 +162,7 @@ export type __Message__ = | __GenerateAddressMessage__ | __GetNodeInfoMessage__ | __GetParticipationEventMessage__ + | __GetParticipationEventIdsMessage__ | __GetParticipationEventsMessage__ | __GetParticipationEventStatusMessage__ | __HexToBech32__ diff --git a/src/message_interface/message.rs b/src/message_interface/message.rs index 41d01856a..a602195a7 100644 --- a/src/message_interface/message.rs +++ b/src/message_interface/message.rs @@ -7,7 +7,10 @@ use std::{ }; #[cfg(feature = "participation")] -use iota_client::{node_api::participation::types::EventId, node_manager::node::Node}; +use iota_client::{ + node_api::participation::types::{EventId, ParticipationEventType}, + node_manager::node::Node, +}; use iota_client::{node_manager::node::NodeAuth, secret::GenerateAddressOptions}; use serde::{Deserialize, Serialize}; @@ -213,6 +216,9 @@ pub enum Message { #[serde(rename = "eventId")] event_id: EventId, }, + /// Expected response: [`ParticipationEventIds`](crate::message_interface::Response::ParticipationEventIds) + #[cfg(feature = "participation")] + GetParticipationEventIds(Option), /// Expected response: [`ParticipationEventStatus`](crate::message_interface::Response::ParticipationEventStatus) #[cfg(feature = "participation")] GetParticipationEventStatus { @@ -321,6 +327,10 @@ impl Debug for Message { write!(f, "GetParticipationEvent({event_id:?})") } #[cfg(feature = "participation")] + Message::GetParticipationEventIds(event_type) => { + write!(f, "GetParticipationEventIds({event_type:?})") + } + #[cfg(feature = "participation")] Message::GetParticipationEventStatus { event_id } => { write!(f, "GetParticipationEventStatus({event_id:?})") } diff --git a/src/message_interface/message_handler.rs b/src/message_interface/message_handler.rs index f3ca9715a..42c2dde4f 100644 --- a/src/message_interface/message_handler.rs +++ b/src/message_interface/message_handler.rs @@ -370,6 +370,14 @@ impl WalletMessageHandler { .await } #[cfg(feature = "participation")] + Message::GetParticipationEventIds(event_type) => { + convert_async_panics(|| async { + let event_ids = self.account_manager.get_participation_event_ids(event_type).await?; + Ok(Response::ParticipationEventIds(event_ids)) + }) + .await + } + #[cfg(feature = "participation")] Message::GetParticipationEventStatus { event_id } => { convert_async_panics(|| async { let event_status = self.account_manager.get_participation_event_status(&event_id).await?; diff --git a/src/message_interface/response.rs b/src/message_interface/response.rs index 802e770ff..aef2ff5bf 100644 --- a/src/message_interface/response.rs +++ b/src/message_interface/response.rs @@ -19,7 +19,7 @@ use serde::Serialize; #[cfg(feature = "participation")] use { crate::account::operations::participation::AccountParticipationOverview, - iota_client::node_api::participation::types::{Event, EventStatus}, + iota_client::node_api::participation::types::{Event, EventId, EventStatus}, }; use crate::{ @@ -143,6 +143,10 @@ pub enum Response { #[cfg(feature = "participation")] ParticipationEvent(Option), /// Response for + /// [`GetParticipationEventIds`](crate::message_interface::GetParticipationEventIds) + #[cfg(feature = "participation")] + ParticipationEventIds(Vec), + /// Response for /// [`GetParticipationEventStatus`](crate::message_interface::GetParticipationEventStatus) #[cfg(feature = "participation")] ParticipationEventStatus(EventStatus), @@ -238,6 +242,8 @@ impl Debug for Response { #[cfg(feature = "participation")] Response::ParticipationEvents(events) => write!(f, "ParticipationEvents({events:?})"), #[cfg(feature = "participation")] + Response::ParticipationEventIds(event_ids) => write!(f, "ParticipationEventIds({event_ids:?})"), + #[cfg(feature = "participation")] Response::VotingPower(amount) => write!(f, "VotingPower({amount:?})"), #[cfg(feature = "participation")] Response::AccountParticipationOverview(overview) => {