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

    case script do
      # P2PKH input (compressed): sig_size <signature> 33 <pubkey>
      <<sig_size, _sig :: bytes-size(sig_size), 33, pk :: bytes-size(33)>> ->
        address = pk
        |> Base.encode16(case: :lower)
        |> BitcoinTool.process!(:pubkey_hex)
        {:ok, address }

      # P2PKH input (uncompressed): sig_size <signature> 65 <pubkey>
      <<sig_size, _sig :: bytes-size(sig_size), 65, pk :: bytes-size(65)>> ->
        address = pk
        |> Base.encode16(case: :lower)
        |> BitcoinTool.process!(:pubkey_hex)
        {:ok, address }

      # P2PK input: sig_size <signature>
      <<sig_size, _sig :: bytes-size(sig_size)>> ->


      # 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
      _ ->
