Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All transaction related notification should take an unresolved address #731

Merged
merged 4 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
68 changes: 66 additions & 2 deletions e2e/infrastructure/Listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import { filter, mergeMap } from 'rxjs/operators';
import { TransactionSearchCriteria } from '../../src/infrastructure/searchCriteria/TransactionSearchCriteria';
import { TransactionGroup } from '../../src/infrastructure/TransactionGroup';
import { TransactionRepository } from '../../src/infrastructure/TransactionRepository';
import { Account, Address } from '../../src/model/account';
import { Account, UnresolvedAddress } from '../../src/model/account';
import { PlainMessage } from '../../src/model/message/PlainMessage';
import { Currency } from '../../src/model/mosaic';
import { NamespaceId } from '../../src/model/namespace';
import { NetworkType } from '../../src/model/network/NetworkType';
import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction';
import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction';
Expand All @@ -44,6 +45,7 @@ describe('Listener', () => {
let generationHash: string;
let networkType: NetworkType;
let transactionRepository: TransactionRepository;
const unresolvedAddress = new NamespaceId('address');

before(() => {
return helper.start({ openListener: true }).then(() => {
Expand All @@ -67,7 +69,11 @@ describe('Listener', () => {
setTimeout(done, 200);
});

const createSignedAggregatedBondTransaction = (aggregatedTo: Account, signer: Account, recipient: Address): SignedTransaction => {
const createSignedAggregatedBondTransaction = (
aggregatedTo: Account,
signer: Account,
recipient: UnresolvedAddress,
): SignedTransaction => {
const transferTransaction = TransferTransaction.create(
Deadline.create(helper.epochAdjustment),
recipient,
Expand Down Expand Up @@ -175,6 +181,46 @@ describe('Listener', () => {
});
});

describe('UnConfirmed', () => {
it('unconfirmedTransactionsAdded with unresolved address', (done) => {
const transferTransaction = TransferTransaction.create(
Deadline.create(helper.epochAdjustment),
unresolvedAddress,
[],
PlainMessage.create('test-message'),
networkType,
helper.maxFee,
);
const signedTransaction = account.sign(transferTransaction, generationHash);
helper.listener
.unconfirmedAdded(unresolvedAddress)
.pipe(filter((_) => _.transactionInfo!.hash === signedTransaction.hash))
.subscribe(() => {
done();
});
transactionRepository.announce(signedTransaction);
});

it('unconfirmedTransactionsRemoved with unresolved address', (done) => {
const transferTransaction = TransferTransaction.create(
Deadline.create(helper.epochAdjustment),
unresolvedAddress,
[],
PlainMessage.create('test-message'),
networkType,
helper.maxFee,
);
const signedTransaction = account.sign(transferTransaction, generationHash);
helper.listener
.unconfirmedRemoved(unresolvedAddress)
.pipe(filter((hash) => hash === signedTransaction.hash))
.subscribe(() => {
done();
});
transactionRepository.announce(signedTransaction);
});
});

describe('TransferTransaction', () => {
it('standalone', () => {
const transferTransaction = TransferTransaction.create(
Expand Down Expand Up @@ -312,6 +358,24 @@ describe('Listener', () => {
});
});

describe('Aggregate Bonded Transactions', () => {
it('aggregateBondedTransactionsAdded', (done) => {
const signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, account, account2.address);
createHashLockTransactionAndAnnounce(signedAggregatedTx, account, helper.networkCurrency);
helper.listener.aggregateBondedAdded(unresolvedAddress).subscribe(() => {
done();
});
helper.listener.confirmed(unresolvedAddress).subscribe(() => {
transactionRepository.announceAggregateBonded(signedAggregatedTx);
});
helper.listener.status(unresolvedAddress).subscribe((error) => {
console.log('Error:', error);
assert(false);
done();
});
});
});

describe('MultisigAccountModificationTransaction - Restore multisig Accounts', () => {
it('Restore Multisig Account', () => {
const removeCosigner1 = MultisigAccountModificationTransaction.create(
Expand Down
30 changes: 15 additions & 15 deletions src/infrastructure/IListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { Observable } from 'rxjs';
import { Address } from '../model/account/Address';
import { UnresolvedAddress } from '../model';
import { FinalizedBlock } from '../model/blockchain/FinalizedBlock';
import { NewBlock } from '../model/blockchain/NewBlock';
import { AggregateTransaction } from '../model/transaction/AggregateTransaction';
Expand Down Expand Up @@ -72,75 +72,75 @@ export interface IListener {
* Each time a transaction is in confirmed state an it involves the address,
* it emits a new Transaction in the event stream.
*
* @param address address we listen when a transaction is in confirmed state
* @param unresolvedAddress unresolved address we listen when a transaction is in confirmed state
* @param transactionHash transactionHash for filtering multiple transactions
* @return an observable stream of Transaction with state confirmed
*/

confirmed(address: Address, transactionHash?: string): Observable<Transaction>;
confirmed(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<Transaction>;

/**
* Returns an observable stream of Transaction for a specific address.
* Each time a transaction is in unconfirmed state an it involves the address,
* it emits a new Transaction in the event stream.
*
* @param address address we listen when a transaction is in unconfirmed state
* @param unresolvedAddress unresolved address we listen when a transaction is in unconfirmed state
* @param transactionHash transactionHash for filtering multiple transactions
* @return an observable stream of Transaction with state unconfirmed
*/
unconfirmedAdded(address: Address, transactionHash?: string): Observable<Transaction>;
unconfirmedAdded(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<Transaction>;

/**
* Returns an observable stream of Transaction Hashes for specific address.
* Each time a transaction with state unconfirmed changes its state,
* it emits a new message with the transaction hash in the event stream.
*
* @param address address we listen when a transaction is removed from unconfirmed state
* @param unresolvedAddress unresolved address we listen when a transaction is removed from unconfirmed state
* @param transactionHash the transaction hash filter.
* @return an observable stream of Strings with the transaction hash
*/
unconfirmedRemoved(address: Address, transactionHash?: string): Observable<string>;
unconfirmedRemoved(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<string>;

/**
* Return an observable of {@link AggregateTransaction} for specific address.
* Each time an aggregate bonded transaction is announced,
* it emits a new {@link AggregateTransaction} in the event stream.
*
* @param address address we listen when a transaction with missing signatures state
* @param unresolvedAddress unresolved address we listen when a transaction with missing signatures state
* @param transactionHash transactionHash for filtering multiple transactions
* @return an observable stream of AggregateTransaction with missing signatures state
*/
aggregateBondedAdded(address: Address, transactionHash?: string): Observable<AggregateTransaction>;
aggregateBondedAdded(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<AggregateTransaction>;

/**
* Returns an observable stream of Transaction Hashes for specific address.
* Each time an aggregate bonded transaction is announced,
* it emits a new message with the transaction hash in the event stream.
*
* @param address address we listen when a transaction is confirmed or rejected
* @param unresolvedAddress unresolved address we listen when a transaction is confirmed or rejected
* @param transactionHash the transaction hash filter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid address name in docs

* @return an observable stream of Strings with the transaction hash
*/
aggregateBondedRemoved(address: Address, transactionHash?: string): Observable<string>;
aggregateBondedRemoved(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<string>;

/**
* Returns an observable stream of {@link TransactionStatusError} for specific address.
* Each time a transaction contains an error,
* it emits a new message with the transaction status error in the event stream.
*
* @param address address we listen to be notified when some error happened
* @param unresolvedAddress unresolved address we listen to be notified when some error happened
* @param transactionHash transactionHash for filtering multiple transactions
* @return an observable stream of {@link TransactionStatusError}
*/
status(address: Address, transactionHash?: string): Observable<TransactionStatusError>;
status(unresolvedAddress: UnresolvedAddress, transactionHash?: string): Observable<TransactionStatusError>;

/**
* Returns an observable stream of {@link CosignatureSignedTransaction} for specific address.
* Each time a cosigner signs a transaction the address initialized,
* it emits a new message with the cosignatory signed transaction in the even stream.
*
* @param address address we listen when a cosignatory is added to some transaction address sent
* @param unresolvedAddress unresolved address we listen when a cosignatory is added to some transaction address sent
* @return an observable stream of {@link CosignatureSignedTransaction}
*/
cosignatureAdded(address: Address): Observable<CosignatureSignedTransaction>;
cosignatureAdded(unresolvedAddress: UnresolvedAddress): Observable<CosignatureSignedTransaction>;
}