Skip to content

Commit

Permalink
finalize tojson functionality (#1880)
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Tonev <[email protected]>
  • Loading branch information
petreze authored Sep 15, 2023
1 parent d4bf1f6 commit 536f38e
Show file tree
Hide file tree
Showing 12 changed files with 3,460 additions and 3,298 deletions.
201 changes: 103 additions & 98 deletions common_js_test/pnpm-lock.yaml

Large diffs are not rendered by default.

997 changes: 508 additions & 489 deletions examples/pnpm-lock.yaml

Large diffs are not rendered by default.

1,194 changes: 614 additions & 580 deletions examples/simple_rest_signature_provider/pnpm-lock.yaml

Large diffs are not rendered by default.

1,081 changes: 559 additions & 522 deletions packages/proto/pnpm-lock.yaml

Large diffs are not rendered by default.

3,186 changes: 1,621 additions & 1,565 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/ExchangeRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Long from "long";
* @typedef {object} ExchangeRateJSON
* @property {number} hbars
* @property {number} cents
* @property {string} expirationTime
* @property {Date} expirationTime
* @property {number} exchangeRateInCents
*/

Expand Down Expand Up @@ -112,11 +112,11 @@ export default class ExchangeRate {
/**
* @returns {ExchangeRateJSON}
*/
toJSON() {
toJson() {
return {
hbars: this.hbars,
cents: this.cents,
expirationTime: this.expirationTime.toString(),
expirationTime: this.expirationTime,
exchangeRateInCents: this.exchangeRateInCents,
};
}
Expand All @@ -125,6 +125,6 @@ export default class ExchangeRate {
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}
6 changes: 3 additions & 3 deletions src/Transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ export default class Transfer {
/**
* @returns {TransferJSON}
*/
toJSON() {
toJson() {
return {
accountId: this.accountId.toString(),
amount: this.amount,
amount: this.amount.toString(),
isApproved: this.isApproved,
};
}
Expand All @@ -126,6 +126,6 @@ export default class Transfer {
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}
8 changes: 4 additions & 4 deletions src/token/TokenTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import TokenId from "./TokenId.js";
* @property {string} tokenId
* @property {string} accountId
* @property {number | null} expectedDecimals
* @property {Long | number} amount
* @property {Long | number | string} amount
* @property {boolean} isApproved
*/

Expand Down Expand Up @@ -143,12 +143,12 @@ export default class TokenTransfer {
/**
* @returns {TokenTransferJSON}
*/
toJSON() {
toJson() {
return {
tokenId: this.tokenId.toString(),
accountId: this.accountId.toString(),
expectedDecimals: this.expectedDecimals,
amount: this.amount,
amount: this.amount.toString(),
isApproved: this.isApproved,
};
}
Expand All @@ -157,6 +157,6 @@ export default class TokenTransfer {
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}
2 changes: 1 addition & 1 deletion src/transaction/Transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ export default class Transaction extends Executable {
nodeId,
transactionHash,
transactionId,
}).toJSON()
}).toJson()
)}`
);
}
Expand Down
27 changes: 14 additions & 13 deletions src/transaction/TransactionReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ import TransactionId from "../transaction/TransactionId.js";
* @property {?string} tokenId
* @property {?string} scheduleId
* @property {?ExchangeRateJSON} exchangeRate
* @property {?Long} topicSequenceNumber
* @property {?string} topicSequenceNumber
* @property {?Uint8Array} topicRunningHash
* @property {?Long} totalSupply
* @property {?string} totalSupply
* @property {?string} scheduledTransactionId
* @property {Long[]} serials
* @property {TransactionReceipt[]} duplicates
* @property {TransactionReceipt[]} children
* @property {string[]} serials
* @property {TransactionReceiptJSON[]} duplicates
* @property {TransactionReceiptJSON[]} children
*/

/**
Expand Down Expand Up @@ -367,7 +367,7 @@ export default class TransactionReceipt {
/**
* @returns {TransactionReceiptJSON}
*/
toJSON() {
toJson() {
return {
status: this.status.toString(),
accountId:
Expand All @@ -380,28 +380,29 @@ export default class TransactionReceipt {
scheduleId:
this.scheduleId != null ? this.scheduleId.toString() : null,
exchangeRate:
this.exchangeRate != null ? this.exchangeRate.toJSON() : null,
this.exchangeRate != null ? this.exchangeRate.toJson() : null,
topicSequenceNumber:
this.topicSequenceNumber != null
? this.topicSequenceNumber
? this.topicSequenceNumber.toString()
: null,
topicRunningHash:
this.topicRunningHash != null ? this.topicRunningHash : null,
totalSupply: this.totalSupply != null ? this.totalSupply : null,
totalSupply:
this.totalSupply != null ? this.totalSupply.toString() : null,
scheduledTransactionId:
this.scheduledTransactionId != null
? this.scheduledTransactionId.toString()
: null,
serials: this.serials,
duplicates: this.duplicates,
children: this.children,
serials: this.serials.map((serial) => serial.toString()),
duplicates: this.duplicates.map((receipt) => receipt.toJson()),
children: this.children.map((receipt) => receipt.toJson()),
};
}

/**
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}
44 changes: 27 additions & 17 deletions src/transaction/TransactionRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Key from "../Key.js";
import PublicKey from "../PublicKey.js";
import TokenTransfer from "../token/TokenTransfer.js";
import EvmAddress from "../EvmAddress.js";
import * as hex from "../encoding/hex.js";

/**
* @typedef {import("../token/TokenId.js").default} TokenId
Expand All @@ -48,30 +49,30 @@ import EvmAddress from "../EvmAddress.js";
/**
* @typedef {object} TransactionRecordJSON
* @property {TransactionReceiptJSON} receipt
* @property {string} transactionHash
* @property {Timestamp} consensusTimestamp
* @property {?string} transactionHash
* @property {Date} consensusTimestamp
* @property {string} transactionId
* @property {string} transactionMemo
* @property {Hbar} transactionFee
* @property {string} transactionFee
* @property {TransferJSON[]} transfers
* @property {TokenTransferMap} tokenTransfers
* @property {TokenTransferJSON[]} tokenTransfersList
* @property {?ScheduleId} scheduleRef
* @property {AssessedCustomFee[]} assessedCustomFees
* @property {TokenNftTransferMap} nftTransfers
* @property {TokenAssocation[]} automaticTokenAssociations
* @property {Timestamp | null} parentConsensusTimestamp
* @property {Date | null} parentConsensusTimestamp
* @property {PublicKey | null} aliasKey
* @property {TransactionRecord[]} duplicates
* @property {TransactionRecord[]} children
* @property {HbarAllowance[]} hbarAllowanceAdjustments
* @property {TokenAllowance[]} tokenAllowanceAdjustments
* @property {TokenNftAllowance[]} nftAllowanceAdjustments
* @property {string} ethereumHash
* @property {?string} ethereumHash
* @property {Transfer[]} paidStakingRewards
* @property {?Uint8Array} prngBytes
* @property {?number} prngNumber
* @property {string} evmAddress
* @property {?string} evmAddress
*/

/**
Expand Down Expand Up @@ -595,42 +596,51 @@ export default class TransactionRecord {
/**
* @returns {TransactionRecordJSON}
*/
toJSON() {
toJson() {
return {
receipt: this.receipt.toJSON(),
transactionHash: JSON.stringify(this.transactionHash),
consensusTimestamp: this.consensusTimestamp,
receipt: this.receipt.toJson(),
transactionHash: hex.encode(this.transactionHash),
consensusTimestamp: this.consensusTimestamp.toDate(),
transactionId: this.transactionId.toString(),
transactionMemo: this.transactionMemo,
transactionFee: this.transactionFee,
transfers: this.transfers.map((transfer) => transfer.toJSON()),
transactionFee: this.transactionFee.toString(),
transfers: this.transfers.map((transfer) => transfer.toJson()),
tokenTransfers: this.tokenTransfers,
tokenTransfersList: this.tokenTransfersList.map((transfer) =>
transfer.toJSON()
transfer.toJson()
),
scheduleRef: this.scheduleRef,
assessedCustomFees: this.assessedCustomFees,
nftTransfers: this.nftTransfers,
automaticTokenAssociations: this.automaticTokenAssociations,
parentConsensusTimestamp: this.parentConsensusTimestamp,
parentConsensusTimestamp:
this.parentConsensusTimestamp != null
? this.parentConsensusTimestamp.toDate()
: null,
aliasKey: this.aliasKey,
duplicates: this.duplicates,
children: this.children,
hbarAllowanceAdjustments: [],
tokenAllowanceAdjustments: [],
nftAllowanceAdjustments: [],
ethereumHash: JSON.stringify(this.ethereumHash),
ethereumHash:
this.ethereumHash != null && this.ethereumHash.length != 0
? hex.encode(this.ethereumHash)
: null,
paidStakingRewards: this.paidStakingRewards,
prngBytes: this.prngBytes,
prngNumber: this.prngNumber,
evmAddress: JSON.stringify(this.evmAddress),
evmAddress:
this.evmAddress != null && this.evmAddress.toBytes().length != 0
? hex.encode(this.evmAddress.toBytes())
: null,
};
}

/**
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}
4 changes: 2 additions & 2 deletions src/transaction/TransactionResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class TransactionResponse {
/**
* @returns {TransactionResponseJSON}
*/
toJSON() {
toJson() {
return {
nodeId: this.nodeId.toString(),
transactionHash: hex.encode(this.transactionHash),
Expand All @@ -180,6 +180,6 @@ export default class TransactionResponse {
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
return JSON.stringify(this.toJson());
}
}

0 comments on commit 536f38e

Please sign in to comment.