     end
   end
 
+  defp pubkey_to_address(pubkey) do
+    address = pubkey
+    |> Base.encode16(case: :lower)
+    |> BitcoinTool.process!(:pubkey_hex)
+    {:ok, address }
+  end
+
 end


  @network Application.get_env(:rpc, :network)

  # TODO: P2SH in/out, P2PK in/out

  def parse_address(%TransactionOutput{pk_script: script}) do
    case script do


      # P2PK output (compressed): 33 <pubkey> OP_CHECKSIG
      <<33, pk :: bytes-size(33), 172>> ->
        pk |> pubkey_to_address

      # P2PK output (uncompressed): 65 <pubkey> OP_CHECKSIG
      <<65, pk :: bytes-size(65), 172>> ->
        pk |> pubkey_to_address

      # Unmatched
      _ ->
