@@ -35,6 +35,7 @@ impl TokenWallet {
35
35
owner : MsgAddressInt ,
36
36
root_token_contract : MsgAddressInt ,
37
37
handler : Arc < dyn TokenWalletSubscriptionHandler > ,
38
+ preload_transactions : bool ,
38
39
) -> Result < TokenWallet > {
39
40
let state = match transport. get_contract_state ( & root_token_contract) . await ? {
40
41
RawContractState :: Exists ( state) => state,
@@ -52,16 +53,35 @@ impl TokenWallet {
52
53
} = state. guess_details ( ) ?;
53
54
54
55
let address = state. get_wallet_address ( version, & owner) ?;
55
-
56
56
let mut balance = Default :: default ( ) ;
57
- let contract_subscription = ContractSubscription :: subscribe (
58
- clock. clone ( ) ,
59
- transport,
60
- address,
61
- & mut make_contract_state_handler ( clock. clone ( ) , version, & mut balance) ,
62
- Some ( & mut make_transactions_handler ( handler. as_ref ( ) , version) ) ,
63
- )
64
- . await ?;
57
+
58
+ let contract_subscription = {
59
+ let handler = handler. as_ref ( ) ;
60
+
61
+ // NOTE: create handler beforehead to prevent lifetime issues
62
+ let mut on_transactions_found = match preload_transactions {
63
+ true => Some ( make_transactions_handler ( handler, version) ) ,
64
+ false => None ,
65
+ } ;
66
+
67
+ // Manual map is used here due to unsoundness
68
+ // See issue: https://github.com/rust-lang/rust/issues/84305
69
+ #[ allow( trivial_casts) ]
70
+ #[ allow( clippy:: manual_map) ]
71
+ let on_transactions_found = match & mut on_transactions_found {
72
+ Some ( handler) => Some ( handler as _ ) ,
73
+ None => None ,
74
+ } ;
75
+
76
+ ContractSubscription :: subscribe (
77
+ clock. clone ( ) ,
78
+ transport,
79
+ address,
80
+ & mut make_contract_state_handler ( clock. clone ( ) , version, & mut balance) ,
81
+ on_transactions_found,
82
+ )
83
+ . await ?
84
+ } ;
65
85
66
86
handler. on_balance_changed ( balance. clone ( ) ) ;
67
87
0 commit comments