@@ -177,7 +177,46 @@ func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.Led
177177}
178178
179179func UtxoValidateValueNotConservedUtxo (tx common.Transaction , slot uint64 , ls common.LedgerState , pp common.ProtocolParameters ) error {
180- return shelley .UtxoValidateValueNotConservedUtxo (tx , slot , ls , pp )
180+ tmpPparams , ok := pp .(* BabbageProtocolParameters )
181+ if ! ok {
182+ return errors .New ("pparams are not expected type" )
183+ }
184+ // Calculate consumed value
185+ // consumed = value from input(s) + withdrawals + refunds(?)
186+ var consumedValue uint64
187+ for _ , tmpInput := range tx .Inputs () {
188+ tmpUtxo , err := ls .UtxoById (tmpInput )
189+ // Ignore errors fetching the UTxO and exclude it from calculations
190+ if err != nil {
191+ continue
192+ }
193+ consumedValue += tmpUtxo .Output .Amount ()
194+ }
195+ for _ , tmpWithdrawalAmount := range tx .Withdrawals () {
196+ consumedValue += tmpWithdrawalAmount
197+ }
198+ // Calculate produced value
199+ // produced = value from output(s) + fee + deposits
200+ var producedValue uint64
201+ for _ , tmpOutput := range tx .Outputs () {
202+ producedValue += tmpOutput .Amount ()
203+ }
204+ producedValue += tx .Fee ()
205+ for _ , cert := range tx .Certificates () {
206+ switch cert .(type ) {
207+ case * common.PoolRegistrationCertificate :
208+ producedValue += uint64 (tmpPparams .PoolDeposit )
209+ case * common.StakeRegistrationCertificate :
210+ producedValue += uint64 (tmpPparams .KeyDeposit )
211+ }
212+ }
213+ if consumedValue == producedValue {
214+ return nil
215+ }
216+ return shelley.ValueNotConservedUtxoError {
217+ Consumed : consumedValue ,
218+ Produced : producedValue ,
219+ }
181220}
182221
183222func UtxoValidateOutputTooSmallUtxo (tx common.Transaction , slot uint64 , ls common.LedgerState , pp common.ProtocolParameters ) error {
0 commit comments