fuel_core_client/client/schema/
message.rsuse super::{
block::Header,
BlockId,
Bytes32,
HexString,
PageInfo,
TransactionId,
};
use crate::client::{
pagination::{
PageDirection,
PaginationRequest,
},
schema::{
schema,
Address,
Nonce,
U32,
U64,
},
};
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct Message {
pub amount: U64,
pub sender: Address,
pub recipient: Address,
pub nonce: Nonce,
pub data: HexString,
pub da_height: U64,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct NonceArgs {
pub nonce: Nonce,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "NonceArgs"
)]
pub struct MessageQuery {
#[arguments(nonce: $nonce)]
pub message: Option<Message>,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct MessageStatus {
pub(crate) state: MessageState,
}
#[derive(cynic::Enum, Clone, Copy, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub enum MessageState {
Unspent,
Spent,
NotFound,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "OwnedMessagesConnectionArgs"
)]
pub struct OwnedMessageQuery {
#[arguments(owner: $owner, after: $after, before: $before, first: $first, last: $last)]
pub messages: MessageConnection,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct MessageConnection {
pub edges: Vec<MessageEdge>,
pub page_info: PageInfo,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct MessageEdge {
pub cursor: String,
pub node: Message,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct OwnedMessagesConnectionArgs {
pub owner: Option<Address>,
pub after: Option<String>,
pub before: Option<String>,
pub first: Option<i32>,
pub last: Option<i32>,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "MessageProofArgs"
)]
pub struct MessageProofQuery {
#[arguments(
transactionId: $transaction_id,
nonce: $nonce,
commitBlockId: $commit_block_id,
commitBlockHeight: $commit_block_height
)]
pub message_proof: Option<MessageProof>,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct MerkleProof {
pub proof_set: Vec<Bytes32>,
pub proof_index: U64,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct MessageProof {
pub message_proof: MerkleProof,
pub block_proof: MerkleProof,
pub message_block_header: Header,
pub commit_block_header: Header,
pub sender: Address,
pub recipient: Address,
pub nonce: Nonce,
pub amount: U64,
pub data: HexString,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct MessageProofArgs {
pub transaction_id: TransactionId,
pub nonce: Nonce,
pub commit_block_id: Option<BlockId>,
pub commit_block_height: Option<U32>,
}
#[derive(cynic::QueryFragment, Clone, Debug)]
#[cynic(
schema_path = "./assets/schema.sdl",
graphql_type = "Query",
variables = "MessageStatusArgs"
)]
pub struct MessageStatusQuery {
#[arguments(nonce: $nonce)]
pub message_status: MessageStatus,
}
#[derive(cynic::QueryVariables, Debug)]
pub struct MessageStatusArgs {
pub nonce: Nonce,
}
impl From<(Option<Address>, PaginationRequest<String>)> for OwnedMessagesConnectionArgs {
fn from(r: (Option<Address>, PaginationRequest<String>)) -> Self {
match r.1.direction {
PageDirection::Forward => OwnedMessagesConnectionArgs {
owner: r.0,
after: r.1.cursor,
before: None,
first: Some(r.1.results),
last: None,
},
PageDirection::Backward => OwnedMessagesConnectionArgs {
owner: r.0,
after: None,
before: r.1.cursor,
first: None,
last: Some(r.1.results),
},
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn owned_message_query_gql_output() {
use cynic::QueryBuilder;
let operation = OwnedMessageQuery::build(OwnedMessagesConnectionArgs {
owner: Some(Address::default()),
after: None,
before: None,
first: None,
last: None,
});
insta::assert_snapshot!(operation.query)
}
}