diff --git a/Cargo.lock b/Cargo.lock index d47e642..fa40990 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -107,15 +107,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -148,9 +139,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.0" +version = "1.7.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "fca2be1d5c43812bae364ee3f30b3afcb7877cf59f4aeb94c66f313a41d2fac9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" @@ -166,9 +157,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cl-aux" -version = "5.0.0" +version = "5.0.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "6250f1186b49cf971d8af9c1c450e6c7bdda29abb1826d4cf8f9e2d8e9c662f6" +checksum = "5b3d3768cd9a63d040f842cebcd257c0ca78fc9acfc97b6b1a9d88b5648ee7ae" dependencies = [ "serde", "tinyvec", @@ -207,24 +198,28 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "3.2.0" +version = "4.1.3" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest", + "fiat-crypto", + "rustc_version", "subtle", - "zeroize", ] [[package]] -name = "digest" -version = "0.9.0" +name = "curve25519-dalek-derive" +version = "0.1.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "generic-array", + "proc-macro2", + "quote", + "syn 2.0.72", ] [[package]] @@ -233,7 +228,7 @@ version = "0.10.7" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", "crypto-common", ] @@ -245,23 +240,23 @@ checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" [[package]] name = "ed25519" -version = "1.5.3" +version = "2.2.3" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "signature", ] [[package]] name = "ed25519-dalek" -version = "1.0.1" +version = "2.1.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", "sha2", - "zeroize", + "subtle", ] [[package]] @@ -340,6 +335,12 @@ dependencies = [ "uint", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "fixed-hash" version = "0.8.0" @@ -610,12 +611,6 @@ version = "1.19.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -716,7 +711,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -726,15 +721,9 @@ source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.4" @@ -815,6 +804,15 @@ version = "2.1.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.23.12" @@ -862,6 +860,12 @@ version = "1.0.18" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+/~https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" version = "1.0.204" @@ -884,9 +888,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.121" +version = "1.0.122" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "4ab380d7d9f22ef3f21ad3e6c1ebe8e4fc7a2000ccba2e4d71fc96f15b2cb609" +checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", "memchr", @@ -902,20 +906,18 @@ checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest", ] [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.8" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer 0.9.0", "cfg-if", "cpufeatures", - "digest 0.9.0", - "opaque-debug", + "digest", ] [[package]] @@ -924,7 +926,7 @@ version = "0.10.8" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest 0.10.7", + "digest", "keccak", ] @@ -939,9 +941,9 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.4" +version = "2.2.0" source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" [[package]] name = "simdutf8" @@ -1433,17 +1435,3 @@ name = "zeroize" version = "1.8.1" source = "registry+/~https://github.com/rust-lang/crates.io-index" checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+/~https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] diff --git a/Cargo.toml b/Cargo.toml index 01d76c5..473f583 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ base64 = { default-features = false, features = ["alloc"], optional = true, vers bincode = { default-features = false, optional = true, version = "1.0" } bs58 = { default-features = false, features = ["alloc"], optional = true, version = "0.5" } cl-aux = { default-features = false, features = ["alloc", "serde"], version = "5.0" } -ed25519-dalek = { default-features = false, features = ["u64_backend"], optional = true, version = "1.0" } +ed25519-dalek = { default-features = false, optional = true, version = "2.0" } ethabi = { default-features = false, features = ["full-serde"], optional = true, version = "18.0" } ethereum-types = { default-features = false, features = ["serialize"], optional = true, version = "0.14" } hex = { default-features = false, optional = true, version = "0.4" } @@ -28,7 +28,7 @@ base64 = ["dep:base64"] bincode = ["dep:bincode"] bs58 = ["dep:bs58"] default = [] -ed25519-dalek = ["dep:ed25519-dalek", "std"] +ed25519-dalek = ["dep:ed25519-dalek"] ethabi = ["dep:ethabi"] ethereum = ["ethabi", "ethereum-types", "hex", "primitive-types"] ethereum-types = ["dep:ethereum-types"] diff --git a/src/blockchain/ethereum.rs b/src/blockchain/ethereum.rs index 60c7080..162acba 100644 --- a/src/blockchain/ethereum.rs +++ b/src/blockchain/ethereum.rs @@ -9,7 +9,7 @@ //! use wtx::client_api_framework::{dnsn::SerdeJson, network::HttpParams}; //! use wtx_apis::blockchain::ethereum::{Ethereum, PkgsAux}; //! -//! let mut pkgs_aux = PkgsAux::from_minimum(Ethereum, SerdeJson, HttpParams::from_uri("URL")); +//! let mut pkgs_aux = PkgsAux::from_minimum(Ethereum::new(None), SerdeJson, HttpParams::from_uri("URL")); //! let _ = pkgs_aux.eth_block_number().build(); //! # Ok(()) } //! ``` @@ -44,13 +44,30 @@ pub use transaction::Transaction; pub use transaction_condition::TransactionCondition; pub use transaction_request::TransactionRequest; pub use types::*; -use wtx::client_api_framework::Api; +use wtx::client_api_framework::{misc::RequestThrottling, Api}; #[derive(Debug)] #[doc = _generic_api_doc!()] #[wtx_macros::api_params(pkgs_aux(PkgsAux), transport(http, ws))] -pub struct Ethereum; +pub struct Ethereum { + /// If some, tells that each request must respect calling intervals. + pub rt: Option, +} + +impl Ethereum { + /// If desired, it is possible to instantiate directly instead of using this method. + pub const fn new(rt: Option) -> Self { + Self { rt } + } +} impl Api for Ethereum { type Error = crate::Error; + + async fn before_sending(&mut self) -> Result<(), Self::Error> { + if let Some(ref mut rt) = self.rt { + rt.rc.update_params(&rt.rl).await?; + } + Ok(()) + } } diff --git a/src/blockchain/ethereum/contract.rs b/src/blockchain/ethereum/contract.rs index 0a0e870..ab0215d 100644 --- a/src/blockchain/ethereum/contract.rs +++ b/src/blockchain/ethereum/contract.rs @@ -441,7 +441,7 @@ mod tests { trans: &mut Mock, ) -> Contract> { let pair = Pair::new( - EthereumPkgsAux::from_minimum(Ethereum, SerdeJson, HttpParams::from_uri("")), + EthereumPkgsAux::from_minimum(Ethereum::new(None), SerdeJson, HttpParams::from_uri("")), trans, ); Contract::from_json(Address::from_low_u64_be(1), pair, include_bytes!("./resources/token.json")) diff --git a/src/blockchain/ethereum/integration_tests.rs b/src/blockchain/ethereum/integration_tests.rs index ac8b548..707857a 100644 --- a/src/blockchain/ethereum/integration_tests.rs +++ b/src/blockchain/ethereum/integration_tests.rs @@ -1,8 +1,11 @@ use crate::blockchain::ethereum::{BlockNumber, Ethereum, PkgsAux}; +use core::time::Duration; use std::sync::LazyLock; +use tokio::sync::Mutex; use wtx::{ client_api_framework::{ dnsn::SerdeJson, + misc::{RequestLimit, RequestThrottling}, network::{transport::Transport, HttpParams}, }, http::ClientTokioRustls, @@ -10,18 +13,29 @@ use wtx::{ static CLIENT: LazyLock = LazyLock::new(|| ClientTokioRustls::tokio_rustls(1).build()); - -create_http_test!(Ethereum, http(), eth_block_number, &*CLIENT, |pkgs_aux, trans| async { - let _res = trans - .send_recv_decode_contained(&mut pkgs_aux.eth_block_number().build(), pkgs_aux) - .await - .unwrap() - .result - .unwrap(); +static ETHEREUM: LazyLock> = LazyLock::new(|| { + Mutex::new(Ethereum::new(Some(RequestThrottling::from_rl( + RequestLimit::new(1, Duration::from_secs(2)).unwrap(), + )))) }); create_http_test!( - Ethereum, + &mut *ETHEREUM.lock().await, + http(), + eth_block_number, + &*CLIENT, + |pkgs_aux, trans| async { + let _res = trans + .send_recv_decode_contained(&mut pkgs_aux.eth_block_number().build(), pkgs_aux) + .await + .unwrap() + .result + .unwrap(); + } +); + +create_http_test!( + &mut *ETHEREUM.lock().await, http(), eth_block_transaction_count_by_number, &*CLIENT, @@ -41,20 +55,26 @@ create_http_test!( } ); -create_http_test!(Ethereum, http(), eth_get_balance, &*CLIENT, |pkgs_aux, trans| async { - let _res = trans - .send_recv_decode_contained( - &mut pkgs_aux - .eth_get_balance() - .data("0xd6216fc19db775df9774a6e33526131da7d19a2c", &BlockNumber::Latest) - .build(), - pkgs_aux, - ) - .await - .unwrap() - .result - .unwrap(); -}); +create_http_test!( + &mut *ETHEREUM.lock().await, + http(), + eth_get_balance, + &*CLIENT, + |pkgs_aux, trans| async { + let _res = trans + .send_recv_decode_contained( + &mut pkgs_aux + .eth_get_balance() + .data("0xd6216fc19db775df9774a6e33526131da7d19a2c", &BlockNumber::Latest) + .build(), + pkgs_aux, + ) + .await + .unwrap() + .result + .unwrap(); + } +); fn http() -> (SerdeJson, HttpParams) { (SerdeJson, HttpParams::from_uri("https://cloudflare-eth.com:443")) diff --git a/src/blockchain/ethereum/pkg/eth_block_number.rs b/src/blockchain/ethereum/pkg/eth_block_number.rs index 4a5dc30..e051dbe 100644 --- a/src/blockchain/ethereum/pkg/eth_block_number.rs +++ b/src/blockchain/ethereum/pkg/eth_block_number.rs @@ -4,11 +4,11 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::EthereumHttpPkgsAux; + use crate::blockchain::ethereum::HttpPkgsAux; use ethereum_types::U64; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_block_transaction_count_by_number.rs b/src/blockchain/ethereum/pkg/eth_block_transaction_count_by_number.rs index 1f0ab3c..9b18cf6 100644 --- a/src/blockchain/ethereum/pkg/eth_block_transaction_count_by_number.rs +++ b/src/blockchain/ethereum/pkg/eth_block_transaction_count_by_number.rs @@ -4,11 +4,11 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{BlockNumber, EthereumHttpPkgsAux}; + use crate::blockchain::ethereum::{BlockNumber, HttpPkgsAux}; use ethereum_types::U256; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_call.rs b/src/blockchain/ethereum/pkg/eth_call.rs index a93f64b..f493e3d 100644 --- a/src/blockchain/ethereum/pkg/eth_call.rs +++ b/src/blockchain/ethereum/pkg/eth_call.rs @@ -4,10 +4,10 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{BlockId, CallRequest, EthereumHttpPkgsAux}; + use crate::blockchain::ethereum::{BlockId, CallRequest, HttpPkgsAux}; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_estimate_gas.rs b/src/blockchain/ethereum/pkg/eth_estimate_gas.rs index c02b82a..56fb139 100644 --- a/src/blockchain/ethereum/pkg/eth_estimate_gas.rs +++ b/src/blockchain/ethereum/pkg/eth_estimate_gas.rs @@ -4,11 +4,11 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{BlockNumber, CallRequest, EthereumHttpPkgsAux}; + use crate::blockchain::ethereum::{BlockNumber, CallRequest, HttpPkgsAux}; use ethereum_types::U256; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_get_balance.rs b/src/blockchain/ethereum/pkg/eth_get_balance.rs index d8c263c..84d989f 100644 --- a/src/blockchain/ethereum/pkg/eth_get_balance.rs +++ b/src/blockchain/ethereum/pkg/eth_get_balance.rs @@ -4,11 +4,11 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{BlockNumber, EthereumHttpPkgsAux}; + use crate::blockchain::ethereum::{BlockNumber, HttpPkgsAux}; use ethereum_types::U256; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_get_logs.rs b/src/blockchain/ethereum/pkg/eth_get_logs.rs index 9686e8d..1cd19d3 100644 --- a/src/blockchain/ethereum/pkg/eth_get_logs.rs +++ b/src/blockchain/ethereum/pkg/eth_get_logs.rs @@ -4,11 +4,11 @@ transport(http) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{EthereumHttpPkgsAux, Filter, Log}; + use crate::blockchain::ethereum::{Filter, HttpPkgsAux, Log}; use alloc::vec::Vec; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/ethereum/pkg/eth_send_transaction.rs b/src/blockchain/ethereum/pkg/eth_send_transaction.rs index ea2adea..f503787 100644 --- a/src/blockchain/ethereum/pkg/eth_send_transaction.rs +++ b/src/blockchain/ethereum/pkg/eth_send_transaction.rs @@ -4,11 +4,11 @@ transport(http, stub) )] pub(crate) mod pkg { - use crate::blockchain::ethereum::{EthereumHttpPkgsAux, TransactionRequest}; + use crate::blockchain::ethereum::{HttpPkgsAux, TransactionRequest}; use ethereum_types::H256; #[pkg::aux] - impl EthereumHttpPkgsAux {} + impl HttpPkgsAux {} #[derive(Debug, serde::Serialize)] #[pkg::req_data] diff --git a/src/blockchain/solana/integration_tests.rs b/src/blockchain/solana/integration_tests.rs index b430a10..b611e3f 100644 --- a/src/blockchain/solana/integration_tests.rs +++ b/src/blockchain/solana/integration_tests.rs @@ -799,12 +799,12 @@ create_http_test!( http_get_latest_blockhash_send_transaction_and_get_transaction, &*CLIENT, |pkgs_aux, trans| async { - let from_keypair = ed25519_dalek::Keypair::from_bytes(&alice_keypair()[..]).unwrap(); + let from_keypair = ed25519_dalek::SigningKey::from_bytes(&ALICE_SK); let blockhash = latest_blockhash(pkgs_aux, trans).await; let tx = crate::blockchain::solana::TransactionInput::new( &mut pkgs_aux.byte_buffer, blockhash, - transfer_message(blockhash, from_keypair.public.to_bytes()).into(), + transfer_message(blockhash, *ALICE_PK).into(), &[from_keypair], ) .unwrap(); @@ -983,14 +983,6 @@ create_ws_test!( } ); -#[cfg(feature = "ed25519-dalek")] -fn alice_keypair() -> [u8; 64] { - let mut array = [0; 64]; - array[..32].copy_from_slice(&*ALICE_SK); - array[32..].copy_from_slice(&*ALICE_PK); - array -} - fn http() -> (SerdeJson, HttpParams) { (SerdeJson, HttpParams::from_uri(HTTP_URI)) } diff --git a/src/blockchain/solana/transaction/transaction_input.rs b/src/blockchain/solana/transaction/transaction_input.rs index eb5c987..3bc31a2 100644 --- a/src/blockchain/solana/transaction/transaction_input.rs +++ b/src/blockchain/solana/transaction/transaction_input.rs @@ -4,7 +4,7 @@ use wtx::misc::Vector; #[cfg(feature = "ed25519-dalek")] use { crate::blockchain::solana::SolanaBlockhash, - ed25519_dalek::{Keypair, Signer}, + ed25519_dalek::{Signer, SigningKey}, }; /// Transport format suitable for user input. @@ -22,11 +22,11 @@ impl TransactionInput { /// Takes all the necessary parameters to validate and transform data into a suitable format for /// submission. #[cfg(feature = "ed25519-dalek")] - pub fn new<'keypair>( + pub fn new<'sk>( buffer: &mut Vector, blockhash: SolanaBlockhash, message: VersionedMessageInput, - keypairs: impl Clone + IntoIterator, + sk: impl Clone + IntoIterator, ) -> crate::Result { let mut this = Self { signatures: <_>::default(), message }; let VersionedMessageInput::V0(message) = &mut this.message; @@ -34,7 +34,7 @@ impl TransactionInput { message.recent_blockhash = blockhash; } this._set_empty_signatures()?; - this.do_sign(buffer, keypairs)?; + this.do_sign(buffer, sk)?; Ok(this) } @@ -56,26 +56,26 @@ impl TransactionInput { /// Signs or re-signs the contained message with the provided `blockhash` and `keypairs`. #[cfg(feature = "ed25519-dalek")] - pub fn sign<'keypair>( + pub fn sign<'sk>( &mut self, blockhash: SolanaBlockhash, buffer: &mut Vector, - keypairs: impl Clone + IntoIterator, + sk: impl Clone + IntoIterator, ) -> crate::Result<()> { let VersionedMessageInput::V0(message) = &mut self.message; if blockhash != message.recent_blockhash { message.recent_blockhash = blockhash; self.signatures.iter_mut().for_each(|signature| *signature = SolanaSignatureHash::default()); } - self.do_sign(buffer, keypairs)?; + self.do_sign(buffer, sk)?; Ok(()) } #[cfg(feature = "ed25519-dalek")] - fn do_sign<'keypair>( + fn do_sign<'sk>( &mut self, mut buffer: &mut Vector, - keypairs: impl Clone + IntoIterator, + sk: impl Clone + IntoIterator, ) -> crate::Result<()> { buffer.clear(); bincode::serialize_into(&mut buffer, &self.message)?; @@ -85,11 +85,11 @@ impl TransactionInput { .account_keys .get(0..message.header.num_required_signatures.into()) .unwrap_or_default(); - keypairs.clone().into_iter().map(|keypair| { - signed_keys.iter().position(|signed_key| keypair.public.as_bytes() == signed_key) + sk.clone().into_iter().map(|keypair| { + signed_keys.iter().position(|signed_key| keypair.verifying_key().as_ref() == signed_key) }) }; - for (opt, keypair) in signing_keypair_positions.zip(keypairs) { + for (opt, keypair) in signing_keypair_positions.zip(sk) { let signature = keypair.try_sign(buffer.as_ref())?.to_bytes(); let signature_mut = match opt.and_then(|idx| self.signatures.get_mut(idx)) { None => { diff --git a/src/error.rs b/src/error.rs index f8e29c1..8b2eb73 100644 --- a/src/error.rs +++ b/src/error.rs @@ -10,6 +10,8 @@ pub enum Error { /// See [bincode::Error]. #[cfg(feature = "solana")] Bincode(bincode::Error), + /// See [`cl_aux::Error`]. + ClAux(cl_aux::Error), /// See [ed25519_dalek::SignatureError]. #[cfg(feature = "ed25519-dalek")] Ed25519Dalek(ed25519_dalek::SignatureError), @@ -67,6 +69,13 @@ impl From for Error { } } +impl From for Error { + #[inline] + fn from(from: cl_aux::Error) -> Self { + Self::ClAux(from) + } +} + #[cfg(feature = "ed25519-dalek")] impl From for Error { #[inline]