@@ -6,9 +6,13 @@ pub use alloy::rpc::types::{
6
6
Block , BlockId , BlockNumberOrTag , FeeHistory , Filter , FilterBlockOption , Log , Transaction ,
7
7
TransactionReceipt ,
8
8
} ;
9
+ use alloy_primitives:: FixedBytes ;
9
10
pub use alloy_primitives:: { Address , BlockHash , BlockNumber , Bytes , TxHash , U128 , U256 , U64 , U8 } ;
11
+ use alloy_sol_macro:: sol;
12
+ use alloy_sol_types:: SolCall ;
10
13
use serde:: { Deserialize , Serialize } ;
11
14
use std:: collections:: { HashMap , HashSet } ;
15
+ use std:: str:: FromStr ;
12
16
13
17
//
14
18
// types mirrored from runtime module
@@ -180,6 +184,20 @@ impl std::cmp::PartialEq<str> for NodeOrRpcUrl {
180
184
}
181
185
}
182
186
187
+ /// KiMap address. (simulation mode flag in process_lib?)
188
+ const KIMAP : & str = "0x0165878A594ca255338adfa4d48449f69242Eb8F" ;
189
+
190
+ // Sol structures for KiMap requests
191
+ sol ! {
192
+ function get (
193
+ bytes32 entryhash
194
+ ) external view returns (
195
+ address tokenBoundAccount,
196
+ address tokenOwner,
197
+ bytes memory note
198
+ ) ;
199
+ }
200
+
183
201
/// An EVM chain provider. Create this object to start making RPC calls.
184
202
/// Set the chain_id to determine which chain to call: requests will fail
185
203
/// unless the node this process is running on has access to a provider
@@ -554,6 +572,38 @@ impl Provider {
554
572
self . send_request_and_parse_response :: < Bytes > ( action)
555
573
}
556
574
575
+ /// Gets an entry from the KiMap.
576
+ ///
577
+ /// # Parameters
578
+ /// - `entryhash`: The entry to get from the KiMap.
579
+ /// # Returns
580
+ /// A `Result<(Address, Address, Option<Bytes>), EthError>` representing the TBA, owner, and value if the entry is a note.
581
+ pub fn get ( & self , entryhash : & str ) -> Result < ( Address , Address , Option < Bytes > ) , EthError > {
582
+ let get_call = getCall {
583
+ entryhash : FixedBytes :: < 32 > :: from_str ( entryhash)
584
+ . map_err ( |_| EthError :: InvalidParams ) ?,
585
+ }
586
+ . abi_encode ( ) ;
587
+
588
+ let tx_req = TransactionRequest :: default ( )
589
+ . input ( TransactionInput :: new ( get_call. into ( ) ) )
590
+ . to ( Address :: from_str ( KIMAP ) . unwrap ( ) ) ;
591
+
592
+ let res_bytes = self . call ( tx_req, None ) ?;
593
+
594
+ // note need new EthErrors for this! :)
595
+ let res = getCall:: abi_decode_returns ( & res_bytes, false )
596
+ . map_err ( |_| EthError :: RpcMalformedResponse ) ?;
597
+
598
+ let note_data = if res. note == Bytes :: default ( ) {
599
+ None
600
+ } else {
601
+ Some ( res. note )
602
+ } ;
603
+
604
+ Ok ( ( res. tokenBoundAccount , res. tokenOwner , note_data) )
605
+ }
606
+
557
607
/// Sends a raw transaction to the network.
558
608
///
559
609
/// # Parameters
0 commit comments