@@ -56,6 +56,7 @@ impl TxBuilder {
56
56
let input_utxo = admin_utxos. first ( ) . unwrap ( ) ;
57
57
58
58
let script_address = Validator :: address ( network) ;
59
+ println ! ( "Script Address: {:?}" , script_address. to_bech32( ) ) ;
59
60
let player_inbound_address = player
60
61
. inbound_address ( self . admin_pkh , network)
61
62
. context ( "failed to build player multisig inbound address" ) ?;
@@ -104,7 +105,9 @@ impl TxBuilder {
104
105
105
106
let game_state: PlutusData = match game_state_utxo. datum . clone ( ) {
106
107
Datum :: Hash ( _) => bail ! ( "Unexpected datum hash in game utxo" ) ,
107
- Datum :: Inline ( data) => GameState :: try_from ( data) ?,
108
+ Datum :: Inline ( data) => {
109
+ GameState :: try_from ( data) . context ( "failed to decode plutus data for game state" ) ?
110
+ }
108
111
Datum :: None => bail ! ( "No datum in game utxo" ) ,
109
112
}
110
113
. add_player ( player. signing_key . into ( ) )
@@ -260,6 +263,7 @@ impl TxBuilder {
260
263
4 , 1293828 , 28716 , 63 , 0 , 1 , 1006041 , 43623 , 251 , 0 , 1 ,
261
264
] ,
262
265
)
266
+ . disclosed_signer ( self . admin_pkh )
263
267
. fee ( 0 ) ;
264
268
265
269
let tx = tx_builder. build_conway_raw ( ) ?;
@@ -280,24 +284,33 @@ impl TxBuilder {
280
284
281
285
let game_state: GameState = match game_state_utxo. datum . clone ( ) {
282
286
Datum :: Hash ( _) => bail ! ( "Unexpected datum hash in game utxo" ) ,
283
- Datum :: Inline ( data) => data. try_into ( ) ?,
287
+ Datum :: Inline ( data) => data
288
+ . try_into ( )
289
+ . context ( "failed to convert data to GameState" ) ?,
284
290
Datum :: None => bail ! ( "No datum in game utxo" ) ,
285
291
} ;
286
292
287
293
let collateral_utxos = self . find_admin_utxos ( utxos. clone ( ) ) ;
294
+
288
295
let collateral_utxo = collateral_utxos
289
296
. get ( 0 )
290
297
. ok_or_else ( || anyhow ! ( "No collateral utxo found" ) ) ?;
291
298
292
- let redeemer: PlutusData = Redeemer :: new ( 0 , SpendAction :: AddPlayer ) . into ( ) ;
299
+ let redeemer: PlutusData = Redeemer :: new ( 0 , SpendAction :: Collect ) . into ( ) ;
293
300
let mut redeemer_bytes = Vec :: new ( ) ;
294
301
encode ( & redeemer, & mut redeemer_bytes) ?;
295
302
296
303
let mut tx_builder = Some (
297
304
StagingTransaction :: new ( )
298
305
. input ( game_state_utxo. clone ( ) . into ( ) )
306
+ . input ( collateral_utxo. clone ( ) . into ( ) )
299
307
. collateral_input ( collateral_utxo. clone ( ) . into ( ) )
300
- . output ( Output :: new ( collateral_utxo. address . clone ( ) , 0 ) )
308
+ . output (
309
+ collateral_utxo
310
+ . clone ( )
311
+ . try_into ( )
312
+ . context ( "failed to build target output from utxo object" ) ?,
313
+ )
301
314
. add_spend_redeemer (
302
315
game_state_utxo. into ( ) ,
303
316
redeemer_bytes,
@@ -337,14 +350,20 @@ impl TxBuilder {
337
350
338
351
for player in game_state. players {
339
352
let player: Player = player. into ( ) ;
340
- let inbound_address = player. inbound_address ( self . admin_pkh , network) ?;
341
- let outbound_address = player. outbound_address ( self . admin_pkh , network) ?;
353
+ let inbound_address = player
354
+ . inbound_address ( self . admin_pkh , network)
355
+ . context ( "failed to get player inbound address" ) ?;
356
+ let outbound_address = player
357
+ . outbound_address ( self . admin_pkh , network)
358
+ . context ( "failed to get player outbound address" ) ?;
342
359
let inbound_script = player. inbound_script ( self . admin_pkh ) ;
343
360
let mut inbound_bytes = Vec :: new ( ) ;
344
- encode ( & inbound_script, & mut inbound_bytes) ?;
361
+ encode ( & inbound_script, & mut inbound_bytes)
362
+ . context ( "Failed to cbor encode outbound script" ) ?;
345
363
let outbound_script = player. outbound_script ( self . admin_pkh ) ;
346
364
let mut outbound_bytes = Vec :: new ( ) ;
347
- encode ( & outbound_script, & mut outbound_bytes) ?;
365
+ encode ( & outbound_script, & mut outbound_bytes)
366
+ . context ( "Failed to cbor encode outbound script" ) ?;
348
367
let player_utxos: Vec < _ > = utxos
349
368
. clone ( )
350
369
. into_iter ( )
@@ -366,7 +385,12 @@ impl TxBuilder {
366
385
367
386
let tx = tx_builder
368
387
. ok_or ( anyhow ! ( "fatal error: no tx builder" ) )
369
- . and_then ( |builder| builder. build_conway_raw ( ) . map_err ( |e| anyhow ! ( "{}" , e) ) )
388
+ . and_then ( |builder| {
389
+ builder
390
+ . disclosed_signer ( self . admin_pkh )
391
+ . build_conway_raw ( )
392
+ . map_err ( |e| anyhow ! ( "{}" , e) )
393
+ } )
370
394
. map_err ( |e| anyhow ! ( "Failed to build tx: {}" , e) ) ?;
371
395
372
396
let signed_tx = tx
@@ -395,6 +419,8 @@ impl TxBuilder {
395
419
396
420
#[ cfg( test) ]
397
421
mod tests {
422
+ use tracing:: debug;
423
+
398
424
use super :: * ;
399
425
use crate :: model:: cluster:: KeyEnvelope ;
400
426
use std:: { collections:: HashMap , fs:: File } ;
@@ -437,6 +463,6 @@ mod tests {
437
463
. build_new_game ( player. into ( ) , utxos, Network :: Testnet )
438
464
. expect ( "Failed to build tx" ) ;
439
465
440
- println ! ( "{}" , hex:: encode( tx. tx_bytes) ) ;
466
+ debug ! ( "{}" , hex:: encode( tx. tx_bytes) ) ;
441
467
}
442
468
}
0 commit comments