-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
ticket-app/host/src/main.rs
Outdated
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 {}, | ||
}, | ||
}), |
There was a problem hiding this comment.
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
ticket-app/host/src/main.rs
Outdated
// 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
ticket-app/contract/src/lib.rs
Outdated
|
||
match erc20_action { | ||
SimpleTokenAction::Transfer { recipient, amount } => { | ||
if recipient != ctx.caller.0 { |
There was a problem hiding this comment.
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
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:
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
Any kind of help would be very useful. Thanks in advance! |
WIP