@@ -2,7 +2,7 @@ use oasis_contract_sdk::{
22 self as sdk,
33 env:: Env ,
44 types:: {
5- message:: { Message , NotifyReply } ,
5+ message:: { CallResult , Message , NotifyReply , Reply } ,
66 InstanceId ,
77 } ,
88} ;
@@ -14,6 +14,9 @@ use crate::types::{
1414 TokenInstantiation ,
1515} ;
1616
17+ /// Unique identifier for the send subcall.
18+ pub const CALL_ID_SEND : u64 = 1 ;
19+
1720/// Handles an OAS20 request call.
1821pub fn handle_call < C : sdk:: Context > (
1922 ctx : & mut C ,
@@ -34,7 +37,16 @@ pub fn handle_call<C: sdk::Context>(
3437 }
3538 Request :: Send { to, amount, data } => {
3639 let from = ctx. caller_address ( ) . to_owned ( ) ;
37- send ( ctx, balances, from, to, amount, data, 0 , NotifyReply :: Never ) ?;
40+ send (
41+ ctx,
42+ balances,
43+ from,
44+ to,
45+ amount,
46+ data,
47+ CALL_ID_SEND ,
48+ NotifyReply :: OnError , // Rollback if subcall fails.
49+ ) ?;
3850
3951 ctx. emit_event ( Event :: Oas20Sent { from, to, amount } ) ;
4052
@@ -120,6 +132,24 @@ pub fn handle_query<C: sdk::Context>(
120132 }
121133}
122134
135+ /// Handles a reply from OAS20 execution.
136+ pub fn handle_reply < C : sdk:: Context > (
137+ _ctx : & mut C ,
138+ _token_info : PublicCell < TokenInformation > ,
139+ _balances : PublicMap < Address , u128 > ,
140+ _allowances : PublicMap < ( Address , Address ) , u128 > ,
141+ reply : Reply ,
142+ ) -> Result < Option < Response > , Error > {
143+ match reply {
144+ Reply :: Call {
145+ id : CALL_ID_SEND ,
146+ result : CallResult :: Failed { module, code } ,
147+ ..
148+ } => Err ( Error :: ReceiverCallFailed ( module, code) ) ,
149+ _ => Ok ( None ) ,
150+ }
151+ }
152+
123153/// Instantiates the contract state.
124154pub fn instantiate < C : sdk:: Context > (
125155 ctx : & mut C ,
0 commit comments