Ask ENS for azimuth.eth instead of hardcoding

This commit is contained in:
Elliot Glaysher 2019-09-20 10:41:58 -07:00
parent dc189f3227
commit e422a2ac7d

View File

@ -2,7 +2,7 @@
module Vere.Dawn where
import Arvo.Common
import Arvo.Event
import Arvo.Event hiding (Address)
import Azimuth.Azimuth
import UrbitPrelude hiding (Call, to)
@ -13,8 +13,9 @@ import Network.Ethereum.Web3
import Data.Text (splitOn)
import qualified Data.ByteArray as BA
import qualified Data.Map.Strict as M
import qualified Data.ByteArray as BA
import qualified Data.Map.Strict as M
import qualified Network.Ethereum.Ens as Ens
{-TODOs:
@ -30,23 +31,28 @@ import qualified Data.Map.Strict as M
provider = HttpProvider
"https://mainnet.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87"
azimuthContract = "0x223c067F8CF28ae173EE5CafEa60cA44C335fecB"
--azimuthContract = "0x223c067F8CF28ae173EE5CafEa60cA44C335fecB"
bytes32ToAtom :: BytesN 32 -> Atom
bytes32ToAtom bytes =
(reverse (BA.pack $ BA.unpack bytes)) ^. from atomBytes
-- retrievePoint :: Quantity -> Int -> Web3 ()
-- retrievePoint bloq point =
-- withAccount () $
-- withParam (to .~ azimuthContract) $
-- withParam (block .~ (BlockWithNumber bloq)) $
-- (pubKey, _, _, _, _, _, _, _, keyRev, continuity) <- points idx
retrieveGalaxyTable :: Quantity -> Web3 (Map Ship (Rift, Life, Pass))
retrieveGalaxyTable bloq =
retrievePoint :: Quantity -> Address -> Int -> Web3 (Atom)
retrievePoint bloq azimuth p =
withAccount () $
withParam (to .~ azimuthContract) $
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 =
withAccount () $
withParam (to .~ azimuth) $
withParam (block .~ (BlockWithNumber bloq)) $
M.fromList <$> mapM getRow [0..5]
where
@ -56,11 +62,12 @@ retrieveGalaxyTable bloq =
fromIntegral keyRev,
bytes32ToAtom pubKey))
-- Reads the Turf domains off the blockchain at block height `bloq`.
readAmesDomains :: Quantity -> Web3 ([Turf])
readAmesDomains bloq =
readAmesDomains :: Quantity -> Address -> Web3 ([Turf])
readAmesDomains bloq azimuth =
withAccount () $
withParam (to .~ azimuthContract) $
withParam (to .~ azimuth) $
withParam (block .~ (BlockWithNumber bloq)) $
mapM getTurf [0..2]
where
@ -85,6 +92,10 @@ dawnVent (Seed (Ship ship) life ring oaf) = do
hs <- runWeb3' provider $ do
-- Block number (dBloq)
dBloq <- blockNumber
print ("Eth block: " ++ (show dBloq))
azimuth <- withAccount () $ Ens.resolve "azimuth.eth"
print ("Azimuth: " ++ (show azimuth))
-- TODO: Do the entire point:...:dawn flow. This now should work in theory
--
@ -93,11 +104,11 @@ dawnVent (Seed (Ship ship) life ring oaf) = do
-- points 15
-- Retrieve the galaxy table [MUST FIX s/5/255/]
galaxyTable <- retrieveGalaxyTable dBloq
print $ show galaxyTable
-- galaxyTable <- retrieveGalaxyTable dBloq azimuth
-- print $ show galaxyTable
-- Read Ames domains [DONE]
-- dTurf <- readAmesDomains dBloq
-- dTurf <- readAmesDomains dBloq azimuth
-- print $ show dTurf
pure (dBloq)