Skip to content

Commit

Permalink
fix: remove tag from receipt result container
Browse files Browse the repository at this point in the history
fix: try with receipt error

fix: add tag to operation content
  • Loading branch information
zcabter committed Nov 18, 2024
1 parent 18dedda commit eb1a5a3
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 149 deletions.
8 changes: 4 additions & 4 deletions crates/jstz_cli/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use boa_engine::JsError;
use jstz_proto::{
context::account::ParsedCode,
operation::{Content, DeployFunction, Operation, SignedOperation},
receipt::ReceiptContent,
receipt::{ReceiptContent, ReceiptResult},
};
use log::{debug, info};

Expand Down Expand Up @@ -96,11 +96,11 @@ pub async fn exec(
debug!("Receipt: {:?}", receipt);

let address = match receipt.inner {
Ok(ReceiptContent::DeployFunction(deploy)) => deploy.address,
Ok(_) => {
ReceiptResult::Success(ReceiptContent::DeployFunction(deploy)) => deploy.address,
ReceiptResult::Success(_) => {
bail!("Expected a `DeployFunction` receipt, but got something else.")
}
Err(err) => {
ReceiptResult::Failed { source: err } => {
bail_user_error!("Failed to deploy smart function with error {err:?}.")
}
};
Expand Down
10 changes: 6 additions & 4 deletions crates/jstz_cli/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jstz_proto::context::account::Address;
use jstz_proto::executor::JSTZ_HOST;
use jstz_proto::{
operation::{Content as OperationContent, Operation, RunFunction, SignedOperation},
receipt::ReceiptContent,
receipt::{ReceiptContent, ReceiptResult},
};
use log::{debug, info};
use spinners::{Spinner, Spinners};
Expand Down Expand Up @@ -165,14 +165,16 @@ pub async fn exec(

debug!("Receipt: {:?}", receipt);
let (status_code, headers, body) = match receipt.inner {
Ok(ReceiptContent::RunFunction(run_function)) => (
ReceiptResult::Success(ReceiptContent::RunFunction(run_function)) => (
run_function.status_code,
run_function.headers,
run_function.body,
),
Ok(_) => bail!("Expected a `RunFunction` receipt, but got something else."),
ReceiptResult::Success(_) => {
bail!("Expected a `RunFunction` receipt, but got something else.")
}

Err(err) => bail_user_error!("{err}"),
ReceiptResult::Failed { source: err } => bail_user_error!("{err}"),
};

if let Some(spinner) = spinner.as_mut() {
Expand Down
232 changes: 124 additions & 108 deletions crates/jstz_node/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@
}
}
}
]
],
"title": "DeployFunction"
},
{
"allOf": [
Expand All @@ -461,7 +462,8 @@
}
}
}
]
],
"title": "RunFunction"
}
]
},
Expand Down Expand Up @@ -667,122 +669,130 @@
"type": "string"
},
"inner": {
"$ref": "#/components/schemas/ReceiptResult_ReceiptContent"
"$ref": "#/components/schemas/ReceiptResult"
}
}
},
"ReceiptResult_ReceiptContent": {
"ReceiptContent": {
"oneOf": [
{
"allOf": [
{
"oneOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/DeployFunctionReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"DeployFunction"
]
}
}
}
"$ref": "#/components/schemas/DeployFunctionReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"DeployFunction"
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/RunFunctionReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"RunFunction"
]
}
}
}
}
}
}
],
"title": "DeployFunction"
},
{
"allOf": [
{
"$ref": "#/components/schemas/RunFunctionReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"RunFunction"
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/DepositReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"Deposit"
]
}
}
}
}
}
}
],
"title": "RunFunction"
},
{
"allOf": [
{
"$ref": "#/components/schemas/DepositReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"Deposit"
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/FaDepositReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"FaDeposit"
]
}
}
}
}
}
}
],
"title": "Deposit"
},
{
"allOf": [
{
"$ref": "#/components/schemas/FaDepositReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"FaDeposit"
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/FaWithdrawReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"FaWithdraw"
]
}
}
}
}
}
}
],
"title": "FaDeposit"
},
{
"allOf": [
{
"$ref": "#/components/schemas/FaWithdrawReceipt"
},
{
"type": "object",
"required": [
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"FaWithdraw"
]
}
]
}
}
],
"title": "FaWithdraw"
}
]
},
"ReceiptResult": {
"oneOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/ReceiptContent"
},
{
"type": "object",
Expand All @@ -793,24 +803,30 @@
"_type": {
"type": "string",
"enum": [
"Ok"
"Success"
]
}
}
}
]
],
"title": "Success"
},
{
"type": "object",
"title": "Failure",
"required": [
"source",
"_type"
],
"properties": {
"_type": {
"type": "string",
"enum": [
"Err"
"Failed"
]
},
"source": {
"type": "string"
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions crates/jstz_proto/src/executor/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ mod test {

use crate::{
operation::external::Deposit,
receipt::{DepositReceipt, ReceiptContent},
receipt::{DepositReceipt, ReceiptContent, ReceiptResult},
};

use super::execute;
Expand All @@ -54,11 +54,13 @@ mod test {
tx.begin();
let receipt = execute(&mut host, &mut tx, deposit);
assert!(matches!(
receipt.inner,
Ok(ReceiptContent::Deposit(DepositReceipt {
receipt.clone().inner,
ReceiptResult::Success(ReceiptContent::Deposit(DepositReceipt {
account,
updated_balance,
})) if account == receiver && updated_balance == 20
))
));
let raw_json_payload = r#"{"hash":[39,12,7,148,87,7,176,168,111,219,214,147,14,123,179,202,232,151,138,59,207,182,101,158,128,98,239,57,236,88,195,42],"inner":{"_type":"Success","inner":{"_type":"DepositReceipt","account":"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx","updated_balance":20}}}"#;
assert_eq!(raw_json_payload, serde_json::to_string(&receipt).unwrap());
}
}
Loading

0 comments on commit eb1a5a3

Please sign in to comment.