Beispiel #1
0
	def dataTransaction(self, data, timestamp=0):
		if not self.privateKey:
			logging.error('Private key required')
		else:
			if timestamp == 0:
				timestamp = int(time.time() * 1000)
			dataObject = {
				"type": 12,
				"version": 1,
				"senderPublicKey": self.publicKey,
				"data": data,
				"fee": 0,
				"timestamp": timestamp,
				"proofs": ['']
			}
			dataBinary = b''
			for i in range(0, len(data)):
				d = data[i]
				keyBytes = crypto.str2bytes(d['key'])
				dataBinary += struct.pack(">H", len(keyBytes))
				dataBinary += keyBytes
				if d['type'] == 'binary':
					dataBinary += b'\2'
					valueAsBytes = d['value']
					dataBinary += struct.pack(">H", len(valueAsBytes))
					dataBinary += crypto.str2bytes(valueAsBytes)
				elif d['type'] == 'boolean':
					if d['value']:
						dataBinary += b'\1\1'
					else:
						dataBinary += b'\1\0'
				elif d['type'] == 'integer':
					dataBinary += b'\0'
					dataBinary += struct.pack(">Q", d['value'])
				elif d['type'] == 'string':
					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
			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)
Beispiel #2
0
 def _postOrder(self,
                amountAsset,
                priceAsset,
                orderType,
                amount,
                price,
                maxLifetime=30 * 86400,
                matcherFee=pywaves.DEFAULT_MATCHER_FEE,
                timestamp=0):
     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
     })
     req = pywaves.wrapper('/matcher/orderbook', data, host=pywaves.MATCHER)
     id = -1
     if 'status' in req:
         if req['status'] == 'OrderRejected':
             logging.error('Order Rejected - %s' % req['message'])
         elif req['status'] == 'OrderAccepted':
             id = req['message']['id']
             logging.info('Order Accepted - ID: %s' % id)
     elif not pywaves.OFFLINE:
         logging.error(req)
     else:
         return req
     return id
Beispiel #3
0
 def deleteOrderHistory(self, assetPair):
     orders = self.getOrderHistory(assetPair)
     for order in orders:
         orderId = order['id']
         sData = base58.b58decode(self.publicKey) + \
                 base58.b58decode(orderId)
         signature = crypto.sign(self.privateKey, sData)
         data = json.dumps({
             "sender": self.publicKey,
             "orderId": orderId,
             "signature": signature
         })
         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)
Beispiel #4
0
    def massTransferAssets(self, transfers, asset, attachment='', timestamp=0):
        txFee = 100000 + len(transfers) * 50000
        totalAmount = 0

        for i in range(0, len(transfers)):
            totalAmount += transfers[i]['amount']

        if not self.privateKey:
            logging.error('Private key required')
        elif len(transfers) > 100:
            logging.error('Too many recipients')
        elif not pywaves.OFFLINE and self.balance() < totalAmount + txFee:
            logging.error('Insufficient Waves balance')
        else:
            if timestamp == 0:
                timestamp = int(time.time() * 1000)
            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,
                "assetId":
                asset.assetId,
                "senderPublicKey":
                self.publicKey,
                "fee":
                txFee,
                "timestamp":
                timestamp,
                "transfers":
                transfers,
                "attachment":
                base58.b58encode(crypto.str2bytes(attachment)),
                "signature":
                signature
            })

            return pywaves.wrapper('/transactions/broadcast', data)
Beispiel #5
0
 def __str__(self):
     if self.address:
         ab = []
         try:
             assets_balances = pywaves.wrapper('/assets/balance/%s' % self.address)['balances']
             for a in assets_balances:
                 if a['balance'] > 0:
                     ab.append("  %s (%s) = %d" % (a['assetId'], a['issueTransaction']['name'].encode('ascii', 'ignore'), a['balance']))
         except:
             pass
         return 'address = %s\npublicKey = %s\nprivateKey = %s\nseed = %s\nnonce = %d\nbalances:\n  Waves = %d%s' % (self.address, self.publicKey, self.privateKey, self.seed, self.nonce, self.balance(), '\n'+'\n'.join(ab) if ab else '')
