Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Companion tiny-wallet for the direct chain component. This module provide some useful utilities to tracking the wallet's UTXO, and accessing it
Synopsis
- type Address = Addr StandardCrypto
- type TxIn = TxIn StandardCrypto
- type TxOut = TxOut LedgerEra
- data TinyWallet m = TinyWallet {}
- data WalletInfoOnChain = WalletInfoOnChain {
- walletUTxO :: Map TxIn TxOut
- systemStart :: SystemStart
- tip :: ChainPoint
- type ChainQuery m = QueryPoint -> Address ShelleyAddr -> m WalletInfoOnChain
- watchUTxOUntil :: (Map TxIn TxOut -> Bool) -> TinyWallet IO -> IO (Map TxIn TxOut)
- newTinyWallet :: Tracer IO TinyWalletLog -> NetworkId -> (VerificationKey PaymentKey, SigningKey PaymentKey) -> ChainQuery IO -> IO (EpochInfo (Either Text)) -> IO (PParams Conway) -> IO (TinyWallet IO)
- applyTxs :: [Tx] -> (Address -> Bool) -> Map TxIn TxOut -> Map TxIn TxOut
- getTxId :: (HashAlgorithm (HASH crypto), HashAnnotated (TxBody (era crypto)) EraIndependentTxBody crypto) => AlonzoTx (era crypto) -> TxId crypto
- data ErrCoverFee
- = ErrNotEnoughFunds ChangeError
- | ErrNoFuelUTxOFound
- | ErrUnknownInput { }
- | ErrScriptExecutionFailed { }
- | ErrTranslationError (ContextError LedgerEra)
- | ErrConwayUpgradeError (TxUpgradeError Conway)
- data ChangeError = ChangeError {
- inputBalance :: Coin
- outputBalance :: Coin
- coverFee_ :: (EraCrypto era ~ StandardCrypto, EraPlutusContext era, AlonzoEraTx era, ScriptsNeeded era ~ AlonzoScriptsNeeded era, EraUTxO era, BabbageEraTxBody era) => PParams era -> SystemStart -> EpochInfo (Either Text) -> Map TxIn (TxOut era) -> Map TxIn (TxOut era) -> Tx era -> Either ErrCoverFee (Tx era)
- findLargestUTxO :: EraTxOut era => Map TxIn (TxOut era) -> Maybe (TxIn, TxOut era)
- estimateScriptsCost :: forall era. (AlonzoEraTx era, EraPlutusContext era, ScriptsNeeded era ~ AlonzoScriptsNeeded era, EraCrypto era ~ StandardCrypto, EraUTxO era) => PParams era -> SystemStart -> EpochInfo (Either Text) -> Map TxIn (TxOut era) -> Tx era -> Either ErrCoverFee (Map (PlutusPurpose AsIx era) ExUnits)
- data TinyWalletLog
- = BeginInitialize
- | EndInitialize {
- initialUTxO :: UTxO
- tip :: ChainPoint
- | BeginUpdate {
- point :: ChainPoint
- | EndUpdate {
- newUTxO :: UTxO
- | SkipUpdate {
- point :: ChainPoint
Documentation
data TinyWallet m Source #
A TinyWallet
is a small abstraction of a wallet with basic UTXO
management. The wallet is assumed to have only one address, and only one UTXO
at that address. It can sign transactions and keeps track of its UTXO behind
the scene.
The wallet is connecting to the node initially and when asked to $sel:reset:TinyWallet
.
Otherwise it can be fed blocks via $sel:update:TinyWallet
as the chain rolls forward.
TinyWallet | |
|
data WalletInfoOnChain Source #
WalletInfoOnChain | |
|
type ChainQuery m = QueryPoint -> Address ShelleyAddr -> m WalletInfoOnChain Source #
:: Tracer IO TinyWalletLog | A tracer for logging |
-> NetworkId | Network identifier to generate our address. |
-> (VerificationKey PaymentKey, SigningKey PaymentKey) | Credentials of the wallet. |
-> ChainQuery IO | A function to query UTxO, pparams, system start and epoch info from the node. Initially and on demand later. |
-> IO (EpochInfo (Either Text)) | |
-> IO (PParams Conway) | A means to query some pparams. |
-> IO (TinyWallet IO) |
Create a new tiny wallet handle.
applyTxs :: [Tx] -> (Address -> Bool) -> Map TxIn TxOut -> Map TxIn TxOut Source #
Apply a block to our wallet. Does nothing if the transaction does not modify the UTXO set, or else, remove consumed utxos and add produced ones.
To determine whether a produced output is ours, we apply the given function checking the output's address.
getTxId :: (HashAlgorithm (HASH crypto), HashAnnotated (TxBody (era crypto)) EraIndependentTxBody crypto) => AlonzoTx (era crypto) -> TxId crypto Source #
data ErrCoverFee Source #
This are all the error that can happen during coverFee.
ErrNotEnoughFunds ChangeError | |
ErrNoFuelUTxOFound | |
ErrUnknownInput | |
ErrScriptExecutionFailed | |
| |
ErrTranslationError (ContextError LedgerEra) | |
ErrConwayUpgradeError (TxUpgradeError Conway) |
Instances
Show ErrCoverFee Source # | |
Defined in Hydra.Chain.Direct.Wallet |
data ChangeError Source #
ChangeError | |
|
Instances
Show ChangeError Source # | |
Defined in Hydra.Chain.Direct.Wallet |
coverFee_ :: (EraCrypto era ~ StandardCrypto, EraPlutusContext era, AlonzoEraTx era, ScriptsNeeded era ~ AlonzoScriptsNeeded era, EraUTxO era, BabbageEraTxBody era) => PParams era -> SystemStart -> EpochInfo (Either Text) -> Map TxIn (TxOut era) -> Map TxIn (TxOut era) -> Tx era -> Either ErrCoverFee (Tx era) Source #
Cover fee for a transaction body using the given UTXO set. This calculate necessary fees and augments inputs outputs collateral accordingly to cover for the transaction cost and get the change back.
XXX: All call sites of this function use cardano-api types
:: forall era. (AlonzoEraTx era, EraPlutusContext era, ScriptsNeeded era ~ AlonzoScriptsNeeded era, EraCrypto era ~ StandardCrypto, EraUTxO era) | |
=> PParams era | Protocol parameters |
-> SystemStart | Start of the blockchain, for converting slots to UTC times |
-> EpochInfo (Either Text) | Information about epoch sizes, for converting slots to UTC times |
-> Map TxIn (TxOut era) | A UTXO needed to resolve inputs |
-> Tx era | The pre-constructed transaction |
-> Either ErrCoverFee (Map (PlutusPurpose AsIx era) ExUnits) |
Estimate cost of script executions on the transaction. This is only an estimates because the transaction isn't sealed at this point and adding new elements to it like change outputs or script integrity hash may increase that cost a little.
data TinyWalletLog Source #
BeginInitialize | |
EndInitialize | |
| |
BeginUpdate | |
| |
EndUpdate | |
| |
SkipUpdate | |
|