-
Notifications
You must be signed in to change notification settings - Fork 236
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
Changes from 6 commits
9b798f8
8f1338a
430939c
c0c8baa
b93ff61
5c4f886
e651a5c
0263d18
96448fd
a57e1c5
3920e7b
86ae879
45ade56
dc1776d
3a1a025
f830b28
98b2dc4
38e9e05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Changelog |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "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 |
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. |
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::*; | ||
|
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>> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use a copy of these types here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.