Add ChannelDeposit operation.

This commit is contained in:
Alejandro Cabeza Romero 2026-03-09 11:29:08 +00:00
parent 9b56a4c8d8
commit 45365f8c97
No known key found for this signature in database
GPG Key ID: DA3D14AE478030FD
3 changed files with 45 additions and 1 deletions

View File

@ -9,6 +9,7 @@ class ContentType(Enum):
CHANNEL_INSCRIBE = "ChannelInscribe"
CHANNEL_BLOB = "ChannelBlob"
CHANNEL_SET_KEYS = "ChannelSetKeys"
CHANNEL_DEPOSIT = "ChannelDeposit"
SDP_DECLARE = "SDPDeclare"
SDP_WITHDRAW = "SDPWithdraw"
SDP_ACTIVE = "SDPActive"
@ -19,6 +20,13 @@ class NbeContent(NbeSchema):
type: str
class ChannelDeposit(NbeContent):
type: Literal["ChannelDeposit"] = "ChannelDeposit"
channel_id: HexBytes
amount: int
metadata: HexBytes
class ChannelInscribe(NbeContent):
type: Literal["ChannelInscribe"] = "ChannelInscribe"
channel_id: HexBytes
@ -77,4 +85,6 @@ class LeaderClaim(NbeContent):
mantle_tx_hash: HexBytes
OperationContent = ChannelInscribe | ChannelBlob | ChannelSetKeys | SDPDeclare | SDPWithdraw | SDPActive | LeaderClaim
OperationContent = (
ChannelInscribe | ChannelBlob | ChannelSetKeys | SDPDeclare | SDPWithdraw | SDPActive | LeaderClaim | ChannelDeposit
)

View File

@ -8,6 +8,7 @@ from pydantic import BeforeValidator, Field
from core.models import NbeSerializer
from models.transactions.operations.contents import (
ChannelBlob,
ChannelDeposit,
ChannelInscribe,
ChannelSetKeys,
LeaderClaim,
@ -221,6 +222,31 @@ class LeaderClaimSerializer(OperationContentSerializer):
)
class ChannelDepositSerializer(OperationContentSerializer):
channel_id: BytesFromHex = Field(description="Channel ID in hex format.")
amount: int
metadata: BytesFromHex = Field(description="Metadata in hex format.")
def into_operation_content(self) -> ChannelDeposit:
return ChannelDeposit.model_validate(
{
"channel_id": self.channel_id,
"amount": self.amount,
"metadata": self.metadata,
}
)
@classmethod
def from_random(cls) -> Self:
return cls.model_validate(
{
"channel_id": random_bytes(32).hex(),
"amount": randint(1, 1_000_000),
"metadata": random_bytes(32).hex(),
}
)
OPCODE_TO_SERIALIZER: dict[int, type[OperationContentSerializer]] = {
0: ChannelInscribeSerializer,
1: ChannelBlobSerializer,
@ -229,6 +255,7 @@ OPCODE_TO_SERIALIZER: dict[int, type[OperationContentSerializer]] = {
4: SDPWithdrawSerializer,
5: SDPActiveSerializer,
6: LeaderClaimSerializer,
7: ChannelDepositSerializer,
}
@ -253,6 +280,7 @@ type OperationContentSerializerVariants = Union[
SDPWithdrawSerializer,
SDPActiveSerializer,
LeaderClaimSerializer,
ChannelDepositSerializer,
]
OperationContentSerializerField = Annotated[
OperationContentSerializerVariants,

View File

@ -70,6 +70,12 @@ function opPreview(op) {
return `${type}(${chanShort}\u2026, ${nKeys} keys)`;
}
if (type === 'DepositOp' && content) {
const chanShort = typeof content.channel_id === 'string' ? content.channel_id.slice(0, 8) : '?';
const amount = content.amount != null ? content.amount : '?';
return `${type}(${chanShort}\u2026, ${amount})`;
}
return type;
}