Packages

đŸ’°Customisable Bitcoin-Blockchain ecosystem in Elixir. Includes blockchain, crypto wallets, miners and simulation of transactions.

Current section

Files

Jump to
bitcoinSimulator lib blockchainGenserver.ex
Raw

lib/blockchainGenserver.ex

defmodule BlockChainGenServer do
use GenServer
def start_link() do
GenServer.start_link(__MODULE__, [])
end
def init([]) do
zeroBlock = %{
transactionData: %{"btc" => "", "receiverPublicKey" => ""},
prevHash: "zero_block",
hash: "zero_block",
signedMessage: "first_RSA",
timestamp: NaiveDateTime.utc_now,
sendersPublicKey: ""
}
{:ok, [zeroBlock]}
end
def handle_call({:getBlockChain}, _from, appState) do
{:reply, appState, appState}
end
def handle_cast({:addBlock, newBlock}, state) do
state = state ++ [newBlock]
{:noreply, state}
end
def handle_info(_msg, state) do
# IO.puts "unknown message"
{:noreply, state}
end
end