Skip to content

Commit fe7028a

Browse files
committed
Added #352 aggregate bonded announcing
1 parent 341badb commit fe7028a

File tree

4 files changed

+85
-5
lines changed

4 files changed

+85
-5
lines changed

src/infrastructure/Listener.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export class Listener {
239239
* it emits a new Transaction in the event stream.
240240
*
241241
* @param address address we listen when a transaction is in confirmed state
242-
* @param transactionHash transaction hash for the filter
242+
* @param transactionHash transactionHash for filtering multiple transactions
243243
* @return an observable stream of Transaction with state confirmed
244244
*/
245245
public confirmed(address: Address, transactionHash?: string): Observable<Transaction> {
@@ -249,7 +249,7 @@ export class Listener {
249249
filter((_) => _.message instanceof Transaction),
250250
map((_) => _.message as Transaction),
251251
filter((_) => this.transactionFromAddress(_, address)),
252-
filter((_) => _.transactionInfo!.hash === transactionHash || transactionHash === undefined),
252+
filter((_) => transactionHash === undefined || _.transactionInfo!.hash === transactionHash),
253253
);
254254
}
255255

@@ -292,7 +292,7 @@ export class Listener {
292292
* it emits a new {@link AggregateTransaction} in the event stream.
293293
*
294294
* @param address address we listen when a transaction with missing signatures state
295-
* @param transactionHash transaction hash for the filter
295+
* @param transactionHash transactionHash for filtering multiple transactions
296296
* @return an observable stream of AggregateTransaction with missing signatures state
297297
*/
298298
public aggregateBondedAdded(address: Address, transactionHash?: string): Observable<AggregateTransaction> {
@@ -302,7 +302,7 @@ export class Listener {
302302
filter((_) => _.message instanceof AggregateTransaction),
303303
map((_) => _.message as AggregateTransaction),
304304
filter((_) => this.transactionFromAddress(_, address)),
305-
filter((_) => _.transactionInfo!.hash === transactionHash || transactionHash === undefined),
305+
filter((_) => transactionHash === undefined || _.transactionInfo!.hash === transactionHash),
306306
);
307307
}
308308

src/model/transaction/SignedTransaction.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { Address } from '../account/Address';
18+
import { PublicAccount } from '../account/PublicAccount';
1719
import {NetworkType} from '../blockchain/NetworkType';
1820

1921
/**
@@ -65,4 +67,12 @@ export class SignedTransaction {
6567
networkType: this.networkType,
6668
};
6769
}
70+
71+
/**
72+
* Return signer's address
73+
* @returns {Address}
74+
*/
75+
getSignerAddress(): Address {
76+
return PublicAccount.createFromPublicKey(this.signerPublicKey, this.networkType).address;
77+
}
6878
}

src/service/TransactionService.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@
1616

1717
import {Observable} from 'rxjs';
1818
import { mergeMap, toArray} from 'rxjs/operators';
19+
import { flatMap } from 'rxjs/operators';
20+
import { Listener } from '../infrastructure/Listener';
1921
import { ReceiptHttp } from '../infrastructure/ReceiptHttp';
2022
import { TransactionHttp } from '../infrastructure/TransactionHttp';
23+
import { Address } from '../model/account/Address';
24+
import { MosaicId } from '../model/mosaic/MosaicId';
25+
import { NamespaceId } from '../model/namespace/NamespaceId';
26+
import { ResolutionType } from '../model/receipt/ResolutionType';
27+
import { Statement } from '../model/receipt/Statement';
28+
import { AggregateTransaction } from '../model/transaction/AggregateTransaction';
29+
import { SignedTransaction } from '../model/transaction/SignedTransaction';
2130
import { Transaction } from '../model/transaction/Transaction';
2231
import { ITransactionService } from './interfaces/ITransactionService';
2332

@@ -28,13 +37,15 @@ export class TransactionService implements ITransactionService {
2837

2938
private readonly transactionHttp: TransactionHttp;
3039
private readonly receiptHttp: ReceiptHttp;
40+
private readonly listener: Listener;
3141
/**
3242
* Constructor
3343
* @param url Base catapult-rest url
3444
*/
3545
constructor(url: string) {
3646
this.transactionHttp = new TransactionHttp(url);
3747
this.receiptHttp = new ReceiptHttp(url);
48+
this.listener = new Listener(url);
3849
}
3950

4051
/**
@@ -48,4 +59,39 @@ export class TransactionService implements ITransactionService {
4859
toArray(),
4960
);
5061
}
62+
63+
/**
64+
* @param signedTransaction Signed transaction to be announced.
65+
* @returns {Observable<Transaction>}
66+
*/
67+
public announce(signedTransaction: SignedTransaction): Observable<Transaction> {
68+
return this.transactionHttp.announce(signedTransaction).pipe(
69+
flatMap(() => this.listener.confirmed(signedTransaction.getSignerAddress(), signedTransaction.hash)),
70+
);
71+
}
72+
73+
/**
74+
* Announce aggregate transaction
75+
* @param signedTransaction Signed aggregate bonded transaction.
76+
* @returns {Observable<AggregateTransaction>}
77+
*/
78+
public announceAggregateBonded(signedTransaction: SignedTransaction): Observable<AggregateTransaction> {
79+
return this.transactionHttp.announceAggregateBonded(signedTransaction).pipe(
80+
flatMap(() => this.listener.aggregateBondedAdded(signedTransaction.getSignerAddress(), signedTransaction.hash)),
81+
);
82+
}
83+
84+
/**
85+
* Announce aggregate bonded transaction with lock fund
86+
* @param signedHashLockTransaction Signed hash lock transaction.
87+
* @param signedAggregateTransaction Signed aggregate bonded transaction.
88+
* @returns {Observable<AggregateTransaction>}
89+
*/
90+
public announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction,
91+
signedAggregateTransaction: SignedTransaction): Observable<AggregateTransaction> {
92+
return this.announce(signedHashLockTransaction).pipe(
93+
flatMap(() => this.announceAggregateBonded(signedAggregateTransaction)),
94+
);
95+
96+
}
5197
}

src/service/interfaces/ITransactionService.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
import {Observable} from 'rxjs';
18+
import { AggregateTransaction } from '../../model/transaction/AggregateTransaction';
19+
import { SignedTransaction } from '../../model/transaction/SignedTransaction';
1820
import { Transaction } from '../../model/transaction/Transaction';
1921

2022
/**
@@ -24,7 +26,29 @@ export interface ITransactionService {
2426

2527
/**
2628
* @param transationHashes List of transaction hashes.
27-
* @returns Observable<Transaction[]>
29+
* @returns {Observable<Transaction[]>}
2830
*/
2931
resolveAliases(transationHashes: string[]): Observable<Transaction[]>;
32+
33+
/**
34+
* @param signedTransaction Signed transaction to be announced.
35+
* @returns {Observable<Transaction>}
36+
*/
37+
announce(signedTransaction: SignedTransaction): Observable<Transaction>;
38+
39+
/**
40+
* Announce aggregate transaction
41+
* @param signedTransaction Signed aggregate bonded transaction.
42+
* @returns {Observable<AggregateTransaction>}
43+
*/
44+
announceAggregateBonded(signedTransaction: SignedTransaction): Observable<AggregateTransaction>;
45+
46+
/**
47+
* Announce aggregate bonded transaction with lock fund
48+
* @param signedHashLockTransaction Signed hash lock transaction.
49+
* @param signedAggregateTransaction Signed aggregate bonded transaction.
50+
* @returns {Observable<AggregateTransaction>}
51+
*/
52+
announceHashLockAggregateBonded(signedHashLockTransaction: SignedTransaction,
53+
signedAggregateTransaction: SignedTransaction): Observable<AggregateTransaction>;
3054
}

0 commit comments

Comments
 (0)