Beispiel #6
0
 def tradableBalance(self, assetPair):
     try:
         req = pywaves.wrapper('/matcher/orderbook/%s/%s/tradableBalance/%s' % ('WAVES' if assetPair.asset1.assetId == '' else assetPair.asset1.assetId, 'WAVES' if assetPair.asset2.assetId == '' else assetPair.asset2.assetId, self.address), host=pywaves.MATCHER)
         if pywaves.OFFLINE:
                 return req
         amountBalance = req['WAVES' if assetPair.asset1.assetId == '' else assetPair.asset1.assetId]
         priceBalance = req['WAVES' if assetPair.asset2.assetId == '' else assetPair.asset2.assetId]
     except:
         amountBalance = 0
         priceBalance = 0
     if not pywaves.OFFLINE:
         return amountBalance, priceBalance
Beispiel #7
0
 def cancelOpenOrders(self, assetPair):
     orders = self.getOrderHistory(assetPair)
     for order in orders:
         status = order['status']
         orderId = order['id']
         if status == 'Accepted' or status == 'PartiallyFilled':
             sData = base58.b58decode(self.publicKey) + \
                     base58.b58decode(orderId)
             signature = crypto.sign(self.privateKey, sData)
             data = json.dumps({
                 "sender": self.publicKey,
                 "orderId": orderId,
                 "signature": signature
             })
             pywaves.wrapper('/matcher/orderbook/%s/%s/cancel' %
                             ('WAVES' if assetPair.asset1.assetId == '' else
                              assetPair.asset1.assetId,
                              'WAVES' if assetPair.asset2.assetId == '' else
                              assetPair.asset2.assetId),
                             data,
                             host=pywaves.MATCHER)
Beispiel #8
0
 def status(self):
     try:
         req = pywaves.wrapper(
             '/matcher/orderbook/%s/%s/%s' %
             ('WAVES' if self.assetPair.asset1.assetId == '' else
              self.assetPair.asset1.assetId,
              'WAVES' if self.assetPair.asset2.assetId == '' else
              self.assetPair.asset2.assetId, self.orderId),
             host=self.matcher)
         return req['status']
     except:
         pass
Beispiel #9
0
 def getOrderHistory(self, assetPair, timestamp=0):
     if timestamp == 0:
         timestamp = int(time.time() * 1000)
     sData = base58.b58decode(self.publicKey) + \
             struct.pack(">Q", timestamp)
     signature = crypto.sign(self.privateKey, sData)
     data = {
         "Accept": "application/json",
         "Timestamp": str(timestamp),
         "Signature": signature
     }
     req = pywaves.wrapper('/matcher/orderbook/%s/%s/publicKey/%s' % ('WAVES' if assetPair.asset1.assetId=='' else assetPair.asset1.assetId, 'WAVES' if assetPair.asset2.assetId=='' else assetPair.asset2.assetId, self.publicKey), headers=data, host=pywaves.MATCHER)
     return req
Beispiel #10
0
 def sendAsset(self,
               recipient,
               asset,
               amount,
               attachment='',
               txFee=pywaves.DEFAULT_TX_FEE,
               timestamp=0):
     if not self.privateKey:
         logging.error('Private key required')
     elif not pywaves.OFFLINE and not asset.status():
         logging.error('Asset not issued')
     elif amount <= 0:
         logging.error('Amount must be > 0')
     elif not pywaves.OFFLINE and self.balance(asset.assetId) < amount:
         logging.error('Insufficient asset balance')
     elif not pywaves.OFFLINE and self.balance() < txFee:
         logging.error('Insufficient Waves balance')
     else:
         if timestamp == 0:
             timestamp = int(time.time() * 1000)
         sData = b'\4' + \
                 base58.b58decode(self.publicKey) + \
                 b'\1' + \
                 base58.b58decode(asset.assetId) + \
                 b'\0' + \
                 struct.pack(">Q", timestamp) + \
                 struct.pack(">Q", amount) + \
                 struct.pack(">Q", txFee) + \
                 base58.b58decode(recipient.address) + \
                 struct.pack(">H", len(attachment)) + \
                 crypto.str2bytes(attachment)
         signature = crypto.sign(self.privateKey, sData)
         data = json.dumps({
             "assetId":
             asset.assetId,
             "senderPublicKey":
             self.publicKey,
             "recipient":
             recipient.address,
             "amount":
             amount,
             "feeAssetId":
             txFee,
             "timestamp":
             timestamp,
             "attachment":
             base58.b58encode(crypto.str2bytes(attachment)),
             "signature":
             signature
         })
         return pywaves.wrapper('/assets/broadcast/transfer', data)
Beispiel #11
0
 def status(self):
     if self.assetId!='WAVES':
         try:
             req = pywaves.wrapper('/transactions/info/%s' % self.assetId)
             if req['type'] == 3:
                 self.issuer = req['sender']
                 self.quantity = req['quantity']
                 self.decimals = req['decimals']
                 self.reissuable = req['reissuable']
                 self.name = req['name'].encode('ascii', 'ignore')
                 self.description = req['description'].encode('ascii', 'ignore')
                 return 'Issued'
         except:
             pass
Beispiel #12
0
def set_script_waves(script_source, address_from):
    compile_res = pw.wrapper('/utils/script/compile', script_source)
    print('compiling answer', compile_res, flush=True)
    script = compile_res['script'][7:]
    compiled_script = base64.b64decode(script)
    script_length = len(compiled_script)
    timestamp = int(time.time() * 1000)
    #txFee = pw.DEFAULT_SCRIPT_FEE
    txFee = 1000000
    sData = b'\x0d' + \
        b'\1' + \
        crypto.str2bytes(str(pw.CHAIN_ID)) + \
        base58.b58decode(address_from['publicKey']) + \
        b'\1' + \
        struct.pack(">H", script_length) + \
        compiled_script + \
        struct.pack(">Q", txFee) + \
        struct.pack(">Q", timestamp)
    signature = crypto.sign(address_from['privateKey'], sData)

    data = json.dumps({
        "type":
        13,
        "version":
        1,
        "senderPublicKey":
        address_from['publicKey'].decode('utf-8'),
        "fee":
        txFee,
        "timestamp":
        timestamp,
        "script":
        'base64:' + script,
        "proofs": [signature.decode('utf-8')]
    })

    return pw.wrapper('/transactions/broadcast', data)
Beispiel #13
0
	def SettleTransaction(self,WavesAddress):


		#check transaction WavesAddress and WAVES : attchment BTCaddress and verify assetID 
		# trnc = ModuleHandler.wrapper("/transactions/address/" + WavesAddress + "/limit/1")
		pywaves.setNode(node = pywaves.getNode() , chain = self.CHAIN)
		print("getNode(): ",pywaves.getNode())
		trnc = pywaves.wrapper("/transactions/address/" + WavesAddress + "/limit/1" ,  host = self.TESTNET_NODE )
		print('trnc',trnc)
		BTCaddress = trnc[0][0]['attachment']
		if BTCaddress == '' :
			return {"result" : "there is not any transaction!" }

		
		assetDetail = ModuleHandler.wrapper("/assets/details/" + trnc[0][0]['assetId']  ,  host = self.TESTNET_NODE)
		print('assetDetail :  ',assetDetail)
		decimals = assetDetail['decimals']


		con = lite.connect('test.db')
		with con:
			cur = con.cursor()
			# cur.execute("SELECT MIN(cnt) FROM (SELECT COUNT(*) cnt FROM voting GROUP BY candidate) t;")
			# minimumMigdar = cur.fetchone()
			cur.execute("""SELECT * FROM addresses ORDER BY Inventory DESC """)						#TODO change query for get min count 
			con.commit()
			rows = cur.fetchall()
			cnt = 0
			remind = amount*(10**((-1)*decimals)) #### Decimals Decimals Decimals
			while remind > 0:
				serializedWallet = rows[cnt][1]				#ref to DB structure
				wallet = Wallet.deserialize(serializedWallet , network=BitcoinTestNet)
				inv = rows[cnt][3]

				if inv >= remind :
					
					blockcypher.simple_spend(from_privkey=ModuleHandler.encode( wallet.get_private_key_hex() ) , to_address = BTCaddress , to_satoshis = remind)
					cur.execute(""" UPDATE addresses SET Inventory = ? WHERE WavesAddress = ? """,  ( inv - remind , WavesAddress ))
				

				else :

					blockcypher.simple_spend(from_privkey=ModuleHandler.encode( wallet.get_private_key_hex() ) , to_address = BTCaddress , to_satoshis = inv)
					remind = remind - inv
					cur.execute(""" UPDATE addresses SET Inventory = ? WHERE WavesAddress = ? """,  ( 0 , WavesAddress ))
				con.commit()
			
				
		return res
