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 snakecase 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 snakecase for fields that contain an underscore. As long as you use protobuf's JSON serializer you're fine because it will accept both snakecase 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 snakecase. 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 snakecase fields and update the `json:"snakefield"struct tag tojson:"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.