RPC: Viewing Keys #113
4 changed files with 96 additions and 3 deletions
|
@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Added
|
||||
|
||||
- RPC method `shieldnotes`
|
||||
- RPC method `deshieldfunds`
|
||||
- RPC methods:
|
||||
- `shieldnotes`
|
||||
- `deshieldfunds`
|
||||
- `getfullvk`
|
||||
- `getincomingvk`
|
||||
|
||||
## [0.7.2.0-beta]
|
||||
|
||||
|
|
|
@ -129,6 +129,7 @@ data ZenithMethod
|
|||
| ShieldNotes
|
||||
| DeshieldFunds
|
||||
| GetFVK
|
||||
| GetIVK
|
||||
| UnknownMethod
|
||||
deriving (Eq, Prelude.Show)
|
||||
|
||||
|
@ -147,6 +148,7 @@ instance ToJSON ZenithMethod where
|
|||
toJSON ShieldNotes = Data.Aeson.String "shieldnotes"
|
||||
toJSON DeshieldFunds = Data.Aeson.String "deshieldfunds"
|
||||
toJSON GetFVK = Data.Aeson.String "getfullvk"
|
||||
toJSON GetIVK = Data.Aeson.String "getincomingvk"
|
||||
toJSON UnknownMethod = Data.Aeson.Null
|
||||
|
||||
instance FromJSON ZenithMethod where
|
||||
|
@ -166,6 +168,7 @@ instance FromJSON ZenithMethod where
|
|||
"shieldnotes" -> pure ShieldNotes
|
||||
"deshieldfunds" -> pure DeshieldFunds
|
||||
"getfullvk" -> pure GetFVK
|
||||
"getincomingvk" -> pure GetIVK
|
||||
_ -> pure UnknownMethod
|
||||
|
||||
data ZenithParams
|
||||
|
@ -548,6 +551,16 @@ instance FromJSON RpcCall where
|
|||
pure $ RpcCall v i GetFVK (ViewingKeyParams x)
|
||||
else pure $ RpcCall v i GetFVK BadParams
|
||||
_anyOther -> pure $ RpcCall v i GetFVK BadParams
|
||||
GetIVK -> do
|
||||
p <- obj .: "params"
|
||||
case p of
|
||||
Array a ->
|
||||
if V.length a == 1
|
||||
then do
|
||||
x <- parseJSON $ a V.! 0
|
||||
pure $ RpcCall v i GetIVK (ViewingKeyParams x)
|
||||
else pure $ RpcCall v i GetIVK BadParams
|
||||
_anyOther -> pure $ RpcCall v i GetIVK BadParams
|
||||
|
||||
type ZenithRPC
|
||||
= "status" :> Get '[ JSON] Value :<|> BasicAuth "zenith-realm" Bool :> ReqBody
|
||||
|
@ -1089,6 +1102,34 @@ zenithServer state = getinfo :<|> handleRPC
|
|||
ErrorResponse (callId req) (-32006) "Account does not exist."
|
||||
_anyOtherParams ->
|
||||
return $ ErrorResponse (callId req) (-32602) "Invalid params"
|
||||
GetIVK -> do
|
||||
case parameters req of
|
||||
ViewingKeyParams aid -> do
|
||||
let dbPath = w_dbPath state
|
||||
let net = w_network state
|
||||
pool <- liftIO $ runNoLoggingT $ initPool dbPath
|
||||
acc <- liftIO $ getAccountById pool $ toSqlKey $ fromIntegral aid
|
||||
case acc of
|
||||
Just acc' -> do
|
||||
ivk <-
|
||||
liftIO $
|
||||
try
|
||||
(deriveUivk
|
||||
net
|
||||
(getOrchSK $ zcashAccountOrchSpendKey $ entityVal acc')
|
||||
(getSapSK $ zcashAccountSapSpendKey $ entityVal acc')
|
||||
(getTranSK $ zcashAccountTPrivateKey $ entityVal acc')) :: Handler
|
||||
(Either SomeException T.Text)
|
||||
case ivk of
|
||||
Left _ ->
|
||||
return $
|
||||
ErrorResponse (callId req) (-32010) "Internal Error"
|
||||
Right ivk' -> return $ ViewingKeyResponse (callId req) ivk'
|
||||
Nothing ->
|
||||
return $
|
||||
ErrorResponse (callId req) (-32006) "Account does not exist."
|
||||
_anyOtherParams ->
|
||||
return $ ErrorResponse (callId req) (-32602) "Invalid params"
|
||||
|
||||
authenticate :: Config -> BasicAuthCheck Bool
|
||||
authenticate config = BasicAuthCheck check
|
||||
|
|
|
@ -774,6 +774,55 @@ main = do
|
|||
Left e -> assertFailure e
|
||||
Right (ViewingKeyResponse i c) -> c `shouldNotBe` ""
|
||||
Right x -> assertFailure $ show x
|
||||
describe "Incoming" $ do
|
||||
it "bad credentials" $ do
|
||||
res <-
|
||||
makeZenithCall
|
||||
"127.0.0.1"
|
||||
nodePort
|
||||
"baduser"
|
||||
"idontknow"
|
||||
GetIVK
|
||||
BlankParams
|
||||
res `shouldBe` Left "Invalid credentials"
|
||||
describe "correct credentials" $ do
|
||||
it "no parameters" $ do
|
||||
res <-
|
||||
makeZenithCall
|
||||
"127.0.0.1"
|
||||
nodePort
|
||||
nodeUser
|
||||
nodePwd
|
||||
GetIVK
|
||||
BlankParams
|
||||
case res of
|
||||
Left e -> assertFailure e
|
||||
Right (ErrorResponse i c m) -> c `shouldBe` (-32602)
|
||||
it "invalid account" $ do
|
||||
res <-
|
||||
makeZenithCall
|
||||
"127.0.0.1"
|
||||
nodePort
|
||||
nodeUser
|
||||
nodePwd
|
||||
GetIVK
|
||||
(ViewingKeyParams 27)
|
||||
case res of
|
||||
Left e -> assertFailure e
|
||||
Right (ErrorResponse i c m) -> c `shouldBe` (-32006)
|
||||
it "valid account" $ do
|
||||
res <-
|
||||
makeZenithCall
|
||||
"127.0.0.1"
|
||||
nodePort
|
||||
nodeUser
|
||||
nodePwd
|
||||
GetIVK
|
||||
(ViewingKeyParams 1)
|
||||
case res of
|
||||
Left e -> assertFailure e
|
||||
Right (ViewingKeyResponse i c) -> c `shouldNotBe` ""
|
||||
Right x -> assertFailure $ show x
|
||||
|
||||
startAPI :: Config -> IO ()
|
||||
startAPI config = do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
cabal-version: 3.0
|
||||
name: zenith
|
||||
version: 0.7.2.0-beta
|
||||
version: 0.8.0.0-beta
|
||||
license: MIT
|
||||
license-file: LICENSE
|
||||
author: Rene Vergara
|
||||
|
|
Loading…
Reference in a new issue