Skip to content

Commit

Permalink
feat(ethereum): ✨ add schema to print the ethereum transaction as a t…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
matteo-cristino committed Jul 13, 2023
1 parent fb8acd5 commit 76dd339
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Scenario ethereum

Given I have a 'ethereum signature'

Then print the 'ethereum signature' as 'hex'
Then print the 'ethereum signature' as 'ethereum signature table'

10 changes: 10 additions & 0 deletions src/lua/zencode_ethereum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ local function export_signature_f(obj)
return "0x"..O.to_hex(obj)
end

local function export_signature_table_f(obj)
local res = {}
res.r = obj.r:octet():hex()
res.s = obj.s:octet():hex()
res.v = obj.v:decimal()
return res
end

local function import_method_f(obj)
local res = {}
res.name = ZEN.get(obj, 'name', nil, O.from_string)
Expand Down Expand Up @@ -169,6 +177,8 @@ ZEN.add_schema(
export = big_wei_to_str_wei },
ethereum_signature = { import = import_signature_f,
export = export_signature_f},
ethereum_signature_table = { import = import_signature_f,
export = export_signature_table_f},
ethereum_method = { import = import_method_f,
export = export_method_f},
})
Expand Down
4 changes: 2 additions & 2 deletions test/zencode/ethereum.bats
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,11 @@ Scenario ethereum
Given I have a 'ethereum signature'
Then print the 'ethereum signature' as 'hex'
Then print the 'ethereum signature' as 'ethereum signature table'
EOF
save_output doc_print_ethsig_out.json
assert_output '{"ethereum_signature":{"r":"19373b64e400e237dd7fb23e76621675f8691c0eb14aa171a82f69593b1a2a05","s":"36203582c38585754a785ca504f51e4178bab5cc3f566e985358eaf7cb5d7876","v":"1b"}}'
assert_output '{"ethereum_signature":{"r":"19373b64e400e237dd7fb23e76621675f8691c0eb14aa171a82f69593b1a2a05","s":"36203582c38585754a785ca504f51e4178bab5cc3f566e985358eaf7cb5d7876","v":"27"}}'
}

@test "Import ethereum signature as table" {
Expand Down

0 comments on commit 76dd339

Please sign in to comment.