Beispiel #14
0
	def setAssetScript(self, asset, scriptSource, txFee=pywaves.DEFAULT_ASSET_SCRIPT_FEE, timestamp=0):
		script = pywaves.wrapper('/utils/script/compile', scriptSource)['script'][7:]
		if not self.privateKey:
			logging.error('Private key required')
		else:
			compiledScript = base64.b64decode(script)
			scriptLength = len(compiledScript)
			if timestamp == 0:
				timestamp = int(time.time() * 1000)
			sData = b'\x0f' + \
				b'\1' + \
				crypto.str2bytes(str(pywaves.CHAIN_ID)) + \
				base58.b58decode(self.publicKey) + \
				base58.b58decode(asset.assetId) + \
				struct.pack(">Q", txFee) + \
				struct.pack(">Q", timestamp) + \
				b'\1' + \
				struct.pack(">H", scriptLength) + \
				compiledScript
			signature = crypto.sign(self.privateKey, sData)

			data = json.dumps({
				"type": 15,
				"version": 1,
				"assetId": asset.assetId,
				"senderPublicKey": self.publicKey,
				"fee": txFee,
				"timestamp": timestamp,
				"script": 'base64:' + script,
				"proofs": [
					signature
				]
			})
			print(data)

			return pywaves.wrapper('/transactions/broadcast', data)
Beispiel #15
0
 def tradableBalance(self, assetPair):
     try:
         balances = pywaves.wrapper(
             '/matcher/orderbook/%s/%s/tradableBalance/%s' %
             ('WAVES' if assetPair.asset1.assetId == '' else
              assetPair.asset1.assetId, 'WAVES' if assetPair.asset2.assetId
              == '' else assetPair.asset2.assetId, self.address),
             host=pywaves.MATCHER)
         amountBalance = balances['WAVES' if assetPair.asset1.assetId ==
                                  '' else assetPair.asset1.assetId]
         priceBalance = balances['WAVES' if assetPair.asset2.assetId ==
                                 '' else assetPair.asset2.assetId]
     except:
         amountBalance = 0
         priceBalance = 0
     return amountBalance, priceBalance
Beispiel #16
0
 def __init__(self, address='', publicKey='', privateKey='', seed=''):
     if seed:
         self._generate(seed=seed)
     elif privateKey:
         self._generate(privateKey=privateKey)
     elif address:
         valid = pywaves.wrapper('/addresses/validate/%s' %
                                 address)['valid']
         if not valid:
             raise ValueError("Invalid address")
         else:
             self.address = address
             self.publicKey = publicKey
             self.privateKey = privateKey
             self.seed = seed
     else:
         self._generate()
Beispiel #17
0
 def issueAsset(self,
                name,
                description,
                quantity,
                decimals=0,
                reissuable=False,
                txFee=pywaves.DEFAULT_ASSET_FEE):
     if not self.privateKey:
         msg = 'Private key required'
         logging.error(msg)
         pywaves.throw_error(msg)
     elif len(name) < 4 or len(name) > 16:
         msg = 'Asset name must be between 4 and 16 characters long'
         logging.error(msg)
         pywaves.throw_error(msg)
     else:
         timestamp = int(time.time() * 1000)
         sData = b'\3' + \
                 base58.b58decode(self.publicKey) + \
                 struct.pack(">H", len(name)) + \
                 crypto.str2bytes(name) + \
                 struct.pack(">H", len(description)) + \
                 crypto.str2bytes(description) + \
                 struct.pack(">Q", quantity) + \
                 struct.pack(">B", decimals) + \
                 (b'\1' if reissuable else b'\0') + \
                 struct.pack(">Q", txFee) + \
                 struct.pack(">Q", timestamp)
         signature = crypto.sign(self.privateKey, sData)
         data = json.dumps({
             "senderPublicKey": self.publicKey,
             "name": name,
             "quantity": quantity,
             "timestamp": timestamp,
             "description": description,
             "decimals": decimals,
             "reissuable": reissuable,
             "fee": txFee,
             "signature": signature
         })
         req = pywaves.wrapper('/assets/broadcast/issue', data)
         if pywaves.OFFLINE:
             return req
         else:
             return pywaves.Asset(req['assetId'])
