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' ;
@@ -24,7 +25,6 @@ import { Deadline } from './Deadline';
2425import { InnerTransaction } from './InnerTransaction' ;
2526import { SignedTransaction } from './SignedTransaction' ;
2627import { TransactionInfo } from './TransactionInfo' ;
27- import { SerializeTransactionToJSON } from '../../infrastructure/transaction/SerializeTransactionToJSON' ;
2828
2929/**
3030 * An abstract transaction class that serves as the base class of all NEM transactions.
@@ -172,7 +172,19 @@ export abstract class Transaction {
172172 }
173173
174174 /**
175- * Create JSON object
175+ * @description Serialize a transaction object
176+ * @returns {string }
177+ * @memberof Transaction
178+ */
179+ public serialize ( ) {
180+ const transaction = this . buildTransaction ( ) ;
181+ return transaction . serializeUnsignedTransaction ( ) ;
182+ }
183+
184+ /**
185+ * @description Create JSON object
186+ * @returns {Object }
187+ * @memberof Transaction
176188 */
177189 public toJSON ( ) {
178190 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 @@ -149,6 +149,24 @@ describe('Transaction', () => {
149149 expect ( after ) . to . be . equal ( true ) ;
150150 } ) ;
151151 } ) ;
152+
153+ describe ( 'Transaction serialize' , ( ) => {
154+ it ( 'Should return serialized payload' , ( ) => {
155+ const transaction = TransferTransaction . create (
156+ Deadline . create ( ) ,
157+ Address . createFromRawAddress ( 'SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC' ) ,
158+ [ ] ,
159+ PlainMessage . create ( 'test-message' ) ,
160+ NetworkType . MIJIN_TEST ,
161+ ) ;
162+ const serialized = transaction . serialize ( ) ;
163+
164+ expect ( serialized . substring (
165+ 240 ,
166+ serialized . length ,
167+ ) ) . to . be . equal ( '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D657373616765' ) ;
168+ } ) ;
169+ } ) ;
152170} ) ;
153171
154172class FakeTransaction extends Transaction {
You can’t perform that action at this time.
0 commit comments