mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-11-10 12:29:49 +03:00
Added some new class methods to the Program objects (#8041)
This commit is contained in:
parent
7b2aab99c8
commit
950e78e1f2
@ -12,6 +12,7 @@ from clvm_tools.curry import curry, uncurry
|
||||
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.util.hash import std_hash
|
||||
from chia.util.byte_types import hexstr_to_bytes
|
||||
|
||||
from .tree_hash import sha256_treehash
|
||||
|
||||
@ -54,9 +55,17 @@ class Program(SExp):
|
||||
assert f.read() == b""
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def fromhex(cls, hexstr: str) -> "Program":
|
||||
return cls.from_bytes(hexstr_to_bytes(hexstr))
|
||||
|
||||
def to_serialized_program(self) -> "SerializedProgram":
|
||||
return SerializedProgram.from_bytes(bytes(self))
|
||||
|
||||
@classmethod
|
||||
def from_serialized_program(cls, sp: "SerializedProgram") -> "Program":
|
||||
return cls.from_bytes(bytes(sp))
|
||||
|
||||
def __bytes__(self) -> bytes:
|
||||
f = io.BytesIO()
|
||||
self.stream(f) # type: ignore # noqa
|
||||
@ -166,6 +175,10 @@ class SerializedProgram:
|
||||
ret._buf = bytes(blob)
|
||||
return ret
|
||||
|
||||
@classmethod
|
||||
def fromhex(cls, hexstr: str) -> "SerializedProgram":
|
||||
return cls.from_bytes(hexstr_to_bytes(hexstr))
|
||||
|
||||
@classmethod
|
||||
def from_program(cls, p: Program) -> "SerializedProgram":
|
||||
ret = SerializedProgram()
|
||||
|
Loading…
Reference in New Issue
Block a user