Beispiel #18
0
 def cancelOrderByID(self, assetPair, orderId):
     sData = base58.b58decode(self.publicKey) + \
             base58.b58decode(orderId)
     signature = crypto.sign(self.privateKey, sData)
     data = json.dumps({
         "sender": self.publicKey,
         "orderId": orderId,
         "signature": signature
     })
     req = pywaves.wrapper('/matcher/orderbook/%s/%s/cancel' % ('WAVES' if assetPair.asset1.assetId=='' else assetPair.asset1.assetId, 'WAVES' if assetPair.asset2.assetId=='' else assetPair.asset2.assetId), data, host=pywaves.MATCHER)
     if pywaves.OFFLINE:
         return req
     else:
         id = -1
         if req['status'] == 'OrderCanceled':
             id = req['orderId']
             logging.info('Order Cancelled - ID: %s' % id)
         return id
Beispiel #19
0
 def burnAsset(self, Asset, quantity, txFee=pywaves.DEFAULT_ASSET_FEE):
     timestamp = int(time.time() * 1000)
     sData = '\6' + \
             base58.b58decode(self.publicKey) + \
             base58.b58decode(Asset.assetId) + \
             struct.pack(">Q", quantity) + \
             struct.pack(">Q", txFee) + \
             struct.pack(">Q", timestamp)
     signature = crypto.sign(self.privateKey, sData)
     data = json.dumps({
         "senderPublicKey": self.publicKey,
         "assetId": Asset.assetId,
         "quantity": quantity,
         "timestamp": timestamp,
         "fee": txFee,
         "signature": signature
     })
     return pywaves.wrapper('/assets/broadcast/burn', data)
Beispiel #20
0
def sign_send_waves(address_from, address_to, tx_amount):
    pub = address_from.publicKey
    pk = address_from.privateKey

    attachment = ''
    txFee = pw.DEFAULT_TX_FEE
    timestamp = int(time.time() * 1000)

    sData = b'\4' + \
            b'\2' + \
            base58.b58decode(pub) + \
            b'\0\0' + \
            struct.pack(">Q", timestamp) + \
            struct.pack(">Q", tx_amount) + \
            struct.pack(">Q", txFee) + \
            base58.b58decode(address_to) + \
            struct.pack(">H", len(attachment)) + \
            crypto.str2bytes(attachment)
    signature = crypto.sign(pk, sData)
    data = json.dumps({
        "type":
        4,
        "version":
        2,
        "senderPublicKey":
        pub.decode('utf-8'),
        "recipient":
        address_to.decode('utf-8'),
        "amount":
        tx_amount,
        "fee":
        txFee,
        "timestamp":
        timestamp,
        "attachment":
        base58.b58encode(crypto.str2bytes(attachment)).decode('utf-8'),
        "signature":
        signature.decode('utf-8'),
        "proofs": [signature.decode('utf-8')]
    })

    print('signed tx', data, flush=True)

    return pw.wrapper('/transactions/broadcast', data)
Beispiel #21
0
 def lease(self,
           recipient,
           amount,
           txFee=pywaves.DEFAULT_LEASE_FEE,
           timestamp=0):
     if not self.privateKey:
         msg = 'Private key required'
         logging.error(msg)
         pywaves.throw_error(msg)
     elif amount <= 0:
         msg = 'Amount must be > 0'
         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)
         if pywaves.OFFLINE:
             return req
         else:
             return req['id']
Beispiel #22
0
 def createAlias(self, alias, txFee=pywaves.DEFAULT_ALIAS_FEE):
     aliasWithNetwork = b'\x02' + str(pywaves.CHAIN_ID) + struct.pack(
         ">H", len(alias)) + crypto.str2bytes(alias)
     if not self.privateKey:
         logging.error('Private key required')
     else:
         timestamp = int(time.time() * 1000)
         sData = b'\x0a' + \
                 base58.b58decode(self.publicKey) + \
                 struct.pack(">H", len(aliasWithNetwork)) + \
                 crypto.str2bytes(aliasWithNetwork) + \
                 struct.pack(">Q", txFee) + \
                 struct.pack(">Q", timestamp)
         signature = crypto.sign(self.privateKey, sData)
         data = json.dumps({
             "alias": alias,
             "senderPublicKey": self.publicKey,
             "fee": txFee,
             "timestamp": timestamp,
             "signature": signature
         })
         return pywaves.wrapper('/alias/broadcast/create', data)
