address.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:PyWaves 作者: PyWaves 项目源码 文件源码
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,
                "fee": txFee,
                "timestamp": timestamp,
                "attachment": base58.b58encode(crypto.str2bytes(attachment)),
                "signature": signature
            })
            return pywaves.wrapper('/assets/broadcast/transfer', data)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号