Skip to content

Instantly share code, notes, and snippets.

@ssadler
Last active June 2, 2017 09:40
Show Gist options
  • Save ssadler/f669dd1fd761933919258d7aa4859b6f to your computer and use it in GitHub Desktop.
Save ssadler/f669dd1fd761933919258d7aa4859b6f to your computer and use it in GitHub Desktop.
Transaction changes in 1.0

Output amount is now a string

BigchainDB transactions may have multiple inputs and outputs, and each output has an amount, which is the integral number of the asset being transferred. In prior versions of BigchainDB, the amount was encoded as a number, which on the face of it is the obvious way to encode an integer. However, as usual the devil is in the details; JSON, the encoding of choice for BigchainDB transactions, encodes all numbers including integers as floating point. This isn't a problem for the majority of circumstances where numbers are small, however in some environments and for some use cases*, the number may lose precision.

In order to safeguard against this, amounts are now encoded as strings, and it is recommended to use a decimal math library (such as big.js) when dealing with large numbers in Javascript. Additionally, numbers are capped at 9e18 to stay comfortably within the boundary of a 64 bit signed integer.

* Try this in the Chrome developer console: 2**60 == 2**60+1.

Signing payload is now the transaction body

The signature payload of a BigchainDB transaction is now "just" the JSON serialized body of the transaction. This change is invisible to applications that do not produce transactions with more than one input. However, prior to the 1.0 release, transactions with multiple inputs had a special siging protocol, which included reassembly of the transaction. This was identified as being unneeded, so now the payload that is signed is always just the serialized transaction, minus signatures. More details here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment