Skip to content

Commit e295b5a

Browse files
committed
Added #352 aggregate bonded announcing
1 parent a7890a6 commit e295b5a

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

src/infrastructure/Listener.ts

Lines changed: 2 additions & 2 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> {
@@ -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> {

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: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616

1717
import {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';
1920
import { ReceiptHttp } from '../infrastructure/ReceiptHttp';
2021
import { TransactionHttp } from '../infrastructure/TransactionHttp';
2122
import { NamespaceId } from '../model/namespace/NamespaceId';
@@ -28,6 +29,7 @@ import { MosaicMetadataTransaction } from '../model/transaction/MosaicMetadataTr
2829
import { MosaicSupplyChangeTransaction } from '../model/transaction/MosaicSupplyChangeTransaction';
2930
import { SecretLockTransaction } from '../model/transaction/SecretLockTransaction';
3031
import { SecretProofTransaction } from '../model/transaction/SecretProofTransaction';
32+
import { SignedTransaction } from '../model/transaction/SignedTransaction';
3133
import { Transaction } from '../model/transaction/Transaction';
3234
import { TransactionType } from '../model/transaction/TransactionType';
3335
import { 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
}

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)