Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PyWaves authored Mar 24, 2017
1 parent fcd026f commit a125d01
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 16 deletions.
32 changes: 30 additions & 2 deletions address.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,12 @@ def sendAsset(self, recipient, asset, amount, attachment='', txFee=pywaves.DEFAU
def _postOrder(self, amountAsset, priceAsset, orderType, price, amount, maxLifetime=30*86400, matcherFee=pywaves.DEFAULT_MATCHER_FEE):
timestamp = int(time.time() * 1000) -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) + \
b'\1' + base58.b58decode(amountAsset.assetId) + \
b'\1' + base58.b58decode(priceAsset.assetId) + \
asset1 + \
asset2 + \
orderType + \
struct.pack(">Q", price) + \
struct.pack(">Q", amount) + \
Expand Down Expand Up @@ -535,4 +537,30 @@ def leaseCancel(self, leaseId, txFee=pywaves.DEFAULT_LEASE_FEE):
if 'leaseId' in req:
return req['leaseId']

def createAlias(self, alias, 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'\x0A' + \
base58.b58decode(self.publicKey) + \
struct.pack(">H", len(alias)) + \
crypto.str2bytes(alias) + \
struct.pack(">Q", txFee) + \
struct.pack(">Q", timestamp) + \
base58.b58decode(leaseId)
signature = crypto.sign(self.privateKey, sData)
data = json.dumps({
"senderPublicKey": self.publicKey,
"alias": alias,
"fee": txFee,
"timestamp": timestamp,
"signature": signature
})
print data
req = pywaves.wrapper('/alias/broadcast/create', data)
print req


35 changes: 21 additions & 14 deletions asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

class Asset(object):
def __init__(self, assetId):
self.assetId = assetId
self.assetId='' if assetId == 'WAVES' else assetId
self.issuer = self.name = self.description = ''
self.quantity = self.decimals = 0
self.reissuable = False
self.status()
if self.assetId=='':
self.quantity=100000000e8
self.decimals=8
else:
self.status()

def __str__(self):
return 'status = %s\n' \
Expand All @@ -21,18 +25,19 @@ def __str__(self):
__repr__ = __str__

def status(self):
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']
self.description = req['description']
return 'Issued'
except:
pass
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']
self.description = req['description']
return 'Issued'
except:
pass

class AssetPair(object):
def __init__(self, asset1, asset2):
Expand Down Expand Up @@ -64,3 +69,5 @@ def second(self):
return self.asset1

__repr__ = __str__

WAVES = Asset('')

0 comments on commit a125d01

Please sign in to comment.