2024-05-27 18:58:45 +04:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
|
|
|
|
from partial_transaction import PartialTransaction
|
2024-05-29 12:50:24 +04:00
|
|
|
from crypto import Field, Point
|
2024-05-27 18:58:45 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class TransactionBundle:
|
|
|
|
|
bundle: list[PartialTransaction]
|
|
|
|
|
|
|
|
|
|
def is_balanced(self) -> bool:
|
|
|
|
|
# TODO: move this to a NOIR constraint
|
2024-05-29 12:50:24 +04:00
|
|
|
balance_commitment = sum(
|
|
|
|
|
(ptx.balance() + ptx.zero().negate() for ptx in self.bundle),
|
|
|
|
|
start=Point.zero(),
|
|
|
|
|
)
|
|
|
|
|
return Point.zero() == balance_commitment
|
2024-05-27 18:58:45 +04:00
|
|
|
|
|
|
|
|
def verify(self) -> bool:
|
|
|
|
|
return self.is_balanced() and all(ptx.verify() for ptx in self.bundle)
|