@@ -5,10 +5,15 @@ use std::{
5
5
6
6
use futures:: { Future , FutureExt } ;
7
7
use futures_util:: Stream ;
8
+ use futures_util:: TryStreamExt ;
9
+
10
+ use penumbra_proto:: view:: v1:: broadcast_transaction_response:: Status as BroadcastStatus ;
11
+
8
12
use penumbra_asset:: Value ;
9
13
use penumbra_custody:: { AuthorizeRequest , CustodyClient } ;
10
14
use penumbra_keys:: { Address , FullViewingKey } ;
11
15
use penumbra_transaction:: memo:: MemoPlaintext ;
16
+ use penumbra_txhash:: TransactionId ;
12
17
use penumbra_view:: ViewClient ;
13
18
use penumbra_wallet:: plan:: Planner ;
14
19
use pin_project_lite:: pin_project;
51
56
V : ViewClient + Clone + Send + ' static ,
52
57
C : CustodyClient + Clone + Send + ' static ,
53
58
{
54
- type Response = penumbra_transaction :: Id ;
59
+ type Response = TransactionId ;
55
60
type Error = anyhow:: Error ;
56
61
type Future =
57
62
Pin < Box < dyn Future < Output = Result < Self :: Response , Self :: Error > > + Send + ' static > > ;
@@ -71,13 +76,15 @@ where
71
76
planner. output ( value, address) ;
72
77
}
73
78
planner
74
- . memo ( MemoPlaintext {
75
- text : "Hello from Galileo, the Penumbra faucet bot" . to_string ( ) ,
76
- return_address : self2. fvk . payment_address ( 0 . into ( ) ) . 0 ,
77
- } )
79
+ . memo (
80
+ MemoPlaintext :: new (
81
+ self2. fvk . payment_address ( 0 . into ( ) ) . 0 ,
82
+ "Hello from Galileo, the Penumbra faucet bot" . to_string ( ) ,
83
+ )
84
+ . expect ( "can create memo" ) ,
85
+ )
78
86
. unwrap ( ) ;
79
- let plan = planner. plan ( & mut self2. view , self2. fvk . wallet_id ( ) , self2. account . into ( ) ) ;
80
- let plan = plan. await ?;
87
+ let plan = planner. plan ( & mut self2. view , self2. account . into ( ) ) . await ?;
81
88
82
89
// 2. Authorize and build the transaction.
83
90
let auth_data = self2
@@ -90,14 +97,32 @@ where
90
97
. data
91
98
. ok_or_else ( || anyhow:: anyhow!( "no auth data" ) ) ?
92
99
. try_into ( ) ?;
93
- let witness_data = self2. view . witness ( self2 . fvk . wallet_id ( ) , & plan) . await ?;
100
+ let witness_data = self2. view . witness ( & plan) . await ?;
94
101
let tx = plan
95
102
. build_concurrent ( & self2. fvk , & witness_data, & auth_data)
96
103
. await ?;
97
104
98
105
// 3. Broadcast the transaction and wait for confirmation.
99
- let ( tx_id, _detection_height) = self2. view . broadcast_transaction ( tx, true ) . await ?;
100
- Ok ( tx_id)
106
+ let id = tx. id ( ) ;
107
+ let mut rsp = self2. view . broadcast_transaction ( tx, true ) . await ?;
108
+ while let Some ( rsp) = rsp. try_next ( ) . await ? {
109
+ match rsp. status {
110
+ Some ( BroadcastStatus :: BroadcastSuccess ( _) ) => {
111
+ println ! ( "transaction broadcast successfully: {}" , id) ;
112
+ }
113
+ Some ( BroadcastStatus :: Confirmed ( c) ) => {
114
+ println ! (
115
+ "transaction confirmed and detected: {} @ height {}" ,
116
+ id, c. detection_height
117
+ ) ;
118
+ return Ok ( id) ;
119
+ }
120
+ _ => { }
121
+ }
122
+ }
123
+ Err ( anyhow:: anyhow!(
124
+ "view server closed stream without reporting transaction confirmation"
125
+ ) )
101
126
}
102
127
. boxed ( )
103
128
}
@@ -128,7 +153,7 @@ impl<S> SenderSet<S> {
128
153
129
154
impl < S > Stream for SenderSet < S >
130
155
where
131
- S : Service < ( Address , Vec < Value > ) , Response = penumbra_transaction :: Id , Error = anyhow:: Error > ,
156
+ S : Service < ( Address , Vec < Value > ) , Response = TransactionId , Error = anyhow:: Error > ,
132
157
{
133
158
type Item = Result < Change < Key , S > , anyhow:: Error > ;
134
159
0 commit comments