python - 插入 QLDB 时摘要不匹配
问题描述
我正在尝试使用 Go 中的 AWS 开发工具包将记录插入 QLDB 分类帐。我以 Python QLDB 驱动程序为例,并记录了那里产生的最终事务哈希。这在事务提交期间用于与 QLDB 端生成的哈希进行比较,以验证事务并允许它提交,python 驱动程序成功完成了该操作。
不过,目前还没有 Go 版本的 IonHash,因此我在 Go 中实现了 StartTransaction、InsertInto 和 CommitTransaction 步骤,并包含一个 Python 可执行 IonHash 实现来计算用于最后比较摘要的 IonHash。
// Go (pseudocode)
import "github.com/fernomac/ion-go" as ion
import python_hash_module as python
func (client qldbClient) StartTransaction(transactionID string) {
// hash transactionID using python ionhash
}
func (client) InsertInto (statement string, params string) {
// MarshalText using ion module in aws-sdk
ionParam := ion.MarshalText(params)
// hash statement using python executable
client.statementHash = python.ion_hash(statement)
// hash parameters using python executable (only one parameter)
client.paramHash = python.ion_hash(ionParam)
// dot paramHash with statement hash
client.statementHash = client.statementHash.dot(client.paramHash)
// dot statement hash with transactionhash - this transaction hash matches the python calculation!
client.transactionHash = client.transactionHash.dot(statementHash)
}
func (client) Commit() {
res, err := client.execute(statement) // compares calculated transaction hash with AWS calculated transaction hash
if err != nil {
log.Prinln(err)
}
代码在提交步骤期间失败,并出现以下错误:
{
Code_: "412",
Message_: "Digests don't match"
}
2020/03/22 11:16:41 xxxx.go:xxx: BadRequestException: Digests don't match
{
Code_: "412",
Message_: "Digests don't match"
}
我不明白为什么在提交期间摘要不匹配,当此实现生成与确实提交的 python 代码相同的摘要时。为什么 python 代码在生成与 go 代码相同的提交时不会抱怨摘要不匹配?更重要的是,如何通过 Go 成功插入 QLDB(不是 python 或节点驱动程序?)
解决方案
不确定这是否仍然有用,但亚马逊最近发布了 QLDB Go 驱动程序的预览版 ( https://github.com/awslabs/amazon-qldb-driver-go )。
它具有 Ion 和 Ion Hash 作为其依赖项,因此这应该使您在使用 QLDB 时更容易。
推荐阅读
- azure - 我可以使用 Azure Active Directory 库 (ADAL) 从 Azure AD 获取 SAML 响应吗?
- java - Spring如何知道bean注入@Bean和方法调用
- sql - 为什么我不能将 yyyymmdd(存储为文本)插入日期列
- c# - (发送消息)行上的 Amazon SES 问题
- javascript - Date.parse() 无法识别 hh:mm:ss.sss
- python - PySimpleDMX 不知道自己的类
- laravel - 将 URI 添加到 laravel 响应
- eclipse - Xtend 的命令行编译器不起作用
- c# - 如何根据 ViewModel 更改正确设置 CheckBoxFor 值?
- android - 当我在 TextView 中使用 layout_width=0 时,我得到了奇怪的结果