Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Hydra.Chain.Direct.Wallet
Description
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
- pparams :: PParams LedgerEra
- systemStart :: SystemStart
- epochInfo :: EpochInfo (Either Text)
- 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 (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 {
- scriptFailure :: (RdmrPtr, TransactionScriptFailure LedgerEra)
- | ErrTranslationError (TranslationError StandardCrypto)
- data ChangeError = ChangeError {
- inputBalance :: Coin
- outputBalance :: Coin
- coverFee_ :: PParams LedgerEra -> SystemStart -> EpochInfo (Either Text) -> Map TxIn TxOut -> Map TxIn TxOut -> AlonzoTx LedgerEra -> Either ErrCoverFee (AlonzoTx LedgerEra)
- findLargestUTxO :: Map TxIn TxOut -> Maybe (TxIn, TxOut)
- estimateScriptsCost :: PParams LedgerEra -> SystemStart -> EpochInfo (Either Text) -> Map TxIn TxOut -> AlonzoTx LedgerEra -> Either ErrCoverFee (Map RdmrPtr 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.
Constructors
TinyWallet | |
Fields
|
data WalletInfoOnChain Source #
Constructors
WalletInfoOnChain | |
Fields
|
type ChainQuery m = QueryPoint -> Address ShelleyAddr -> m WalletInfoOnChain Source #
Arguments
:: 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 (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.
Constructors
ErrNotEnoughFunds ChangeError | |
ErrNoFuelUTxOFound | |
ErrUnknownInput | |
ErrScriptExecutionFailed | |
Fields
| |
ErrTranslationError (TranslationError StandardCrypto) |
Instances
Show ErrCoverFee Source # | |
Defined in Hydra.Chain.Direct.Wallet |
data ChangeError Source #
Constructors
ChangeError | |
Fields
|
Instances
Show ChangeError Source # | |
Defined in Hydra.Chain.Direct.Wallet |
coverFee_ :: PParams LedgerEra -> SystemStart -> EpochInfo (Either Text) -> Map TxIn TxOut -> Map TxIn TxOut -> AlonzoTx LedgerEra -> Either ErrCoverFee (AlonzoTx LedgerEra) 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.
TODO: The fee calculation is currently very dumb and static. XXX: All call sites of this function use cardano-api types
Arguments
:: PParams LedgerEra | 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 | A UTXO needed to resolve inputs |
-> AlonzoTx LedgerEra | The pre-constructed transaction |
-> Either ErrCoverFee (Map RdmrPtr 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 #
Constructors
BeginInitialize | |
EndInitialize | |
Fields
| |
BeginUpdate | |
Fields
| |
EndUpdate | |
Fields
| |
SkipUpdate | |
Fields
|