Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet namespace types #1448

Merged
merged 18 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rpc-types-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
29 changes: 29 additions & 0 deletions crates/rpc-types-wallet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "wallet-rpc-types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "wallet-rpc-types"
name = "alloy-wallet-rpc-types"

description = "Types for the 'wallet' Ethereum JSON-RPC namespace"

version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
exclude.workspace = true

[dependencies]
alloy-primitives = { workspace = true, features = ["map"] }
alloy-serde = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }

[features]
default = ["serde", "std"]
std = ["alloy-primitives/map"]
serde = [
"dep:serde",
"dep:alloy-serde"
]

[lints]
workspace = true
3 changes: 3 additions & 0 deletions crates/rpc-types-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# alloy-rpc-types-wallet

Type definitions of `wallet` Ethereum JSON-RPC namespace.
10 changes: 10 additions & 0 deletions crates/rpc-types-wallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod wallet;
pub use wallet::*;

80 changes: 80 additions & 0 deletions crates/rpc-types-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
use std::vec::Vec;
use alloy_primitives::{map::HashMap, Address, Bytes, ChainId, U256};

/// Type of permisssion values
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum PermissionValue {
/// Permission of boolean type
Bool(bool),
/// Array of permission values of String type
Array(Vec<String>),
/// Map of rpc call's capabilities
Dictionary(HashMap<String, String>),
/// Value of String type
Text(String)
}

/// Request that a wallet submits a batch of calls
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct SendCallsRequest {
/// RPC version
pub version: String,
/// Sender's address
pub from: Address,
/// A batch of calls to be submitted
pub calls: Vec<CallParams>,
/// Enabled permissions per chain
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub capabilities: Option<HashMap<String, PermissionValue>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just use serde value here and remove the permissionValue

}

/// Call parameters
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct CallParams {
/// Recepient address
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub to: Option<Address>,
/// Tx data field
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub data: Option<Bytes>,
/// Transfered value
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub value: Option<U256>,
/// Id of target chain
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub chain_id: Option<ChainId>
}

impl SendCallsRequest {
/// Creates new [SendCallsRequest]
pub const fn new(version: String, from: Address, calls: Vec<CallParams>, capabilities: Option<HashMap<String, PermissionValue>>) -> Self {
Self {version, from, calls, capabilities}
}
nadtech-hub marked this conversation as resolved.
Show resolved Hide resolved
}

impl CallParams {
/// Creates new [CallParams]
pub const fn new(to: Option<Address>, data: Option<Bytes>, value: Option<U256>, chain_id: Option<ChainId>) -> Self {
Self {to, data, value, chain_id}
}
}
nadtech-hub marked this conversation as resolved.
Show resolved Hide resolved

/// Response type for RPC call.
///
/// See [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792#wallet_getcapabilities)
pub type GetCapabilitiesResult = HashMap<ChainId, HashMap<String, PermissionValue>>;

/// Response type of wallet_sendCalls
pub type SendCallsResult = String;

/// Request params of RPC call wallet_getCapabilities
pub type GetCapabilitiesParams = Vec<Address>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove these aliases, these are not very useful


/// Alias for wallet_sendCalls params
pub type SendCallsParams = CallParams;