Skip to content

Commit

Permalink
UtxoId changes (#114)
Browse files Browse the repository at this point in the history
* UtxoId changes

* Some nitpicks
  • Loading branch information
rakita authored Jan 18, 2022
1 parent 8dc1299 commit 82bfb4d
Show file tree
Hide file tree
Showing 24 changed files with 284 additions and 173 deletions.
68 changes: 51 additions & 17 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions fuel-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ chrono = { version = "0.4", features = ["serde"] }
cynic = { version = "0.14", features = ["surf"] }
derive_more = { version = "0.99" }
fuel-storage = "0.1"
fuel-tx = { version = "0.1", features = ["serde-types"] }
fuel-tx = { version = "0.2", features = ["serde-types"] }
fuel-types = { version = "0.1", features = ["serde-types"] }
fuel-vm = { version = "0.1", features = ["serde-types"] }
fuel-vm = { version = "0.2", features = ["serde-types"] }
futures = "0.3"
hex = "0.4"
serde = { version = "1.0", features = ["derive"] }
Expand All @@ -36,9 +36,9 @@ surf = "2.2"
thiserror = "1.0"

[dev-dependencies]
fuel-gql-client = { path = ".", features = ["test-helpers"] }
fuel-core = { path = "../fuel-core", features = ["test-helpers"] }
fuel-vm = { version = "0.1", features = ["serde-types", "random"] }
fuel-gql-client = { path = ".", features = ["test-helpers"] }
fuel-vm = { version = "0.2", features = ["serde-types", "random"] }
insta = "1.8"
itertools = "0.10"
rand = "0.8"
Expand Down
9 changes: 5 additions & 4 deletions fuel-client/assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ChangeOutput {
color: HexString256!
}
type Coin {
id: HexString256!
utxoId: HexStringUtxoId!
owner: HexString256!
amount: U64!
color: HexString256!
Expand Down Expand Up @@ -111,9 +111,10 @@ type FailureStatus {
}
scalar HexString
scalar HexString256
scalar HexStringUtxoId
union Input = | InputCoin | InputContract
type InputCoin {
utxoId: HexString256!
utxoId: HexStringUtxoId!
owner: HexString256!
amount: Int!
color: HexString256!
Expand All @@ -123,7 +124,7 @@ type InputCoin {
predicateData: HexString!
}
type InputContract {
utxoId: HexString256!
utxoId: HexStringUtxoId!
balanceRoot: HexString256!
stateRoot: HexString256!
contractId: HexString256!
Expand Down Expand Up @@ -178,7 +179,7 @@ type Query {
Returns true when the GraphQL API is serving requests.
"""
health: Boolean!
coin(id: HexString256!): Coin
coin(utxoId: HexStringUtxoId!): Coin
coins(after: String, before: String, first: Int, last: Int, filter: CoinFilterInput!): CoinConnection!
}
type Receipt {
Expand Down
4 changes: 3 additions & 1 deletion fuel-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ impl FuelClient {
}

pub async fn coin(&self, id: &str) -> io::Result<Option<Coin>> {
let query = schema::coin::CoinByIdQuery::build(CoinByIdArgs { id: id.parse()? });
let query = schema::coin::CoinByIdQuery::build(CoinByIdArgs {
utxo_id: id.parse()?,
});
let coin = self.query(query).await?.coin;
Ok(coin)
}
Expand Down
10 changes: 5 additions & 5 deletions fuel-client/src/client/schema/coin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::client::schema::{schema, HexString256, PageInfo, U64};
use crate::client::schema::{schema, HexString256, HexStringUtxoId, PageInfo, U64};
use crate::client::{PageDirection, PaginatedResult, PaginationRequest};

#[derive(cynic::FragmentArguments, Debug)]
pub struct CoinByIdArgs {
pub id: HexString256,
pub utxo_id: HexStringUtxoId,
}

#[derive(cynic::QueryFragment, Debug)]
Expand All @@ -13,7 +13,7 @@ pub struct CoinByIdArgs {
argument_struct = "CoinByIdArgs"
)]
pub struct CoinByIdQuery {
#[arguments(id = &args.id)]
#[arguments(utxo_id = &args.utxo_id)]
pub coin: Option<Coin>,
}

Expand Down Expand Up @@ -113,7 +113,7 @@ pub struct Coin {
pub amount: U64,
pub block_created: U64,
pub color: HexString256,
pub id: HexString256,
pub utxo_id: HexStringUtxoId,
pub maturity: U64,
pub owner: HexString256,
pub status: CoinStatus,
Expand All @@ -134,7 +134,7 @@ mod tests {
fn coin_by_id_query_gql_output() {
use cynic::QueryBuilder;
let operation = CoinByIdQuery::build(CoinByIdArgs {
id: HexString256::default(),
utxo_id: HexStringUtxoId::default(),
});
insta::assert_snapshot!(operation.query)
}
Expand Down
19 changes: 19 additions & 0 deletions fuel-client/src/client/schema/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::schema;
use crate::client::schema::ConversionError;
use crate::client::schema::ConversionError::HexStringPrefixError;
use cynic::impl_scalar;
use fuel_tx::UtxoId;
use fuel_types::{Address, Bytes32, Color, ContractId, Salt};
use serde::de::Error;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down Expand Up @@ -93,6 +94,24 @@ impl From<HexString256> for Salt {
}
}

#[derive(cynic::Scalar, Debug, Clone, Default)]
pub struct HexStringUtxoId(pub HexFormatted<UtxoId>);

impl FromStr for HexStringUtxoId {
type Err = ConversionError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let b = HexFormatted::<UtxoId>::from_str(s)?;
Ok(HexStringUtxoId(b))
}
}

impl From<HexStringUtxoId> for UtxoId {
fn from(s: HexStringUtxoId) -> Self {
s.0 .0
}
}

#[derive(cynic::Scalar, Debug, Clone)]
pub struct HexString(pub Bytes);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
source: fuel-client/src/client/schema/coin.rs
assertion_line: 124
expression: operation.query

---
query Query($_0: HexString256!) {
coin(id: $_0) {
query Query($_0: HexStringUtxoId!) {
coin(utxoId: $_0) {
amount
blockCreated
color
id
utxoId
maturity
owner
status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ query Query($_0: CoinFilterInput!, $_1: String, $_2: String, $_3: Int, $_4: Int)
amount
blockCreated
color
id
utxoId
maturity
owner
status
Expand Down
6 changes: 3 additions & 3 deletions fuel-client/src/client/schema/tx/tests/transparent_tx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::client::schema::{
schema,
tx::{tests::transparent_receipt::Receipt, TransactionStatus, TxIdArgs},
ConnectionArgs, ConversionError, HexString, HexString256, PageInfo,
ConnectionArgs, ConversionError, HexString, HexString256, HexStringUtxoId, PageInfo,
};
use core::convert::{TryFrom, TryInto};

Expand Down Expand Up @@ -146,7 +146,7 @@ pub enum Input {
#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct InputCoin {
pub utxo_id: HexString256,
pub utxo_id: HexStringUtxoId,
pub owner: HexString256,
pub amount: i32,
pub color: HexString256,
Expand All @@ -159,7 +159,7 @@ pub struct InputCoin {
#[derive(cynic::QueryFragment, Debug)]
#[cynic(schema_path = "./assets/schema.sdl")]
pub struct InputContract {
pub utxo_id: HexString256,
pub utxo_id: HexStringUtxoId,
pub balance_root: HexString256,
pub state_root: HexString256,
pub contract_id: HexString256,
Expand Down
Loading

0 comments on commit 82bfb4d

Please sign in to comment.