diff --git a/__tests__/unit/explorer.test.js b/__tests__/unit/explorer.test.js index 0dbd205..486b06f 100644 --- a/__tests__/unit/explorer.test.js +++ b/__tests__/unit/explorer.test.js @@ -8,7 +8,7 @@ test("Ensure that a testnet explorer url returns", () => { const url = Explorer.getExplorerUrl(placeholderTx) - expect(url.explorer_url).toBe(`https://ledger-testnet.hashlog.io/tx/${placeholderTx}`) + expect(url).toBe(`https://ledger-testnet.hashlog.io/tx/${placeholderTx}`) }) test("Ensure that a mainnet explorer url returns", () => { @@ -16,7 +16,7 @@ test("Ensure that a mainnet explorer url returns", () => { const url = Explorer.getExplorerUrl(placeholderTx) - expect(url.explorer_url).toBe(`https://ledger.hashlog.io/tx/${placeholderTx}`) + expect(url).toBe(`https://ledger.hashlog.io/tx/${placeholderTx}`) }) test("Ensure that a previewnet explorer url returns nothing", () => { @@ -24,5 +24,5 @@ test("Ensure that a previewnet explorer url returns nothing", () => { const url = Explorer.getExplorerUrl(placeholderTx) - expect(!url.explorer_url) + expect(!url) }) diff --git a/app/hashgraph/client.js b/app/hashgraph/client.js index bd96afd..0af8d3d 100644 --- a/app/hashgraph/client.js +++ b/app/hashgraph/client.js @@ -1,15 +1,12 @@ import { - Client, - MirrorClient, PrivateKey, - PublicKey, AccountBalanceQuery, TopicInfoQuery, - MirrorConsensusTopicQuery, TopicCreateTransaction, TopicUpdateTransaction, TopicMessageSubmitTransaction, - TransactionRecordQuery + TransactionRecordQuery, + TopicId } from "@hashgraph/sdk" import HashgraphClientContract from "./contract" import HashgraphNodeNetwork from "./network" @@ -53,7 +50,7 @@ class HashgraphClient extends HashgraphClientContract { return { ...transactionResponse, - topic: receipt.topicId + topic: receipt.topicId.toString() } } @@ -97,7 +94,7 @@ class HashgraphClient extends HashgraphClientContract { const client = this.#client const transaction = await new TopicMessageSubmitTransaction({ - topicId: topic_id, + topicId: TopicId.fromString(topic_id), message: message }).execute(client) @@ -105,20 +102,25 @@ class HashgraphClient extends HashgraphClientContract { const messageTransactionResponse = { reference, topic_id, - transaction_id: transaction.toString(), - explorer_url: Explorer.getExplorerUrl(transaction) + transaction_id: transaction.transactionId.toString(), + explorer_url: Explorer.getExplorerUrl(transaction.transactionId) } const syncMessageConsensus = async () => { await sleep() const record = await new TransactionRecordQuery() - .setTransactionId(transaction) + .setTransactionId(transaction.transactionId) .execute(client) + const { seconds, nanos } = record.consensusTimestampstamp + const consensusResult = { ...messageTransactionResponse, - consensus_timestamp: record.consensusTimestamp, + consensus_timestamp: { + seconds: seconds.toString(), + nanos: nanos.toString() + }, reference: reference } @@ -132,7 +134,7 @@ class HashgraphClient extends HashgraphClientContract { } if (Config.webhookUrl) { - syncMessageConsensus() + await syncMessageConsensus() } return messageTransactionResponse diff --git a/app/utils/explorer.js b/app/utils/explorer.js index baafd1f..9dc969b 100644 --- a/app/utils/explorer.js +++ b/app/utils/explorer.js @@ -10,8 +10,8 @@ const ExplorerUrl = { function getExplorerUrl(tx) { const network = Config.HEDERA_NETWORK || Environment.TESTNET - return { - explorer_url: ExplorerUrl[network] + tx + if (network) { + return ExplorerUrl[network] + tx } }