@@ -22,8 +22,8 @@ use gdk_common::be::{
22
22
use gdk_common:: error:: fn_err;
23
23
use gdk_common:: model:: {
24
24
parse_path, AccountInfo , AddressAmount , AddressPointer , Balances , CreateTransaction ,
25
- GetTransactionsOpt , SPVVerifyTxResult , TransactionMeta , UnspentOutput , UpdateAccountOpt ,
26
- UtxoStrategy ,
25
+ GetTransactionsOpt , SPVVerifyTxResult , TransactionMeta , TransactionOutput , UnspentOutput ,
26
+ UpdateAccountOpt , UtxoStrategy ,
27
27
} ;
28
28
use gdk_common:: scripts:: { p2pkh_script, p2shwpkh_script_sig, ScriptType } ;
29
29
use gdk_common:: util:: is_confidential_txoutsecrets;
@@ -308,6 +308,49 @@ impl Account {
308
308
p2pkh_script ( public_key) . into ( )
309
309
}
310
310
311
+ pub fn tx_outputs ( & self , tx : & BETransaction ) -> Result < Vec < TransactionOutput > , Error > {
312
+ let store_read = self . store . read ( ) ?;
313
+ let acc_store = store_read. account_cache ( self . account_num ) ?;
314
+ let mut tx_outputs = vec ! [ ] ;
315
+ for vout in 0 ..tx. output_len ( ) as u32 {
316
+ let address = tx. output_address ( vout, self . network . id ( ) ) . unwrap_or_default ( ) ;
317
+ let satoshi = tx. output_value ( vout, & acc_store. unblinded ) . unwrap_or_default ( ) ;
318
+ let script_pubkey = tx. output_script ( vout) ;
319
+ tx_outputs. push ( match acc_store. paths . get ( & script_pubkey) {
320
+ None => TransactionOutput {
321
+ address,
322
+ satoshi,
323
+ address_type : "" . into ( ) ,
324
+ is_relevant : false ,
325
+ is_change : false ,
326
+ subaccount : self . account_num ,
327
+ is_internal : false ,
328
+ pointer : 0 ,
329
+ pt_idx : vout,
330
+ script : "" . into ( ) ,
331
+ user_path : vec ! [ ] ,
332
+ } ,
333
+ Some ( account_path) => {
334
+ let ( is_internal, pointer) = parse_path ( & account_path) ?;
335
+ TransactionOutput {
336
+ address,
337
+ satoshi,
338
+ address_type : self . script_type . to_string ( ) ,
339
+ is_relevant : true ,
340
+ is_change : true , // same as is_relevant
341
+ subaccount : self . account_num ,
342
+ is_internal,
343
+ pointer,
344
+ pt_idx : vout,
345
+ script : self . script_code ( & account_path) . to_hex ( ) ,
346
+ user_path : self . get_full_path ( & account_path) . into ( ) ,
347
+ }
348
+ }
349
+ } ) ;
350
+ }
351
+ Ok ( tx_outputs)
352
+ }
353
+
311
354
fn txo ( & self , outpoint : & BEOutPoint ) -> Result < UnspentOutput , Error > {
312
355
let vout = outpoint. vout ( ) ;
313
356
let txid = outpoint. txid ( ) ;
@@ -1243,6 +1286,7 @@ pub fn create_tx(
1243
1286
}
1244
1287
1245
1288
let used_utxos = account. used_utxos ( & tx) ?;
1289
+ let tx_outputs = account. tx_outputs ( & tx) ?;
1246
1290
let mut created_tx = TransactionMeta :: new (
1247
1291
tx,
1248
1292
None ,
@@ -1256,6 +1300,7 @@ pub fn create_tx(
1256
1300
SPVVerifyTxResult :: InProgress ,
1257
1301
) ;
1258
1302
created_tx. used_utxos = used_utxos;
1303
+ created_tx. transaction_outputs = tx_outputs;
1259
1304
created_tx. changes_used = Some ( changes. len ( ) as u32 ) ;
1260
1305
created_tx. addressees_read_only = request. previous_transaction . is_some ( ) ;
1261
1306
info ! ( "returning: {:?}" , created_tx) ;
0 commit comments