Skip to content

Commit

Permalink
added setScript and sponsorAsset tx
Browse files Browse the repository at this point in the history
  • Loading branch information
jansenmarc committed May 6, 2018
1 parent 21f8274 commit 89d0d20
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 50 deletions.
30 changes: 20 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,43 @@ __pywaves.Address(address, publicKey, privateKey, seed)__ _Creates a new Address

`assets()` returns a list of assets owned by the address

`issueAsset(name, description, quantity, decimals=0, reissuable=False, txFee=DEFAULT_ASSET_FEE, timestamp)` issue a new asset
`issueAsset(name, description, quantity, decimals=0, reissuable=False, txFee=DEFAULT_ASSET_FEE, timestamp=0)` issue a new asset

`reissueAsset(Asset, quantity, reissuable=False, txFee=DEFAULT_ASSET_FEE, timestamp)` reissue an asset
`reissueAsset(Asset, quantity, reissuable=False, txFee=DEFAULT_ASSET_FEE, timestamp=0)` reissue an asset

`burnAsset(Asset, quantity, txFee=DEFAULT_ASSET_FEE, timestamp)` burn the specified quantity of an asset
`burnAsset(Asset, quantity, txFee=DEFAULT_ASSET_FEE, timestamp=0)` burn the specified quantity of an asset

`sendWaves(recipient, amount, attachment='', txFee=DEFAULT_TX_FEE, timestamp)` send specified amount of Waves to recipient
`sendWaves(recipient, amount, attachment='', txFee=DEFAULT_TX_FEE, timestamp=0)` send specified amount of Waves to recipient

