Commit fc30ac27 authored by Moul's avatar Moul

[enh] Transaction: add 'time' variable for read and write but not for doc generation

parent 8ea505a1
...@@ -448,7 +448,7 @@ class Transaction(Document): ...@@ -448,7 +448,7 @@ class Transaction(Document):
def __init__(self, version: int, currency: str, blockstamp: Optional[BlockUID], locktime: int, issuers: List[str], def __init__(self, version: int, currency: str, blockstamp: Optional[BlockUID], locktime: int, issuers: List[str],
inputs: List[InputSource], unlocks: List[Unlock], outputs: List[OutputSource], inputs: List[InputSource], unlocks: List[Unlock], outputs: List[OutputSource],
comment: str, signatures: List[str]) -> None: comment: str, time: int, signatures: List[str]) -> None:
""" """
Init Transaction instance Init Transaction instance
...@@ -461,6 +461,7 @@ class Transaction(Document): ...@@ -461,6 +461,7 @@ class Transaction(Document):
:param unlocks: List of Unlock instances :param unlocks: List of Unlock instances
:param outputs: List of OutputSource instances :param outputs: List of OutputSource instances
:param comment: Comment field :param comment: Comment field
:param time: time when the transaction enters the blockchain
:param signatures: List of signatures :param signatures: List of signatures
""" """
super().__init__(version, currency, signatures) super().__init__(version, currency, signatures)
...@@ -471,6 +472,8 @@ class Transaction(Document): ...@@ -471,6 +472,8 @@ class Transaction(Document):
self.unlocks = unlocks self.unlocks = unlocks
self.outputs = outputs self.outputs = outputs
self.comment = comment self.comment = comment
self.time = time
@classmethod @classmethod
def from_bma_history(cls: Type[TransactionType], currency: str, tx_data: Dict) -> TransactionType: def from_bma_history(cls: Type[TransactionType], currency: str, tx_data: Dict) -> TransactionType:
...@@ -501,7 +504,7 @@ Outputs: ...@@ -501,7 +504,7 @@ Outputs:
{multiline_outputs} {multiline_outputs}
Comment: {comment} Comment: {comment}
{multiline_signatures} {multiline_signatures}
""".format(**tx_data)) """.format(**tx_data), tx_data["time"])
@classmethod @classmethod
def from_compact(cls: Type[TransactionType], currency: str, compact: str) -> TransactionType: def from_compact(cls: Type[TransactionType], currency: str, compact: str) -> TransactionType:
...@@ -572,10 +575,10 @@ Comment: {comment} ...@@ -572,10 +575,10 @@ Comment: {comment}
else: else:
raise MalformedDocumentError("Compact TX Signatures") raise MalformedDocumentError("Compact TX Signatures")
return cls(version, currency, blockstamp, locktime, issuers, inputs, unlocks, outputs, comment, signatures) return cls(version, currency, blockstamp, locktime, issuers, inputs, unlocks, outputs, comment, 0, signatures)
@classmethod @classmethod
def from_signed_raw(cls: Type[TransactionType], raw: str) -> TransactionType: def from_signed_raw(cls: Type[TransactionType], raw: str, time: int = 0) -> TransactionType:
""" """
Return a Transaction instance from a raw string format Return a Transaction instance from a raw string format
...@@ -645,7 +648,7 @@ Comment: {comment} ...@@ -645,7 +648,7 @@ Comment: {comment}
n += 1 n += 1
return cls(version, currency, blockstamp, locktime, issuers, inputs, unlocks, outputs, return cls(version, currency, blockstamp, locktime, issuers, inputs, unlocks, outputs,
comment, signatures) comment, time, signatures)
def raw(self) -> str: def raw(self) -> str:
""" """
...@@ -732,7 +735,7 @@ class SimpleTransaction(Transaction): ...@@ -732,7 +735,7 @@ class SimpleTransaction(Transaction):
def __init__(self, version: int, currency: str, blockstamp: BlockUID, locktime: int, issuer: str, def __init__(self, version: int, currency: str, blockstamp: BlockUID, locktime: int, issuer: str,
single_input: InputSource, unlocks: List[Unlock], outputs: List[OutputSource], comment: str, single_input: InputSource, unlocks: List[Unlock], outputs: List[OutputSource], comment: str,
signature: str) -> None: time: int, signature: str) -> None:
""" """
Init instance Init instance
...@@ -745,10 +748,11 @@ class SimpleTransaction(Transaction): ...@@ -745,10 +748,11 @@ class SimpleTransaction(Transaction):
:param unlocks: List of Unlock instances :param unlocks: List of Unlock instances
:param outputs: List of OutputSource instances :param outputs: List of OutputSource instances
:param comment: Comment field :param comment: Comment field
:param time: time when the transaction enters the blockchain
:param signature: Signature :param signature: Signature
""" """
super().__init__(version, currency, blockstamp, locktime, [issuer], [single_input], unlocks, super().__init__(version, currency, blockstamp, locktime, [issuer], [single_input], unlocks,
outputs, comment, [signature]) outputs, comment, time ,[signature])
@staticmethod @staticmethod
def is_simple(tx: Transaction) -> bool: def is_simple(tx: Transaction) -> bool:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment