From 1433eb6e89f7c2b9f0f76020418f48e6a2b93e8d Mon Sep 17 00:00:00 2001 From: Izel Nakri Date: Sat, 2 Sep 2017 02:20:13 +0200 Subject: [PATCH] decodes are always mixed case now --- lib/eth/transaction.ex | 10 ++++++---- lib/eth/utils.ex | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/eth/transaction.ex b/lib/eth/transaction.ex index fcae3ad..78819d3 100644 --- a/lib/eth/transaction.ex +++ b/lib/eth/transaction.ex @@ -31,7 +31,7 @@ defmodule ETH.Transaction do to: _to, value: _value, data: _data, gas_price: _gas_price, gas_limit: _gas_limit, nonce: _nonce, chain_id: _chain_id }, << encoded_private_key :: binary-size(64) >>) do - decoded_private_key = Base.decode16!(encoded_private_key, case: :lower) + decoded_private_key = Base.decode16!(encoded_private_key, case: :mixed) sign_transaction(transaction, decoded_private_key) end @@ -61,7 +61,7 @@ defmodule ETH.Transaction do transaction |> Map.merge(%{v: encode16(<>), r: <<>>, s: <<>>}) |> to_list - |> Enum.map(fn(x) -> Base.decode16!(x, case: :lower) end) + |> Enum.map(fn(x) -> Base.decode16!(x, case: :mixed) end) |> hash end @@ -84,7 +84,7 @@ defmodule ETH.Transaction do |> Map.merge(%{r: encode16(r), s: encode16(s), v: encode16(<>)}) |> adjust_v_for_chain_id |> to_list - |> Enum.map(fn(x) -> Base.decode16!(x, case: :lower) end) + |> Enum.map(fn(x) -> Base.decode16!(x, case: :mixed) end) |> ExRLP.encode end @@ -93,7 +93,7 @@ defmodule ETH.Transaction do nonce: _nonce, chain_id: chain_id, v: v, r: r, s: s }) do if chain_id > 0 do - current_v_bytes = Base.decode16!(v, case: :lower) |> :binary.decode_unsigned + current_v_bytes = Base.decode16!(v, case: :mixed) |> :binary.decode_unsigned target_v_bytes = current_v_bytes + (chain_id * 2 + 8) transaction |> Map.merge(%{v: encode16(<< target_v_bytes >>)}) else @@ -109,4 +109,6 @@ defmodule ETH.Transaction do s = Map.get(transaction, :s, "") [nonce, gas_price, gas_limit, to, value, data, v, r, s] end + + def to_hex(value), do: Hexate.encode(value) end diff --git a/lib/eth/utils.ex b/lib/eth/utils.ex index 688e1ef..cf026c7 100644 --- a/lib/eth/utils.ex +++ b/lib/eth/utils.ex @@ -18,7 +18,7 @@ defmodule ETH.Utils do "0x#{Base.encode16(eth_address)}" end def get_address(<< encoded_private_key :: binary-size(64) >>) do - public_key = Base.decode16!(encoded_private_key) |> get_public_key() + public_key = Base.decode16!(encoded_private_key, case: :mixed) |> get_public_key() << 4 :: size(8), key :: binary-size(64) >> = public_key << _ :: binary-size(12), eth_address :: binary-size(20) >> = keccak256(key) "0x#{Base.encode16(eth_address)}" @@ -28,7 +28,7 @@ defmodule ETH.Utils do "0x#{Base.encode16(eth_address)}" end def get_address(<< encoded_public_key :: binary-size(130) >>) do - << 4 :: size(8), key :: binary-size(64) >> = Base.decode16!(encoded_public_key) + << 4 :: size(8), key :: binary-size(64) >> = Base.decode16!(encoded_public_key, case: :mixed) << _ :: binary-size(12), eth_address :: binary-size(20) >> = keccak256(key) "0x#{Base.encode16(eth_address)}" end