Skip to content

Commit

Permalink
Merge branch 'master' into feature/return-back-diskovery-test
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx authored May 3, 2024
2 parents 527ba9e + fd68745 commit b275b41
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 54 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- [#1879](https://github.com/FuelLabs/fuel-core/pull/1879): Return the old behaviour for the `discovery_works` test.
- [#1848](https://github.com/FuelLabs/fuel-core/pull/1848): Added `version` field to the `Block` and `BlockHeader` GraphQL entities. Added corresponding `version` field to the `Block` and `BlockHeader` client types in `fuel-core-client`.

## [Version 0.26.0]

Expand Down Expand Up @@ -40,7 +41,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- [#1844](https://github.com/FuelLabs/fuel-core/pull/1844): Fixed the publishing of the `fuel-core 0.25.1` release.
- [1842](https://github.com/FuelLabs/fuel-core/pull/1842): Ignore RUSTSEC-2024-0336: `rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network
- [#1842](https://github.com/FuelLabs/fuel-core/pull/1842): Ignore RUSTSEC-2024-0336: `rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network

## [Version 0.25.1]

Expand Down
13 changes: 13 additions & 0 deletions crates/client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ input BalanceFilterInput {
}

type Block {
version: BlockVersion!
id: BlockId!
height: U32!
header: Header!
Expand Down Expand Up @@ -83,6 +84,10 @@ type BlockEdge {

scalar BlockId

enum BlockVersion {
V1
}


"""
Breakpoint, defined as a tuple of contract ID and relative PC offset inside it
Expand Down Expand Up @@ -475,6 +480,10 @@ type Genesis {
}

type Header {
"""
Version of the header
"""
version: HeaderVersion!
"""
Hash of the header
"""
Expand Down Expand Up @@ -529,6 +538,10 @@ type Header {
applicationHash: Bytes32!
}

enum HeaderVersion {
V1
}

type HeavyOperation {
base: U64!
gasPerUnit: U64!
Expand Down
23 changes: 19 additions & 4 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,12 @@ impl FuelClient {
id: Some((*id).into()),
});

let block = self.query(query).await?.block.map(Into::into);
let block = self
.query(query)
.await?
.block
.map(TryInto::try_into)
.transpose()?;

Ok(block)
}
Expand All @@ -759,7 +764,12 @@ impl FuelClient {
height: Some(U32(height.into())),
});

let block = self.query(query).await?.block.map(Into::into);
let block = self
.query(query)
.await?
.block
.map(TryInto::try_into)
.transpose()?;

Ok(block)
}
Expand All @@ -771,7 +781,7 @@ impl FuelClient {
) -> io::Result<PaginatedResult<types::Block, String>> {
let query = schema::block::BlocksQuery::build(request.into());

let blocks = self.query(query).await?.blocks.into();
let blocks = self.query(query).await?.blocks.try_into()?;

Ok(blocks)
}
Expand Down Expand Up @@ -967,7 +977,12 @@ impl FuelClient {
commit_block_height,
});

let proof = self.query(query).await?.message_proof.map(Into::into);
let proof = self
.query(query)
.await?
.message_proof
.map(TryInto::try_into)
.transpose()?;

Ok(proof)
}
Expand Down
16 changes: 15 additions & 1 deletion crates/client/src/client/schema/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ pub struct BlockEdge {
pub node: Block,
}

/// Block with transactiuon ids
#[derive(cynic::Enum, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum BlockVersion {
V1,
}

/// Block with transaction ids
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Block {
pub version: BlockVersion,
pub id: BlockId,
pub header: Header,
pub consensus: Consensus,
Expand Down Expand Up @@ -115,9 +122,16 @@ pub struct BlockMutation {
pub produce_blocks: U32,
}

#[derive(cynic::Enum, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum HeaderVersion {
V1,
}

#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Header {
pub version: HeaderVersion,
pub id: BlockId,
pub da_height: U64,
pub consensus_parameters_version: U32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ expression: operation.query
---
query($height: U32) {
block(height: $height) {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ expression: operation.query
---
query($id: BlockId) {
block(id: $id) {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ query($after: String, $before: String, $first: Int, $last: Int) {
edges {
cursor
node {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ query {
daHeight
name
latestBlock {
version
id
header {
version
id
daHeight
consensusParametersVersion
Expand Down
98 changes: 60 additions & 38 deletions crates/client/src/client/types/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::client::{
schema,
schema::ConversionError,
types::primitives::{
BlockId,
Hash,
Expand All @@ -10,6 +11,11 @@ use crate::client::{
},
PaginatedResult,
};

use crate::client::schema::block::{
BlockVersion,
HeaderVersion,
};
use tai64::Tai64;

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -67,24 +73,28 @@ pub struct PoAConsensus {

// GraphQL Translation

impl From<schema::block::Header> for Header {
fn from(value: schema::block::Header) -> Self {
Self {
id: value.id.into(),
da_height: value.da_height.into(),
consensus_parameters_version: value.consensus_parameters_version.into(),
state_transition_bytecode_version: value
.state_transition_bytecode_version
.into(),
transactions_count: value.transactions_count.into(),
message_receipt_count: value.message_receipt_count.into(),
transactions_root: value.transactions_root.into(),
message_outbox_root: value.message_outbox_root.into(),
event_inbox_root: value.event_inbox_root.into(),
height: value.height.into(),
prev_root: value.prev_root.into(),
time: value.time.0,
application_hash: value.application_hash.into(),
impl TryFrom<schema::block::Header> for Header {
type Error = ConversionError;

fn try_from(value: schema::block::Header) -> Result<Self, Self::Error> {
match value.version {
HeaderVersion::V1 => Ok(Self {
id: value.id.into(),
da_height: value.da_height.into(),
consensus_parameters_version: value.consensus_parameters_version.into(),
state_transition_bytecode_version: value
.state_transition_bytecode_version
.into(),
transactions_count: value.transactions_count.into(),
message_receipt_count: value.message_receipt_count.into(),
transactions_root: value.transactions_root.into(),
message_outbox_root: value.message_outbox_root.into(),
event_inbox_root: value.event_inbox_root.into(),
height: value.height.into(),
prev_root: value.prev_root.into(),
time: value.time.0,
application_hash: value.application_hash.into(),
}),
}
}
}
Expand Down Expand Up @@ -124,32 +134,44 @@ impl From<schema::block::PoAConsensus> for PoAConsensus {
}
}

impl From<schema::block::Block> for Block {
fn from(value: schema::block::Block) -> Self {
let transactions = value
.transactions
.iter()
.map(|tx| tx.id.clone())
.map(Into::into)
.collect::<Vec<TransactionId>>();
let block_producer = value.block_producer();
Self {
id: value.id.into(),
header: value.header.into(),
consensus: value.consensus.into(),
transactions,
block_producer,
impl TryFrom<schema::block::Block> for Block {
type Error = ConversionError;

fn try_from(value: schema::block::Block) -> Result<Self, Self::Error> {
match value.version {
BlockVersion::V1 => {
let transactions = value
.transactions
.iter()
.map(|tx| tx.id.clone())
.map(Into::into)
.collect::<Vec<TransactionId>>();
let block_producer = value.block_producer();
Ok(Self {
id: value.id.into(),
header: value.header.try_into()?,
consensus: value.consensus.into(),
transactions,
block_producer,
})
}
}
}
}

impl From<schema::block::BlockConnection> for PaginatedResult<Block, String> {
fn from(conn: schema::block::BlockConnection) -> Self {
PaginatedResult {
impl TryFrom<schema::block::BlockConnection> for PaginatedResult<Block, String> {
type Error = ConversionError;

fn try_from(conn: schema::block::BlockConnection) -> Result<Self, Self::Error> {
Ok(PaginatedResult {
cursor: conn.page_info.end_cursor,
has_next_page: conn.page_info.has_next_page,
has_previous_page: conn.page_info.has_previous_page,
results: conn.edges.into_iter().map(|e| e.node.into()).collect(),
}
results: conn
.edges
.into_iter()
.map(|e| e.node.try_into())
.collect::<Result<_, _>>()?,
})
}
}
2 changes: 1 addition & 1 deletion crates/client/src/client/types/chain_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl TryFrom<schema::chain::ChainInfo> for ChainInfo {
Ok(Self {
da_height: value.da_height.into(),
name: value.name,
latest_block: value.latest_block.into(),
latest_block: value.latest_block.try_into()?,
consensus_parameters: value.consensus_parameters.try_into()?,
})
}
Expand Down
15 changes: 9 additions & 6 deletions crates/client/src/client/types/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::client::{
schema,
schema::ConversionError,
types::{
block::Header,
primitives::{
Expand Down Expand Up @@ -89,18 +90,20 @@ impl From<schema::message::MessageConnection> for PaginatedResult<Message, Strin
}
}

impl From<schema::message::MessageProof> for MessageProof {
fn from(value: schema::message::MessageProof) -> Self {
Self {
impl TryFrom<schema::message::MessageProof> for MessageProof {
type Error = ConversionError;

fn try_from(value: schema::message::MessageProof) -> Result<Self, Self::Error> {
Ok(Self {
message_proof: value.message_proof.into(),
block_proof: value.block_proof.into(),
message_block_header: value.message_block_header.into(),
commit_block_header: value.commit_block_header.into(),
message_block_header: value.message_block_header.try_into()?,
commit_block_header: value.commit_block_header.try_into()?,
sender: value.sender.into(),
recipient: value.recipient.into(),
nonce: value.nonce.into(),
amount: value.amount.into(),
data: value.data.into(),
}
})
}
}
Loading

0 comments on commit b275b41

Please sign in to comment.