Skip to content

Add refund ticket functionality #40

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

necipsagiro
Copy link

WIP

@necipsagiro necipsagiro marked this pull request as draft March 15, 2025 14:32
Copy link
Member

@BertrandD BertrandD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR thanks ! I made a few comments, I hope are clear.

To add support of caller/callee on the example token, you basically need to change the parse_raw_contract_input of this contract to a parse_contract_input (the contract will then expect a StructuredBlobData` as input blob.

Comment on lines 285 to 292
sdk::Blob::from(sdk::StructuredBlob {
contract_name: contract_name.clone().into(),
data: sdk::StructuredBlobData {
caller: None,
callees: Some(vec![sdk::BlobIndex(2)]),
parameters: TicketAppAction::RefundTicket {},
},
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use to have a as_blob() helper function on the action (trait ContractAction) to simplify these lines, but it's just sugar

Comment on lines 343 to 352
// let state_commitment = client
// .get_contract(&initial_state.ticket_price.0.clone().into())
// .await
// .unwrap()
// .state;

// // Deserialize the state manually
// let initial_state_a: Hyllar = borsh::from_slice(&state_commitment.0)
// .map_err(|_| "Could not decode hyllar state".to_string())
// .unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the on-chain state of hyllar contrat is only a hash of the full state, so there you won't be able to rebuild a Hyllar. We do have an endpoint on the indexer that rebuilds a full state to be used here, you should have a function fetch_current_state on the IndexerApiHttpClient you could use.

nonce: cli.nonce.parse().unwrap(),
};

let identity_contract_name = cli.user.rsplit_once(".").unwrap().1.to_string();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if you update to a newer version, you might need to change that as we now use the @ instead of . to split the identity & contract name


match erc20_action {
SimpleTokenAction::Transfer { recipient, amount } => {
if recipient != ctx.caller.0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recipient of the transfer is the user, but the ctx.caller here should be the contract name (that's what caller/callee does). The transfer is expected to be from the contract to the user.

So here I would rather check that the recipient correspond to the identity of the transaction, and that the caller is the contract_name

@necipsagiro
Copy link
Author

Hey @BertrandD thank you for the review, i'm implementing the code according to your guidance. But I keep getting this error when trying to register simple-identity contract to test:

guest: error: failed to run LLVM passes: unknown pass name 'loweratomic'
guest: 
guest: error: could not compile `subtle` (lib) due to 1 previous error
guest: warning: build failed, waiting for other jobs to finish...
guest: error: could not compile `rand_core` (lib) due to 1 previous error
guest: error: could not compile `const-oid` (lib) due to 1 previous error
guest: error: could not compile `once_cell` (lib) due to 1 previous error
error: failed to run custom build command for `methods-identity v0.1.0 (/Users/necipsagiroglu/projects/hyle-examples-fork/simple-identity/methods)`

Caused by:
  process didn't exit successfully: `/Users/necipsagiroglu/projects/hyle-examples-fork/simple-identity/target/debug/build/methods-identity-0b4f915cc0f45d74/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=RISC0_SKIP_BUILD
  Building guest package methods-identity.guest
  cargo:rerun-if-env-changed=RISC0_SKIP_BUILD
  Using rustc: /Users/necipsagiroglu/.rustup/toolchains/risc0/bin/rustc
  cargo:rerun-if-env-changed=RISC0_RUST_SRC
  Building guest package: cargo build --target riscv32im-risc0-zkvm-elf
  cargo:rerun-if-env-changed=RISC0_BUILD_DEBUG
warning: build failed, waiting for other jobs to finish...

I tried changing some versions for risc0 toolchain but it didn't it work. The exact error message is only mentioned in SP1 docs. I'm confused :D. For reference this is rzup check output:

cargo-risczero - Update Available : 1.2.5 -> 2.0.2
cpp - Up to date : 2024.1.5
r0vm - Update Available : 1.2.5 -> 2.0.2
rust - Up to date : 1.85.0

Any kind of help would be very useful. Thanks in advance!

@necipsagiro necipsagiro marked this pull request as ready for review May 21, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants