From 87a9f4e6673cc047ffa64e9aef2d610b2b2ff2e6 Mon Sep 17 00:00:00 2001 From: Elliot Glaysher Date: Thu, 19 Sep 2019 15:40:23 -0700 Subject: [PATCH] Can retrieve the ames domains from Ethereum using web3. Partial support for retrieving the galaxy table, but I'm having problems converting the public key type. --- pkg/king/app/CLI.hs | 18 ++++-- pkg/king/app/Main.hs | 9 +++ pkg/king/lib/Arvo/Event.hs | 3 +- pkg/king/lib/Azimuth/Azimuth.hs | 5 ++ pkg/king/lib/Azimuth/azimuth.json | 1 + pkg/king/lib/Vere/Dawn.hs | 99 +++++++++++++++++++++++++++++++ pkg/king/lib/Vere/Pier.hs | 3 + pkg/king/package.yaml | 2 + 8 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 pkg/king/lib/Azimuth/Azimuth.hs create mode 100644 pkg/king/lib/Azimuth/azimuth.json create mode 100644 pkg/king/lib/Vere/Dawn.hs diff --git a/pkg/king/app/CLI.hs b/pkg/king/app/CLI.hs index 5d9547df50..d635eabeb4 100644 --- a/pkg/king/app/CLI.hs +++ b/pkg/king/app/CLI.hs @@ -27,11 +27,11 @@ data Opts = Opts deriving (Show) data New = New - { nPillPath :: FilePath - , nShipAddr :: Text - , nPierPath :: Maybe FilePath -- Derived from ship name if not specified. - , nArvoDir :: Maybe FilePath - , nBootFake :: Bool + { nPillPath :: FilePath + , nShipAddr :: Text + , nPierPath :: Maybe FilePath -- Derived from ship name if not specified. + , nArvoDir :: Maybe FilePath + , nBootFake :: Bool } deriving (Show) @@ -62,6 +62,7 @@ data Bug , bFirstEvt :: Word64 , bFinalEvt :: Word64 } + | CheckDawn deriving (Show) data Cmd @@ -247,6 +248,9 @@ checkFx = ValidateFX <$> pierPath <*> firstEv <*> lastEv browseEvs :: Parser Bug browseEvs = EventBrowser <$> pierPath +checkDawn :: Parser Bug +checkDawn = pure CheckDawn + bugCmd :: Parser Cmd bugCmd = fmap CmdBug $ subparser @@ -270,6 +274,10 @@ bugCmd = fmap CmdBug ( info (checkFx <**> helper) $ progDesc "Parse all data in event log" ) + <> command "dawn" + ( info (checkDawn <**> helper) + $ progDesc "Test run dawn" + ) conCmd :: Parser Cmd conCmd = do diff --git a/pkg/king/app/Main.hs b/pkg/king/app/Main.hs index d45fa6aa46..05dda2a6fd 100644 --- a/pkg/king/app/Main.hs +++ b/pkg/king/app/Main.hs @@ -104,6 +104,7 @@ import System.Environment (getProgName) import System.Posix.Signals (Handler(Catch), installHandler, sigTERM) import Text.Show.Pretty (pPrint) import Urbit.Time (Wen) +import Vere.Dawn import Vere.LockFile (lockFile) import qualified CLI as CLI @@ -326,6 +327,13 @@ startBrowser pierPath = runRAcquire $ do log <- Log.existing (pierPath <> "/.urb/log") rio $ EventBrowser.run log +checkDawn :: HasLogFunc e => RIO e () +checkDawn = do + e <- dawnVent (Seed (Ship 0) 1 (fromIntegral 1) Nothing) + case e of + Left x -> putStrLn "Left" + Right y -> putStrLn "Right" + main :: IO () main = do mainTid <- myThreadId @@ -342,6 +350,7 @@ main = do CLI.CmdBug (CLI.ValidatePill pax pil seq) -> testPill pax pil seq CLI.CmdBug (CLI.ValidateEvents pax f l) -> checkEvs pax f l CLI.CmdBug (CLI.ValidateFX pax f l) -> checkFx pax f l + CLI.CmdBug CLI.CheckDawn -> checkDawn CLI.CmdCon port -> connTerm port diff --git a/pkg/king/lib/Arvo/Event.hs b/pkg/king/lib/Arvo/Event.hs index 385f1bdaa3..cca4f1bb2e 100644 --- a/pkg/king/lib/Arvo/Event.hs +++ b/pkg/king/lib/Arvo/Event.hs @@ -15,6 +15,7 @@ import qualified Network.HTTP.Types.Method as H -- Misc Types ------------------------------------------------------------------ type Pass = Atom -- Public Key +type Rift = Atom -- Continuity number type Life = Word -- Number of Azimoth key revs. type Bloq = Atom -- TODO type Ring = Atom -- Private Key @@ -74,7 +75,7 @@ data Snap = Snap (NounMap Ship Public) data Dawn = MkDawn { dSeed :: Seed , dShip :: Ship - , dCzar :: NounMap Ship (Life, Pass) + , dCzar :: NounMap Ship (Rift, Life, Pass) , dTurf :: [Turf] , dBloq :: Bloq , dNode :: (Maybe PUrl) diff --git a/pkg/king/lib/Azimuth/Azimuth.hs b/pkg/king/lib/Azimuth/Azimuth.hs new file mode 100644 index 0000000000..8a4faaeec7 --- /dev/null +++ b/pkg/king/lib/Azimuth/Azimuth.hs @@ -0,0 +1,5 @@ +module Azimuth.Azimuth where + +import Network.Ethereum.Contract.TH + +[abiFrom|lib/Azimuth/azimuth.json|] diff --git a/pkg/king/lib/Azimuth/azimuth.json b/pkg/king/lib/Azimuth/azimuth.json new file mode 100644 index 0000000000..148d1925c8 --- /dev/null +++ b/pkg/king/lib/Azimuth/azimuth.json @@ -0,0 +1 @@ +[{"constant":true,"inputs":[{"name":"","type":"uint32"},{"name":"","type":"uint32"}],"name":"escapeRequestsIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_whose","type":"address"}],"name":"getOwnedPoints","outputs":[{"name":"ownedPoints","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"votingFor","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"rights","outputs":[{"name":"owner","type":"address"},{"name":"managementProxy","type":"address"},{"name":"spawnProxy","type":"address"},{"name":"votingProxy","type":"address"},{"name":"transferProxy","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"transferringFor","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_sponsor","type":"uint32"}],"name":"isSponsor","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getManagementProxy","outputs":[{"name":"manager","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getContinuityNumber","outputs":[{"name":"continuityNumber","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"},{"name":"","type":"uint256"}],"name":"sponsoring","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_whose","type":"address"}],"name":"getOwnedPointCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"doEscape","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_whose","type":"address"},{"name":"_index","type":"uint256"}],"name":"getOwnedPointAtIndex","outputs":[{"name":"point","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getTransferProxy","outputs":[{"name":"transferProxy","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"isSpawnProxy","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"pointsOwnedBy","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"address"}],"name":"operators","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getSpawnCount","outputs":[{"name":"spawnCount","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"setSpawnProxy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"setTransferProxy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"},{"name":"","type":"uint32"}],"name":"sponsoringIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"isTransferProxy","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getVotingProxy","outputs":[{"name":"voter","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"isManagementProxy","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint32"}],"name":"votingForIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"isLive","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_sponsor","type":"uint32"}],"name":"getEscapeRequests","outputs":[{"name":"requests","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getSponsor","outputs":[{"name":"sponsor","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_sponsor","type":"uint32"}],"name":"getEscapeRequestsCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint32"}],"name":"pointOwnerIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getManagerFor","outputs":[{"name":"mfor","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint32"}],"name":"managerForIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"managerFor","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"isActive","outputs":[{"name":"equals","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getOwner","outputs":[{"name":"owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"}],"name":"points","outputs":[{"name":"encryptionKey","type":"bytes32"},{"name":"authenticationKey","type":"bytes32"},{"name":"hasSponsor","type":"bool"},{"name":"active","type":"bool"},{"name":"escapeRequested","type":"bool"},{"name":"sponsor","type":"uint32"},{"name":"escapeRequestedTo","type":"uint32"},{"name":"cryptoSuiteVersion","type":"uint32"},{"name":"keyRevisionNumber","type":"uint32"},{"name":"continuityNumber","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getSpawningForCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"hasBeenLinked","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_who","type":"address"}],"name":"canTransfer","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint32"}],"name":"spawningForIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"hasSponsor","outputs":[{"name":"has","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"activatePoint","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getSpawned","outputs":[{"name":"spawned","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"setManagementProxy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_who","type":"address"}],"name":"canSpawnAs","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getKeyRevisionNumber","outputs":[{"name":"revision","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_who","type":"address"}],"name":"canManage","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getTransferringFor","outputs":[{"name":"tfor","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getPointSize","outputs":[{"name":"_size","type":"uint8"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"_sponsor","type":"uint32"}],"name":"getSponsoringCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getSpawningFor","outputs":[{"name":"sfor","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"isEscaping","outputs":[{"name":"escaping","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint32"},{"name":"","type":"uint256"}],"name":"escapeRequests","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"setVotingProxy","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sponsor","type":"uint32"}],"name":"getSponsoring","outputs":[{"name":"sponsees","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_sponsor","type":"uint32"}],"name":"setEscapeRequest","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"}],"name":"isOperator","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_who","type":"address"}],"name":"canVoteAs","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_primary","type":"string"},{"name":"_secondary","type":"string"},{"name":"_tertiary","type":"string"}],"name":"setDnsDomains","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"loseSponsor","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"},{"name":"_operator","type":"address"},{"name":"_approved","type":"bool"}],"name":"setOperator","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"registerSpawned","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getKeys","outputs":[{"name":"crypt","type":"bytes32"},{"name":"auth","type":"bytes32"},{"name":"suite","type":"uint32"},{"name":"revision","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"cancelEscape","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_address","type":"address"}],"name":"isOwner","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getManagerForCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint32"}],"name":"transferringForIndexes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getVotingFor","outputs":[{"name":"vfor","type":"uint32[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"},{"name":"","type":"uint256"}],"name":"spawningFor","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_owner","type":"address"}],"name":"setOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getTransferringForCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_proxy","type":"address"}],"name":"isVotingProxy","outputs":[{"name":"result","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getPrefix","outputs":[{"name":"prefix","type":"uint16"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"dnsDomains","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"}],"name":"incrementContinuityNumber","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getSpawnProxy","outputs":[{"name":"spawnProxy","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"}],"name":"getEscapeRequest","outputs":[{"name":"escape","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_point","type":"uint32"},{"name":"_encryptionKey","type":"bytes32"},{"name":"_authenticationKey","type":"bytes32"},{"name":"_cryptoSuiteVersion","type":"uint32"}],"name":"setKeys","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_proxy","type":"address"}],"name":"getVotingForCount","outputs":[{"name":"count","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_point","type":"uint32"},{"name":"_sponsor","type":"uint32"}],"name":"isRequestingEscapeTo","outputs":[{"name":"equals","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"owner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"}],"name":"Activated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"prefix","type":"uint32"},{"indexed":true,"name":"child","type":"uint32"}],"name":"Spawned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"sponsor","type":"uint32"}],"name":"EscapeRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"sponsor","type":"uint32"}],"name":"EscapeCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"sponsor","type":"uint32"}],"name":"EscapeAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"sponsor","type":"uint32"}],"name":"LostSponsor","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":false,"name":"encryptionKey","type":"bytes32"},{"indexed":false,"name":"authenticationKey","type":"bytes32"},{"indexed":false,"name":"cryptoSuiteVersion","type":"uint32"},{"indexed":false,"name":"keyRevisionNumber","type":"uint32"}],"name":"ChangedKeys","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":false,"name":"number","type":"uint32"}],"name":"BrokeContinuity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"spawnProxy","type":"address"}],"name":"ChangedSpawnProxy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"transferProxy","type":"address"}],"name":"ChangedTransferProxy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"managementProxy","type":"address"}],"name":"ChangedManagementProxy","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"point","type":"uint32"},{"indexed":true,"name":"votingProxy","type":"address"}],"name":"ChangedVotingProxy","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"primary","type":"string"},{"indexed":false,"name":"secondary","type":"string"},{"indexed":false,"name":"tertiary","type":"string"}],"name":"ChangedDns","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}] diff --git a/pkg/king/lib/Vere/Dawn.hs b/pkg/king/lib/Vere/Dawn.hs new file mode 100644 index 0000000000..f3e805eacb --- /dev/null +++ b/pkg/king/lib/Vere/Dawn.hs @@ -0,0 +1,99 @@ +{-# OPTIONS_GHC -Wwarn #-} +module Vere.Dawn where + +import Arvo.Common +import Arvo.Event +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) + +import qualified Data.Map.Strict as M + +{-TODOs: + + - Dawn takes a NounMap instead of a Map. Need a conversion function. + +-} + + +-- During boot, use the infura provider +provider = HttpProvider + "https://mainnet.infura.io/v3/196a7f37c7d54211b4a07904ec73ad87" + +azimuthContract = "0x223c067F8CF28ae173EE5CafEa60cA44C335fecB" + + +-- Reads the +-- +-- TODO: I don't know how to change a BytesN 32 to an Atom. +retrieveGalaxyTable :: Quantity -> Web3 (Map Ship (Rift, Life, Pass)) +retrieveGalaxyTable bloq = + withAccount () $ + withParam (to .~ azimuthContract) $ + withParam (block .~ (BlockWithNumber bloq)) $ + M.fromList <$> mapM getRow [0..5] + where + getRow idx = do + (pubKey, _, _, _, _, _, _, _, keyRev, continuity) <- points idx + -- pubKey is a sort of ByteArray. + pure (fromIntegral idx, (fromIntegral continuity, + fromIntegral keyRev, + fromIntegral 0)) + -- pubKey ^. from atomBytes)) + +-- Reads the Turf domains off the blockchain at block height `bloq`. +readAmesDomains :: Quantity -> Web3 ([Turf]) +readAmesDomains bloq = + withAccount () $ + withParam (to .~ azimuthContract) $ + 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 + + -- TODO: Do the entire point:...:dawn flow. This now should work in theory + -- + -- (x ...) <- withAccount () $ + -- withParam (to .~ azimuthContract) $ + -- points 15 + + -- Retrieve the galaxy table [MUST FIX s/5/255/ AND PUBKEY TO ATOM] + -- galaxyTable <- retrieveGalaxyTable dBloq + -- print $ show galaxyTable + + -- Read Ames domains [DONE] + -- dTurf <- readAmesDomains dBloq + -- print $ show dTurf + + pure (dBloq) + + print $ show hs + + pure (Left "bad") + diff --git a/pkg/king/lib/Vere/Pier.hs b/pkg/king/lib/Vere/Pier.hs index ff517016e3..1718858e3c 100644 --- a/pkg/king/lib/Vere/Pier.hs +++ b/pkg/king/lib/Vere/Pier.hs @@ -214,6 +214,9 @@ pier pierPath mPort (serf, log, ss) = do Left (txt, exn) -> logError $ displayShow ("Somthing died", txt, exn) Right tag -> logError $ displayShow ("something simply exited", tag) + atomically $ (Term.spin muxed) (Just "shutdown") + + death :: Text -> Async () -> STM (Either (Text, SomeException) Text) death tag tid = do waitCatchSTM tid <&> \case diff --git a/pkg/king/package.yaml b/pkg/king/package.yaml index d20954366e..8dab7c3349 100644 --- a/pkg/king/package.yaml +++ b/pkg/king/package.yaml @@ -57,6 +57,7 @@ dependencies: - lmdb - lock-file - megaparsec + - memory - mtl - multimap - network @@ -99,6 +100,7 @@ dependencies: - wai-conduit - warp - warp-tls + - web3 - websockets default-extensions: