Returns code at a given address.
(
data: JsonRpcData<C>,
Params((address, block_id)): Params<(et::H160, et::BlockId)>,
)
| 834 | |
| 835 | /// Returns code at a given address. |
| 836 | pub async fn get_code<C>( |
| 837 | data: JsonRpcData<C>, |
| 838 | Params((address, block_id)): Params<(et::H160, et::BlockId)>, |
| 839 | ) -> JsonRpcResult<et::Bytes> |
| 840 | where |
| 841 | C: Client + Sync + Send, |
| 842 | { |
| 843 | let height = data.query_height(block_id).await?; |
| 844 | |
| 845 | // Return empty if not an EVM actor. |
| 846 | if data.get_actor_type(&address, height).await? != ActorType::EVM { |
| 847 | return Ok(Default::default()); |
| 848 | } |
| 849 | |
| 850 | // This method has no input parameters. |
| 851 | let params = RawBytes::default(); |
| 852 | |
| 853 | let ret = data |
| 854 | .read_evm_actor::<evm::BytecodeReturn>(address, evm::Method::GetBytecode, params, height) |
| 855 | .await?; |
| 856 | |
| 857 | match ret.and_then(|r| r.code) { |
| 858 | None => Ok(et::Bytes::default()), |
| 859 | Some(cid) => { |
| 860 | let code = data |
| 861 | .client |
| 862 | .ipld(&cid, height) |
| 863 | .await |
| 864 | .context("failed to fetch bytecode")?; |
| 865 | |
| 866 | Ok(code.map(et::Bytes::from).unwrap_or_default()) |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | /// Returns an object with data about the sync status or false. |
| 872 | pub async fn syncing<C>(data: JsonRpcData<C>) -> JsonRpcResult<et::SyncingStatus> |
nothing calls this directly
no test coverage detected