Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorporate log data in receipts #88

Merged
merged 1 commit into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions assets/schema.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ type Receipt {
rawPayload: HexString!
result: U64
gasUsed: U64
data: HexString
}
enum ReceiptType {
CALL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ query Query($_0: HexString256!) {
len
result
gasUsed
data
}
script
scriptData
Expand Down
16 changes: 14 additions & 2 deletions fuel-client/src/client/schema/tx/tests/transparent_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::client::schema::{
schema, ConversionError, ConversionError::MissingField, HexString256, U64,
schema, ConversionError, ConversionError::MissingField, HexString, HexString256, U64,
};
use fuel_types::Word;

Expand Down Expand Up @@ -28,6 +28,7 @@ pub struct Receipt {
pub len: Option<U64>,
pub result: Option<U64>,
pub gas_used: Option<U64>,
pub data: Option<HexString>,
}

#[derive(cynic::Enum, Clone, Copy, Debug)]
Expand Down Expand Up @@ -119,7 +120,14 @@ impl TryFrom<Receipt> for fuel_vm::prelude::Receipt {
.len
.ok_or_else(|| MissingField("len".to_string()))?
.into(),
digest: Default::default(),
digest: schema
.digest
.ok_or_else(|| MissingField("digest".to_string()))?
.into(),
data: schema
.data
.ok_or_else(|| MissingField("data".to_string()))?
.into(),
pc: schema
.pc
.ok_or_else(|| MissingField("pc".to_string()))?
Expand Down Expand Up @@ -220,6 +228,10 @@ impl TryFrom<Receipt> for fuel_vm::prelude::Receipt {
.digest
.ok_or_else(|| MissingField("digest".to_string()))?
.into(),
data: schema
.data
.ok_or_else(|| MissingField("data".to_string()))?
.into(),
pc: schema
.pc
.ok_or_else(|| MissingField("pc".to_string()))?
Expand Down
2 changes: 1 addition & 1 deletion fuel-core/src/schema/scalars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl CursorType for SortedTxCursor {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, derive_more::Into, derive_more::From)]
pub struct HexString(pub(crate) Vec<u8>);

#[Scalar(name = "HexString")]
Expand Down
9 changes: 6 additions & 3 deletions fuel-core/src/schema/tx/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub enum ReceiptType {
ScriptResult,
}

impl From<TxReceipt> for ReceiptType {
fn from(r: TxReceipt) -> Self {
impl From<&TxReceipt> for ReceiptType {
fn from(r: &TxReceipt) -> Self {
match r {
TxReceipt::Call { .. } => ReceiptType::Call,
TxReceipt::Return { .. } => ReceiptType::Return,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Receipt {
self.0.len().map(Into::into)
}
async fn receipt_type(&self) -> ReceiptType {
self.0.into()
(&self.0).into()
}
async fn raw_payload(&self) -> HexString {
HexString(self.0.clone().to_bytes())
Expand All @@ -109,4 +109,7 @@ impl Receipt {
async fn gas_used(&self) -> Option<U64> {
self.0.gas_used().map(Into::into)
}
async fn data(&self) -> Option<HexString> {
self.0.data().map(|d| d.to_vec().into())
}
}