Skip to content

Commit

Permalink
Remove some undefined values to generate payment
Browse files Browse the repository at this point in the history
Also added lovelaceToTxOutValue which is not exported from Cardano.Api
  • Loading branch information
abailly-iohk committed Nov 22, 2021
1 parent 6e1c888 commit 01b7d1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 3 additions & 0 deletions local-cluster/src/CardanoClient.hs
Expand Up @@ -73,6 +73,9 @@ txOutLovelace (TxOut _ val _) =
TxOutAdaOnly _ l -> l
TxOutValue _ v -> selectLovelace v

lovelaceToTxOutValue :: Lovelace -> TxOutValue AlonzoEra
lovelaceToTxOutValue lovelace = TxOutValue MultiAssetInAlonzoEra (lovelaceToValue lovelace)

-- |Query current protocol parameters.
--
-- Throws 'CardanoClientException' if query fails.
Expand Down
19 changes: 10 additions & 9 deletions local-cluster/test/Test/DirectChainSpec.hs
Expand Up @@ -7,9 +7,10 @@ module Test.DirectChainSpec where
import Hydra.Prelude
import Test.Hydra.Prelude

import Cardano.Api (Lovelace (Lovelace), NetworkId (Testnet), UTxO (UTxO))
import Cardano.Api (Key (getVerificationKey), Lovelace (Lovelace), NetworkId (Testnet), SigningKey (PaymentSigningKey), UTxO (UTxO))
import Cardano.Api.Shelley (VerificationKey (PaymentVerificationKey))
import Cardano.Ledger.Keys (VKey (VKey))
import CardanoClient (build, queryUtxo, sign, submit, waitForPayment)
import CardanoClient (build, buildAddress, queryUtxo, sign, submit, waitForPayment)
import CardanoCluster (
ClusterLog,
keysFor,
Expand Down Expand Up @@ -169,27 +170,27 @@ generatePaymentToCommit ::
Cardano.VerificationKey ->
Natural ->
IO (Utxo CardanoTx)
generatePaymentToCommit (RunningNode _ nodeSocket) _sk _vk lovelace = do
generatePaymentToCommit (RunningNode _ nodeSocket) sk vk lovelace = do
UTxO availableUtxo <- queryUtxo networkId nodeSocket [spendingAddress]
let inputs = (,Nothing) <$> Map.keys availableUtxo
build networkId nodeSocket spendingAddress inputs [] theOutput >>= \case
Left e -> error (show e)
Right body -> do
let tx = sign cardanoSigningKey body
let tx = sign sk body
submit networkId nodeSocket tx
convertUtxo <$> waitForPayment networkId nodeSocket amountLovelace receivingAddress
where
networkId = Testnet magic

cardanoSigningKey = error "convert from sk"
spendingSigningKey = PaymentSigningKey sk

cardanoVerificationKey = error "convert from vk"
receivingVerificationKey = PaymentVerificationKey $ VKey vk

spendingAddress = error "create from sk"
spendingAddress = buildAddress (getVerificationKey spendingSigningKey) networkId

receivingAddress = error "create from vk"
receivingAddress = buildAddress receivingVerificationKey networkId

theOutput = error "should pay lovelace to vk"
theOutput = TxOut receivingAddress (lovelaceToTxOutValue lovelace) TxOutDatumNone

convertUtxo = error "convert utxo"

Expand Down

0 comments on commit 01b7d1c

Please sign in to comment.