Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
prev_hash = None
prev_issuer = None
if number > 0:
prev_hash = str(Block.parse_field("PreviousHash", lines[n]))
n += 1
prev_issuer = str(Block.parse_field("PreviousIssuer", lines[n]))
n += 1
parameters = None
if number == 0:
try:
params_match = Block.re_parameters.match(lines[n])
if params_match is None:
raise MalformedDocumentError("Parameters")
parameters = params_match.groups()
n += 1
except AttributeError:
raise MalformedDocumentError("Parameters")
members_count = int(Block.parse_field("MembersCount", lines[n]))
n += 1
identities = []
joiners = []
actives = []
leavers = []
revoked = []
excluded = []
certifications = []
transactions = []
def raw(self) -> str:
"""
Return Revocation raw document string
:return:
"""
if not isinstance(self.identity, Identity):
raise MalformedDocumentError(
"Can not return full revocation document created from inline"
)
return """Version: {version}
Type: Revocation
Currency: {currency}
Issuer: {pubkey}
IdtyUniqueID: {uid}
IdtyTimestamp: {timestamp}
IdtySignature: {signature}
""".format(
version=self.version,
currency=self.currency,
pubkey=self.identity.pubkey,
uid=self.identity.uid,
timestamp=self.identity.timestamp,
def from_str(cls: Type[BlockUIDType], blockid: str) -> BlockUIDType:
"""
:param blockid: The block id
"""
data = BlockUID.re_block_uid.match(blockid)
if data is None:
raise MalformedDocumentError("BlockUID")
try:
number = int(data.group(1))
except AttributeError:
raise MalformedDocumentError("BlockUID")
try:
sha_hash = data.group(2)
except AttributeError:
raise MalformedDocumentError("BlockHash")
return cls(number, sha_hash)
v1.signature,
v1.api,
v1.head,
v1.pubkey,
v1.blockstamp,
v1.ws2pid,
v1.software,
v1.software_version,
v1.pow_prefix,
free_member_room,
free_mirror_room,
),
"",
)
except AttributeError:
raise MalformedDocumentError("HeadV2")
) -> RevocationType:
"""
Return Revocation document instance from inline string
Only self.pubkey is populated.
You must populate self.identity with an Identity instance to use raw/sign/signed_raw methods
:param version: Version number
:param currency: Name of the currency
:param inline: Inline document
:return:
"""
cert_data = Revocation.re_inline.match(inline)
if cert_data is None:
raise MalformedDocumentError("Revokation")
pubkey = cert_data.group(1)
signature = cert_data.group(2)
return cls(version, currency, pubkey, signature)
:param certifications: certifications documents
:param transactions: transactions documents
:param inner_hash: the block hash
:param nonce: the nonce value of the block
:param signature: the block signature
"""
super().__init__(version, currency, [signature])
documents_versions = max(
max([1] + [i.version for i in identities]),
max([1] + [m.version for m in actives + leavers + joiners]),
max([1] + [r.version for r in revokations]),
max([1] + [c.version for c in certifications]),
max([1] + [t.version for t in transactions]),
)
if self.version < documents_versions:
raise MalformedDocumentError(
"Block version is too low : {0} < {1}".format(
self.version, documents_versions
)
)
self.number = number
self.powmin = powmin
self.time = time
self.mediantime = mediantime
self.ud = ud
self.unit_base = unit_base
self.issuer = issuer
self.issuers_frame = issuers_frame
self.issuers_frame_var = issuers_frame_var
self.different_issuers_count = different_issuers_count
self.prev_hash = prev_hash
self.prev_issuer = prev_issuer
def from_inline(cls, inline: str):
data = API.re_inline.match(inline)
if data is None:
raise MalformedDocumentError("WS2P API Document")
private = "" if data.group(1) is None else data.group(1)
public = "" if data.group(2) is None else data.group(2)
return cls(private, public)
unlocks.append(unlock)
n += unlocks_num
for index in range(0, outputs_num):
output_source = OutputSource.from_inline(lines[n + index])
outputs.append(output_source)
n += outputs_num
comment = ""
if has_comment == 1:
data = Transaction.re_compact_comment.match(lines[n])
if data:
comment = data.group(1)
n += 1
else:
raise MalformedDocumentError("Compact TX Comment")
while n < len(lines):
data = Transaction.re_signature.match(lines[n])
if data:
signatures.append(data.group(1))
n += 1
else:
raise MalformedDocumentError("Compact TX Signatures")
return cls(
version,
currency,
blockstamp,
locktime,
issuers,
inputs,
def from_inline(cls, inline: str, signature: str):
try:
data = HeadV0.re_inline.match(inline)
if data is None:
raise MalformedDocumentError("HeadV0")
api = API.from_inline(data.group(1))
head = Head.from_inline(data.group(2), "")
pubkey = data.group(3)
blockstamp = BlockUID.from_str(data.group(4))
offload = data.group(5)
return cls(head.version, signature, api, head, pubkey, blockstamp), offload
except AttributeError:
raise MalformedDocumentError("HeadV0")
currency: str,
membership_type: str,
inline: str,
) -> MembershipType:
"""
Return Membership instance from inline format
:param version: Version of the document
:param currency: Name of the currency
:param membership_type: "IN" or "OUT" to enter or exit membership
:param inline: Inline string format
:return:
"""
data = Membership.re_inline.match(inline)
if data is None:
raise MalformedDocumentError("Inline membership ({0})".format(inline))
issuer = data.group(1)
signature = data.group(2)
membership_ts = BlockUID.from_str(data.group(3))
identity_ts = BlockUID.from_str(data.group(4))
uid = data.group(5)
return cls(
version,
currency,
issuer,
membership_ts,
membership_type,
uid,
identity_ts,
signature,
)