Skip to content

Commit

Permalink
refactor(ethereum): ♻️ small improvements following the lua lint CI o…
Browse files Browse the repository at this point in the history
…utput
  • Loading branch information
matteo-cristino authored and jaromil committed Mar 30, 2023
1 parent 97adccb commit 0a5dc53
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/lua/crypto_ethereum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ end
function ETH.encodeRLP(data)
local header = nil
local res = nil
local byt = nil

if type(data) == 'zenroom.big' then
data = ETH.n2o(data)
Expand Down Expand Up @@ -401,7 +400,7 @@ end
-- T[k] for any dynamic T and any k >= 0
-- (T1,...,Tk) if Ti is dynamic for some 1 <= i <= k
function is_dynamic(t)
dyn = t == 'string' or t == 'bytes' or string.match(t, '[a-zA-Z0-9]+%[%]')
local dyn = t == 'string' or t == 'bytes' or string.match(t, '[a-zA-Z0-9]+%[%]')
if not dyn then
t = string.match(t, '([a-zA-Z]+)%[%d+%]')
if t then
Expand All @@ -414,22 +413,18 @@ end
function encode_tuple(params, args)
local res = O.empty()

if type(params) == 'string' then
elseif type(params) ~= 'table' then
if type(params) ~= 'table' then
error("Type not encodable as tuple")
end

local tails = {}
local heads = {}
local head
local tail

local head_size = 0;
local tail_size = 0;
-- check if there are dynamic types and compute tails
for i, v in ipairs(params) do
if is_dynamic(v) then
local arg = nil;
head_size = head_size + 32
table.insert(tails, encode(v, args[i]))
else
Expand All @@ -456,10 +451,10 @@ function encode_tuple(params, args)
end

-- implement O.concat for memory efficient concat
for i, v in pairs(heads) do
for _, v in pairs(heads) do
res = res .. v
end
for i, v in pairs(tails) do
for _, v in pairs(tails) do
res = res .. v
end
return res
Expand Down

0 comments on commit 0a5dc53

Please sign in to comment.