duniterpy.documents package
Subpackages
Submodules
duniterpy.documents.block module
- class duniterpy.documents.block.Block(number: int, powmin: int, time: int, mediantime: int, ud: int | None, unit_base: int, issuer: str, issuers_frame: int, issuers_frame_var: int, different_issuers_count: int, prev_hash: str | None, prev_issuer: str | None, parameters: Sequence[str] | None, members_count: int, identities: List[Identity], joiners: List[Membership], actives: List[Membership], leavers: List[Membership], revokations: List[Revocation], excluded: List[str], certifications: List[Certification], transactions: List[Transaction], inner_hash: str, nonce: int, signing_key: SigningKey | None = None, version: int = 12, currency: str = 'g1')
Bases:
Document
The class Block handles Block documents.
Note
A block document is specified by the following format :
Version: VERSIONType: BlockCurrency: CURRENCYNonce: NONCENumber: BLOCK_NUMBERPoWMin: NUMBER_OF_ZEROSTime: GENERATED_ONMedianTime: MEDIAN_DATEUniversalDividend: DIVIDEND_AMOUNTIssuer: ISSUER_KEYPreviousHash: PREVIOUS_HASHPreviousIssuer: PREVIOUS_ISSUER_KEYParameters: PARAMETERSMembersCount: WOT_MEM_COUNTIdentities:PUBLIC_KEY:SIGNATURE:TIMESTAMP:USER_ID…Joiners:PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID…Actives:PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID…Leavers:PUBLIC_KEY:SIGNATURE:NUMBER:HASH:TIMESTAMP:USER_ID…Excluded:PUBLIC_KEY…Certifications:PUBKEY_FROM:PUBKEY_TO:BLOCK_NUMBER:SIGNATURE…Transactions:COMPACT_TRANSACTION…BOTTOM_SIGNATURE- check_signature(pubkey: str)
Check if the signature is from pubkey
- Parameters:
pubkey – Base58 public key
- Returns:
- computed_inner_hash() str
Return inner hash of the Block
- Returns:
- fields_parsers: Dict[str, Pattern] = {'Actives': re.compile('Actives:\n'), 'Certifications': re.compile('Certifications:\n'), 'Currency': re.compile('Currency: ([^\n]+)\n'), 'DifferentIssuersCount': re.compile('DifferentIssuersCount: ([0-9]+)\n'), 'Excluded': re.compile('Excluded:\n'), 'Identities': re.compile('Identities:\n'), 'InnerHash': re.compile('InnerHash: ([0-9a-fA-F]{5,64})\n'), 'Issuer': re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'IssuersFrame': re.compile('IssuersFrame: ([0-9]+)\n'), 'IssuersFrameVar': re.compile('IssuersFrameVar: (0|-?[1-9]\\d{0,18})\n'), 'Joiners': re.compile('Joiners:\n'), 'Leavers': re.compile('Leavers:\n'), 'MedianTime': re.compile('MedianTime: ([0-9]+)\n'), 'MembersCount': re.compile('MembersCount: ([0-9]+)\n'), 'Nonce': re.compile('Nonce: ([0-9]+)\n'), 'Number': re.compile('Number: ([0-9]+)\n'), 'Parameters': re.compile('Parameters: ([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):([0-9]+), 'PoWMin': re.compile('PoWMin: ([0-9]+)\n'), 'PreviousHash': re.compile('PreviousHash: ([0-9a-fA-F]{5,64})\n'), 'PreviousIssuer': re.compile('PreviousIssuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Revoked': re.compile('Revoked:\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Time': re.compile('Time: ([0-9]+)\n'), 'Transactions': re.compile('Transactions:\n'), 'Type': re.compile('Type: (Block)\n'), 'UD': re.compile('UniversalDividend: ([0-9]+)\n'), 'UnitBase': re.compile('UnitBase: ([0-9]+)\n'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_parsed_json(parsed_json_block: dict) BlockType
Return a Block instance from the python dict produced when parsing json
- Parameters:
parsed_json_block – Block as a Python dict
- Returns:
- classmethod from_signed_raw(signed_raw: str) BlockType
Create Block instance from signed raw format string
- Parameters:
signed_raw – Signed raw format string
- Returns:
- proof_of_work() str
Return Proof of Work hash for the Block
- Returns:
- raw() str
Return Block in raw format
- Returns:
- re_actives = re.compile('Actives:\n')
- re_certifications = re.compile('Certifications:\n')
- re_different_issuers_count = re.compile('DifferentIssuersCount: ([0-9]+)\n')
- re_excluded = re.compile('Excluded:\n')
- re_exclusion = re.compile('((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_hash = re.compile('InnerHash: ([0-9a-fA-F]{5,64})\n')
- re_identities = re.compile('Identities:\n')
- re_issuer = re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_issuers_frame = re.compile('IssuersFrame: ([0-9]+)\n')
- re_issuers_frame_var = re.compile('IssuersFrameVar: (0|-?[1-9]\\d{0,18})\n')
- re_joiners = re.compile('Joiners:\n')
- re_leavers = re.compile('Leavers:\n')
- re_mediantime = re.compile('MedianTime: ([0-9]+)\n')
- re_memberscount = re.compile('MembersCount: ([0-9]+)\n')
- re_nonce = re.compile('Nonce: ([0-9]+)\n')
- re_number = re.compile('Number: ([0-9]+)\n')
- re_parameters = re.compile('Parameters: ([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+\\.[0-9]+):([0-9]+)
- re_powmin = re.compile('PoWMin: ([0-9]+)\n')
- re_previoushash = re.compile('PreviousHash: ([0-9a-fA-F]{5,64})\n')
- re_previousissuer = re.compile('PreviousIssuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_revoked = re.compile('Revoked:\n')
- re_time = re.compile('Time: ([0-9]+)\n')
- re_transactions = re.compile('Transactions:\n')
- re_type = re.compile('Type: (Block)\n')
- re_unitbase = re.compile('UnitBase: ([0-9]+)\n')
- re_universaldividend = re.compile('UniversalDividend: ([0-9]+)\n')
- sign(key: SigningKey) None
Sign the current document with key
- Parameters:
key – Libnacl SigningKey instance
- Returns:
- exception duniterpy.documents.block.SignatureException
Bases:
Exception
duniterpy.documents.block_id module
- class duniterpy.documents.block_id.BlockID(number: int, sha_hash: str)
Bases:
object
A simple block id
- classmethod empty() BlockIDType
- classmethod from_str(blockid: str) BlockIDType
- Parameters:
blockid – The block id
- re_block_id = re.compile('([0-9]+)-([0-9a-fA-F]{5,64})')
- re_hash = re.compile('([0-9a-fA-F]{5,64})')
duniterpy.documents.certification module
- class duniterpy.documents.certification.Certification(pubkey_from: str, identity: Identity | str, block_id: BlockID, signing_key: SigningKey | None = None, version: int = 10, currency: str = 'g1')
Bases:
Document
A document describing a certification.
- fields_parsers: Dict[str, Pattern] = {'CertTimestamp': re.compile('CertTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Currency': re.compile('Currency: ([^\n]+)\n'), 'Issuer': re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Type': re.compile('Type: (Certification)'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_inline(block_hash: str | None, inline: str, version: int = 10, currency: str = 'g1') CertificationType
Return Certification instance from inline document
Only self.pubkey_to is populated. You must populate self.identity with an Identity instance to use raw/sign/signed_raw methods
- Parameters:
block_hash – Hash of the block
inline – Inline document
version – Document version (default=certification.VERSION)
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
- Returns:
- classmethod from_signed_raw(signed_raw: str) CertificationType
Return Certification instance from signed raw document
- Parameters:
signed_raw – Signed raw document
- Returns:
- inline() str
Return inline document string
- Returns:
- raw() str
Return a raw document of the certification
- re_cert_block_id = re.compile('CertTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_inline = re.compile('((?![OIl])[1-9A-Za-z]{42,45}):((?![OIl])[1-9A-Za-z]{42,45}):([0-9]+):([A-Za-z0-9+/]+(?:=|==)?)\n')
- re_issuer = re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_type = re.compile('Type: (Certification)')
- sign(key: SigningKey) None
Sign the current document with the key for the certified Identity given
- Parameters:
key – Libnacl key instance
- signed_raw() str
Return signed raw document of the certification for the certified Identity instance
- Returns:
duniterpy.documents.document module
- class duniterpy.documents.document.Document(version: int, currency: str)
Bases:
object
- check_signature(pubkey: str) bool
Check if the signature is from pubkey
- Parameters:
pubkey – Base58 public key
- Returns:
- fields_parsers: Dict[str, Pattern] = {'Currency': re.compile('Currency: ([^\n]+)\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod parse_field(field_name: str, line: str) Any
Parse a document field with regular expression and return the value
- Parameters:
field_name – Name of the field
line – Line string to parse
- Returns:
- raw() str
Returns the raw document in string format
- re_currency = re.compile('Currency: ([^\n]+)\n')
- re_signature = re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n')
- re_version = re.compile('Version: ([0-9]+)\n')
- property sha_hash: str
Return uppercase hex sha256 hash from signed raw document
- Returns:
- sign(key: SigningKey) None
Sign the current document with key
- Parameters:
key – Libnacl key instance
- signed_raw() str
- Returns:
- exception duniterpy.documents.document.MalformedDocumentError(field_name: str)
Bases:
Exception
Malformed document exception
- exception duniterpy.documents.document.SignatureException
Bases:
Exception
duniterpy.documents.identity module
- class duniterpy.documents.identity.Identity(pubkey: str, uid: str, block_id: BlockID, signing_key: SigningKey | None = None, version: int = 10, currency: str = 'g1')
Bases:
Document
A document describing a self certification.
- fields_parsers: Dict[str, Pattern] = {'Currency': re.compile('Currency: ([^\n]+)\n'), 'IdtyIssuer': re.compile('IdtyIssuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'IdtySignature': re.compile('IdtySignature: ([A-Za-z0-9+/]+(?:=|==)?)\n'), 'IdtyTimestamp': re.compile('IdtyTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'IdtyUniqueID': re.compile('IdtyUniqueID: ([A-Za-z0-9_-]{2,100})\n'), 'Issuer': re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Timestamp': re.compile('Timestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Type': re.compile('Type: (Identity)'), 'UniqueID': re.compile('UniqueID: ([A-Za-z0-9_-]{2,100})\n'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_bma_lookup_response(currency: str, pubkey: str, lookup_response: dict, version: int = 10) IdentityType
Return Identity instance from bma.lookup request response
- Parameters:
currency – Currency codename
pubkey – Requested identity pubkey
lookup_response – Lookup request response
version – Document version (default=identity.VERSION)
- Returns:
- classmethod from_certification_raw(certification_raw: str) IdentityType
Return Identity instance from certification_raw
- Parameters:
certification_raw – Certification raw format
- Returns:
- classmethod from_inline(inline: str, version: int = 10, currency: str = 'g1') IdentityType
Return Identity instance from inline Identity string
- Parameters:
inline – Inline string of the Identity
version – Document version (default=certification.VERSION)
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
- Returns:
- classmethod from_revocation_raw(revocation_raw: str) IdentityType
Return Identity instance from revocation_raw
- Parameters:
revocation_raw – Revocation raw format
- Returns:
- classmethod from_signed_raw(signed_raw: str) IdentityType
Return Identity instance from a signed_raw string
- Parameters:
signed_raw – Signed raw document
- Returns:
- inline() str
Return an inline string of the Identity
- Returns:
- raw() str
Return a raw document of the Identity
- Returns:
- re_block_id = re.compile('Timestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_idty_block_id = re.compile('IdtyTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_idty_issuer = re.compile('IdtyIssuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_idty_signature = re.compile('IdtySignature: ([A-Za-z0-9+/]+(?:=|==)?)\n')
- re_idty_unique_id = re.compile('IdtyUniqueID: ([A-Za-z0-9_-]{2,100})\n')
- re_inline = re.compile('((?![OIl])[1-9A-Za-z]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):([0-9]+-[0-9a-fA-F]{5,64}):([^\n]+)\n')
- re_issuer = re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_meta_ts = re.compile('META:TS:([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_type = re.compile('Type: (Identity)')
- re_uid = re.compile('UID:([^\n]+)\n')
- re_unique_id = re.compile('UniqueID: ([A-Za-z0-9_-]{2,100})\n')
- exception duniterpy.documents.identity.IdentityException
Bases:
Exception
duniterpy.documents.membership module
- class duniterpy.documents.membership.Membership(issuer: str, membership_block_id: BlockID, uid: str, identity_block_id: BlockID, signing_key: SigningKey | None = None, version: int = 10, currency: str = 'g1', membership_type: str = 'IN')
Bases:
Document
Note
A membership document is specified by the following format :
Version: VERSIONType: MembershipCurrency: CURRENCY_NAMEIssuer: ISSUERBlock: NUMBER-HASHMembership: MEMBERSHIP_TYPEUserID: USER_IDCertTS: CERTIFICATION_TS- fields_parsers: Dict[str, Pattern] = {'Block': re.compile('Block: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'CertTS': re.compile('CertTS: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Currency': re.compile('Currency: ([^\n]+)\n'), 'Issuer': re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Membership': re.compile('Membership: (IN|OUT)'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Type': re.compile('Type: (Membership)'), 'UserID': re.compile('UserID: ([^\n]+)\n'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_inline(inline: str, version: int = 10, currency: str = 'g1', membership_type: str = 'IN') MembershipType
Return Membership instance from inline format
- Parameters:
inline – Inline string format
version – Document version (default=membership.VERSION)
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
membership_type – “IN” or “OUT” to enter or exit membership. Default “IN”
- Returns:
- classmethod from_signed_raw(signed_raw: str) MembershipType
Return Membership instance from signed raw format
- Parameters:
signed_raw – Signed raw format string
- Returns:
- inline() str
Return inline string format of the Membership instance :return:
- raw() str
Return signed raw format string of the Membership instance
- Returns:
- re_block = re.compile('Block: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_certts = re.compile('CertTS: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_inline = re.compile('((?![OIl])[1-9A-Za-z]{42,45}):([A-Za-z0-9+/]+(?:=|==)?):([0-9]+-[0-9a-fA-F]{5,64}):([0-9]+-[0-9a-fA-F]{5,64}):([^\n]+)\n')
- re_issuer = re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_membership_type = re.compile('Membership: (IN|OUT)')
- re_type = re.compile('Type: (Membership)')
- re_userid = re.compile('UserID: ([^\n]+)\n')
duniterpy.documents.peer module
- class duniterpy.documents.peer.Peer(pubkey: str, block_id: BlockID, endpoints: List[Endpoint], signing_key: SigningKey | None = None, version: int = 10, currency: str = 'g1')
Bases:
Document
Note
A peer document is specified by the following format :
Version: VERSIONType: PeerCurrency: CURRENCY_NAMEPublicKey: NODE_PUBLICKEYBlock: BLOCKEndpoints:END_POINT_1END_POINT_2END_POINT_3[…]- fields_parsers: Dict[str, Pattern] = {'Block': re.compile('Block: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Currency': re.compile('Currency: ([^\n]+)\n'), 'Endpoints': re.compile('(Endpoints:)\n'), 'Pubkey': re.compile('PublicKey: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Type': re.compile('Type: (Peer)'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_bma(data: dict) PeerType
- classmethod from_signed_raw(raw: str) PeerType
Return a Peer instance from a signed raw format string
- Parameters:
raw – Signed raw format string
- Returns:
- raw() str
Return a raw format string of the Peer document
- Returns:
- re_block = re.compile('Block: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_endpoints = re.compile('(Endpoints:)\n')
- re_pubkey = re.compile('PublicKey: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_type = re.compile('Type: (Peer)')
duniterpy.documents.revocation module
- class duniterpy.documents.revocation.Revocation(identity: Identity | str, signing_key: SigningKey | None = None, version: int = 10, currency: str = 'g1')
Bases:
Document
A document describing a self-revocation.
- static extract_self_cert(signed_raw: str) Identity
Return self-certified Identity instance from the signed raw Revocation document
- Parameters:
signed_raw – Signed raw revocation document string
- Returns:
- fields_parsers: Dict[str, Pattern] = {'Currency': re.compile('Currency: ([^\n]+)\n'), 'IdtySignature': re.compile('IdtySignature: ([A-Za-z0-9+/]+(?:=|==)?)\n'), 'IdtyTimestamp': re.compile('IdtyTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'IdtyUniqueID': re.compile('IdtyUniqueID: ([^\n]+)\n'), 'Issuer': re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'Type': re.compile('Type: (Revocation)'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_inline(inline: str, version: int = 10, currency: str = 'g1') 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
- Parameters:
inline – Inline document
version – Document version (default=revocation.VERSION)
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
- Returns:
- classmethod from_signed_raw(signed_raw: str) RevocationType
Return Revocation document instance from a signed raw string
- Parameters:
signed_raw – raw document file in duniter format
- Returns:
- inline() str
Return inline document string
- Returns:
- raw() str
Return Revocation raw document string
- Returns:
- re_block_id = re.compile('IdtyTimestamp: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_idtysignature = re.compile('IdtySignature: ([A-Za-z0-9+/]+(?:=|==)?)\n')
- re_inline = re.compile('((?![OIl])[1-9A-Za-z]{42,45}):([A-Za-z0-9+/]+(?:=|==)?)\n')
- re_issuer = re.compile('Issuer: ((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_type = re.compile('Type: (Revocation)')
- re_uniqueid = re.compile('IdtyUniqueID: ([^\n]+)\n')
- sign(key: SigningKey) None
Sign the current document
- Parameters:
key – Libnacl key instance
- Returns:
- signed_raw() str
Return Revocation signed raw document string
- Returns:
duniterpy.documents.transaction module
- class duniterpy.documents.transaction.InputSource(amount: int, base: int, source: str, origin_id: str, index: int)
Bases:
object
A Transaction INPUT
Note
Compact : INDEX:SOURCE:FINGERPRINT:AMOUNT
- classmethod from_inline(inline: str) InputSourceType
Return Transaction instance from inline string format
- Parameters:
inline – Inline string format
- Returns:
- inline() str
Return an inline string format of the document
- Returns:
- re_inline = re.compile('([0-9]+):([0-9]):(?:(?:(D):((?![OIl])[1-9A-Za-z]{42,45}):([0-9]+))|(?:(T):([0-9a-fA-F]{5,64}):([0-9]+)))')
- class duniterpy.documents.transaction.OutputSource(amount: int, base: int, condition: str)
Bases:
object
A Transaction OUTPUT
- static condition_from_text(text) Condition
Return a Condition instance with PEG grammar from text
- Parameters:
text – PEG parsable string
- Returns:
- classmethod from_inline(inline: str) OutputSourceType
Return OutputSource instance from inline string format
- Parameters:
inline – Inline string format
- Returns:
- inline() str
Return an inline string format of the output source
- Returns:
- inline_condition() str
Return an inline string format of the output source’s condition
- Returns:
- re_inline = re.compile('([0-9]+):([0-9]):(.*)')
- class duniterpy.documents.transaction.SIGParameter(index: int)
Bases:
object
A Transaction UNLOCK SIG parameter
- classmethod from_parameter(parameter: str) SIGParameterType | None
Return a SIGParameter instance from an index parameter
- Parameters:
parameter – Index parameter
- Returns:
- re_sig = re.compile('SIG\\(([0-9]+)\\)')
- exception duniterpy.documents.transaction.SignatureException
Bases:
Exception
- class duniterpy.documents.transaction.SimpleTransaction(block_id: BlockID, locktime: int, issuer: str, single_input: InputSource, unlocks: List[Unlock], outputs: List[OutputSource], comment: str, time: int = 0, signing_keys: SigningKey | List[SigningKey] | None = None, version: int = 10, currency: str = 'g1')
Bases:
Transaction
As transaction class, but for only one issuer. …
- static is_simple(tx: Transaction) bool
Filter a transaction and checks if it is a basic one A simple transaction is a tx which has only one issuer and two outputs maximum. The unlocks must be done with simple “SIG” functions, and the outputs must be simple SIG conditions.
- Parameters:
tx – the transaction to check
- Returns:
True if a simple transaction
- class duniterpy.documents.transaction.Transaction(block_id: BlockID | None, locktime: int, issuers: List[str], inputs: List[InputSource], unlocks: List[Unlock], outputs: List[OutputSource], comment: str, time: int | None = None, signing_keys: SigningKey | List[SigningKey] | None = None, version: int = 10, currency: str = 'g1')
Bases:
Document
Note
A transaction document is specified by the following format :
Document format :Version: VERSIONType: TransactionCurrency: CURRENCY_NAMEIssuers:PUBLIC_KEY…Inputs:INDEX:SOURCE:NUMBER:FINGERPRINT:AMOUNT…Outputs:PUBLIC_KEY:AMOUNT…Comment: COMMENT…Compact format :TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_OUTPUTS:HAS_COMMENTPUBLIC_KEY:INDEX…INDEX:SOURCE:FINGERPRINT:AMOUNT…PUBLIC_KEY:AMOUNT…COMMENTSIGNATURE…- check_signature(pubkey: str) bool
Check if document is signed by pubkey
- Parameters:
pubkey – Base58 pubkey
- Returns:
- check_signatures(pubkeys: str | List[str]) bool
Check if the signatures matches a public key or a list of public keys
- Parameters:
pubkeys – Base58 public key or list of them
- Returns:
- compact() str
Return a transaction in its compact format from the instance
- Returns:
TX:VERSION:NB_ISSUERS:NB_INPUTS:NB_UNLOCKS:NB_OUTPUTS:HAS_COMMENT:LOCKTIME PUBLIC_KEY:INDEX … INDEX:SOURCE:FINGERPRINT:AMOUNT … PUBLIC_KEY:AMOUNT … COMMENT
- fields_parsers: Dict[str, Pattern] = {'Blockstamp': re.compile('Blockstamp: ([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Comment': re.compile('Comment: ([^\n]*)\n'), 'Compact comment': re.compile('([^\n]+)\n'), 'CompactBlockstamp': re.compile('([0-9]+-[0-9a-fA-F]{5,64})\n'), 'Currency': re.compile('Currency: ([^\n]+)\n'), 'Inputs': re.compile('Inputs:\n'), 'Issuers': re.compile('Issuers:\n'), 'Locktime': re.compile('Locktime: ([0-9]+)\n'), 'Outputs': re.compile('Outputs:\n'), 'Pubkey': re.compile('((?![OIl])[1-9A-Za-z]{42,45})\n'), 'Signature': re.compile('([A-Za-z0-9+/]+(?:=|==)?)\n'), 'TX': re.compile('TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([01]):([0-9]+)\n'), 'Type': re.compile('Type: (Transaction)\n'), 'Unlocks': re.compile('Unlocks:\n'), 'Version': re.compile('Version: ([0-9]+)\n')}
- classmethod from_bma_history(tx_data: Dict, currency: str = 'g1') TransactionType
Get the transaction instance from json
- Parameters:
tx_data – json data of the transaction
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
- Returns:
- classmethod from_compact(compact: str, currency: str = 'g1') TransactionType
Return Transaction instance from compact string format
- Parameters:
compact – Compact format string
currency – Currency codename (default=constants.CURRENCY_CODENAME_G1)
- Returns:
- classmethod from_signed_raw(raw: str, time: int = 0) TransactionType
Return a Transaction instance from a raw string format
- Parameters:
raw – Raw string format
time – time when the transaction enters the blockchain
- Returns:
- multi_sign(keys: SigningKey | List[SigningKey]) None
Add signature(s) to the document from one key or a list of multiple keys
- Parameters:
keys – Libnacl key or list of them
- raw() str
Return raw string format from the instance
- Returns:
- re_block_id = re.compile('Blockstamp: ([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_comment = re.compile('Comment: ([^\n]*)\n')
- re_compact_block_id = re.compile('([0-9]+-[0-9a-fA-F]{5,64})\n')
- re_compact_comment = re.compile('([^\n]+)\n')
- re_header = re.compile('TX:([0-9]+):([0-9]+):([0-9]+):([0-9]+):([0-9]+):([01]):([0-9]+)\n')
- re_inputs = re.compile('Inputs:\n')
- re_issuers = re.compile('Issuers:\n')
- re_locktime = re.compile('Locktime: ([0-9]+)\n')
- re_outputs = re.compile('Outputs:\n')
- re_pubkey = re.compile('((?![OIl])[1-9A-Za-z]{42,45})\n')
- re_type = re.compile('Type: (Transaction)\n')
- re_unlocks = re.compile('Unlocks:\n')
- sign(key: SigningKey) None
Add a signature to the document from key
- Parameters:
key – SigningKey instance
- Returns:
- signed_raw() str
Return signed raw format string
- Returns:
- class duniterpy.documents.transaction.Unlock(index: int, parameters: List[SIGParameter | XHXParameter])
Bases:
object
A Transaction UNLOCK
- classmethod from_inline(inline: str) UnlockType
Return an Unlock instance from inline string format
- Parameters:
inline – Inline string format
- Returns:
- inline() str
Return inline string format of the instance
- Returns:
- re_inline = re.compile('([0-9]+):((?:SIG\\([0-9]+\\)|XHX\\([0-9]+\\)|\\s)+)')
- class duniterpy.documents.transaction.UnlockParameter
Bases:
object
- compute()
- classmethod from_parameter(parameter: str) SIGParameter | XHXParameter | None
Return UnlockParameter instance from parameter string
- Parameters:
parameter – Parameter string
- Returns:
- class duniterpy.documents.transaction.XHXParameter(integer: int)
Bases:
object
A Transaction UNLOCK XHX parameter
- compute()
- classmethod from_parameter(parameter: str) XHXParameterType | None
Return a XHXParameter instance from an index parameter
- Parameters:
parameter – Index parameter
- Returns:
- re_xhx = re.compile('XHX\\(([0-9]+)\\)')
- duniterpy.documents.transaction.reduce_base(amount: int, base: int) Tuple[int, int]
Compute the reduced base of the given parameters
- Parameters:
amount – the amount value
base – current base value
- Returns:
tuple containing computed (amount, base)