1515 */
1616
1717import { Observable , of } from 'rxjs' ;
18- import { map , mergeMap , toArray } from 'rxjs/operators' ;
18+ import { flatMap , map , mergeMap , toArray } from 'rxjs/operators' ;
19+ import { Listener } from '../infrastructure/Listener' ;
1920import { ReceiptHttp } from '../infrastructure/ReceiptHttp' ;
2021import { TransactionHttp } from '../infrastructure/TransactionHttp' ;
2122import { NamespaceId } from '../model/namespace/NamespaceId' ;
@@ -28,6 +29,7 @@ import { MosaicMetadataTransaction } from '../model/transaction/MosaicMetadataTr
2829import { MosaicSupplyChangeTransaction } from '../model/transaction/MosaicSupplyChangeTransaction' ;
2930import { SecretLockTransaction } from '../model/transaction/SecretLockTransaction' ;
3031import { SecretProofTransaction } from '../model/transaction/SecretProofTransaction' ;
32+ import { SignedTransaction } from '../model/transaction/SignedTransaction' ;
3133import { Transaction } from '../model/transaction/Transaction' ;
3234import { TransactionType } from '../model/transaction/TransactionType' ;
3335import { TransferTransaction } from '../model/transaction/TransferTransaction' ;
@@ -40,13 +42,15 @@ export class TransactionService implements ITransactionService {
4042
4143 private readonly transactionHttp : TransactionHttp ;
4244 private readonly receiptHttp : ReceiptHttp ;
45+ private readonly listener : Listener ;
4346 /**
4447 * Constructor
4548 * @param url Base catapult-rest url
4649 */
4750 constructor ( url : string ) {
4851 this . transactionHttp = new TransactionHttp ( url ) ;
4952 this . receiptHttp = new ReceiptHttp ( url ) ;
53+ this . listener = new Listener ( url ) ;
5054 }
5155
5256 /**
@@ -143,4 +147,39 @@ export class TransactionService implements ITransactionService {
143147 map ( ( statement ) => transaction . resolveAliases ( statement , aggregateIndex ) ) ,
144148 ) ;
145149 }
150+
151+ /**
152+ * @param signedTransaction Signed transaction to be announced.
153+ * @returns {Observable<Transaction> }
154+ */
155+ public announce ( signedTransaction : SignedTransaction ) : Observable < Transaction > {
156+ return this . transactionHttp . announce ( signedTransaction ) . pipe (
157+ flatMap ( ( ) => this . listener . confirmed ( signedTransaction . getSignerAddress ( ) , signedTransaction . hash ) ) ,
158+ ) ;
159+ }
160+
161+ /**
162+ * Announce aggregate transaction
163+ * @param signedTransaction Signed aggregate bonded transaction.
164+ * @returns {Observable<AggregateTransaction> }
165+ */
166+ public announceAggregateBonded ( signedTransaction : SignedTransaction ) : Observable < AggregateTransaction > {
167+ return this . transactionHttp . announceAggregateBonded ( signedTransaction ) . pipe (
168+ flatMap ( ( ) => this . listener . aggregateBondedAdded ( signedTransaction . getSignerAddress ( ) , signedTransaction . hash ) ) ,
169+ ) ;
170+ }
171+
172+ /**
173+ * Announce aggregate bonded transaction with lock fund
174+ * @param signedHashLockTransaction Signed hash lock transaction.
175+ * @param signedAggregateTransaction Signed aggregate bonded transaction.
176+ * @returns {Observable<AggregateTransaction> }
177+ */
178+ public announceHashLockAggregateBonded ( signedHashLockTransaction : SignedTransaction ,
179+ signedAggregateTransaction : SignedTransaction ) : Observable < AggregateTransaction > {
180+ return this . announce ( signedHashLockTransaction ) . pipe (
181+ flatMap ( ( ) => this . announceAggregateBonded ( signedAggregateTransaction ) ) ,
182+ ) ;
183+
184+ }
146185}
0 commit comments