Skip to content

Commit

Permalink
Merge pull request #19 from trustenterprises/hotfix_regression_webhook
Browse files Browse the repository at this point in the history
Hotfix regression webhook
  • Loading branch information
mattsmithies authored Feb 18, 2021
2 parents f43c06d + a57732c commit 38a7297
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 3 additions & 3 deletions __tests__/unit/explorer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ 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", () => {
Config.HEDERA_NETWORK = 'mainnet'

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", () => {
Config.HEDERA_NETWORK = 'previewnet'

const url = Explorer.getExplorerUrl(placeholderTx)

expect(!url.explorer_url)
expect(!url)
})
26 changes: 14 additions & 12 deletions app/hashgraph/client.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -53,7 +50,7 @@ class HashgraphClient extends HashgraphClientContract {

return {
...transactionResponse,
topic: receipt.topicId
topic: receipt.topicId.toString()
}
}

Expand Down Expand Up @@ -97,28 +94,33 @@ 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)

// Remember to allow for mainnet links for explorer
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
}

Expand All @@ -132,7 +134,7 @@ class HashgraphClient extends HashgraphClientContract {
}

if (Config.webhookUrl) {
syncMessageConsensus()
await syncMessageConsensus()
}

return messageTransactionResponse
Expand Down
4 changes: 2 additions & 2 deletions app/utils/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 38a7297

Please sign in to comment.