File tree Expand file tree Collapse file tree 3 files changed +32
-18
lines changed Expand file tree Collapse file tree 3 files changed +32
-18
lines changed Original file line number Diff line number Diff line change 1515 */
1616
1717import { VerifiableTransaction } from 'nem2-library' ;
18+ import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON' ;
1819import { Account } from '../account/Account' ;
1920import { PublicAccount } from '../account/PublicAccount' ;
2021import { NetworkType } from '../blockchain/NetworkType' ;
@@ -25,7 +26,6 @@ import { InnerTransaction } from './InnerTransaction';
2526import { SignedTransaction } from './SignedTransaction' ;
2627import { TransactionInfo } from './TransactionInfo' ;
2728import { TransactionType } from './TransactionType' ;
28- import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON' ;
2929
3030/**
3131 * An abstract transaction class that serves as the base class of all NEM transactions.
@@ -176,7 +176,19 @@ export abstract class Transaction {
176176 }
177177
178178 /**
179- * Create JSON object
179+ * @description Serialize a transaction object
180+ * @returns {string }
181+ * @memberof Transaction
182+ */
183+ public serialize ( ) {
184+ const transaction = this . buildTransaction ( ) ;
185+ return transaction . serializeUnsignedTransaction ( ) ;
186+ }
187+
188+ /**
189+ * @description Create JSON object
190+ * @returns {Object }
191+ * @memberof Transaction
180192 */
181193 public toJSON ( ) {
182194 const commonTransactionObject = {
Original file line number Diff line number Diff line change @@ -37,20 +37,4 @@ export class TransactionMapping {
3737 public static createFromPayload ( dataBytes : string ) : Transaction {
3838 return CreateTransactionFromPayload ( dataBytes ) ;
3939 }
40-
41- /**
42- * Serialize a transaction.
43- * @returns {string } Serialized transaction in binary.
44- */
45- public static serialize ( ) : string {
46- throw new Error ( ) ;
47- }
48-
49- /**
50- * Create transaction class from Json.
51- * @returns {object } Serialized transaction in json object.
52- */
53- public static serializeJson ( ) : object {
54- throw new Error ( ) ;
55- }
5640}
Original file line number Diff line number Diff line change @@ -180,6 +180,24 @@ describe('Transaction', () => {
180180 } ) . to . throw ( Error , 'Inner transaction cannot be an aggregated transaction.' ) ;
181181 } ) ;
182182 } ) ;
183+
184+ describe ( 'Transaction serialize' , ( ) => {
185+ it ( 'Should return serialized payload' , ( ) => {
186+ const transaction = TransferTransaction . create (
187+ Deadline . create ( ) ,
188+ Address . createFromRawAddress ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ,
189+ [ ] ,
190+ PlainMessage . create ( 'test-message' ) ,
191+ NetworkType . MIJIN_TEST ,
192+ ) ;
193+ const serialized = transaction . serialize ( ) ;
194+
195+ expect ( serialized . substring (
196+ 240 ,
197+ serialized . length ,
198+ ) ) . to . be . equal ( '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765' ) ;
199+ } ) ;
200+ } ) ;
183201} ) ;
184202
185203class FakeTransaction extends Transaction {
You can’t perform that action at this time.
0 commit comments