登录
首页 >  Golang >  Go问答

在QLDB中插入时的摘要不匹配

来源:stackoverflow

时间:2024-03-14 13:51:26 402浏览 收藏

今天golang学习网给大家带来了《在QLDB中插入时的摘要不匹配》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~

问题内容

我正在尝试使用 go 中的 aws 开发工具包将记录插入到 qldb 分类账中。我使用 python qldb 驱动程序作为示例,并记录了其中生成的最终事务哈希。这在事务提交期间用于与 qldb 端生成的哈希进行比较,以验证事务并允许其提交,python 驱动程序成功完成了这一点。

不过,还没有 ionhash 的 go 版本,因此我在 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"
}

我不明白为什么在 go 提交期间摘要不匹配,当这个实现生成与 python 代码相同的摘要时,python 代码确实提交了。为什么 python 代码在生成与 go 代码相同的提交时不会抱怨摘要不匹配?更重要的是,如何通过 go(而不是 python 或节点驱动程序?)成功插入到 qldb?


解决方案


不确定这是否仍然有帮助,但 Amazon 最近发布了 QLDB Go 驱动程序的预览版本 (https://github.com/awslabs/amazon-qldb-driver-go)。

它具有 Ion 和 Ion Hash 作为其依赖项,因此这应该会让您在使用 QLDB 时变得更加轻松。

今天关于《在QLDB中插入时的摘要不匹配》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>