Skip to content

Commit

Permalink
Add Rest client
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-lorenzini committed Nov 1, 2024
1 parent c16ed99 commit a439f54
Show file tree
Hide file tree
Showing 12 changed files with 271 additions and 103 deletions.
3 changes: 3 additions & 0 deletions rust/main/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rust/main/chains/hyperlane-sovereign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ version = "0.1.0"
edition.workspace = true

[dependencies]
async-trait.workspace = true

hyperlane-core = { path = "../../hyperlane-core", features = ["async"] }

async-trait.workspace = true
reqwest.workspace = true
serde_json.workspace = true
url.workspace = true
8 changes: 4 additions & 4 deletions rust/main/chains/hyperlane-sovereign/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
InterchainGasPaymaster, H256,
HyperlaneProvider, InterchainGasPaymaster, H256,
};

#[derive(Debug)]
Expand All @@ -28,17 +28,17 @@ impl SovereignInterchainGasPaymaster {
}

impl HyperlaneContract for SovereignInterchainGasPaymaster {
fn address(&self) -> hyperlane_core::H256 {
fn address(&self) -> H256 {
self.address
}
}

impl HyperlaneChain for SovereignInterchainGasPaymaster {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.provider.clone())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, InterchainSecurityModule, ModuleType, H256, U256,
HyperlaneMessage, HyperlaneProvider, InterchainSecurityModule, ModuleType, H256, U256,
};

#[derive(Debug)]
Expand All @@ -28,17 +28,17 @@ impl SovereignInterchainSecurityModule {
}

impl HyperlaneContract for SovereignInterchainSecurityModule {
fn address(&self) -> hyperlane_core::H256 {
fn address(&self) -> H256 {
self.address
}
}

impl HyperlaneChain for SovereignInterchainSecurityModule {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.provider.clone())
}
}
Expand All @@ -50,10 +50,14 @@ impl InterchainSecurityModule for SovereignInterchainSecurityModule {
_message: &HyperlaneMessage,
_metadata: &[u8],
) -> ChainResult<Option<U256>> {
todo!()
let result = self.provider.client().dry_run().await?;

Ok(result)
}

async fn module_type(&self) -> ChainResult<ModuleType> {
todo!()
let module_type = self.provider.client().module_type().await?;

Ok(module_type)
}
}
30 changes: 19 additions & 11 deletions rust/main/chains/hyperlane-sovereign/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl SovereignMailbox {
}

