Created
September 12, 2020 17:35
-
-
Save yatender-oktalk/aa0f5370846111c8d826e8b3e18df3b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, great tutorial, but line 17 needs to be:
@spec new(pos_integer(), String.t(), String.t(), any()) :: Block.t()
- there is a missingString.t()