`sendAsset(recipient, asset, amount, attachment='', txFee=DEFAULT_TX_FEE, timestamp)` send specified amount of an asset to recipient
massTransferWaves(transfers, attachment='', timestamp=0)` sending Waves tokens via a mass transfer

`sendAsset(recipient, asset, amount, attachment='', txFee=DEFAULT_TX_FEE, timestamp=0)` send specified amount of an asset to recipient

`massTransferWaves(self, transfers, attachment='', timestamp=0)` sending an asset via mass transfer

`cancelOrder(assetPair, order)` cancel an order

`buy(assetPair, amount price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp)` post a buy order
`buy(assetPair, amount price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp=0)` post a buy order

`tradableBalance(assetPair)` get tradable balance for the specified asset pair

`sell(assetPair, amount, price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp)` post a sell order
`sell(assetPair, amount, price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp=0)` post a sell order

`lease(recipient, amount, txFee=DEFAULT_LEASE_FEE, timestamp)` post a lease transaction
`lease(recipient, amount, txFee=DEFAULT_LEASE_FEE, timestamp=0)` post a lease transaction

`leaseCancel(leaseId, txFee=DEFAULT_LEASE_FEE, timestamp)` cancel a lease
`leaseCancel(leaseId, txFee=DEFAULT_LEASE_FEE, timestamp=0)` cancel a lease

`getOrderHistory(assetPair)` get order history for the specified asset pair

`cancelOpenOrders(assetPair)` cancel all open orders for the specified asset pair

`deleteOrderHistory(assetPair)` delete order history for the specified asset pair

`createAlias(alias, txFee=DEFAULT_ALIAS_FEE, timestamp)` create alias
`createAlias(alias, txFee=DEFAULT_ALIAS_FEE, timestamp=0)` create alias

`sponsorAsset(assetId, minimalFeeInAssets, txFee=pywaves.DEFAULT_SPONSOR_FEE, timestamp=0)` sponsoring assets

`setScript(script, txFee=pywaves.DEFAULT_SCRIPT_FEE, timestamp=0)` sets a script for this address

### Asset Class
__pywaves.Asset(assetId)__ _Creates a new Asset object_
Expand Down Expand Up @@ -168,6 +176,8 @@ The fees for waves/asset transfers, asset issue/reissue/burn and matcher transac
* DEFAULT_MATCHER_FEE = 1000000
* DEFAULT_LEASE_FEE = 100000
* DEFAULT_ALIAS_FEE = 100000
* DEFAULT_SPONSOR_FEE = 100000000
* DEFAULT_SCRIPT_FEE = 100000

## More Examples

Expand Down
2 changes: 2 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
DEFAULT_MATCHER_FEE = 300000
DEFAULT_LEASE_FEE = 100000
DEFAULT_ALIAS_FEE = 100000
DEFAULT_SPONSOR_FEE = 100000000
DEFAULT_SCRIPT_FEE = 100000
VALID_TIMEFRAMES = (5, 15, 30, 60, 240, 1440)
MAX_WDF_REQUEST = 100

Expand Down
115 changes: 75 additions & 40 deletions address.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,9 @@ def __str__(self):
def balance(self, assetId='', confirmations=0):
try:
if assetId:
if hasattr(self.address, 'decode'):
return pywaves.wrapper('/assets/balance/%s/%s' % (self.address.decode(), assetId))['balance']
else:
return pywaves.wrapper('/assets/balance/%s/%s' % (self.address, assetId))['balance']
return pywaves.wrapper('/assets/balance/%s/%s' % (self.address, assetId))['balance']
else:
if hasattr(self.address, 'decode'):
return pywaves.wrapper('/addresses/balance/%s%s' % (self.address.decode(), '' if confirmations==0 else '/%d' % confirmations))['balance']
else:
return pywaves.wrapper('/addresses/balance/%s%s' % (self.address, '' if confirmations == 0 else '/%d' % confirmations))['balance']
return pywaves.wrapper('/addresses/balance/%s%s' % (self.address, '' if confirmations==0 else '/%d' % confirmations))['balance']
except:
return 0

Expand Down Expand Up @@ -404,24 +398,13 @@ def sendWaves(self, recipient, amount, attachment='', txFee=pywaves.DEFAULT_TX_F
struct.pack(">H", len(attachment)) + \
crypto.str2bytes(attachment)
signature = crypto.sign(self.privateKey, sData)
attachmentDec = base58.b58encode(crypto.str2bytes(attachment))
senderPublicKeyDec = self.publicKey
recAddress = recipient.address
if hasattr(signature, 'decode'):
signature = signature.decode()
if hasattr(attachmentDec, 'decode'):
attachmentDec = attachmentDec.decode()
if hasattr(senderPublicKeyDec, 'decode'):
senderPublicKeyDec = senderPublicKeyDec.decode()
if hasattr(recAddress, 'decode'):
recAddress = recAddress.decode()
data = json.dumps({
"senderPublicKey": senderPublicKeyDec,
"recipient": recAddress,
"senderPublicKey": self.publicKey,
"recipient": recipient.address,
"amount": amount,
"fee": txFee,
"timestamp": timestamp,
"attachment": attachmentDec,
"attachment": base58.b58encode(crypto.str2bytes(attachment)),
"signature": signature
})

Expand Down Expand Up @@ -505,33 +488,21 @@ def sendAsset(self, recipient, asset, amount, attachment='', feeAsset='', txFee=
struct.pack(">H", len(attachment)) + \
crypto.str2bytes(attachment)
signature = crypto.sign(self.privateKey, sData)
attachmentDec = base58.b58encode(crypto.str2bytes(attachment))
senderPublicKeyDec = self.publicKey
recAddress = recipient.address
if hasattr(signature, 'decode'):
signature = signature.decode()
if hasattr(attachmentDec, 'decode'):
attachmentDec = attachmentDec.decode()
if hasattr(senderPublicKeyDec, 'decode'):
senderPublicKeyDec = senderPublicKeyDec.decode()
if hasattr(recAddress, 'decode'):
print('converting recipient address')
recAddress = recAddress.decode()
data = json.dumps({
"assetId": (asset.assetId if asset else ""),
"feeAssetId": (feeAsset.assetId if feeAsset else ""),
"senderPublicKey": senderPublicKeyDec,
"recipient": recAddress,
"senderPublicKey": self.publicKey,
"recipient": recipient.address,
"amount": amount,
"fee": txFee,
"timestamp": timestamp,
"attachment": attachmentDec,
"attachment": base58.b58encode(crypto.str2bytes(attachment)),
"signature": signature
})

return pywaves.wrapper('/assets/broadcast/transfer', data)

def massTransferAssets(self, transfers, asset, attachment='', timestamp=0):
def `
txFee = 100000 + len(transfers) * 50000
totalAmount = 0

