Skip to content

Commit d1c4675

Browse files
committed
Refactored
1 parent 341badb commit d1c4675

24 files changed

+384
-546
lines changed

src/model/receipt/Statement.ts

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { Address } from '../account/Address';
18+
import { Mosaic } from '../mosaic/Mosaic';
1819
import { MosaicId } from '../mosaic/MosaicId';
1920
import { NamespaceId } from '../namespace/NamespaceId';
2021
import { ResolutionStatement } from './ResolutionStatement';
@@ -45,6 +46,61 @@ export class Statement {
4546
}
4647

4748
/**
49+
* Resolve unresolvedAddress from statement
50+
* @param unresolvedAddress Unresolved address
51+
* @param height Block height
52+
* @param transactionIndex Transaction index
53+
* @param aggregateTransactionIndex Aggregate transaction index
54+
* @returns {Address}
55+
*/
56+
public resolveAddress(unresolvedAddress: Address | NamespaceId,
57+
height: string,
58+
transactionIndex: number,
59+
aggregateTransactionIndex: number = 0): Address {
60+
return unresolvedAddress instanceof NamespaceId ?
61+
this.getResolvedFromReceipt(ResolutionType.Address, unresolvedAddress as NamespaceId,
62+
transactionIndex, height, aggregateTransactionIndex) as Address :
63+
unresolvedAddress;
64+
}
65+
66+
/**
67+
* Resolve unresolvedMosaicId from statement
68+
* @param unresolvedMosaicId Unresolved mosaic id
69+
* @param height Block height
70+
* @param transactionIndex Transaction index
71+
* @param aggregateTransactionIndex Aggregate transaction index
72+
* @returns {MosaicId}
73+
*/
74+
public resolveMosaicId(unresolvedMosaicId: MosaicId | NamespaceId,
75+
height: string,
76+
transactionIndex: number,
77+
aggregateTransactionIndex: number = 0): MosaicId {
78+
return unresolvedMosaicId instanceof NamespaceId ?
79+
this.getResolvedFromReceipt(ResolutionType.Mosaic, unresolvedMosaicId as NamespaceId,
80+
transactionIndex, height, aggregateTransactionIndex) as MosaicId :
81+
unresolvedMosaicId;
82+
}
83+
84+
/**
85+
* Resolve unresolvedMosaic from statement
86+
* @param unresolvedMosaic Unresolved mosaic
87+
* @param height Block height
88+
* @param transactionIndex Transaction index
89+
* @param aggregateTransactionIndex Aggregate transaction index
90+
* @returns {Mosaic}
91+
*/
92+
public resolveMosaic(unresolvedMosaic: Mosaic,
93+
height: string,
94+
transactionIndex: number,
95+
aggregateTransactionIndex: number = 0): Mosaic {
96+
return unresolvedMosaic.id instanceof NamespaceId ?
97+
new Mosaic(this.getResolvedFromReceipt(ResolutionType.Mosaic, unresolvedMosaic.id as NamespaceId,
98+
transactionIndex, height, aggregateTransactionIndex) as MosaicId, unresolvedMosaic.amount) :
99+
unresolvedMosaic;
100+
}
101+
102+
/**
103+
* @internal
48104
* Extract resolved address | mosaic from block receipt
49105
* @param resolutionType Resolution type: Address / Mosaic
50106
* @param unresolved Unresolved address / mosaicId
@@ -53,11 +109,11 @@ export class Statement {
53109
* @param aggregateTransactionIndex Transaction index for aggregate
54110
* @returns {MosaicId | Address}
55111
*/
56-
public getResolvedFromReceipt(resolutionType: ResolutionType,
57-
unresolved: NamespaceId,
58-
transactionIndex: number,
59-
height: string,
60-
aggregateTransactionIndex?: number): MosaicId | Address {
112+
private getResolvedFromReceipt(resolutionType: ResolutionType,
113+
unresolved: NamespaceId,
114+
transactionIndex: number,
115+
height: string,
116+
aggregateTransactionIndex?: number): MosaicId | Address {
61117

62118
const resolutionStatement = (resolutionType === ResolutionType.Address ? this.addressResolutionStatements :
63119
this.mosaicResolutionStatements).find((resolution) => resolution.height.toString() === height &&

src/model/transaction/AccountAddressRestrictionTransaction.ts

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

17-
import { combineLatest, of } from 'rxjs';
18-
import { Observable } from 'rxjs/internal/Observable';
19-
import { map } from 'rxjs/operators';
2017
import { Convert } from '../../core/format';
2118
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
2219
import { AccountAddressRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountAddressRestrictionTransactionBuilder';
@@ -28,13 +25,11 @@ import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2825
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2926
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
3027
import { UnresolvedAddressDto } from '../../infrastructure/catbuffer/UnresolvedAddressDto';
31-
import { ReceiptHttp } from '../../infrastructure/ReceiptHttp';
32-
import { TransactionService } from '../../service/TransactionService';
3328
import { Address } from '../account/Address';
3429
import { PublicAccount } from '../account/PublicAccount';
3530
import { NetworkType } from '../blockchain/NetworkType';
3631
import { NamespaceId } from '../namespace/NamespaceId';
37-
import { ResolutionType } from '../receipt/ResolutionType';
32+
import { Statement } from '../receipt/Statement';
3833
import { AccountRestrictionFlags } from '../restriction/AccountRestrictionType';
3934
import { UInt64 } from '../UInt64';
4035
import { Deadline } from './Deadline';
@@ -198,56 +193,25 @@ export class AccountAddressRestrictionTransaction extends Transaction {
198193

199194
/**
200195
* @internal
201-
* @param receiptHttp ReceiptHttp
196+
* @param statement Block receipt statement
202197
* @param aggregateTransactionIndex Transaction index for aggregated transaction
203-
* @returns {Observable<AccountAddressRestrictionTransaction>}
198+
* @returns {AccountAddressRestrictionTransaction}
204199
*/
205-
resolveAliases(receiptHttp: ReceiptHttp, aggregateTransactionIndex?: number): Observable<AccountAddressRestrictionTransaction> {
206-
const hasUnresolved = this.restrictionAdditions.find((address) => address instanceof NamespaceId) !== undefined ||
207-
this.restrictionDeletions.find((address) => address instanceof NamespaceId) !== undefined;
208-
209-
if (!hasUnresolved) {
210-
return of(this);
211-
}
212-
200+
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountAddressRestrictionTransaction {
213201
const transactionInfo = this.checkTransactionHeightAndIndex();
214-
215-
const statementObservable = receiptHttp.getBlockReceipts(transactionInfo.height.toString());
216-
const restrictionAdditions = statementObservable.pipe(
217-
map((statement) => {
218-
return this.restrictionAdditions.map((addition) => {
219-
return addition instanceof NamespaceId ?
220-
statement.getResolvedFromReceipt(ResolutionType.Address, addition as NamespaceId,
221-
transactionInfo.index, transactionInfo.height.toString(), aggregateTransactionIndex) as Address :
222-
addition;
223-
});
224-
}),
202+
return new AccountAddressRestrictionTransaction(
203+
this.networkType,
204+
this.version,
205+
this.deadline,
206+
this.maxFee,
207+
this.restrictionFlags,
208+
this.restrictionAdditions.map((addition) => statement.resolveAddress(addition, transactionInfo.height.toString(),
209+
transactionInfo.index, aggregateTransactionIndex)),
210+
this.restrictionDeletions.map((deletion) => statement.resolveAddress(deletion, transactionInfo.height.toString(),
211+
transactionInfo.index, aggregateTransactionIndex)),
212+
this.signature,
213+
this.signer,
214+
this.transactionInfo,
225215
);
226-
227-
const restrictionDeletions = statementObservable.pipe(
228-
map((statement) => {
229-
return this.restrictionDeletions.map((deletion) => {
230-
return deletion instanceof NamespaceId ?
231-
statement.getResolvedFromReceipt(ResolutionType.Address, deletion as NamespaceId,
232-
transactionInfo.index, transactionInfo.height.toString(), aggregateTransactionIndex) as Address :
233-
deletion;
234-
});
235-
}),
236-
);
237-
238-
return combineLatest(restrictionAdditions, restrictionDeletions, (additions, deletions) => {
239-
return new AccountAddressRestrictionTransaction(
240-
this.networkType,
241-
this.version,
242-
this.deadline,
243-
this.maxFee,
244-
this.restrictionFlags,
245-
additions,
246-
deletions,
247-
this.signature,
248-
this.signer,
249-
this.transactionInfo,
250-
);
251-
});
252216
}
253217
}

src/model/transaction/AccountLinkTransaction.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Observable } from 'rxjs/internal/Observable';
18-
import { of } from 'rxjs/internal/observable/of';
1917
import { Convert } from '../../core/format';
2018
import { AccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/AccountLinkTransactionBuilder';
2119
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
2220
import { EmbeddedAccountLinkTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountLinkTransactionBuilder';
2321
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2422
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2523
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
26-
import { ReceiptHttp } from '../../infrastructure/ReceiptHttp';
2724
import { PublicAccount } from '../account/PublicAccount';
2825
import { NetworkType } from '../blockchain/NetworkType';
2926
import { UInt64 } from '../UInt64';
@@ -169,10 +166,9 @@ export class AccountLinkTransaction extends Transaction {
169166

170167
/**
171168
* @internal
172-
* @param receiptHttp ReceiptHttp
173-
* @returns {Observable<AccountLinkTransaction>}
169+
* @returns {AccountLinkTransaction}
174170
*/
175-
resolveAliases(receiptHttp: ReceiptHttp): Observable<AccountLinkTransaction> {
176-
return of(this);
171+
resolveAliases(): AccountLinkTransaction {
172+
return this;
177173
}
178174
}

src/model/transaction/AccountMetadataTransaction.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Observable } from 'rxjs/internal/Observable';
18-
import { of } from 'rxjs/internal/observable/of';
1917
import { Convert } from '../../core/format';
2018
import { AccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/AccountMetadataTransactionBuilder';
2119
import { AmountDto } from '../../infrastructure/catbuffer/AmountDto';
2220
import { EmbeddedAccountMetadataTransactionBuilder } from '../../infrastructure/catbuffer/EmbeddedAccountMetadataTransactionBuilder';
2321
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2422
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2523
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
26-
import { ReceiptHttp } from '../../infrastructure/ReceiptHttp';
2724
import { PublicAccount } from '../account/PublicAccount';
2825
import { NetworkType } from '../blockchain/NetworkType';
2926
import { UInt64 } from '../UInt64';
@@ -199,10 +196,9 @@ export class AccountMetadataTransaction extends Transaction {
199196

200197
/**
201198
* @internal
202-
* @param receiptHttp ReceiptHttp
203-
* @returns {Observable<AccountMetadataTransaction>}
199+
* @returns {AccountMetadataTransaction}
204200
*/
205-
resolveAliases(receiptHttp: ReceiptHttp): Observable<AccountMetadataTransaction> {
206-
return of(this);
201+
resolveAliases(): AccountMetadataTransaction {
202+
return this;
207203
}
208204
}

src/model/transaction/AccountMosaicRestrictionTransaction.ts

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

17-
import { combineLatest, of } from 'rxjs';
18-
import { Observable } from 'rxjs/internal/Observable';
19-
import { map } from 'rxjs/operators';
2017
import { Convert } from '../../core/format';
2118
import { UnresolvedMapping } from '../../core/utils/UnresolvedMapping';
2219
import { AccountMosaicRestrictionTransactionBuilder } from '../../infrastructure/catbuffer/AccountMosaicRestrictionTransactionBuilder';
@@ -28,13 +25,11 @@ import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2825
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2926
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
3027
import { UnresolvedMosaicIdDto } from '../../infrastructure/catbuffer/UnresolvedMosaicIdDto';
31-
import { ReceiptHttp } from '../../infrastructure/ReceiptHttp';
32-
import { TransactionService } from '../../service/TransactionService';
3328
import { PublicAccount } from '../account/PublicAccount';
3429
import { NetworkType } from '../blockchain/NetworkType';
3530
import { MosaicId } from '../mosaic/MosaicId';
3631
import { NamespaceId } from '../namespace/NamespaceId';
37-
import { ResolutionType } from '../receipt/ResolutionType';
32+
import { Statement } from '../receipt/Statement';
3833
import { AccountRestrictionFlags } from '../restriction/AccountRestrictionType';
3934
import { UInt64 } from '../UInt64';
4035
import { Deadline } from './Deadline';
@@ -198,56 +193,25 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
198193

199194
/**
200195
* @internal
201-
* @param receiptHttp ReceiptHttp
196+
* @param statement Block receipt statement
202197
* @param aggregateTransactionIndex Transaction index for aggregated transaction
203-
* @returns {Observable<AccountMosaicRestrictionTransaction>}
198+
* @returns {AccountMosaicRestrictionTransaction}
204199
*/
205-
resolveAliases(receiptHttp: ReceiptHttp, aggregateTransactionIndex?: number): Observable<AccountMosaicRestrictionTransaction> {
206-
const hasUnresolved = this.restrictionAdditions.find((mosaicId) => mosaicId instanceof NamespaceId) !== undefined ||
207-
this.restrictionDeletions.find((mosaicId) => mosaicId instanceof NamespaceId) !== undefined;
208-
209-
if (!hasUnresolved) {
210-
return of(this);
211-
}
212-
200+
resolveAliases(statement: Statement, aggregateTransactionIndex: number = 0): AccountMosaicRestrictionTransaction {
213201
const transactionInfo = this.checkTransactionHeightAndIndex();
214-
215-
const statementObservable = receiptHttp.getBlockReceipts(transactionInfo.height.toString());
216-
const restrictionAdditions = statementObservable.pipe(
217-
map((statement) => {
218-
return this.restrictionAdditions.map((addition) => {
219-
return addition instanceof NamespaceId ?
220-
statement.getResolvedFromReceipt(ResolutionType.Mosaic, addition as NamespaceId,
221-
transactionInfo.index, transactionInfo.height.toString(), aggregateTransactionIndex) as MosaicId :
222-
addition;
223-
});
224-
}),
202+
return new AccountMosaicRestrictionTransaction(
203+
this.networkType,
204+
this.version,
205+
this.deadline,
206+
this.maxFee,
207+
this.restrictionFlags,
208+
this.restrictionAdditions.map((addition) => statement.resolveMosaicId(addition, transactionInfo.height.toString(),
209+
transactionInfo.index, aggregateTransactionIndex)),
210+
this.restrictionDeletions.map((deletion) => statement.resolveMosaicId(deletion, transactionInfo.height.toString(),
211+
transactionInfo.index, aggregateTransactionIndex)),
212+
this.signature,
213+
this.signer,
214+
this.transactionInfo,
225215
);
226-
227-
const restrictionDeletions = statementObservable.pipe(
228-
map((statement) => {
229-
return this.restrictionDeletions.map((deletion) => {
230-
return deletion instanceof NamespaceId ?
231-
statement.getResolvedFromReceipt(ResolutionType.Mosaic, deletion as NamespaceId,
232-
transactionInfo.index, transactionInfo.height.toString(), aggregateTransactionIndex) as MosaicId :
233-
deletion;
234-
});
235-
}),
236-
);
237-
238-
return combineLatest(restrictionAdditions, restrictionDeletions, (additions, deletions) => {
239-
return new AccountMosaicRestrictionTransaction(
240-
this.networkType,
241-
this.version,
242-
this.deadline,
243-
this.maxFee,
244-
this.restrictionFlags,
245-
additions,
246-
deletions,
247-
this.signature,
248-
this.signer,
249-
this.transactionInfo,
250-
);
251-
});
252216
}
253217
}

src/model/transaction/AccountOperationRestrictionTransaction.ts

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

17-
import { Observable } from 'rxjs/internal/Observable';
18-
import { of } from 'rxjs/internal/observable/of';
1917
import { Convert } from '../../core/format';
2018
import {
2119
AccountOperationRestrictionTransactionBuilder,
@@ -27,7 +25,6 @@ import {
2725
import { KeyDto } from '../../infrastructure/catbuffer/KeyDto';
2826
import { SignatureDto } from '../../infrastructure/catbuffer/SignatureDto';
2927
import { TimestampDto } from '../../infrastructure/catbuffer/TimestampDto';
30-
import { ReceiptHttp } from '../../infrastructure/ReceiptHttp';
3128
import { PublicAccount } from '../account/PublicAccount';
3229
import { NetworkType } from '../blockchain/NetworkType';
3330
import { AccountRestrictionFlags } from '../restriction/AccountRestrictionType';
@@ -180,10 +177,9 @@ export class AccountOperationRestrictionTransaction extends Transaction {
180177

181178
/**
182179
* @internal
183-
* @param receiptHttp ReceiptHttp
184-
* @returns {Observable<AccountOperationRestrictionTransaction>}
180+
* @returns {AccountOperationRestrictionTransaction}
185181
*/
186-
resolveAliases(receiptHttp: ReceiptHttp): Observable<AccountOperationRestrictionTransaction> {
187-
return of(this);
182+
resolveAliases(): AccountOperationRestrictionTransaction {
183+
return this;
188184
}
189185
}

src/model/transaction/AddressAliasTransaction.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,9 @@ export class AddressAliasTransaction extends Transaction {
189189

190190
/**
191191
* @internal
192-
* @param receiptHttp ReceiptHttp
193-
* @returns {Observable<AddressAliasTransaction>}
192+
* @returns {AddressAliasTransaction}
194193
*/
195-
resolveAliases(receiptHttp: ReceiptHttp): Observable<AddressAliasTransaction> {
196-
return of(this);
194+
resolveAliases(): AddressAliasTransaction {
195+
return this;
197196
}
198197
}

0 commit comments

Comments
 (0)