-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update topicMessage REST response to use transactionId json format (#…
…3222) In v0.49.0 we added transactionId info to the topicMessage chunkInfo response. Given the nature of the transactionId format a more scalable format should be used to allow for expansion - Add a `transactionIdViewModel.js` to handle display format logic from Protobuf or db schema - Update `topicMessageViewModel.js` to use `transactionIdViewModel.js` as a component - Add a `transactionId.js` model class to dictate transactionId format for use by `transactionIdViewModel` - Update OpenAPI spec - Update spec test files - Update viewmodel test js files Signed-off-by: Nana-EC <nana.essilfie-conduah@hedera.com> Signed-off-by: Matheus DallRosa <matheus.dallrosa@swirlds.com>
- Loading branch information
1 parent
60415fd
commit 1629a19
Showing
12 changed files
with
158 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*- | ||
* | ||
* Hedera Mirror Node | ||
* | ||
* Copyright (C) 2019 - 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
class TransactionId { | ||
constructor(payerAccountId, validStartTimestamp, nonce, scheduled) { | ||
this.payerAccountId = payerAccountId; | ||
this.nonce = nonce; | ||
this.scheduled = scheduled; | ||
this.validStartTimestamp = validStartTimestamp; | ||
} | ||
} | ||
|
||
module.exports = TransactionId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*- | ||
* | ||
* Hedera Mirror Node | ||
* | ||
* Copyright (C) 2019 - 2022 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const _ = require('lodash'); | ||
|
||
const EntityId = require('../entityId'); | ||
const {TransactionID} = require('@hashgraph/proto'); | ||
const utils = require('../utils'); | ||
|
||
/** | ||
* TransactionId view model | ||
*/ | ||
class TransactionIdViewModel { | ||
/** | ||
* Constructs transactionId view model from proto transaction id or TransactionId model | ||
* | ||
* @param {TransactionId|TransactionID} transactionId | ||
*/ | ||
constructor(transactionId) { | ||
if (transactionId instanceof TransactionID) { | ||
// handle proto format | ||
const {accountID, transactionValidStart, nonce, scheduled} = transactionId; | ||
this.account_id = EntityId.of(accountID.shardNum, accountID.realmNum, accountID.accountNum).toString(); | ||
this.nonce = Number(nonce); | ||
this.scheduled = scheduled; | ||
this.transaction_valid_start = `${transactionValidStart.seconds}.${transactionValidStart.nanos | ||
.toString() | ||
.padStart(9, '0')}`; | ||
} else { | ||
// handle db format. Handle nil case for nonce and scheduled | ||
this.account_id = EntityId.parse(transactionId.payerAccountId).toString(); | ||
this.nonce = _.isNil(transactionId.nonce) ? null : Number(transactionId.nonce); | ||
this.scheduled = transactionId.scheduled; | ||
this.transaction_valid_start = utils.nsToSecNs(transactionId.validStartTimestamp); | ||
} | ||
} | ||
} | ||
|
||
module.exports = TransactionIdViewModel; |