Returns code at a given address.
(
data: JsonRpcData<C>,
Params((address, block_id)): Params<(et::H160, et::BlockId)>,
)
| 812 | |
| 813 | /// Returns code at a given address. |
| 814 | pub async fn get_code<C>( |
| 815 | data: JsonRpcData<C>, |
| 816 | Params((address, block_id)): Params<(et::H160, et::BlockId)>, |
| 817 | ) -> JsonRpcResult<et::Bytes> |
| 818 | where |
| 819 | C: Client + Sync + Send, |
| 820 | { |
| 821 | let height = data.query_height(block_id).await?; |
| 822 | |
| 823 | // Return empty if not an EVM actor. |
| 824 | if data.get_actor_type(&address, height).await? != ActorType::EVM { |
| 825 | return Ok(Default::default()); |
| 826 | } |
| 827 | |
| 828 | // This method has no input parameters. |
| 829 | let params = RawBytes::default(); |
| 830 | |
| 831 | let ret = data |
| 832 | .read_evm_actor::<evm::BytecodeReturn>(address, evm::Method::GetBytecode, params, height) |
| 833 | .await?; |
| 834 | |
| 835 | match ret.and_then(|r| r.code) { |
| 836 | None => Ok(et::Bytes::default()), |
| 837 | Some(cid) => { |
| 838 | let code = data |
| 839 | .client |
| 840 | .ipld(&cid, height) |
| 841 | .await |
| 842 | .context("failed to fetch bytecode")?; |
| 843 | |
| 844 | Ok(code.map(et::Bytes::from).unwrap_or_default()) |
| 845 | } |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | /// Returns an object with data about the sync status or false. |
| 850 | pub async fn syncing<C>(data: JsonRpcData<C>) -> JsonRpcResult<et::SyncingStatus> |
nothing calls this directly
no test coverage detected