I'm trying to insert a record into a QLDB ledger using the AWS SDK in Go. I used the Python QLDB driver as an example and logged the final transaction hash produced there. This is used during the transaction commit to compare with the hash produced on QLDB's side to verify the transaction and allow it to commit, which the python driver does successfully.
There isn't a Go version of IonHash yet, though, so I've implemented up the StartTransaction, InsertInto, and CommitTransaction steps in Go and included a Python executable IonHash implementation to calculate the IonHashes used to compare the digest at the end.
// 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)
}
The code fails during the commit step with the following error:
{
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"
}
I don't understand why the digests don't match during the commit in go, when this implementation is producing the same digest as the python code, which does commit. Why does the python code not complain about digests not matching when it's producing the same commits as the go code? More importantly, how can I successfully insert to QLDB through Go (not the python or the node drivers?)