-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to generate reward account addresses
- Loading branch information
Julian Ospald
committed
Aug 18, 2020
1 parent
17dfc99
commit e3ccb78
Showing
5 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{-# LANGUAGE NamedFieldPuns #-} | ||
|
||
{-# OPTIONS_HADDOCK hide #-} | ||
|
||
module Command.Address.Reward | ||
( Cmd | ||
, mod | ||
, run | ||
) where | ||
|
||
import Prelude hiding | ||
( mod ) | ||
|
||
import Cardano.Address | ||
( NetworkTag(..), bech32 ) | ||
import Cardano.Address.Style.Shelley | ||
( MkNetworkDiscriminantError (..), mkNetworkDiscriminant ) | ||
import Options.Applicative.Discrimination | ||
( networkTagOpt ) | ||
import Options.Applicative | ||
( CommandFields | ||
, Mod | ||
, command | ||
, footerDoc | ||
, header | ||
, helper | ||
, info | ||
, progDesc | ||
) | ||
import Options.Applicative.Help.Pretty | ||
( bold, indent, string, vsep ) | ||
import Options.Applicative.Style | ||
( Style (..) ) | ||
import System.IO | ||
( stdin, stdout ) | ||
import System.IO.Extra | ||
( hGetXPub, progName ) | ||
|
||
import qualified Cardano.Address.Style.Shelley as Shelley | ||
import qualified Data.ByteString.Char8 as B8 | ||
import qualified Data.Text.Encoding as T | ||
|
||
|
||
newtype Cmd = Cmd | ||
{ networkTag :: NetworkTag | ||
} deriving (Show) | ||
|
||
mod :: (Cmd -> parent) -> Mod CommandFields parent | ||
mod liftCmd = command "reward" $ | ||
info (helper <*> fmap liftCmd parser) $ mempty | ||
<> progDesc "Create a reward account address" | ||
<> header "Create a reward account address \ | ||
\that references a staking key (1-1)." | ||
<> footerDoc (Just $ vsep | ||
[ string "The is read from stdin." | ||
, string "" | ||
, string "Example:" | ||
, indent 2 $ bold $ string $ "$ "<>progName<>" recovery-phrase generate --size 15 \\" | ||
, indent 4 $ bold $ string $ "| "<>progName<>" key from-recovery-phrase Shelley > root.prv" | ||
, indent 2 $ string "" | ||
, indent 2 $ bold $ string "$ cat root.prv \\" | ||
, indent 4 $ bold $ string $ "| "<>progName<>" key child 1852H/1815H/0H/2/0 > stake.prv" | ||
, indent 2 $ string "" | ||
, indent 2 $ bold $ string "$ cat stake.prv \\" | ||
, indent 4 $ bold $ string $ "| "<>progName<>" key public \\" | ||
, indent 4 $ bold $ string $ "| "<>progName<>" address reward --network-tag 0" | ||
, indent 2 $ string "addr1uqly0fjvrgguywze067gwhsexggtj8rrdnxczgp5vexe8zgxqns3g" | ||
]) | ||
where | ||
parser = Cmd | ||
<$> networkTagOpt Shelley | ||
|
||
run :: Cmd -> IO () | ||
run Cmd{networkTag} = do | ||
xpub <- hGetXPub stdin | ||
case (mkNetworkDiscriminant . fromIntegral . unNetworkTag) networkTag of | ||
Left ErrWrongNetworkTag{} -> do | ||
fail "Invalid network tag. Must be between [0, 15]" | ||
Right discriminant -> do | ||
let addr = Shelley.rewardAccAddress discriminant (Shelley.liftXPub xpub) | ||
B8.hPutStr stdout $ T.encodeUtf8 $ bech32 addr | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters