2019-09-20 01:40:23 +03:00
|
|
|
{-# OPTIONS_GHC -Wwarn #-}
|
|
|
|
module Vere.Dawn where
|
|
|
|
|
|
|
|
import Arvo.Common
|
2019-09-20 20:41:58 +03:00
|
|
|
import Arvo.Event hiding (Address)
|
2019-09-20 01:40:23 +03:00
|
|
|
import Azimuth.Azimuth
|
|
|
|
import UrbitPrelude hiding (Call, to)
|
|
|
|
|
|
|
|
import Network.Ethereum.Api.Eth
|
|
|
|
import Network.Ethereum.Api.Provider
|
|
|
|
import Network.Ethereum.Api.Types hiding (blockNumber)
|
|
|
|
import Network.Ethereum.Web3
|
|
|
|
|
|
|
|
import Data.Text (splitOn)
|
|
|
|
|
2019-09-20 20:41:58 +03:00
|
|
|
import qualified Data.ByteArray as BA
|
|
|
|
import qualified Data.Map.Strict as M
|
|
|
|
import qualified Network.Ethereum.Ens as Ens
|
2019-09-20 01:40:23 +03:00
|
|
|
|
|
|
|
{-TODOs:
|
|
|
|
|
|
|
|
- Dawn takes a NounMap instead of a Map. Need a conversion function.
|
|
|
|
|
2019-09-20 02:51:34 +03:00
|
|
|
- The Haskell Dawn structure as it exists right now isn't right? It can't
|
|
|
|
parse a real %dawn event in the event browser.
|
|
|
|
|
2019-09-20 01:40:23 +03:00
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
|
|
-- During boot, use the infura provider
|
|
|
|
provider = HttpProvider
|
|
|
|
"https://mainnet.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87"
|
|
|
|
|
2019-09-20 20:41:58 +03:00
|
|
|
|
|
|
|
--azimuthContract = "0x223c067F8CF28ae173EE5CafEa60cA44C335fecB"
|
2019-09-20 01:40:23 +03:00
|
|
|
|
2019-09-20 02:51:34 +03:00
|
|
|
bytes32ToAtom :: BytesN 32 -> Atom
|
|
|
|
bytes32ToAtom bytes =
|
|
|
|
(reverse (BA.pack $ BA.unpack bytes)) ^. from atomBytes
|
|
|
|
|
2019-09-20 01:40:23 +03:00
|
|
|
|
2019-09-20 20:41:58 +03:00
|
|
|
retrievePoint :: Quantity -> Address -> Int -> Web3 (Atom)
|
|
|
|
retrievePoint bloq azimuth p =
|
|
|
|
withAccount () $
|
|
|
|
withParam (to .~ azimuth) $
|
|
|
|
withParam (block .~ (BlockWithNumber bloq)) $ do
|
|
|
|
(pubKey, _, _, _, _, _, _, _, keyRev, continuity) <-
|
|
|
|
points (fromIntegral p)
|
|
|
|
pure $ bytes32ToAtom pubKey
|
|
|
|
|
|
|
|
|
|
|
|
retrieveGalaxyTable :: Quantity -> Address -> Web3 (Map Ship (Rift, Life, Pass))
|
|
|
|
retrieveGalaxyTable bloq azimuth =
|
2019-09-20 01:40:23 +03:00
|
|
|
withAccount () $
|
2019-09-20 20:41:58 +03:00
|
|
|
withParam (to .~ azimuth) $
|
2019-09-20 01:40:23 +03:00
|
|
|
withParam (block .~ (BlockWithNumber bloq)) $
|
|
|
|
M.fromList <$> mapM getRow [0..5]
|
|
|
|
where
|
|
|
|
getRow idx = do
|
|
|
|
(pubKey, _, _, _, _, _, _, _, keyRev, continuity) <- points idx
|
|
|
|
pure (fromIntegral idx, (fromIntegral continuity,
|
|
|
|
fromIntegral keyRev,
|
2019-09-20 02:51:34 +03:00
|
|
|
bytes32ToAtom pubKey))
|
2019-09-20 01:40:23 +03:00
|
|
|
|
2019-09-20 20:41:58 +03:00
|
|
|
|
2019-09-20 01:40:23 +03:00
|
|
|
-- Reads the Turf domains off the blockchain at block height `bloq`.
|
2019-09-20 20:41:58 +03:00
|
|
|
readAmesDomains :: Quantity -> Address -> Web3 ([Turf])
|
|
|
|
readAmesDomains bloq azimuth =
|
2019-09-20 01:40:23 +03:00
|
|
|
withAccount () $
|
2019-09-20 20:41:58 +03:00
|
|
|
withParam (to .~ azimuth) $
|
2019-09-20 01:40:23 +03:00
|
|
|
withParam (block .~ (BlockWithNumber bloq)) $
|
|
|
|
mapM getTurf [0..2]
|
|
|
|
where
|
|
|
|
getTurf idx = do
|
|
|
|
str <- dnsDomains idx
|
|
|
|
pure $ Turf $ fmap Cord $ reverse $ splitOn "." str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{-
|
|
|
|
[%dawn seed sponsor galaxies domains block eth-url snap]
|
|
|
|
-}
|
|
|
|
|
|
|
|
-- Produces either an error or a validated boot event structure.
|
|
|
|
dawnVent :: Seed -> RIO e (Either Text Dawn)
|
|
|
|
dawnVent (Seed (Ship ship) life ring oaf) = do
|
|
|
|
-- TODO: The dawn code tries to switch which ethereum provider it uses based
|
|
|
|
-- on a ships' rank, but then doesn't do anything with it other than passing
|
|
|
|
-- it into the ship and just uses the hardcoded infura node?
|
|
|
|
|
|
|
|
hs <- runWeb3' provider $ do
|
|
|
|
-- Block number (dBloq)
|
|
|
|
dBloq <- blockNumber
|
2019-09-20 20:41:58 +03:00
|
|
|
print ("Eth block: " ++ (show dBloq))
|
|
|
|
|
|
|
|
azimuth <- withAccount () $ Ens.resolve "azimuth.eth"
|
|
|
|
print ("Azimuth: " ++ (show azimuth))
|
2019-09-20 01:40:23 +03:00
|
|
|
|
|
|
|
-- TODO: Do the entire point:...:dawn flow. This now should work in theory
|
|
|
|
--
|
|
|
|
-- (x ...) <- withAccount () $
|
|
|
|
-- withParam (to .~ azimuthContract) $
|
|
|
|
-- points 15
|
|
|
|
|
2019-09-20 02:51:34 +03:00
|
|
|
-- Retrieve the galaxy table [MUST FIX s/5/255/]
|
2019-09-20 20:41:58 +03:00
|
|
|
-- galaxyTable <- retrieveGalaxyTable dBloq azimuth
|
|
|
|
-- print $ show galaxyTable
|
2019-09-20 01:40:23 +03:00
|
|
|
|
|
|
|
-- Read Ames domains [DONE]
|
2019-09-20 20:41:58 +03:00
|
|
|
-- dTurf <- readAmesDomains dBloq azimuth
|
2019-09-20 01:40:23 +03:00
|
|
|
-- print $ show dTurf
|
|
|
|
|
|
|
|
pure (dBloq)
|
|
|
|
|
|
|
|
print $ show hs
|
|
|
|
|
|
|
|
pure (Left "bad")
|
|
|
|
|