pins pre-boot validation eth rpc requests to a single block

This commit is contained in:
Joe Bryan 2018-10-29 14:02:36 -04:00
parent fb07d9eada
commit 087b6c92b0
3 changed files with 69 additions and 14 deletions

View File

@ -1 +1 @@
d9cfb8de356512e6bb6abd69b9af5dcced129a0c
770207e18637fdccdaca4e8408d9c1f87eec0b01

View File

@ -7992,38 +7992,74 @@
++ give
=/ tract ships:contracts:constitution:ethe
|%
:: +bloq:give:dawn: Eth RPC for latest block number
::
++ bloq
^- octs
%- as-octt:mimes:html
%- en-json:html
%+ request-to-json:ethereum
`~.0
[%eth-block-number ~]
:: +czar:give:dawn: Eth RPC for galaxy table
::
++ czar
|= boq=@ud
^- octs
%- as-octt:mimes:html
%- en-json:html
%- batch-read-request:ethereum
:- %a
%+ turn (gulf 0 255)
|=(gal=@ [`(scot %ud gal) tract ['getKeys(uint32)' [%uint gal]~]])
|= gal=@
%+ request-to-json:ethereum
`(scot %ud gal)
:+ %eth-call
=- [from=~ to=tract gas=~ price=~ value=~ data=-]
(encode-call:ethereum 'getKeys(uint32)' [%uint gal]~)
[%number boq]
:: +hull:give:dawn: Eth RPC for ship's contract state
::
++ hull
|= who=ship
|= [boq=@ud who=ship]
^- octs
%- as-octt:mimes:html
%- en-json:html
(read-request:ethereum [`~.0 tract ['ships(uint32)' [%uint `@`who]~]])
%+ request-to-json:ethereum
`~.0
:+ %eth-call
=- [from=~ to=tract gas=~ price=~ value=~ data=-]
(encode-call:ethereum 'ships(uint32)' [%uint `@`who]~)
[%number boq]
:: +turf:give:dawn: Eth RPC for network domains
::
++ turf
|= boq=@ud
^- octs
%- as-octt:mimes:html
%- en-json:html
%- batch-read-request:ethereum
:- %a
%+ turn (gulf 0 2)
|=(idx=@ [`(scot %ud idx) tract ['dnsDomains(uint256)' [%uint idx]~]])
|= idx=@
%+ request-to-json:ethereum
`(scot %ud idx)
:+ %eth-call
=- [from=~ to=tract gas=~ price=~ value=~ data=-]
(encode-call:ethereum 'dnsDomains(uint256)' [%uint idx]~)
[%number boq]
--
:: |take:dawn: parse responses for pre-boot validation
::
++ take
=, dejs:format
|%
:: +bloq:take:dawn: parse block number
::
++ bloq
|= rep=octs
^- @ud
=/ jon=json (need (de-json:html q.rep))
=/ res=cord ((ot result+so ~) jon)
(hex-to-num:ethereum res)
:: +czar:take:dawn: parse galaxy table
::
++ czar

View File

@ -28,6 +28,14 @@
%- crip
%+ weld "0x"
(render-hex-bytes:ethereum 20 `@`ships:contracts:constitution:ethe)
::
++ test-give-bloq
=/ oct
%- as-octs:mimes:html
'{"jsonrpc":"2.0","id":"0","method":"eth_blockNumber","params":[]}'
%+ expect-eq
!> oct
!> bloq:give:dawn
:: this produces a 1000+ line payload, so we just check that it doesn't crash
::
++ test-give-czar
@ -41,14 +49,14 @@
=/ oct
%- as-octs:mimes:html
%+ rap 3
:~ '{"jsonrpc":"2.0","method":"eth_call","params":[{"data":"'
:~ '{"jsonrpc":"2.0","id":"0","method":"eth_call","params":[{"data":"'
'0xb3220694'
'0000000000000000000000000000000000000000000000000000000000000000'
'","to":"' ships '"},"latest"]}'
'","to":"' ships '"},"0x0"]}'
==
%+ expect-eq
!> oct
!> (hull:give:dawn ~zod)
!> (hull:give:dawn 0 ~zod)
::
++ test-give-turf
=/ oct
@ -57,19 +65,30 @@
:~ '[{"jsonrpc":"2.0","id":"0","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000000'
'","to":"' ships '"},"latest"]},'
'","to":"' ships '"},"0x0"]},'
'{"jsonrpc":"2.0","id":"1","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000001'
'","to":"' ships '"},"latest"]},'
'","to":"' ships '"},"0x0"]},'
'{"jsonrpc":"2.0","id":"2","method":"eth_call","params":[{"data":"'
'0xeccc8ff1'
'0000000000000000000000000000000000000000000000000000000000000002'
'","to":"' ships '"},"latest"]}]'
'","to":"' ships '"},"0x0"]}]'
==
%+ expect-eq
!> oct
!> turf:give:dawn
!> (turf:give:dawn 0)
::
++ test-take-bloq
=/ oct
%- as-octs:mimes:html
%+ rap 3
:~ ''
==
=/ boq 32
%+ expect-eq
!> boq
!> (bloq:take:dawn oct)
::
++ test-take-czar
=/ oct