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
14 changes: 8 additions & 6 deletions src/model/transaction/TransferTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,15 @@ export class TransferTransaction extends Transaction {
if (!this.message || !this.message.payload) {
return Uint8Array.of();
}
const messgeHex =
this.message.type === MessageType.PersistentHarvestingDelegationMessage
? this.message.payload
: Convert.utf8ToHex(this.message.payload);
const payloadBuffer = Convert.hexToUint8(messgeHex);
const isPersistentHarvestingDelegationMessage = this.message.type === MessageType.PersistentHarvestingDelegationMessage;
const isRawMessage = this.message.type === MessageType.RawMessage;

const messageHex =
isPersistentHarvestingDelegationMessage || isRawMessage ? this.message.payload : Convert.utf8ToHex(this.message.payload);
const payloadBuffer = Convert.hexToUint8(messageHex);
const typeBuffer = GeneratorUtils.uintToBuffer(this.message.type, 1);
return this.message.type === MessageType.PersistentHarvestingDelegationMessage || !this.message.payload

return isPersistentHarvestingDelegationMessage || isRawMessage || !this.message.payload
? payloadBuffer
: GeneratorUtils.concatTypedArrays(typeBuffer, payloadBuffer);
}
Expand Down
25 changes: 24 additions & 1 deletion test/model/transaction/TransferTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { TransactionMapping } from '../../../src/core/utils';
import { CreateTransactionFromPayload } from '../../../src/infrastructure/transaction';
import { PersistentHarvestingDelegationMessage, UInt64 } from '../../../src/model';
import { Account, Address } from '../../../src/model/account';
import { EmptyMessage, MessageMarker, MessageType, PlainMessage } from '../../../src/model/message';
import { EmptyMessage, MessageMarker, MessageType, PlainMessage, RawMessage } from '../../../src/model/message';
import { Mosaic, MosaicId } from '../../../src/model/mosaic';
import { NamespaceId } from '../../../src/model/namespace';
import { NetworkType } from '../../../src/model/network';
Expand Down Expand Up @@ -133,6 +133,29 @@ describe('TransferTransaction', () => {
);
});

it('should createComplete an TransferTransaction object with raw message', () => {
// Arrange:
const messageBytes = new Uint8Array([3, 2, 1, 123, 0, 255]);
const messageHex = '0302017B00FF';

// Act:
const transferTransaction = TransferTransaction.create(
Deadline.create(epochAdjustment),
testAddress,
[],
RawMessage.create(messageBytes),
TestNetworkType,
);
const transactionPayload = transferTransaction.signWith(account, generationHash).payload;
const recreatedTransferTransaction = TransferTransaction.createFromPayload(transactionPayload) as TransferTransaction;

// Assert:
expect(transferTransaction.message.type).to.be.equal(MessageType.RawMessage);
expect(transferTransaction.message.payload).to.be.equal(messageHex);
expect(recreatedTransferTransaction.message.type).to.be.equal(MessageType.RawMessage);
expect(recreatedTransferTransaction.message.payload).to.be.equal(messageHex);
});

it('should createComplete an TransferTransaction object and sign it with mosaics', () => {
const transferTransaction = TransferTransaction.create(
Deadline.create(epochAdjustment),
Expand Down