| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Morley.Client.TezosClient.Impl
Contents
Description
Interface to the octez-client executable expressed in Haskell types.
Synopsis
- data TezosClientError
- = UnexpectedClientFailure Int Text Text
- | AlreadyRevealed ImplicitAlias
- | InvalidOperationHash OperationHash
- | CounterIsAlreadyUsed Text Text
- | EConnreset
- | ConfigParseError String
- | TezosClientCryptoParseError Text CryptoParseError
- | TezosClientParseAddressError Text ParseAddressError
- | TezosClientParseFeeError Text Text
- | TezosClientUnexpectedOutputFormat Text
- | CantRevealContract ImplicitAlias
- | ContractSender ContractAddress Text
- | EmptyImplicitContract ImplicitAlias
- | TezosClientUnexpectedSignatureOutput Text
- | TezosClientParseEncryptionTypeError Text Text
- | DuplicateAlias Text
- | AmbiguousAlias Text ContractAddress ImplicitAddress
- | ResolveError ResolveError
- signBytes :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> ByteString -> m Signature
- rememberContract :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => AliasBehavior -> ContractAddress -> ContractAlias -> m ()
- importKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => Bool -> ImplicitAlias -> SecretKey -> m ImplicitAddressWithAlias
- genKey :: (MonadThrow m, MonadCatch m, WithClientLog env m, HasTezosClientEnv env, MonadIO m, HasTezosClient m) => ImplicitAlias -> m ImplicitAddress
- genFreshKey :: (MonadThrow m, MonadCatch m, WithClientLog env m, HasTezosClientEnv env, MonadIO m, HasTezosClient m) => ImplicitAlias -> m ImplicitAddress
- revealKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> m ()
- revealKeyUnlessRevealed :: (WithClientLog env m, HasTezosRpc m, MonadIO m, HasTezosClientEnv env) => ImplicitAddressWithAlias -> Maybe ScrubbedBytes -> m ()
- data ResolveError where
- REAliasNotFound :: Text -> ResolveError
- REWrongKind :: Alias expectedKind -> Address -> ResolveError
- REAddressNotFound :: KindedAddress kind -> ResolveError
- class Resolve addressOrAlias where
- type ResolvedAddress addressOrAlias :: Type
- type ResolvedAlias addressOrAlias :: Type
- type ResolvedAddressAndAlias addressOrAlias :: Type
- resolveAddressEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAddress addressOrAlias))
- getAliasEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAlias addressOrAlias))
- resolveAddressWithAliasEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAddressAndAlias addressOrAlias))
- resolveAddress :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAddress addressOrAlias)
- resolveAddressMaybe :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAddress addressOrAlias))
- getAlias :: forall addressOrAlias m env. (HasTezosClient m, WithClientLog env m, MonadThrow m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAlias addressOrAlias)
- getAliasMaybe :: forall addressOrAlias m env. (HasTezosClient m, WithClientLog env m, MonadThrow m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAlias addressOrAlias))
- getPublicKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> m PublicKey
- getSecretKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> m SecretKey
- getTezosClientConfig :: FilePath -> Maybe FilePath -> IO TezosClientConfig
- calcTransferFee :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => AddressOrAlias kind -> Maybe ScrubbedBytes -> TezosInt64 -> [CalcTransferFeeData] -> m [TezosMutez]
- calcOriginationFee :: (UntypedValScope st, WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => CalcOriginationFeeData cp st -> m TezosMutez
- calcRevealFee :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> TezosInt64 -> m TezosMutez
- getKeyPassword :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadMask m) => ImplicitAlias -> m (Maybe ScrubbedBytes)
- registerDelegate :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> m ()
- getAliasesAndAddresses :: forall m env. (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => m [(Text, Text)]
- resolveAddressWithAlias :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAddressAndAlias addressOrAlias)
- resolveAddressWithAliasMaybe :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAddressAndAlias addressOrAlias))
- findAddress :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => Text -> m FindAddressResult
- data FindAddressResult
- = FARUnambiguous L1Address
- | FARAmbiguous ContractAddress ImplicitAddress
- | FARNone
- data CallMode
- callTezosClient :: forall env m. (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => (Text -> Text -> IO Bool) -> [String] -> CallMode -> Maybe ScrubbedBytes -> m Text
- callTezosClientStrict :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => [String] -> CallMode -> Maybe ScrubbedBytes -> m Text
Documentation
data TezosClientError Source #
A data type for all predicatable errors that can happen during
octez-client usage.
Constructors
| UnexpectedClientFailure |
|
| AlreadyRevealed | Public key of the given address is already revealed. |
Fields
| |
| InvalidOperationHash OperationHash | Can't wait for inclusion of operation with given hash because the hash is invalid. |
| CounterIsAlreadyUsed | Error that indicates when given counter is already used for given contract. |
| EConnreset | Network error with which |
| ConfigParseError String | A parse error occurred during config parsing. |
| TezosClientCryptoParseError Text CryptoParseError |
|
| TezosClientParseAddressError Text ParseAddressError |
|
| TezosClientParseFeeError Text Text |
|
| TezosClientUnexpectedOutputFormat Text |
|
| CantRevealContract | Given alias is a contract and cannot be revealed. |
Fields
| |
| ContractSender ContractAddress Text | Given contract is a source of a transfer or origination operation. |
| EmptyImplicitContract | Given alias is an empty implicit contract. |
Fields
| |
| TezosClientUnexpectedSignatureOutput Text |
|
| TezosClientParseEncryptionTypeError Text Text |
|
| DuplicateAlias Text | Tried to save alias, but such alias already exists. |
| AmbiguousAlias Text ContractAddress ImplicitAddress | Expected an alias to be associated with either an implicit address or a contract address, but it was associated with both. |
| ResolveError ResolveError | |
Instances
| Exception TezosClientError Source # | |
Defined in Morley.Client.TezosClient.Impl Methods toException :: TezosClientError -> SomeException # | |
| Show TezosClientError Source # | |
Defined in Morley.Client.TezosClient.Impl Methods showsPrec :: Int -> TezosClientError -> ShowS # show :: TezosClientError -> String # showList :: [TezosClientError] -> ShowS # | |
| Buildable TezosClientError Source # | |
Defined in Morley.Client.TezosClient.Impl Methods build :: TezosClientError -> Builder # | |
octez-client api
signBytes :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> ByteString -> m Signature Source #
Sign an arbtrary bytestring using octez-client.
Secret key of the address corresponding to give AddressOrAlias must be known.
rememberContract :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => AliasBehavior -> ContractAddress -> ContractAlias -> m () Source #
Save a contract with given address and alias.
If replaceExisting is False and a contract with given alias
already exists, this function does nothing.
importKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => Bool -> ImplicitAlias -> SecretKey -> m ImplicitAddressWithAlias Source #
genKey :: (MonadThrow m, MonadCatch m, WithClientLog env m, HasTezosClientEnv env, MonadIO m, HasTezosClient m) => ImplicitAlias -> m ImplicitAddress Source #
Generate a new secret key and save it with given alias. If an address with given alias already exists, it will be returned and no state will be changed.
genFreshKey :: (MonadThrow m, MonadCatch m, WithClientLog env m, HasTezosClientEnv env, MonadIO m, HasTezosClient m) => ImplicitAlias -> m ImplicitAddress Source #
Generate a new secret key and save it with given alias. If an address with given alias already exists, it will be removed and replaced with a fresh one.
revealKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> m () Source #
Reveal public key corresponding to the given alias. Fails if it's already revealed.
revealKeyUnlessRevealed :: (WithClientLog env m, HasTezosRpc m, MonadIO m, HasTezosClientEnv env) => ImplicitAddressWithAlias -> Maybe ScrubbedBytes -> m () Source #
Reveal key for implicit address if necessary.
data ResolveError where Source #
Constructors
| REAliasNotFound | |
Fields
| |
| REWrongKind | |
Fields
| |
| REAddressNotFound | |
Fields
| |
Instances
| Show ResolveError Source # | |
Defined in Morley.Client.TezosClient.Impl Methods showsPrec :: Int -> ResolveError -> ShowS # show :: ResolveError -> String # showList :: [ResolveError] -> ShowS # | |
| Buildable ResolveError Source # | |
Defined in Morley.Client.TezosClient.Impl Methods build :: ResolveError -> Builder # | |
class Resolve addressOrAlias where Source #
Associated Types
type ResolvedAddress addressOrAlias :: Type Source #
type ResolvedAlias addressOrAlias :: Type Source #
type ResolvedAddressAndAlias addressOrAlias :: Type Source #
Methods
resolveAddressEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAddress addressOrAlias)) Source #
Looks up the address associated with the given addressOrAlias.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the address with the requested kind.
getAliasEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAlias addressOrAlias)) Source #
Looks up the alias associated with the given addressOrAlias.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the alias of the address with the requested kind.
The primary (and probably only) reason this function exists is that
octez-client sign command only works with aliases. It was
reported upstream: https://gitlab.com/tezos/tezos/-/issues/836.
resolveAddressWithAliasEither :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => addressOrAlias -> m (Either ResolveError (ResolvedAddressAndAlias addressOrAlias)) Source #
Resolve both address and alias at the same time
Instances
resolveAddress :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAddress addressOrAlias) Source #
Looks up the address associated with the given addressOrAlias.
Will throw a TezosClientError if addressOrAlias is an alias and:
- the alias does not exist.
- the alias exists but its address is of the wrong kind.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the address with the requested kind.
resolveAddressMaybe :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAddress addressOrAlias)) Source #
Looks up the address associated with the given addressOrAlias.
Will return Nothing if addressOrAlias is an alias and:
- the alias does not exist.
- the alias exists but its address is of the wrong kind.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the address with the requested kind.
getAlias :: forall addressOrAlias m env. (HasTezosClient m, WithClientLog env m, MonadThrow m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAlias addressOrAlias) Source #
Looks up the alias associated with the given addressOrAlias.
Will throw a TezosClientError if addressOrAlias:
- is an address that is not associated with any alias.
- is an alias that does not exist.
- is an alias that exists but its address is of the wrong kind.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the alias.
getAliasMaybe :: forall addressOrAlias m env. (HasTezosClient m, WithClientLog env m, MonadThrow m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAlias addressOrAlias)) Source #
Looks up the alias associated with the given addressOrAlias.
Will return Nothing if addressOrAlias:
- is an address that is not associated with any alias.
- is an alias that does not exist.
- is an alias that exists but its address is of the wrong kind.
When the alias is associated with both an implicit and a contract address:
- The
SomeAddressOrAliasinstance will throw aTezosClientError, unless the alias is prefixed withimplicit:orcontract:to disambiguate. - The
AddressOrAliasinstance will return the alias.
getPublicKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> m PublicKey Source #
Return PublicKey corresponding to given AddressOrAlias.
getSecretKey :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> m SecretKey Source #
Return SecretKey corresponding to given AddressOrAlias.
getTezosClientConfig :: FilePath -> Maybe FilePath -> IO TezosClientConfig Source #
Read octez-client configuration.
calcTransferFee :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => AddressOrAlias kind -> Maybe ScrubbedBytes -> TezosInt64 -> [CalcTransferFeeData] -> m [TezosMutez] Source #
Calc baker fee for transfer using octez-client.
calcOriginationFee :: (UntypedValScope st, WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => CalcOriginationFeeData cp st -> m TezosMutez Source #
Calc baker fee for origination using octez-client.
calcRevealFee :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> TezosInt64 -> m TezosMutez Source #
Calc baker fee for revealing using octez-client.
Note that octez-client does not support passing an address here,
at least at the moment of writing.
getKeyPassword :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadMask m) => ImplicitAlias -> m (Maybe ScrubbedBytes) Source #
Get password for secret key associated with given address in case this key is password-protected
registerDelegate :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => ImplicitAlias -> Maybe ScrubbedBytes -> m () Source #
Register alias as delegate
getAliasesAndAddresses :: forall m env. (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => m [(Text, Text)] Source #
Calls octez-client list known contracts and returns
a list of (alias, address) pairs.
Note that an alias can be ambiguous: it can refer to both a contract and an implicit account. When an alias "abc" is ambiguous, the list will contain two entries:
("abc", "KT1...")
("key:abc", "tz1...")resolveAddressWithAlias :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (ResolvedAddressAndAlias addressOrAlias) Source #
Looks up the address and alias with the given addressOrAlias.
resolveAddressWithAliasMaybe :: forall addressOrAlias m env. (HasTezosClient m, MonadThrow m, WithClientLog env m, Resolve addressOrAlias) => addressOrAlias -> m (Maybe (ResolvedAddressAndAlias addressOrAlias)) Source #
Looks up the address and alias with the given addressOrAlias.
Internals
findAddress :: forall m env. (HasTezosClient m, MonadThrow m, WithClientLog env m) => Text -> m FindAddressResult Source #
Finds the implicit/contract addresses assigned to the given alias.
Note that an alias can be ambiguous: it can refer to both a contract and an
implicit account. When an alias "abc" is ambiguous, octez-client list known
contracts will return two entries with the following format:
abc: KT1... key:abc: tz1...
So, in order to check whether the alias is ambiguous, we check whether both "abc" and "key:abc" are present in the output.
If only "abc" is present, then we know it's not ambiguous (and it refers to either a contract or an implicit account).
data FindAddressResult Source #
Whether an alias is associated with an implicit address, a contract address, or both.
Constructors
| FARUnambiguous L1Address | |
| FARAmbiguous ContractAddress ImplicitAddress | |
| FARNone |
Datatype that represents modes for calling node from octez-client.
Constructors
| MockupMode | Mode in which |
| ClientMode | Normal mode in which |
callTezosClient :: forall env m. (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => (Text -> Text -> IO Bool) -> [String] -> CallMode -> Maybe ScrubbedBytes -> m Text Source #
Call octez-client with given arguments. Arguments defined by
config are added automatically. The second argument specifies what
should be done in failure case. It takes stdout and stderr
output. Possible handling:
- Parse a specific error and throw it.
- Parse an expected error that shouldn't cause a failure.
Return
Truein this case. - Detect an unexpected error, return
False. In this caseUnexpectedClientFailurewill be throw.
callTezosClientStrict :: (WithClientLog env m, HasTezosClientEnv env, MonadIO m, MonadCatch m) => [String] -> CallMode -> Maybe ScrubbedBytes -> m Text Source #
Call octez-client and expect success.