Blockchain core¶
Transaction class¶
-
class
dposlib.blockchain.tx.
Transaction
(*args, **kwargs)[source]¶ A python
dict
that implements all the necessities to manually generate valid transactions.-
datetime
¶ Transaction timestamp returned as python datetime object
-
feeIncluded
¶ if True then
amount
+fee
= total arktoshi flow
-
finalize
(secret=None, secondSecret=None, fee=None, fee_included=False)[source]¶ Finalize a transaction by setting
fee
, signatures andid
.Parameters: - secret (
str
) – passphrase - secondSecret (
str
) – second passphrase - fee (
int
) – manually set fee value insatoshi
- fee_included (
bool
) – seeTransaction.feeIncluded
- secret (
-
link
(secret=None, secondSecret=None)[source]¶ Save public and private keys derived from secrets. This is equivalent to wallet login. it limits number of secret keyboard entries.
Parameters: - secret (
str
) – passphrase - secondSecret (
str
) – second passphrase
- secret (
-
multiSignWithKey
(privateKey)[source]¶ Add a signature in
signatures
field according to given index and privateKey.Parameters: privateKey ( str
) – private key as hex string
-
multiSignWithSecret
(secret)[source]¶ Add a signature in
signatures
field.Parameters: - index (
int
) – signature index - secret (
str
) – passphrase
- index (
-
recipient
¶ Receiver address checker and setter
-
recipientId
¶ Receiver address checker and setter
-
secondSignature
¶ Second signature
-
sender
¶ Sender address checker and setter
-
senderId
¶ Sender address checker and setter
-
senderPublicKey
¶ Initialize transaction according to senderPublicKey value
-
static
setDynamicFee
(value='minFee')¶ Activate and configure dynamic fees parameters. Value can be either an integer defining the fee multiplier constant or a string defining the fee level to use acccording to the 30-days-average. possible values are
avgFee
minFee
(default) andmaxFee
.Parameters: value ( str
orint
) – constant or fee multiplier
-
setFee
(value=None)[source]¶ Set
fee
field manually or according to inner parameters.Parameters: value ( int
) – fee value instatoshi
to set manually
-
signSign
()[source]¶ Generate the
signSignature
field. Transaction have to be signed and second private key have to be set first. Seelink()
.
-
signSignWithKey
(secondPrivateKey)[source]¶ Generate the
signSignature
field using second private key. It is stored tillunlink()
is called.Parameters: secondPrivateKey ( str
) – second private key as hex string
-
signSignWithSecondSecret
(secondSecret)[source]¶ Generate the
signSignature
field using second passphrase. The associated second public and private keys are stored tillunlink()
is called.Parameters: secondSecret ( str
) – second passphrase
-
signSignature
¶ Second signature
-
signWithKeys
(publicKey, privateKey)[source]¶ Generate the
signature
field using public and private keys. They are tillunlink()
is called.Parameters: - publicKey (
str
) – public key as hex string - privateKey (
str
) – private key as hex string
- publicKey (
-
signWithSecret
(secret)[source]¶ Generate the
signature
field using passphrase. The associated public and private keys are stored tillunlink()
is called.Parameters: secret ( str
) – passphrase
-
timestamp
¶ Transaction timestamp setter
-
static
useDynamicFee
(value='minFee')[source]¶ Activate and configure dynamic fees parameters. Value can be either an integer defining the fee multiplier constant or a string defining the fee level to use acccording to the 30-days-average. possible values are
avgFee
minFee
(default) andmaxFee
.Parameters: value ( str
orint
) – constant or fee multiplier
-
Crypto utils¶
-
dposlib.ark.crypto.
checkTransaction
(tx, secondPublicKey=None, multiPublicKeys=[])[source]¶ Verify transaction validity.
Parameters: - tx (
dict
orTransaction
) – transaction object - secondPublicKey (
str
) – second public key to use if needed - multiPublicKeys (
list
) – owners public keys (sorted according to associated type-4-tx asset)
Returns: true if transaction is valid
Return type: bool
- tx (
-
dposlib.ark.crypto.
getAddress
(publicKey, marker=None)[source]¶ Compute ARK address from publicKey.
Parameters: - publicKey (
str
) – public key - marker (
int
) – network marker (optional)
Returns: the address
Return type: str
- publicKey (
-
dposlib.ark.crypto.
getAddressFromSecret
(secret, marker=None)[source]¶ Compute ARK address from secret.
Parameters: - secret (
str
) – secret string - marker (
int
) – network marker (optional)
Returns: the address
Return type: str
- secret (
-
dposlib.ark.crypto.
getBytes
(tx, **options)[source]¶ Hash transaction.
Parameters: tx (
dict
orTransaction
) – transaction objectKeyword Arguments: - exclude_sig (
bool
) – exclude signature during tx serialization [defalut: True] - exclude_multi_sig (
bool
) – exclude signatures during tx serialization [defalut: True] - exclude_second_sig (
bool
) – exclude second signatures during tx serialization [defalut: True]
Returns: bytes sequence
Return type: bytes
- exclude_sig (
-
dposlib.ark.crypto.
getId
(tx)[source]¶ Generate transaction id.
Parameters: tx ( dict
orTransaction
) – transaction objectReturns: id as hex string Return type: str
-
dposlib.ark.crypto.
getIdFromBytes
(data)[source]¶ Generate data id.
Parameters: data ( bytes
) – data as bytes sequenceReturns: id as hex string Return type: str
-
dposlib.ark.crypto.
getKeys
(secret)[source]¶ Generate keyring containing secp256k1 keys-pair and wallet import format (WIF).
Parameters: secret ( str
,bytes
orint
) – anything that could issue a private key on secp256k1 curveReturns: public, private and WIF keys Return type: dict
-
dposlib.ark.crypto.
getMultiSignaturePublicKey
(minimum, *publicKeys)[source]¶ Compute ARK multi signature public key according to ARK AIP #18.
Parameters: - minimum (
int
) – minimum signature required - publicKeys (
list of str
) – public key list
Returns: the multisignature public key
Return type: str
- minimum (
-
dposlib.ark.crypto.
getSignature
(tx, privateKey, **options)[source]¶ Generate transaction signature using private key.
Parameters: - tx (
dict
orTransaction
) – transaction description - privateKey (
str
) – private key as hex string
Keyword Arguments: - exclude_sig (
bool
) – exclude signature during tx serialization [defalut: True] - exclude_multi_sig (
bool
) – exclude signatures during tx serialization [defalut: True] - exclude_second_sig (
bool
) – exclude second signatures during tx serialization [defalut: True]
Returns: signature
Return type: str
- tx (
-
dposlib.ark.crypto.
getSignatureFromBytes
(data, privateKey)[source]¶ Generate signature from data using private key.
Parameters: - data (
bytes
) – bytes sequence - privateKey (
str
) – private key as hex string
Returns: signature as hex string
Return type: str
- data (
-
dposlib.ark.crypto.
getWIF
(seed)[source]¶ Compute WIF address from seed.
Parameters: seed ( bytes
) – a sha256 sequence bytesReturns: WIF address Return type: str
-
dposlib.ark.crypto.
verifySignature
(value, publicKey, signature)[source]¶ Verify signature.
Parameters: - value (
str
) – value as hex string - publicKey (
str
) – public key as hex string - signature (
str
) – signature as hex string
Returns: true if signature matches the public key
Return type: bool
- value (
-
dposlib.ark.crypto.
verifySignatureFromBytes
(data, publicKey, signature)[source]¶ Verify signature.
Parameters: - data (
bytes
) – data - publicKey (
str
) – public key as hex string - signature (
str
) – signature as hex string
Returns: true if signature matches the public key
Return type: bool
- data (
Signature utils¶
Transaction builders¶
-
dposlib.ark.v3.
transfer
(amount, address, vendorField=None, expiration=0)[source]¶ Build a transfer transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - amount (
float
) – transaction amount in ark - address (
str
) – valid recipient address - vendorField (
str
) – vendor field message - expiration (
float
) – time of persistance in hour
Returns: transaction object
Return type: - amount (
-
dposlib.ark.v3.
registerSecondSecret
(secondSecret)[source]¶ Build a second secret registration transaction.
Parameters: secondSecret ( str
) – passphraseReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
registerSecondPublicKey
(secondPublicKey)[source]¶ Build a second secret registration transaction.
Note
You must own the secret issuing secondPublicKey
Parameters: secondPublicKey ( str
) – public key as hex stringReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
registerAsDelegate
(username)[source]¶ Build a delegate registration transaction.
Parameters: username ( str
) – delegate usernameReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
upVote
(*usernames)[source]¶ Build an upvote transaction.
Parameters: usernames ( iterable
) – delegate usernames asstr
iterableReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
downVote
(*usernames)[source]¶ Build a downvote transaction.
Parameters: usernames ( iterable
) – delegate usernames asstr
iterableReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
registerMultiSignature
(minSig, *publicKeys)[source]¶ Build a multisignature registration transaction.
Parameters: - minSig (
int
) – minimum signature required - publicKeys (
list of str
) – public key list
Returns: transaction object
Return type: - minSig (
-
dposlib.ark.v3.
registerIpfs
(ipfs)[source]¶ Build an IPFS registration transaction.
Parameters: ipfs ( str
) – ipfs DAGReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
multiPayment
(*pairs, **kwargs)[source]¶ Build multi-payment transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - pairs (
iterable
) – recipient-amount pair iterable - vendorField (
str
) – vendor field message
Returns: transaction object
Return type: - pairs (
-
dposlib.ark.v3.
delegateResignation
()[source]¶ Build a delegate resignation transaction.
Returns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
htlcSecret
(secret)[source]¶ Compute an HTLC secret hex string from passphrase.
Parameters: secret ( str
) – passphraseReturns: transaction object Return type: dposlib.blockchain.tx.Transaction
-
dposlib.ark.v3.
htlcLock
(amount, address, secret, expiration=24, vendorField=None)[source]¶ Build an HTLC lock transaction. Emoji can be included in transaction vendorField using unicode formating.
>>> u"message with sparkles \u2728"
Parameters: - amount (
float
) – transaction amount in ark - address (
str
) – valid recipient address - secret (
str
) – lock passphrase - expiration (
float
) – transaction validity in hour - vendorField (
str
) – vendor field message
Returns: transaction object
Return type: - amount (
-
dposlib.ark.v3.
htlcClaim
(txid, secret)[source]¶ Build an HTLC claim transaction.
Parameters: - txid (
str
) – htlc lock transaction id - secret (
str
) – passphrase used by htlc lock transaction
Returns: transaction object
Return type: - txid (
-
dposlib.ark.v3.
htlcRefund
(txid)[source]¶ Build an HTLC refund transaction.
Parameters: txid ( str
) – htlc lock transaction idReturns: transaction object Return type: dposlib.blockchain.tx.Transaction