impl HyperlaneContract for SovereignMailbox {
fn address(&self) -> hyperlane_core::H256 {
todo!("fn address(&self) -> hyperlane_core::H256")
fn address(&self) -> H256 {
todo!()
}
}

Expand All @@ -51,8 +51,8 @@ impl HyperlaneChain for SovereignMailbox {

#[async_trait]
impl Mailbox for SovereignMailbox {
async fn count(&self, _lag: Option<NonZeroU64>) -> ChainResult<u32> {
let count = self.provider.grpc().get_count().await?;
async fn count(&self, lag: Option<NonZeroU64>) -> ChainResult<u32> {
let count = self.provider.client().get_count(lag).await?;

Ok(count)
}
Expand All @@ -61,19 +61,23 @@ impl Mailbox for SovereignMailbox {
let message_id = do_something_with_id(id);
let delivered = self
.provider
.grpc()
.client()
.get_delivered_status(message_id)
.await?;

Ok(delivered)
}

async fn default_ism(&self) -> ChainResult<H256> {
todo!("async fn default_ism(&self) -> ChainResult<H256>")
let ism = self.provider.client().default_ism().await?;

Ok(ism)
}

async fn recipient_ism(&self, _recipient: H256) -> ChainResult<H256> {
todo!("async fn recipient_ism(&self, recipient: H256) -> ChainResult<H256>")
let ism = self.provider.client().recipient_ism().await?;

Ok(ism)
}

async fn process(
Expand All @@ -82,21 +86,25 @@ impl Mailbox for SovereignMailbox {
_metadata: &[u8],
_tx_gas_limit: Option<U256>,
) -> ChainResult<TxOutcome> {
let _delivered = self.provider.grpc().process_message().await?;
let result = self.provider.client().process().await?;

todo!()
Ok(result)
}

async fn process_estimate_costs(
&self,
_message: &HyperlaneMessage,
_metadata: &[u8],
) -> ChainResult<TxCostEstimate> {
todo!("async fn process_estimate_costs(&self, message: &HyperlaneMessage, metadata: &[u8]) -> ChainResult<TxCostEstimate>")
let costs = self.provider.client().process_estimate_costs().await?;

Ok(costs)
}

fn process_calldata(&self, _message: &HyperlaneMessage, _metadata: &[u8]) -> Vec<u8> {
todo!("async fn process_calldata(&self, message: &HyperlaneMessage, metadata: &[u8]) -> Vec<u8>")
let calldata = self.provider.client().process_calldata();

calldata
}
}

Expand Down
20 changes: 13 additions & 7 deletions rust/main/chains/hyperlane-sovereign/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
accumulator::incremental::IncrementalMerkle, ChainResult, Checkpoint, ContractLocator,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, MerkleTreeHook, H256,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneProvider, MerkleTreeHook, H256,
};
use std::num::NonZeroU64;

Expand All @@ -29,32 +29,38 @@ impl SovereignMerkleTreeHook {
}

impl HyperlaneChain for SovereignMerkleTreeHook {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.provider.clone())
}
}

impl HyperlaneContract for SovereignMerkleTreeHook {
fn address(&self) -> hyperlane_core::H256 {
fn address(&self) -> H256 {
self.address
}
}

#[async_trait]
impl MerkleTreeHook for SovereignMerkleTreeHook {
async fn tree(&self, _lag: Option<NonZeroU64>) -> ChainResult<IncrementalMerkle> {
todo!()
let tree = self.provider.client().tree().await?;

Ok(tree)
}

async fn count(&self, _lag: Option<NonZeroU64>) -> ChainResult<u32> {
todo!()
let count = self.provider.client().count().await?;

Ok(count)
}

async fn latest_checkpoint(&self, _lag: Option<NonZeroU64>) -> ChainResult<Checkpoint> {
todo!()
let checkpoint = self.provider.client().latest_checkpoint().await?;

Ok(checkpoint)
}
}
12 changes: 7 additions & 5 deletions rust/main/chains/hyperlane-sovereign/src/multisig_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{ConnectionConf, Signer, SovereignProvider};
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, MultisigIsm, H256,
HyperlaneMessage, HyperlaneProvider, MultisigIsm, H256,
};

#[derive(Debug)]
Expand All @@ -28,17 +28,17 @@ impl SovereignMultisigIsm {
}

impl HyperlaneContract for SovereignMultisigIsm {
fn address(&self) -> hyperlane_core::H256 {
fn address(&self) -> H256 {
self.address
}
}

impl HyperlaneChain for SovereignMultisigIsm {
fn domain(&self) -> &hyperlane_core::HyperlaneDomain {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn hyperlane_core::HyperlaneProvider> {
fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.provider.clone())
}
}
Expand All @@ -49,6 +49,8 @@ impl MultisigIsm for SovereignMultisigIsm {
&self,
_message: &HyperlaneMessage,
) -> ChainResult<(Vec<H256>, u8)> {
todo!()
let validators = self.provider.client().validators_and_threshold().await?;

Ok(validators)
}
}
69 changes: 9 additions & 60 deletions rust/main/chains/hyperlane-sovereign/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use hyperlane_core::{
H256, U256,
};

mod rest_client;

/// A wrapper around a Sovereign provider to get generic blockchain information.
#[derive(Debug, Clone)]
pub struct SovereignProvider {
domain: HyperlaneDomain,
client: SovClient,
provider: SovProvider,
client: rest_client::SovereignRestClient,
#[allow(dead_code)]
signer: Option<Signer>,
}
Expand All @@ -21,20 +22,18 @@ impl SovereignProvider {
conf: &ConnectionConf,
signer: Option<Signer>,
) -> Self {
let provider = SovProvider::new(conf);
let client = SovClient::new(conf);
let client = rest_client::SovereignRestClient::new(conf);

Self {
domain,
client,
provider,
signer,
}
}

/// Get a grpc client.
pub fn grpc(&self) -> &SovProvider {
&self.provider
/// Get a rest client.
pub(crate) fn client(&self) -> &rest_client::SovereignRestClient {
&self.client
}
}

Expand All @@ -50,8 +49,8 @@ impl HyperlaneChain for SovereignProvider {

#[async_trait]
impl HyperlaneProvider for SovereignProvider {
async fn get_block_by_hash(&self, _hash: &H256) -> ChainResult<BlockInfo> {
let block = self.client.get_block_by_hash().await?;
async fn get_block_by_hash(&self, hash: &H256) -> ChainResult<BlockInfo> {
let block = self.client.get_block_by_hash(hash).await?;
Ok(block)
}

Expand All @@ -75,53 +74,3 @@ impl HyperlaneProvider for SovereignProvider {
Ok(metrics)
}
}

#[derive(Clone, Debug)]
pub struct SovClient {}

impl SovClient {
fn new(_conf: &ConnectionConf) -> Self {
SovClient {}
}

async fn get_block_by_hash(&self) -> ChainResult<BlockInfo> {
todo!()
}

async fn get_txn_by_hash(&self) -> ChainResult<TxnInfo> {
todo!()
}

async fn is_contract(&self) -> ChainResult<bool> {
todo!()
}

async fn get_balance(&self) -> ChainResult<U256> {
todo!()
}

async fn get_chain_metrics(&self) -> ChainResult<Option<ChainInfo>> {
todo!()
}
}

#[derive(Clone, Debug)]
pub struct SovProvider {}

impl SovProvider {
fn new(_conf: &ConnectionConf) -> Self {
todo!()
}

pub async fn get_count(&self) -> ChainResult<u32> {
todo!()
}

pub async fn get_delivered_status(&self, _message_id: u32) -> ChainResult<bool> {
todo!()
}

pub async fn process_message(&self) -> ChainResult<bool> {
todo!()
}
}
Loading

0 comments on commit a439f54

Please sign in to comment.