dposlib.ark.api
isLinked
def isLinked(func)
Python decorator.
First argument of decorated function have to be a
dposlib.ark.api.Content
or an object containing a valid address, _derivationPath or publicKey
attribute. It executes the decorated function if the object is correctly
linked using dposlib.ark.api.link definition.
link
def link(cls, secret=None, secondSecret=None)
Associates crypto keys into a dposlib.ark.api.Content object according to secrets. If secret or secondSecret are not str,
they are considered as None. In this case secrets will be asked and
checked from console untill success or Ctrl+c keyboard interruption.
Arguments:
clsContent - content object.secretstr - secret string. Default set toNone.secondSecretstr - second secret string. Default set toNone.
Returns:
bool- True if secret and second secret match.
unlink
def unlink(cls)
Remove crypto keys association.
JSDict Objects
class JSDict(dict)
Read only dictionary with js object behaviour.
>>> jsdic = dposlib.ark.JSDict(value=5)
>>> jsdic
{'value': 5}
>>> jsdic.value
5
Content Objects
class Content(object)
Live object connected to blockchain. It is initialized with
dposlib.rest.GET request. Object is
updated every 30s. Endpoint response can be a dict or a list. If it is
a list, it is stored in data attribute else all fields are stored as
instance attribute.
>>> txs = dposlib.ark.Content(rest.GET.api.transactions)
>>> txs.data[0]["timestamp"]
{
'epoch': 121912776,
'unix': 1612013976,
'human': '2021-01-30T13:39:36.000Z'
}
>>> tx = dposlib.ark.Content(
rest.GET.api.transactions,
"d36a164a54df9d1c7889521ece15318d6945e9971fecd0a96a9c18e74e0adbf9",
)
>>> tx.timestamp
{
'epoch': 121919704,
'unix': 1612020904,
'human': '2021-01-30T15:35:04.000Z'
}
>>> tx.amount
212963052
>>> tx.datetime
datetime.datetime(2021, 1, 30, 15, 35, 4, tzinfo=<UTC>)
__init__
def __init__(ndpt, *args, **kwargs)
Arguments:
ndptusrv.req.Endpoint - endpoint class to be called.*args- Variable length argument list used byusrv.req.Endpoint.
Kwargs:
keep_alivebool - set hook to update data from blockcahin. Default to True.
filter
def filter(data)
Convert data as JSDict object converting string values in int if possible.
Wallet Objects
class Wallet(Content)
Wallet root class that implements basic wallet behaviour.
delegate
Delegate attributes if wallet is registered as delegate.
username
Delegate username if wallet is registered as delegate.
secondPublicKey
Second public key if second signature is set to wallet.
__init__
def __init__(address, **kw)
Arguments:
addressstr - wallet address or delegate username.**kwargs- Variable key argument used bydposlib.ark.api.Content.
Specific kwargs:
keep_alivebool - automatic update data from blockcahin. Default to True.feeint or str - set fee level as fee multiplier string value or one of minFee, avgFee, maxFee. Default to avgFee.fee_includedbool - set to True if amout + fee is the total desired out flow. Default to False.
link
def link(*args, **kwargs)
See dposlib.ark.api.link.
unlink
def unlink()
send
@isLinked
def send(amount, address, vendorField=None, expiration=0)
Broadcast a transfer transaction to the ledger.
See dposlib.ark.builders.v2.transfer.
setSecondSecret
@isLinked
def setSecondSecret(secondSecret)
Broadcast a second secret registration transaction to the ledger.
See dposlib.ark.builders.v2.registerSecondSecret.
setSecondPublicKey
@isLinked
def setSecondPublicKey(secondPublicKey)
Broadcast a second secret registration transaction into the ledger.
See dposlib.ark.builders.v2.registerSecondPublicKey.
setDelegate
@isLinked
def setDelegate(username)
Broadcast a delegate registration transaction to the ledger.
See dposlib.ark.builders.v2.registerAsDelegate.
upVote
@isLinked
def upVote(*usernames)
Broadcast an up-vote transaction to the ledger.
See dposlib.ark.builders.v2.multiVote.
downVote
@isLinked
def downVote(*usernames)
Broadcast a down-vote transaction to the ledger.
See dposlib.ark.builders.v2.downVote.
sendIpfs
@isLinked
def sendIpfs(ipfs)
See dposlib.ark.builders.v2.registerIpfs.
multiSend
@isLinked
def multiSend(*pairs, **kwargs)
See dposlib.ark.builder.multiPayment.
resignate
@isLinked
def resignate()
See dposlib.ark.builders.v2.delegateResignation.
sendHtlc
@isLinked
def sendHtlc(amount, address, secret, expiration=24, vendorField=None)
See dposlib.ark.builders.v2.htlcLock.
claimHtlc
@isLinked
def claimHtlc(txid, secret)
See dposlib.ark.builders.v2.htlcClaim.
refundHtlc
@isLinked
def refundHtlc(txid)
See dposlib.ark.builders.v2.htlcRefund.
createEntity
@isLinked
def createEntity(name, type="business", subtype=0, ipfsData=None)
See dposlib.ark.builders.v2.entityRegister.
updateEntity
@isLinked
def updateEntity(registrationId, ipfsData, name=None)
See dposlib.ark.builders.v2.entityUpdate.
resignEntity
@isLinked
def resignEntity(registrationId)
See dposlib.ark.builders.v2.entityResign.
Ledger Objects
class Ledger(Wallet)
Ledger wallet api.
Webhook Objects
class Webhook(Content)
>>> import dposlib
>>> peer = "http:/127.0.0.1:4004"
>>> target = "http://127.0.0.1/targetted/endpoint"
>>> wh = dposlib.core.api.Webhook(
... peer, "transaction.applied", target, "amount<1"
... )
security token: 9f86d081884c7d659a2feaa0c55ad015...2b0b822cd15d6c15b0f00a08
>>> dposlib.core.api.webhook.verify("9f86d081884c7d659a2feaa0c55ad015")
True
>>> wh.delete()
{"sucess": True, "status": 204}
condition
@staticmethod
def condition(expr)
Webhook condition builder from str expression. It is internally used
by Webhook.create method.
| webhook | dposlib |
|---|---|
lt / lte |
< / <= |
gt / gte |
> / >= |
eq / ne |
== / != |
truthy / falsy |
? / !? |
regexp / contains |
\\ / $ |
between / not-between |
<> / !<> |
>>> import dposlib.ark.api as api
>>> api.Webhook.condition("vendorField\\^.*payroll.*$")
{'value': '^.*payroll.*$', 'key': 'vendorField', 'condition': 'regexp'}
>>> api.Webhook.condition("amount<>2000000000000:4000000000000")
{
'value': {'min': '2000000000000', 'max': '4000000000000'},
'condition': 'between',
'key': 'amount'
}
Arguments:
exprstr - human readable expression.
Returns:
dict- webhook conditions