1616
1717import { Observable } from 'rxjs' ;
1818import { mergeMap , toArray } from 'rxjs/operators' ;
19+ import { flatMap } from 'rxjs/operators' ;
20+ import { Listener } from '../infrastructure/Listener' ;
1921import { ReceiptHttp } from '../infrastructure/ReceiptHttp' ;
2022import { TransactionHttp } from '../infrastructure/TransactionHttp' ;
2123import { Address } from '../model/account/Address' ;
2224import { MosaicId } from '../model/mosaic/MosaicId' ;
2325import { NamespaceId } from '../model/namespace/NamespaceId' ;
2426import { ResolutionType } from '../model/receipt/ResolutionType' ;
2527import { Statement } from '../model/receipt/Statement' ;
28+ import { AggregateTransaction } from '../model/transaction/AggregateTransaction' ;
29+ import { SignedTransaction } from '../model/transaction/SignedTransaction' ;
2630import { Transaction } from '../model/transaction/Transaction' ;
2731import { ITransactionService } from './interfaces/ITransactionService' ;
2832
@@ -33,13 +37,15 @@ export class TransactionService implements ITransactionService {
3337
3438 private readonly transactionHttp : TransactionHttp ;
3539 private readonly receiptHttp : ReceiptHttp ;
40+ private readonly listener : Listener ;
3641 /**
3742 * Constructor
3843 * @param url Base catapult-rest url
3944 */
4045 constructor ( url : string ) {
4146 this . transactionHttp = new TransactionHttp ( url ) ;
4247 this . receiptHttp = new ReceiptHttp ( url ) ;
48+ this . listener = new Listener ( url ) ;
4349 }
4450
4551 /**
@@ -65,7 +71,7 @@ export class TransactionService implements ITransactionService {
6571 ( resolution . unresolved as NamespaceId ) . equals ( unresolved ) ) ;
6672
6773 if ( ! resolutionStatement ) {
68- throw new Error ( ' No resolution statement found' ) ;
74+ throw new Error ( ` No resolution statement found for unsolved value: ${ unresolved . toHex ( ) } ` ) ;
6975 }
7076 // source (0,0) is reserved for blocks, source (n, 0) is for txes, where n is 1-based index
7177 const resolutionEntry = resolutionStatement . resolutionEntries
@@ -74,7 +80,7 @@ export class TransactionService implements ITransactionService {
7480 entry . source . secondaryId === ( aggregateTransactionIndex !== undefined ? transactionIndex + 1 : 0 ) ) ;
7581
7682 if ( ! resolutionEntry ) {
77- throw new Error ( ' No resolution entry found' ) ;
83+ throw new Error ( ` No resolution entry found for unsolved value: ${ unresolved . toHex ( ) } ` ) ;
7884 }
7985
8086 return resolutionEntry . resolved ;
@@ -91,4 +97,39 @@ export class TransactionService implements ITransactionService {
9197 toArray ( ) ,
9298 ) ;
9399 }
100+
101+ /**
102+ * @param signedTransaction Signed transaction to be announced.
103+ * @returns {Observable<Transaction> }
104+ */
105+ public announce ( signedTransaction : SignedTransaction ) : Observable < Transaction > {
106+ return this . transactionHttp . announce ( signedTransaction ) . pipe (
107+ flatMap ( ( ) => this . listener . confirmed ( signedTransaction . getSignerAddress ( ) , signedTransaction . hash ) ) ,
108+ ) ;
109+ }
110+
111+ /**
112+ * Announce aggregate transaction
113+ * @param signedTransaction Signed aggregate bonded transaction.
114+ * @returns {Observable<AggregateTransaction> }
115+ */
116+ public announceAggregateBonded ( signedTransaction : SignedTransaction ) : Observable < AggregateTransaction > {
117+ return this . transactionHttp . announceAggregateBonded ( signedTransaction ) . pipe (
118+ flatMap ( ( ) => this . listener . aggregateBondedAdded ( signedTransaction . getSignerAddress ( ) , signedTransaction . hash ) ) ,
119+ ) ;
120+ }
121+
122+ /**
123+ * Announce aggregate bonded transaction with lock fund
124+ * @param signedHashLockTransaction Signed hash lock transaction.
125+ * @param signedAggregateTransaction Signed aggregate bonded transaction.
126+ * @returns {Observable<AggregateTransaction> }
127+ */
128+ public announceHashLockAggregateBonded ( signedHashLockTransaction : SignedTransaction ,
129+ signedAggregateTransaction : SignedTransaction ) : Observable < AggregateTransaction > {
130+ return this . announce ( signedHashLockTransaction ) . pipe (
131+ flatMap ( ( ) => this . announceAggregateBonded ( signedAggregateTransaction ) ) ,
132+ ) ;
133+
134+ }
94135}
0 commit comments