coincoin makes a strong distinction between the blockchain and the transactions stored on it.
The blockchain only requires that data stored in each block implements this simple protocol:
defprotocol Blockchain.Data do
def hash(data)
def verify(data, chain)
end
This is ok so far but the problem is that when data are sent through the network, they are JSON encode / decoded. So for example, when I send a Token.Transaction to the blockchain, I send it as a raw Map (because even if I don't once decoded data will be seen as a raw Map by other peers), so I had to implement the Blockchain.Data protocol for Map. This is not ok, Map is way to generic, that makes the code not reusable at all !
The only way I can think of to improve this is to store somewhere the type of the data in the blockchain. So when blocks get decoded the data field is not a Map but the user defined type.
coincoin
makes a strong distinction between the blockchain and the transactions stored on it.The blockchain only requires that data stored in each block implements this simple protocol:
This is ok so far but the problem is that when data are sent through the network, they are JSON encode / decoded. So for example, when I send a
Token.Transaction
to the blockchain, I send it as a rawMap
(because even if I don't once decoded data will be seen as a rawMap
by other peers), so I had to implement theBlockchain.Data
protocol forMap
. This is not ok,Map
is way to generic, that makes the code not reusable at all !The only way I can think of to improve this is to store somewhere the type of the data in the blockchain. So when blocks get decoded the
data
field is not aMap
but the user defined type.