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 Oct 27, 2017
1 parent 58f28fa commit 070ed7b
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 72 deletions.
80 changes: 70 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ __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)` issue a new asset
`issueAsset(name, description, quantity, decimals=0, reissuable=False, txFee=DEFAULT_ASSET_FEE, timestamp)` issue a new asset

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

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

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

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

`cancelOrder(assetPair, order)` cancel an order

`buy(assetPair, amount price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE)` post a buy order
`buy(assetPair, amount price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp)` 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)` post a sell order
`sell(assetPair, amount, price, maxLifetime=30*86400, matcherFee=DEFAULT_MATCHER_FEE, timestamp)` post a sell order

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

`leaseCancel(leaseId, txFee=DEFAULT_LEASE_FEE)` cancel a lease
`leaseCancel(leaseId, txFee=DEFAULT_LEASE_FEE, timestamp)` 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)` create alias
`createAlias(alias, txFee=DEFAULT_ALIAS_FEE, timestamp)` create alias

### Asset Class
__pywaves.Asset(assetId)__ _Creates a new Asset object_
Expand Down Expand Up @@ -134,6 +134,12 @@ __pywaves.Order(orderId, assetPair, address='')__ Creates a new Order object
## Other functions
`pywaves.setNode(node, chain)` set node URL ('http://ip-address:port') and chain (either 'mainnet' or 'testnet')

`pywaves.setChain(chain)` set chain (either 'mainnet' or 'testnet')

`pywaves.setOffline()` switch to offline mode; sign tx locally without broadcasting to network

`pywaves.setOnline()` switch to online mode; sign tx locally a broadcast to network

`pywaves.setMatcher(node)` set matcher URL ('http://ip-address:port')

`pywaves.setDatafeed(node)` set datafeed URL ('http://ip-address:port')
Expand Down Expand Up @@ -417,6 +423,60 @@ sender.publicKey = EYNuSmW4Adtcc6AMCZyxkiHMPmF2BZ2XxvjpBip3UFZL
matcher = http://127.0.0.1:6886
```

### Offline signing and custom timestamps

#### Offline signing a future transaction:
```
>>> import pywaves as pw
>>> pw.setOffline()
>>> myAddress=pw.Address(privateKey="F2jVbjrKzjUsZ1AQRdnd8MmxFc85NQz5jwvZX4BXswXv")
>>> recipient=pw.Address("3P8Ya6Ary5gzwnzbBXDp3xjeNG97JEiPcdA")
# sign a future tx to transfer 100 WAVES to recipient
# the tx is valid on Jan 1st, 2020 12:00pm
>>> myAddress.sendWaves(recipient, amount=100e8, timestamp=1577880000000)
{'api-endpoint': '/assets/broadcast/transfer',
'api-type': 'POST',
'api-data': '{"fee": 100000,
"timestamp": 1577880000000,
"senderPublicKey": "27zdzBa1q46RCMamZ8gw2xrTGypZnbzXs5J1Y2HbUmEv",
"amount": 10000000000,
"attachment": "",
"recipient": "3P8Ya6Ary5gzwnzbBXDp3xjeNG97JEiPcdA"
"signature": "YetPopTJWC4WBPXbneWv9g6YEp6J9g9rquZWjewjdQnFbmaxtXjrRsUu69NZzHebVzUGLrhQiFFoguXJwdUn8BH"}'}
```

#### Offline signing time lock/unlock transactions:
```
>>> import pywaves as pw
>>> pw.setOffline()
>>> myAddress=pw.Address(privateKey="F2jVbjrKzjUsZ1AQRdnd8MmxFc85NQz5jwvZX4BXswXv")
# generate a lockbox address
>>> lockAddress=pw.Address()
# sign the 'lock' tx to send 100e8 to the lockbox (valid on Nov 1st, 2017)
>>> myAddress.sendWaves(lockAddress, 100e8, timestamp=1509537600000)
{'api-endpoint': '/assets/broadcast/transfer',
'api-type': 'POST',
'api-data': '{"fee": 100000,
"timestamp": 1509537600000,
"senderPublicKey": "27zdzBa1q46RCMamZ8gw2xrTGypZnbzXs5J1Y2HbUmEv",
"amount": 10000000000,
"attachment": "",
"recipient": "3P3UbyQM9W7WzTgjYkLuBrPZZeWsiUtCcpv",
"signature": "5VgT6qWxJwxEyrxFNfsi67QqbyUiGq9Ka7HVzgovRTTDT8nLRyuQv2wBAJQhRiXDkTTV6zsQmHnBkh8keCaFPoNT"}'}
# sign the 'unlock' tx to send funds back to myAddress (valid on Jan 1st, 2020)
>>> lockAddress.sendWaves(myAddress, 100e8-200000, txFee=200000, timestamp=1577880000000)
{'api-endpoint': '/assets/broadcast/transfer',
'api-type': 'POST',
'api-data': '{"fee": 200000,
"timestamp": 1577880000000,
"senderPublicKey": "52XnBGnAVZmw1CHo9aJPiMsVMiTWeNGSNN9aYJ7cDtx4",
"amount": 9999800000,
"attachment": "",
"recipient": "3P7tfdCaTyYCfg5ojxNahEJDSS4MZ7ybXBY",
"signature": "3beyz1sqKefP96LaXWT3CxdPRW86DAxcj6wgWPyyKq3SgdotVqnKyWXDyeHnBzCq1nC7JA9CChTmo1c1iVAv6C4T"}'}
# delete lockbox address and private key
>>> del lockAddress
```

## Connecting to a different node or chain

Expand Down
31 changes: 24 additions & 7 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
MAX_WDF_REQUEST = 100

import requests
import threading

from .address import *
from .asset import *
from .order import *

OFFLINE = False
NODE = 'https://nodes.wavesnodes.com'
CHAIN = 'mainnet'
CHAIN_ID = 'W'
Expand All @@ -41,16 +41,28 @@
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)

def setNode(node = NODE, chain = CHAIN):
global NODE, CHAIN, CHAIN_ID
NODE = node

def setOffline():
global OFFLINE
OFFLINE = True

def setOnline():
global OFFLINE
OFFLINE = False

def setChain(chain = CHAIN):
global CHAIN, CHAIN_ID
if chain.lower()=='mainnet' or chain.lower()=='w':
CHAIN = 'mainnet'
CHAIN_ID = 'W'
else:
CHAIN = 'testnet'
CHAIN_ID = 'T'
logging.info('Connecting to %s node %s' % (CHAIN, NODE))

def setNode(node = NODE, chain = CHAIN):
global NODE, CHAIN, CHAIN_ID
NODE = node
setChain(chain)

def setMatcher(node = MATCHER):
global MATCHER, MATCHER_PUBLICKEY
Expand All @@ -67,6 +79,13 @@ def setDatafeed(wdf = DATAFEED):
logging.info('Setting datafeed %s ' % (DATAFEED))

def wrapper(api, postData='', host='', headers=''):
global OFFLINE
if OFFLINE:
offlineTx = {}
offlineTx['api-type'] = 'POST' if postData else 'GET'
offlineTx['api-endpoint'] = api
offlineTx['api-data'] = postData
return offlineTx
if not host:
host = NODE
if postData:
Expand Down Expand Up @@ -103,8 +122,6 @@ def symbols():
def markets():
return wrapper('/api/markets', host=DATAFEED)

setNode()
setMatcher()
WAVES = Asset('')


Loading

0 comments on commit 070ed7b

Please sign in to comment.