-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: update progress on allocation query response server
- Loading branch information
1 parent
0a595fd
commit 9116886
Showing
9 changed files
with
140 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::keys; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub(crate) struct Allocations { | ||
meta: Meta, | ||
allocations: Vec<AllocationFragment>, | ||
} | ||
|
||
impl Allocations { | ||
pub fn new(indexer: keys::Indexer) -> Self { | ||
Allocations { | ||
meta: Meta { | ||
block: Block { | ||
number: 123, | ||
hash: "0x0000000000000000000000000000000000000000000000000000000000000000" | ||
.into(), | ||
timestamp: "2021-01-01T00:00:00Z".into(), | ||
}, | ||
}, | ||
allocations: vec![AllocationFragment { | ||
id: "0x123".into(), // TODO: "<allocation id address>" | ||
indexer: Indexer { | ||
id: indexer.address.to_string(), | ||
}, | ||
allocated_tokens: "0".into(), | ||
created_at_block_hash: | ||
"0x0000000000000000000000000000000000000000000000000000000000000000".into(), | ||
created_at_epoch: "1".into(), | ||
closed_at_epoch: None, | ||
subgraph_deployment: SubgraphDeployment { | ||
id: "QmUhiH6Z5xo6o3GNzsSvqpGKLmCt6w5WzKQ1yHk6C8AA8S".into(), | ||
denied_at: "0".into(), | ||
}, | ||
}], | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct AllocationFragment { | ||
id: String, | ||
indexer: Indexer, | ||
allocated_tokens: String, | ||
created_at_block_hash: String, | ||
created_at_epoch: String, | ||
closed_at_epoch: Option<String>, | ||
subgraph_deployment: SubgraphDeployment, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Indexer { | ||
id: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct SubgraphDeployment { | ||
id: String, | ||
denied_at: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Meta { | ||
block: Block, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Block { | ||
number: u128, | ||
hash: String, | ||
timestamp: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![allow(dead_code)] | ||
|
||
use std::{ | ||
fs::File, | ||
io::{self, Write}, | ||
}; | ||
|
||
use alloy::{ | ||
primitives::Address, | ||
signers::{k256::ecdsa::SigningKey, local::LocalSigner}, | ||
}; | ||
use indexer_tap_agent::tap::test_utils::wallet; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Indexer { | ||
pub signer: LocalSigner<SigningKey>, | ||
pub address: Address, | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct QuerySender(pub Address); | ||
|
||
pub fn manage_keys() -> io::Result<(Indexer, QuerySender)> { | ||
let (signer1, address1) = wallet(0); | ||
let (signer2, address2) = wallet(1); | ||
|
||
write_to_file("indexer_wallet", &signer1)?; | ||
write_to_file("sender_wallet", &signer2)?; | ||
|
||
let indexer = Indexer { | ||
signer: signer1, | ||
address: address1, | ||
}; | ||
let sender = QuerySender(address2); | ||
|
||
Ok((indexer, sender)) | ||
} | ||
|
||
fn write_to_file(path: &str, signer: &LocalSigner<SigningKey>) -> io::Result<()> { | ||
let mut file = File::create(path)?; | ||
file.write_all(signer.to_bytes().as_slice())?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod allocations; | ||
pub mod bootstrap; | ||
mod keys; | ||
mod subgraph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,15 @@ | ||
use axum::{response::IntoResponse, Json}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{allocations::Allocations, keys::Indexer}; | ||
|
||
pub(crate) const NETWORK_SUBGRAPH_ROUTE: &str = "/network_subgraph"; | ||
|
||
pub(crate) async fn network_subgraph() -> impl IntoResponse { | ||
Json(GraphqlResponse::Allocations(Allocations { | ||
..Default::default() | ||
})) | ||
pub(crate) async fn network_subgraph(indexer: Indexer) -> impl IntoResponse { | ||
Json(GraphqlResponse::Allocations(Allocations::new(indexer))) | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
enum GraphqlResponse { | ||
pub(crate) enum GraphqlResponse { | ||
Allocations(Allocations), | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Allocations { | ||
meta: Meta, | ||
allocations: Vec<AllocationFragment>, | ||
} | ||
|
||
impl Default for Allocations { | ||
fn default() -> Self { | ||
Allocations { | ||
meta: Meta { | ||
block: Block { | ||
number: 1, | ||
hash: "0x123".into(), | ||
timestamp: "2021-01-01T00:00:00Z".into(), | ||
}, | ||
}, | ||
allocations: vec![AllocationFragment { | ||
id: "0x123".into(), | ||
indexer: Indexer { id: "0x456".into() }, | ||
allocated_tokens: "100".into(), | ||
created_at_block_hash: "0x789".into(), | ||
created_at_epoch: "1".into(), | ||
closed_at_epoch: None, | ||
subgraph_deployment: SubgraphDeployment { | ||
id: "0xabc".into(), | ||
denied_at: "0".into(), | ||
}, | ||
}], | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
struct AllocationFragment { | ||
id: String, | ||
indexer: Indexer, | ||
allocated_tokens: String, | ||
created_at_block_hash: String, | ||
created_at_epoch: String, | ||
closed_at_epoch: Option<String>, | ||
subgraph_deployment: SubgraphDeployment, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Indexer { | ||
id: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct SubgraphDeployment { | ||
id: String, | ||
denied_at: String, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Meta { | ||
block: Block, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
struct Block { | ||
number: u128, | ||
hash: String, | ||
timestamp: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters