@@ -6,7 +6,7 @@ import { TransactionLogs } from "./transactionLogs";
66import { TransactionReceipt } from "./transactionReceipt" ;
77
88export function prepareTransactionForBroadcasting ( transaction : ITransaction | ITransactionNext ) : any {
9- if ( "toSendable" in transaction ) {
9+ if ( "toSendable" in transaction ) {
1010 return transaction . toSendable ( ) ;
1111 }
1212
@@ -15,8 +15,12 @@ export function prepareTransactionForBroadcasting(transaction: ITransaction | IT
1515 value : transaction . value . toString ( ) ,
1616 receiver : transaction . receiver ,
1717 sender : transaction . sender ,
18- senderUsername : transaction . senderUsername ? Buffer . from ( transaction . senderUsername ) . toString ( "base64" ) : undefined ,
19- receiverUsername : transaction . receiverUsername ? Buffer . from ( transaction . receiverUsername ) . toString ( "base64" ) : undefined ,
18+ senderUsername : transaction . senderUsername
19+ ? Buffer . from ( transaction . senderUsername ) . toString ( "base64" )
20+ : undefined ,
21+ receiverUsername : transaction . receiverUsername
22+ ? Buffer . from ( transaction . receiverUsername ) . toString ( "base64" )
23+ : undefined ,
2024 gasPrice : Number ( transaction . gasPrice ) ,
2125 gasLimit : Number ( transaction . gasLimit ) ,
2226 data : transaction . data . length === 0 ? undefined : Buffer . from ( transaction . data ) . toString ( "base64" ) ,
@@ -25,8 +29,15 @@ export function prepareTransactionForBroadcasting(transaction: ITransaction | IT
2529 options : transaction . options ,
2630 guardian : transaction . guardian || undefined ,
2731 signature : Buffer . from ( transaction . signature ) . toString ( "hex" ) ,
28- guardianSignature : transaction . guardianSignature . length === 0 ? undefined : Buffer . from ( transaction . guardianSignature ) . toString ( "hex" ) ,
29- }
32+ guardianSignature :
33+ transaction . guardianSignature . length === 0
34+ ? undefined
35+ : Buffer . from ( transaction . guardianSignature ) . toString ( "hex" ) ,
36+ relayer : transaction . relayer ? transaction . relayer : undefined ,
37+ innerTransactions : transaction . innerTransactions
38+ ? transaction . innerTransactions . map ( ( tx ) => prepareTransactionForBroadcasting ( tx ) )
39+ : undefined ,
40+ } ;
3041}
3142
3243export class TransactionOnNetwork {
@@ -54,18 +65,23 @@ export class TransactionOnNetwork {
5465 receipt : TransactionReceipt = new TransactionReceipt ( ) ;
5566 contractResults : ContractResults = new ContractResults ( [ ] ) ;
5667 logs : TransactionLogs = new TransactionLogs ( ) ;
68+ innerTransactions : ITransactionNext [ ] = [ ] ;
5769
5870 constructor ( init ?: Partial < TransactionOnNetwork > ) {
5971 Object . assign ( this , init ) ;
6072 }
6173
62- static fromProxyHttpResponse ( txHash : string , response : any , processStatus ?: TransactionStatus | undefined ) : TransactionOnNetwork {
74+ static fromProxyHttpResponse (
75+ txHash : string ,
76+ response : any ,
77+ processStatus ?: TransactionStatus | undefined ,
78+ ) : TransactionOnNetwork {
6379 let result = TransactionOnNetwork . fromHttpResponse ( txHash , response ) ;
6480 result . contractResults = ContractResults . fromProxyHttpResponse ( response . smartContractResults || [ ] ) ;
6581
6682 if ( processStatus ) {
6783 result . status = processStatus ;
68- result . isCompleted = result . status . isSuccessful ( ) || result . status . isFailed ( )
84+ result . isCompleted = result . status . isSuccessful ( ) || result . status . isFailed ( ) ;
6985 }
7086
7187 return result ;
@@ -102,10 +118,35 @@ export class TransactionOnNetwork {
102118
103119 result . receipt = TransactionReceipt . fromHttpResponse ( response . receipt || { } ) ;
104120 result . logs = TransactionLogs . fromHttpResponse ( response . logs || { } ) ;
121+ result . innerTransactions = ( response . innerTransactions || [ ] ) . map ( this . innerTransactionFromHttpResource ) ;
105122
106123 return result ;
107124 }
108125
126+ private static innerTransactionFromHttpResource ( resource : any ) : ITransactionNext {
127+ return {
128+ nonce : BigInt ( resource . nonce || 0 ) ,
129+ value : BigInt ( resource . value || 0 ) ,
130+ receiver : resource . receiver ,
131+ sender : resource . sender ,
132+ // We discard "senderUsername" and "receiverUsername" (to avoid future discrepancies between Proxy and API):
133+ senderUsername : "" ,
134+ receiverUsername : "" ,
135+ gasPrice : BigInt ( resource . gasPrice ) ,
136+ gasLimit : BigInt ( resource . gasLimit ) ,
137+ data : Buffer . from ( resource . data || "" , "base64" ) ,
138+ chainID : resource . chainID ,
139+ version : resource . version ,
140+ options : resource . options || 0 ,
141+ guardian : resource . guardian || "" ,
142+ signature : Buffer . from ( resource . signature , "hex" ) ,
143+ guardianSignature : resource . guardianSignature
144+ ? Buffer . from ( resource . guardianSignature , "hex" )
145+ : Buffer . from ( [ ] ) ,
146+ relayer : resource . relayer ,
147+ } ;
148+ }
149+
109150 getDateTime ( ) : Date {
110151 return new Date ( this . timestamp * 1000 ) ;
111152 }
0 commit comments