Expand Down Expand Up @@ -851,7 +822,7 @@ def deleteOrderHistory(self, assetPair):
pywaves.wrapper('/matcher/orderbook/%s/%s/delete' % ('WAVES' if assetPair.asset1.assetId == '' else assetPair.asset1.assetId, 'WAVES' if assetPair.asset2.assetId == '' else assetPair.asset2.assetId), data, host=pywaves.MATCHER)

def createAlias(self, alias, txFee=pywaves.DEFAULT_ALIAS_FEE, timestamp=0):
aliasWithNetwork = b'\x02' + str(pywaves.CHAIN_ID) + struct.pack(">H", len(alias)) + crypto.str2bytes(alias)
aliasWithNetwork = b'\x02' + crypto.str2bytes(str(pywaves.CHAIN_ID)) + struct.pack(">H", len(alias)) + crypto.str2bytes(alias)
if not self.privateKey:
logging.error('Private key required')
else:
Expand All @@ -860,7 +831,7 @@ def createAlias(self, alias, txFee=pywaves.DEFAULT_ALIAS_FEE, timestamp=0):
sData = b'\x0a' + \
base58.b58decode(self.publicKey) + \
struct.pack(">H", len(aliasWithNetwork)) + \
crypto.str2bytes(aliasWithNetwork) + \
crypto.str2bytes(str(aliasWithNetwork)) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)
Expand All @@ -872,3 +843,67 @@ def createAlias(self, alias, txFee=pywaves.DEFAULT_ALIAS_FEE, timestamp=0):
"signature": signature
})
return pywaves.wrapper('/alias/broadcast/create', data)

def sponsorAsset(self, assetId, minimalFeeInAssets, txFee=pywaves.DEFAULT_SPONSOR_FEE, timestamp=0):
if not self.privateKey:
logging.error('Private key required')
else:
if timestamp == 0:
timestamp = int(time.time() * 1000)
sData = b'\x0e' + \
base58.b58decode(self.publicKey) + \
base58.b58decode(assetId) + \
struct.pack(">Q", minimalFeeInAssets) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)

data = json.dumps({
"type": 14,
"version": 1,
"senderPublicKey": self.publicKey,
"assetId": assetId,
"fee": txFee,
"timestamp": timestamp,
"minSponsoredAssetFee": minimalFeeInAssets,
"proofs": [
signature
]
})

return pywaves.wrapper('/transactions/broadcast', data)

def setScript(self, script, txFee=pywaves.DEFAULT_SCRIPT_FEE, timestamp=0):
if not self.privateKey:
logging.error('Private key required')
else:
rawScript = base58.b58decode(script)
scriptLength = len(rawScript)
if timestamp == 0:
timestamp = int(time.time() * 1000)
sData = b'\x0d' + \
b'\1' + \
crypto.str2bytes(str(pywaves.CHAIN_ID)) + \
base58.b58decode(self.publicKey) + \
b'\1' + \
struct.pack(">H", scriptLength) + \
crypto.str2bytes(str(rawScript)) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)

data = json.dumps({
"type": 13,
"version": 1,
"senderPublicKey": self.publicKey,
"fee": txFee,
"timestamp": timestamp,
"script": script,
"proofs": [
signature
]
})

return pywaves.wrapper('/transactions/broadcast', data)


0 comments on commit 89d0d20

Please sign in to comment.