I've been reading through the docs trying to figure out how to commit a transaction in QLDB, and in order to do so, a CommitDigest
is required, and the docs describe it as:
Specifies the commit digest for the transaction to commit. For every active transaction, the commit digest must be passed. QLDB validates CommitDigest and rejects the commit with an error if the digest computed on the client does not match the digest computed by QLDB.
So CommitDigest must be computed, but I'm not quite sure what's required for its computation given this example:
// ** Start Session **
const startSessionResult = await qldbSession.sendCommand({
StartSession: {
LedgerName: ledgerName
}
}).promise(),
sessionToken = startSessionResult.StartSession!.SessionToken!;
// ** Start Transaction **
const startTransactionResult = await qldbSession.sendCommand({
StartTransaction: {},
SessionToken: sessionToken
}).promise(),
transactionId = startTransactionResult.StartTransaction!.TransactionId!;
// ** Insert Document **
const executeStatementResult = await qldbSession.sendCommand({
ExecuteStatement: {
TransactionId: transactionId,
Statement: `INSERT INTO sometable { 'id': 'abc123', 'userId': '123abc' }`
},
SessionToken: sessionToken
}).promise(),
documentId = getDocumentIdFromExecuteStateResult(executeStatementResult)
// ** Get Ledger Digest
const getDigestResult = await qldb.getDigest({
Name: ledgerName
}).promise(),
ledgerDigest = getDigestResult.Digest;
// ** Commit Transaction **
// ** **The API call in question** **
const commitTransactionResult = await qldbSession.sendCommand({
CommitTransaction: {
TransactionId: transactionId,
CommitDigest: `${commitDigest}` // <-- How to compute?
},
SessionToken: sessionToken
}).promise();
// *******************************
// ** End Session **
const endSession = await qldbSession.sendCommand({
EndSession: {},
SessionToken: sessionToken
}).promise();
What do I need to hash for CommitDigest
in the CommitTransaction
api call?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…