Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@types/crypto-js": "^3.1.43",
"crypto-js": "^3.1.9-1",
"js-joda": "^1.6.2",
"nem2-library": "^0.9.11",
"nem2-library": "^0.9.12",
"request": "^2.83.0",
"request-promise-native": "^1.0.5",
"rxjs": "^6.2.1",
Expand Down
15 changes: 12 additions & 3 deletions src/infrastructure/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as WebSocket from 'ws';
import {Address} from '../model/account/Address';
import {PublicAccount} from '../model/account/PublicAccount';
import {BlockInfo} from '../model/blockchain/BlockInfo';
import {NamespaceId} from '../model/namespace/NamespaceId';
import {AggregateTransaction} from '../model/transaction/AggregateTransaction';
import {AggregateTransactionCosignature} from '../model/transaction/AggregateTransactionCosignature';
import {CosignatureSignedTransaction} from '../model/transaction/CosignatureSignedTransaction';
Expand Down Expand Up @@ -375,8 +376,16 @@ export class Listener {
* @param address
* @returns {boolean}
*/
private transactionHasSignerOrReceptor(transaction: Transaction, address: Address): boolean {
return transaction.signer!.address.equals(address) ||
(transaction instanceof TransferTransaction && transaction.recipient.equals(address));
private transactionHasSignerOrReceptor(transaction: Transaction, address: Address | NamespaceId): boolean {

if (address instanceof NamespaceId) {
return transaction instanceof TransferTransaction
&& (transaction.recipient as NamespaceId).equals(address);
}

return transaction.signer!.address.equals(address) || (
transaction instanceof TransferTransaction
&& (transaction.recipient as Address).equals(address)
);
}
}
8 changes: 8 additions & 0 deletions src/model/namespace/MosaicAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ export class MosaicAlias implements Alias {
}
return false;
}

