我正在尝试使用 Node.js 将语句连接并执行到 Amazon QLDB。为了实现这一点,我需要完成计算提交摘要的最后一步。我不知道该怎么做。
我在这里彻底研究了 QLDB Sessions javascript API:https ://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/QLDBSession.html但没有关于计算提交摘要的内容。我碰巧在这里找到了关于堆栈溢出的另一个问题:How to get/compute CommitDigest when commiting a transaction in AWS QLDB? . 我尝试理解评论并弄乱 ion-hash-js 库,看看是否可以创建提交摘要,但每次运行代码时,我都会遇到错误。OP 没有提供任何关于有效/无效的反馈,所以我被困在这里。
const AWS = require('aws-sdk');
const qldb = new AWS.QLDB({apiVersion: '2019-01-02', region: 'us-east-1'});
var qldbSession = new AWS.QLDBSession({apiVersion: '2019-07-11', region: 'us-east-1'});
const ionHashJS = require("ion-hash-js/dist/commonjs/es5/src/IonHash");
const ionJs = require('ion-js')
async function execute(){
let sessionToken;
let transactionId;
let digest;
// ** Start Session **
await qldbSession.sendCommand({
StartSession: {
LedgerName: 'Vehicle-Registration'
}
}).promise().then(data => {
sessionToken = data.StartSession.SessionToken
})
// ** Start Transaction **
await qldbSession.sendCommand({
StartTransaction: {},
SessionToken: sessionToken
}).promise().then(data => {
transactionId = data.StartTransaction.TransactionId
})
// ** Insert Document **
await qldbSession.sendCommand({
ExecuteStatement: {
TransactionId: transactionId,
Statement: `CREATE TABLE Vehicle`
},
SessionToken: sessionToken
}).promise().then(data => {
console.log(data)
})
// ** Get Ledger Digest **
await qldb.getDigest({
Name: 'Vehicle-Registration'
}).promise().then(data => {
digest = data.Digest
}).catch(err => console.log(err))
// ** Commit Transaction **
await qldbSession.sendCommand({
CommitTransaction: {
TransactionId: transactionId,
CommitDigest: digest // <-- How to compute?
},
SessionToken: sessionToken}).promise().then(data => {console.log(data)}).catch(err => console.log(err))
}
execute();
我不断收到“摘要不匹配”错误