Skip to content

Commit

Permalink
Fix an off-by-one error in the handler for AddressChange requests
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed May 11, 2021
1 parent e762b13 commit 421e68c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 12 deletions.
10 changes: 0 additions & 10 deletions marlowe/src/Language/Marlowe/Client.hs
Expand Up @@ -224,9 +224,7 @@ marlowePlutusContract = do
where
create = do
(owners, contract) <- endpoint @"create"
logWarn @String "setup marlowe params"
(params, distributeRoleTokens) <- setupMarloweParams owners contract
logWarn @String "Received marlowe params"
slot <- currentSlot
let StateMachineClient{scInstance} = mkMarloweClient params
let marloweData = MarloweData {
Expand All @@ -237,7 +235,6 @@ marlowePlutusContract = do
let tx = mustPayToTheScript marloweData payValue <> distributeRoleTokens
let lookups = Constraints.scriptInstanceLookups validatorInstance
utx <- either (throwing _ConstraintResolutionError) pure (Constraints.mkTx lookups tx)
logWarn @String "Sumitting tx"
submitTxConfirmed utx
marlowePlutusContract
apply = do
Expand Down Expand Up @@ -362,17 +359,14 @@ setupMarloweParams owners contract = mapError (review _MarloweError) $ do
let roles = extractContractRoles contract
if Set.null roles
then do
logWarn @String "No roles"
let params = MarloweParams
{ rolesCurrency = adaSymbol
, rolePayoutValidatorHash = defaultRolePayoutValidatorHash }
pure (params, mempty)
else if roles `Set.isSubsetOf` Set.fromList (AssocMap.keys owners)
then do
logWarn @String "Roles (I)"
let tokens = fmap (\role -> (role, 1)) $ Set.toList roles
cur <- mapError RolesCurrencyError $ Currency.forgeContract creator tokens
logWarn @String "Roles (I): Curreny obtained."
let rolesSymbol = Currency.currencySymbol cur
let giveToParty (role, pkh) = Constraints.mustPayToPubKey pkh (Val.singleton rolesSymbol role 1)
let distributeRoleTokens = foldMap giveToParty (AssocMap.toList owners)
Expand All @@ -381,7 +375,6 @@ setupMarloweParams owners contract = mapError (review _MarloweError) $ do
, rolePayoutValidatorHash = mkRolePayoutValidatorHash rolesSymbol }
pure (params, distributeRoleTokens)
else do
logWarn @String "Roles (II)"
let missingRoles = roles `Set.difference` Set.fromList (AssocMap.keys owners)
let message = T.pack $ "You didn't specify owners of these roles: " <> show missingRoles
throwing _ContractError $ OtherError message
Expand Down Expand Up @@ -645,17 +638,14 @@ marloweCompanionContract :: Contract CompanionState MarloweCompanionSchema Marlo
marloweCompanionContract = contracts
where
contracts = do
logInfo @String "Initialising marlowe companion contract"
pkh <- pubKeyHash <$> ownPubKey
let ownAddress = pubKeyHashAddress pkh
utxo <- utxoAt ownAddress
let txOuts = fmap (txOutTxOut . snd) $ Map.toList utxo
forM_ txOuts notifyOnNewContractRoles
cont ownAddress
cont ownAddress = do
logInfo @String $ "Starting to watch own adress: " <> show ownAddress
txns <- nextTransactionsAt ownAddress
logInfo @String "Received transactions"
let txOuts = txns >>= txOutputs
forM_ txOuts notifyOnNewContractRoles
cont ownAddress
Expand Down
Expand Up @@ -191,7 +191,7 @@ handleAddressChangedAtQueries = RequestHandler $ \req ->
-- index only learns about those transactions at the beginning of the
-- next slot. So we need to make sure that we are past the current
-- slot.
guard (current > target)
guard (current >= target)
Wallet.Effects.addressChanged req

handleOwnInstanceIdQueries ::
Expand Down
Expand Up @@ -42,7 +42,6 @@ startNodeClient ::
startNodeClient socket slotConfig instancesState = do
env <- STM.atomically emptyBlockchainEnv
_ <- Client.runClientNode socket slotConfig $ \block slot -> do
unless (null block) $ putStrLn $ "node client block: " <> show (txId <$> block)
STM.atomically $ processBlock env block slot
pure env

Expand Down

0 comments on commit 421e68c

Please sign in to comment.