/**
* Get string value of mosaicId
* @returns {string}
*/
public toHex(): string {
return this.mosaicId.toHex();
}
}
4 changes: 2 additions & 2 deletions src/model/transaction/AddressAliasTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class AddressAliasTransaction extends Transaction {
address: Address,
networkType: NetworkType): AddressAliasTransaction {
return new AddressAliasTransaction(networkType,
TransactionVersion.MOSAIC_ALIAS,
TransactionVersion.ADDRESS_ALIAS,
deadline,
new UInt64([0, 0]),
actionType,
Expand Down Expand Up @@ -88,7 +88,7 @@ export class AddressAliasTransaction extends Transaction {
signature?: string,
signer?: PublicAccount,
transactionInfo?: TransactionInfo) {
super(TransactionType.MOSAIC_ALIAS, networkType, version, deadline, fee, signature, signer, transactionInfo);
super(TransactionType.ADDRESS_ALIAS, networkType, version, deadline, fee, signature, signer, transactionInfo);
}

/**
Expand Down
22 changes: 19 additions & 3 deletions src/model/transaction/TransferTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Address } from '../account/Address';
import { PublicAccount } from '../account/PublicAccount';
import { NetworkType } from '../blockchain/NetworkType';
import { Mosaic } from '../mosaic/Mosaic';
import { NamespaceId } from '../namespace/NamespaceId';
import { UInt64 } from '../UInt64';
import { Deadline } from './Deadline';
import { Message } from './Message';
Expand All @@ -41,7 +42,7 @@ export class TransferTransaction extends Transaction {
* @returns {TransferTransaction}
*/
public static create(deadline: Deadline,
recipient: Address,
recipient: Address | NamespaceId,
mosaics: Mosaic[],
message: Message,
networkType: NetworkType): TransferTransaction {
Expand Down Expand Up @@ -73,7 +74,7 @@ export class TransferTransaction extends Transaction {
/**
* The address of the recipient.
*/
public readonly recipient: Address,
public readonly recipient: Address | NamespaceId,
/**
* The array of Mosaic objects.
*/
Expand All @@ -88,6 +89,21 @@ export class TransferTransaction extends Transaction {
super(TransactionType.TRANSFER, networkType, version, deadline, fee, signature, signer, transactionInfo);
}

/**
* Return the string notation for the set recipient
* @internal
* @returns {string}
*/
public recipientToString(): string {
if (this.recipient instanceof NamespaceId) {
// namespaceId available, return hexadecimal notation
return (this.recipient as NamespaceId).toHex();
}

// address available
return (this.recipient as Address).plain();
}

/**
* @internal
* @returns {VerifiableTransaction}
Expand All @@ -97,7 +113,7 @@ export class TransferTransaction extends Transaction {
.addDeadline(this.deadline.toDTO())
.addFee(this.fee.toDTO())
.addVersion(this.versionToDTO())
.addRecipient(this.recipient.plain())
.addRecipient(this.recipientToString())
.addMosaics(this.mosaics.map((mosaic) => mosaic.toDTO()))
.addMessage(this.message)
.build();
Expand Down
78 changes: 76 additions & 2 deletions test/model/transaction/TransferTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Account } from '../../../src/model/account/Account';
import { Address } from '../../../src/model/account/Address';
import { NetworkType } from '../../../src/model/blockchain/NetworkType';
import { NetworkCurrencyMosaic } from '../../../src/model/mosaic/NetworkCurrencyMosaic';
import { NamespaceId } from '../../../src/model/namespace/NamespaceId';
import { Deadline } from '../../../src/model/transaction/Deadline';
import { PlainMessage } from '../../../src/model/transaction/PlainMessage';
import { TransferTransaction } from '../../../src/model/transaction/TransferTransaction';
Expand All @@ -42,7 +43,8 @@ describe('TransferTransaction', () => {

expect(transferTransaction.message.payload).to.be.equal('test-message');
expect(transferTransaction.mosaics.length).to.be.equal(0);
expect(transferTransaction.recipient.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
expect(transferTransaction.recipient).to.be.instanceof(Address);
expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');

const signedTransaction = transferTransaction.signWith(account);

Expand All @@ -65,7 +67,8 @@ describe('TransferTransaction', () => {

expect(transferTransaction.message.payload).to.be.equal('test-message');
expect(transferTransaction.mosaics.length).to.be.equal(1);
expect(transferTransaction.recipient.plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
expect(transferTransaction.recipient).to.be.instanceof(Address);
expect((transferTransaction.recipient as Address).plain()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');

const signedTransaction = transferTransaction.signWith(account);

Expand All @@ -76,4 +79,75 @@ describe('TransferTransaction', () => {
'9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000100746573742D6D657373616765' +
'44B262C46CEABB8500E1F50500000000');
});

it('should createComplete an TransferTransaction object with NamespaceId recipient', () => {
const addressAlias = new NamespaceId('nem.owner');
const transferTransaction = TransferTransaction.create(
Deadline.create(),
addressAlias,
[
NetworkCurrencyMosaic.createRelative(100),
],
PlainMessage.create('test-message'),
NetworkType.MIJIN_TEST,
);

expect(transferTransaction.message.payload).to.be.equal('test-message');
expect(transferTransaction.mosaics.length).to.be.equal(1);
expect(transferTransaction.recipient).to.be.instanceof(NamespaceId);
expect(transferTransaction.recipient).to.be.equal(addressAlias);
expect((transferTransaction.recipient as NamespaceId).toHex()).to.be.equal(addressAlias.toHex());

const signedTransaction = transferTransaction.signWith(account);

expect(signedTransaction.payload.substring(
240,
signedTransaction.payload.length,
)).to.be.equal('9151776168D24257D8000000000000000000000000000000000D000100746573742D6D657373616765' +
'44B262C46CEABB8500E1F50500000000');
});

it('should format TransferTransaction payload with 25 bytes binary address', () => {
const transferTransaction = TransferTransaction.create(
Deadline.create(),
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
[
NetworkCurrencyMosaic.createRelative(100),
],
PlainMessage.create('test-message'),
NetworkType.MIJIN_TEST,
);

// test recipientToString with Address recipient
expect(transferTransaction.recipientToString()).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');

const signedTransaction = transferTransaction.signWith(account);

expect(signedTransaction.payload.substring(
240,
290,
)).to.be.equal('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142');
});

it('should format TransferTransaction payload with 8 bytes binary namespaceId', () => {
const transferTransaction = TransferTransaction.create(
Deadline.create(),
new NamespaceId('nem.owner'),
[
NetworkCurrencyMosaic.createRelative(100),
],
PlainMessage.create('test-message'),
NetworkType.MIJIN_TEST,
);

// test recipientToString with NamespaceId recipient
expect(transferTransaction.recipientToString()).to.be.equal('d85742d268617751');

const signedTransaction = transferTransaction.signWith(account);

expect(signedTransaction.payload.substring(
240,
290,
)).to.be.equal('9151776168D24257D800000000000000000000000000000000');
});
});