1

How does valuePaidTo work ? Does it give the value paid by the script to the pubkeyhash or is it the total value of the pubkeyhash for the pending transactions ? Consider the following TxOut

txOutputs = [ 
   TxOut {
       txOutAddress = Address {
           addressCredential = PubKeyCredential "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [
                (,Map [("",87950820)])
            ]), 
        txOutDatumHash = Nothing
    },
    TxOut {
        txOutAddress = Address {
            addressCredential =
                ScriptCredential "d909e024ee4ed177cee1ec2b93de9afcf1ca1cb082f3af67ffa6a6e0",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [("",2000000)]),
            (64636464636161,Map [("T1",1)])]),
        txOutDatumHash = Just 5b3b53a06a4c34209a6278e9c89b570e9bf76e1e040cd528a7f1bf4ce3535742
    }, 
    TxOut {
        txOutAddress = Address {
            addressCredential = PubKeyCredential "80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7",
            addressStakingCredential = Nothing
        },
        txOutValue = Value (Map [(,Map [("",20000000)])]),
        txOutDatumHash = Nothing
    }
],

In this case the script is paying 20_000_000 to the pubkeyhash 80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7

Will valuePaidTo output 20_000_000 or 107_950_820 ?

1 Answer 1

0

perhaps the source code will explain it better than me.

in any case I'll try to explain it here.

valuePaidTo is defined as:

{-# INLINABLE valuePaidTo #-}
-- | Get the total value paid to a public key address by a pending transaction.
valuePaidTo :: TxInfo -> PubKeyHash -> Value
valuePaidTo ptx pkh = mconcat (pubKeyOutputsAt pkh ptx)

the comment

-- | Get the total value paid to a public key address by a pending 

should already give you answer

in any case, we see that in the definition of valuePaidTo the function pubKeyOutputsAt is used

that function is defined in the same source file just some lines above

in any case only having a look at the type signature should tell us a lot:

pubKeyOutputsAt :: PubKeyHash -> TxInfo -> [Value]

from this, we know that pubKeyOutputsAt returns a list of Value ([Value]), which we can assume (and confirm by reading the source) that are all the Values going to the PublicKeyHash

and from Haskell we know that mconcat (used in valuePaidTo) is something like the following

mconcat :: Monoid a => [a] -> a

where Monoid are "things with a binary operation that returns something of the same type", and Values happen to be a valid instance of Monoid where the operation acts as a "sum"

so what valuePaidTo is doing is

  1. take all the values going to the given PublicKeyHash
  2. "sum" them

in your case then the output lovelaces value would be 107950820

Not the answer you're looking for? Browse other questions tagged or ask your own question.