Beispiel #23
0
 def leaseCancel(self, leaseId, txFee=pywaves.DEFAULT_LEASE_FEE):
     if not self.privateKey:
         logging.error('Private key required')
     elif self.balance() < txFee:
         logging.error('Insufficient Waves balance')
     else:
         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 'leaseId' in req:
             return req['leaseId']
Beispiel #24
0
	def burnAsset(self, Asset, quantity, txFee=pywaves.DEFAULT_TX_FEE):
		timestamp = int(time.time() * 1000)

		sData = '\6' + \
				crypto.bytes2str(base58.b58decode(self.publicKey)) + \
				crypto.bytes2str(base58.b58decode(Asset.assetId)) + \
				crypto.bytes2str(struct.pack(">Q", quantity)) + \
				crypto.bytes2str(struct.pack(">Q", txFee)) + \
				crypto.bytes2str(struct.pack(">Q", timestamp))
		signature = crypto.sign(self.privateKey, crypto.str2bytes(sData))
		data = json.dumps({
			"senderPublicKey": self.publicKey,
			"assetId": Asset.assetId,
			"quantity": quantity,
			"timestamp": timestamp,
			"fee": txFee,
			"signature": signature
		})
		req = pywaves.wrapper('/assets/broadcast/burn', data)
		if pywaves.OFFLINE:
			return req
		else:
			return req.get('id', 'ERROR')
Beispiel #25
0
 def reissueAsset(self, Asset, quantity, reissuable=False, txFee=pywaves.DEFAULT_TX_FEE):
     timestamp = int(time.time() * 1000)
     sData = b'\5' + \
             base58.b58decode(self.publicKey) + \
             base58.b58decode(Asset.assetId) + \
             struct.pack(">Q", quantity) + \
             (b'\1' if reissuable else b'\0') + \
             struct.pack(">Q",txFee) + \
             struct.pack(">Q", timestamp)
     signature = crypto.sign(self.privateKey, sData)
     data = json.dumps({
         "senderPublicKey": self.publicKey,
         "assetId": Asset.assetId,
         "quantity": quantity,
         "timestamp": timestamp,
         "reissuable": reissuable,
         "fee": txFee,
         "signature": signature
     })
     req = pywaves.wrapper('/assets/broadcast/reissue', data)
     if pywaves.OFFLINE:
         return req
     else:
         return req.get('id', 'ERROR')
Beispiel #26
0
 def ticker(self):
     return pywaves.wrapper('/api/ticker/%s/%s' % (self.a1, self.a2), host=pywaves.DATAFEED)
Beispiel #27
0
 def orderbook(self):
     req = pywaves.wrapper('/matcher/orderbook/%s/%s' % (self.a1, self.a2), host=pywaves.MATCHER)
     return req
Beispiel #28
0
 def _getMarketData(self, method, params):
     return pywaves.wrapper('%s/%s/%s/%s' % (method, self.a1, self.a2, params), host=pywaves.DATAFEED)
Beispiel #29
0
    tx += value

randm64 = os.urandom(64)
sign = curve.calculateSignature(randm64, k_pr, tx)
#print(b58encode(sign))
#sign = crypto.sign(b58encode(k_pr), tx)
#print(sign)

#print('result')
#print(b58encode(tx + sign))

data = json.dumps({
    "senderPublicKey": b58encode(k_pub),
    "recipient": '3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8',
    "amount": 300000000,
    "fee": 100000,
    "timestamp": int(time.time() * 1000),
    "attachment": '2VfUX',
    "signature": b58encode(sign)
})
#print(data)
#pywaves.wrapper('/assets/broadcast/transfer', postData=data, host='https://testnode4.wavesnodes.com')
#myAddress.sendWaves(recipient = pywaves.Address('3NBVqYXrapgJP9atQccdBPAgJPwHDKkh6A8'), amount = 500000000)

print(
    pywaves.wrapper('/addresses/balance/%s%s' %
                    (b58encode(address), ''))['balance'])
print(
    pywaves.wrapper('/assets/broadcast/transfer',
                    postData=data,
                    host='https://testnode4.wavesnodes.com'))
Beispiel #30
0
 def aliases(self):
     a = pywaves.wrapper('/alias/by-address/%s' % self.address)
     if type(a) == list:
         for i in range(len(a)):
             a[i] = a[i][8:]
     return a