Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
dataBinary += b'\3'
dataBinary += struct.pack(">H", len(d['value']))
dataBinary += crypto.str2bytes(d['value'])
# check: https://stackoverflow.com/questions/2356501/how-do-you-round-up-a-number-in-python
txFee = (int(((len(crypto.str2bytes(json.dumps(data))) + 2 + 64 )) / 1000.0) + 1 ) * 100000
txFee = max(txFee, 500000)
dataObject['fee'] = txFee
sData = b'\x0c' + \
b'\1' + \
base58.b58decode(self.publicKey) + \
struct.pack(">H", len(data)) + \
dataBinary + \
struct.pack(">Q", timestamp) + \
struct.pack(">Q", txFee)
dataObject['proofs'] = [ crypto.sign(self.privateKey, sData) ]
for entry in dataObject['data']:
if entry['type'] == 'binary':
base64Encoded = base64.b64encode(crypto.str2bytes(entry['value']))
entry['value'] = 'base64:' + crypto.bytes2str(base64Encoded)
dataObjectJSON = json.dumps(dataObject)
return pywaves.wrapper('/transactions/broadcast', dataObjectJSON)
logging.error('Private key required')
else:
compiledScript = base64.b64decode(script)
scriptLength = len(compiledScript)
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) + \
compiledScript + \
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": 'base64:' + script,
"proofs": [
signature
]
})
return pywaves.wrapper('/transactions/broadcast', data)
transfersData = b''
for i in range(0, len(transfers)):
transfersData += base58.b58decode(transfers[i]['recipient']) + struct.pack(">Q", transfers[i]['amount'])
sData = b'\x0b' + \
b'\1' + \
base58.b58decode(self.publicKey) + \
b'\1' + \
base58.b58decode(asset.assetId) + \
struct.pack(">H", len(transfers)) + \
transfersData + \
struct.pack(">Q", timestamp) + \
struct.pack(">Q", txFee) + \
struct.pack(">H", len(attachment)) + \
crypto.str2bytes(attachment)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"type": 11,
"version": 1,
"assetId": asset.assetId,
"senderPublicKey": self.publicKey,
"fee": txFee,
"timestamp": timestamp,
"transfers": transfers,
"attachment": base58.b58encode(crypto.str2bytes(attachment)),
"signature": signature,
"proofs": [
signature
]
})
msg = 'Private key required'
logging.error(msg)
pywaves.throw_error(msg)
elif not pywaves.OFFLINE and self.balance() < txFee:
msg = 'Insufficient Waves balance'
logging.error(msg)
pywaves.throw_error(msg)
else:
if timestamp == 0:
timestamp = int(time.time() * 1000)
sData = b'\x09' + \
base58.b58decode(self.publicKey) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp) + \
base58.b58decode(leaseId)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"senderPublicKey": self.publicKey,
"txId": leaseId,
"fee": txFee,
"timestamp": timestamp,
"signature": signature
})
req = pywaves.wrapper('/leasing/broadcast/cancel', data)
if pywaves.OFFLINE:
return req
elif 'leaseId' in req:
return req['leaseId']
if timestamp == 0:
timestamp = int(time.time() * 1000)
expiration = timestamp + maxLifetime * 1000
asset1 = b'\0' if amountAsset.assetId=='' else b'\1' + base58.b58decode(amountAsset.assetId)
asset2 = b'\0' if priceAsset.assetId=='' else b'\1' + base58.b58decode(priceAsset.assetId)
sData = base58.b58decode(self.publicKey) + \
base58.b58decode(pywaves.MATCHER_PUBLICKEY) + \
asset1 + \
asset2 + \
orderType + \
struct.pack(">Q", price) + \
struct.pack(">Q", amount) + \
struct.pack(">Q", timestamp) + \
struct.pack(">Q", expiration) + \
struct.pack(">Q", matcherFee)
signature = crypto.sign(self.privateKey, sData)
otype = "buy" if orderType==b'\0' else "sell"
data = json.dumps({
"senderPublicKey": self.publicKey,
"matcherPublicKey": pywaves.MATCHER_PUBLICKEY,
"assetPair": {
"amountAsset": amountAsset.assetId,
"priceAsset": priceAsset.assetId,
},
"orderType": otype,
"price": price,
"amount": amount,
"timestamp": timestamp,
"expiration": expiration,
"matcherFee": matcherFee,
"signature": signature
})
else:
if timestamp == 0:
timestamp = int(time.time() * 1000)
'''sData = b'\x0a' + \
base58.b58decode(self.publicKey) + \
struct.pack(">H", len(aliasWithNetwork)) + \
crypto.str2bytes(str(aliasWithNetwork)) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)'''
sData = b'\x0a' + \
base58.b58decode(self.publicKey) + \
struct.pack(">H", len(aliasWithNetwork)) + \
aliasWithNetwork + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"type": 10,
"alias": alias,
"senderPublicKey": self.publicKey,
"fee": txFee,
"timestamp": timestamp,
"signature": signature,
"version": 1
})
return pywaves.wrapper('/alias/broadcast/create', data)
logging.error(msg)
pywaves.throw_error(msg)
elif not pywaves.OFFLINE and self.balance() < amount + txFee:
msg = 'Insufficient Waves balance'
logging.error(msg)
pywaves.throw_error(msg)
else:
if timestamp == 0:
timestamp = int(time.time() * 1000)
sData = b'\x08' + \
base58.b58decode(self.publicKey) + \
base58.b58decode(recipient.address) + \
struct.pack(">Q", amount) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"senderPublicKey": self.publicKey,
"recipient": recipient.address,
"amount": amount,
"fee": txFee,
"timestamp": timestamp,
"signature": signature
})
req = pywaves.wrapper('/leasing/broadcast/lease', data)
return req
base58.b58decode(self.publicKey) + \
base58.b58decode(dappAddress) + \
b'\x01' + \
b'\x09' + \
b'\x01' + \
struct.pack(">L", len(crypto.str2bytes(functionName))) +\
crypto.str2bytes(functionName) + \
struct.pack(">I", len(params)) + \
parameterBytes + \
struct.pack(">H", len(payments)) + \
paymentBytes + \
struct.pack(">Q", txFee) + \
assetIdBytes + \
struct.pack(">Q", timestamp)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"type": 16,
"senderPublicKey": self.publicKey,
"version": 1,
"timestamp": timestamp,
"fee": txFee,
"proofs": [signature],
"feeAssetId": feeAsset,
"dApp": dappAddress,
"call": {
"function": functionName,
"args": params
},
"payment": payments
})
req = pywaves.wrapper('/transactions/broadcast', data)