Closed 0x009922 closed 2 years ago
After thinking, I'd suggest to separate transaction build from submission, because "submit then calculate hash" would not give clients time to subscribe events specifying the hash
I guess this issue is closed after merging of #124.
Now you can compute transaction hash with ease in the following pipeline:
import { Client, computeTransactionHash, makeSignedTransaction, makeTransactionPayload } from '@iroha2/client'
import { Executable, VecInstruction } from '@iroha2/data-model'
// 0. We have a `Client`, or just a `Signer` + `Torii`
declare const client: Client
// 1. Building a TX payload with a helper or without it
const payload = makeTransactionPayload({
executable: Executable(
'Instructions',
VecInstruction([
/* ... */
]),
),
accountId: client.signer.accountId,
// options like `nonce` etc
})
// 2. Computing the transaction hash for our needs
const hash = computeTransactionHash(payload)
// ^^^^
// 3. Wrapping the payload into `VersionedTransaction` with a signature
const tx = makeSignedTransaction(payload, client.signer)
// 4. Submitting it
await client.torii.submit(tx)
Description
Transaction hash might be needed to listen for related events after its submitting.
Currently
submit
methods returnsPromise<void>
, but it can return a shortcut to get the hash of the submitted transaction.How it might look like
transactionHash()
is a function to avoid unnecessary hash computations when it is not really needed.