Skip to content

Commit

Permalink
chore: update NodeJS bindings for participation method (#1717)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
maxwellmattryan and thibault-martinez authored Jan 10, 2023
1 parent 38dcadd commit 5c0141c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand Down
27 changes: 19 additions & 8 deletions bindings/nodejs/lib/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -226,6 +227,16 @@ export class AccountManager {
return JSON.parse(response).payload;
}

async getParticipationEventIds(eventType?: ParticipationEventType): Promise<EventId[]> {
const response = await this.messageHandler.sendMessage({
cmd: 'getParticipationEventIds',
payload: {
eventType,
},
});
return JSON.parse(response).payload;
}

async getParticipationEvents(): Promise<Event[]> {
const response = await this.messageHandler.sendMessage({
cmd: 'getParticipationEvents',
Expand Down
9 changes: 8 additions & 1 deletion bindings/nodejs/types/bridge/accountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -97,6 +97,13 @@ export type __GetParticipationEventMessage__ = {
};
};

export type __GetParticipationEventIdsMessage__ = {
cmd: 'getParticipationEventIds';
payload: {
eventType?: ParticipationEventType;
};
};

export type __GetParticipationEventsMessage__ = {
cmd: 'getParticipationEvents';
};
Expand Down
2 changes: 2 additions & 0 deletions bindings/nodejs/types/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import type {
__GetParticipationEventMessage__,
__GetParticipationEventsMessage__,
__GetParticipationEventStatusMessage__,
__GetParticipationEventIdsMessage__,
} from './accountManager';

export type __AccountMethod__ =
Expand Down Expand Up @@ -161,6 +162,7 @@ export type __Message__ =
| __GenerateAddressMessage__
| __GetNodeInfoMessage__
| __GetParticipationEventMessage__
| __GetParticipationEventIdsMessage__
| __GetParticipationEventsMessage__
| __GetParticipationEventStatusMessage__
| __HexToBech32__
Expand Down
12 changes: 11 additions & 1 deletion src/message_interface/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<ParticipationEventType>),
/// Expected response: [`ParticipationEventStatus`](crate::message_interface::Response::ParticipationEventStatus)
#[cfg(feature = "participation")]
GetParticipationEventStatus {
Expand Down Expand Up @@ -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:?})")
}
Expand Down
8 changes: 8 additions & 0 deletions src/message_interface/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
8 changes: 7 additions & 1 deletion src/message_interface/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -143,6 +143,10 @@ pub enum Response {
#[cfg(feature = "participation")]
ParticipationEvent(Option<Event>),
/// Response for
/// [`GetParticipationEventIds`](crate::message_interface::GetParticipationEventIds)
#[cfg(feature = "participation")]
ParticipationEventIds(Vec<EventId>),
/// Response for
/// [`GetParticipationEventStatus`](crate::message_interface::GetParticipationEventStatus)
#[cfg(feature = "participation")]
ParticipationEventStatus(EventStatus),
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 5c0141c

Please sign in to comment.