Skip to content
Official Go implementation of https://github.com/stratumn/chainscript.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
chainscripttest
cmd
proto
.codecov.yml
.dockerignore
.gitignore
.travis.yml
CHANGELOG.md
Dockerfile
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
chainscript.pb.go
const.go
doc.go
evidence.go
evidence_test.go
link.go
link_test.go
linkbuilder.go
linkbuilder_test.go
linkhash.go
linkhash_test.go
marshal.go
marshal_test.go
proof.go
regression_test.go
segment.go
segment_test.go
signature.go
signature_test.go

README.md

Go ChainScript

GoDoc build status codecov Go Report Card

Official Go implementation of ChainScript. This is the recommended way to use ChainScript in your Go projects.

However, it is opinionated and tries to keep the application data as abstract as possible. Some applications will have different requirements and might want to optimize for specific use-cases. If you are in that case, don't hesitate to implement your own ChainScript library. If you do so, don't forget to set the client_id field to make it easy for others to deserialize and validate your data.

Updating ChainScript

The ChainScript definitions are imported as a git subtree. Changes to the protobuf files should be done in the ChainScript repository.

To get the latest ChainScript definitions in this project, run:

make update_chainscript

Note that when you update the git subtree, you must not squash your commits when merging to the master branch, otherwise the subtree update will fail because it will be unable to find the previous subtree commit.

Compile the new protobuf definitions:

make protobuf

Fixing JSON struct tags

If the protobuf compiler added json tags (json:"map_id") to your structs, you might need to manually fix them if you want to be fully compatible with other languages.

Those tags create an issue for fields that contain an underscore in the proto definitions. For such fields you'll need to manually update the generated go file until the protobuf compiler provides configuration options to generate json tags properly.

Protobuf uses snake_case for field definitions (in your .proto files) but follows the JSON recommendation to use camelCase when serializing those fields to JSON. However the protobuf compiler also adds struct tags to tell the JSON serializer to use snake_case for fields that contain an underscore. As long as you use protobuf's JSON serializer you're fine because it will accept both snake_case and camelCase, but if you need to use another serializer at some point (in our case canonical-json for signatures v1.0.0) your JSON representation will use snake_case. Javascript correctly uses camelCase so your Javascript code will not be able to validate signatures generated by Go code (and the other way around as well).

The fix is simple: track all your snake_case fields and update the json:"snake_field" struct tag to json:"snakeField".

Updating dependencies

When updating dependencies (go-crypto, canonical-json, etc) we must stay backwards-compatible. That means that each dependency update should thoroughly check whether it introduces breaking changes in the serialized data. If it does, the version of some fields (link, signature) needs to be updated accordingly.

You can’t perform that action at this time.