Skip to content

Instantly share code, notes, and snippets.

@yatender-oktalk
Created September 12, 2020 17:35
Show Gist options
  • Save yatender-oktalk/aa0f5370846111c8d826e8b3e18df3b9 to your computer and use it in GitHub Desktop.
Save yatender-oktalk/aa0f5370846111c8d826e8b3e18df3b9 to your computer and use it in GitHub Desktop.
defmodule ExChain.BlockChain.Block do
@moduledoc """
This module is the single block struct in a blockchain
"""
alias __MODULE__
@type t :: %Block{
timestamp: pos_integer(),
last_hash: String.t(),
hash: String.t(),
data: any()
}
defstruct ~w(timestamp last_hash hash data)a
@spec new(pos_integer(), String.t(), any()) :: Block.t()
def new(timestamp, hash, last_hash, data) do
%__MODULE__{timestamp: timestamp, last_hash: last_hash, hash: hash, data: data}
end
@spec genesis() :: Block.t()
def genesis() do
__MODULE__.new(1_599_909_623_805_627, "genesis-hash", "-", "genesis data")
end
end
@mstruebing
Copy link

Hey, great tutorial, but line 17 needs to be: @spec new(pos_integer(), String.t(), String.t(), any()) :: Block.t() - there is a missing String.t()

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