Skip to content

Commit 8a3b595

Browse files
committed
Merge branch 'release/0.3.2'
2 parents 1946721 + 73323fb commit 8a3b595

File tree

11 files changed

+132
-26
lines changed

11 files changed

+132
-26
lines changed

bitshares/asset.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def max_market_fee(self):
5555
from .amount import Amount
5656

5757
return Amount(
58-
{"amount": self["options"]["max_market_fee"], "asset_id": self["id"]}
58+
{"amount": self["options"]["max_market_fee"], "asset_id": self["id"]},
59+
blockchain_instance=self.blockchain,
5960
)
6061

6162
@property
@@ -222,10 +223,12 @@ def release(
222223
{
223224
"flags": flags_int,
224225
"whitelist_authorities": [
225-
Account(a)["id"] for a in whitelist_authorities
226+
Account(a, blockchain_instance=self.blockchain)["id"]
227+
for a in whitelist_authorities
226228
],
227229
"blacklist_authorities": [
228-
Account(a)["id"] for a in blacklist_authorities
230+
Account(a, blockchain_instance=self.blockchain)["id"]
231+
for a in blacklist_authorities
229232
],
230233
"whitelist_markets": [Asset(a)["id"] for a in whitelist_markets],
231234
"blacklist_markets": [Asset(a)["id"] for a in blacklist_markets],
@@ -330,11 +333,17 @@ def add_authorities(self, type, authorities=[]):
330333
options = self["options"]
331334
if type == "whitelist":
332335
options["whitelist_authorities"].extend(
333-
[Account(a)["id"] for a in authorities]
336+
[
337+
Account(a, blockchain_instance=self.blockchain)["id"]
338+
for a in authorities
339+
]
334340
)
335341
if type == "blacklist":
336342
options["blacklist_authorities"].extend(
337-
[Account(a)["id"] for a in authorities]
343+
[
344+
Account(a, blockchain_instance=self.blockchain)["id"]
345+
for a in authorities
346+
]
338347
)
339348
op = operations.Asset_update(
340349
**{
@@ -360,10 +369,14 @@ def remove_authorities(self, type, authorities=[]):
360369
options = self["options"]
361370
if type == "whitelist":
362371
for a in authorities:
363-
options["whitelist_authorities"].remove(Account(a)["id"])
372+
options["whitelist_authorities"].remove(
373+
Account(a, blockchain_instance=self.blockchain)["id"]
374+
)
364375
if type == "blacklist":
365376
for a in authorities:
366-
options["blacklist_authorities"].remove(Account(a)["id"])
377+
options["blacklist_authorities"].remove(
378+
Account(a, blockchain_instance=self.blockchain)["id"]
379+
)
367380
op = operations.Asset_update(
368381
**{
369382
"fee": {"amount": 0, "asset_id": "1.3.0"},
@@ -396,9 +409,19 @@ def add_markets(self, type, authorities=[], force_enable=True):
396409
), "whitelist feature not enabled"
397410

398411
if type == "whitelist":
399-
options["whitelist_markets"].extend([Asset(a)["id"] for a in authorities])
412+
options["whitelist_markets"].extend(
413+
[
414+
Asset(a, blockchain_instance=self.blockchain)["id"]
415+
for a in authorities
416+
]
417+
)
400418
if type == "blacklist":
401-
options["blacklist_markets"].extend([Asset(a)["id"] for a in authorities])
419+
options["blacklist_markets"].extend(
420+
[
421+
Asset(a, blockchain_instance=self.blockchain)["id"]
422+
for a in authorities
423+
]
424+
)
402425
op = operations.Asset_update(
403426
**{
404427
"fee": {"amount": 0, "asset_id": "1.3.0"},
@@ -422,10 +445,14 @@ def remove_markets(self, type, authorities=[]):
422445
options = self["options"]
423446
if type == "whitelist":
424447
for a in authorities:
425-
options["whitelist_markets"].remove(Asset(a)["id"])
448+
options["whitelist_markets"].remove(
449+
Asset(a, blockchain_instance=self.blockchain)["id"]
450+
)
426451
if type == "blacklist":
427452
for a in authorities:
428-
options["blacklist_markets"].remove(Asset(a)["id"])
453+
options["blacklist_markets"].remove(
454+
Asset(a, blockchain_instance=self.blockchain)["id"]
455+
)
429456
op = operations.Asset_update(
430457
**{
431458
"fee": {"amount": 0, "asset_id": "1.3.0"},
@@ -481,7 +508,10 @@ def update_feed_producers(self, producers):
481508
"fee": {"amount": 0, "asset_id": "1.3.0"},
482509
"issuer": self["issuer"],
483510
"asset_to_update": self["id"],
484-
"new_feed_producers": [Account(a)["id"] for a in producers],
511+
"new_feed_producers": [
512+
Account(a, blockchain_instance=self.blockchain)["id"]
513+
for a in producers
514+
],
485515
"extensions": [],
486516
}
487517
)
@@ -495,7 +525,7 @@ def change_issuer(self, new_issuer, **kwargs):
495525
"""
496526
from .account import Account
497527

498-
new_issuer = Account(new_issuer)
528+
new_issuer = Account(new_issuer, blockchain_instance=self.blockchain)
499529
op = operations.Asset_update_issuer(
500530
**{
501531
"fee": {"amount": 0, "asset_id": "1.3.0"},
@@ -517,9 +547,11 @@ def issue(self, amount, to, memo=None, **kwargs):
517547
from .memo import Memo
518548
from .account import Account
519549

520-
to = Account(to)
550+
to = Account(to, blockchain_instance=self.blockchain)
521551
account = Account(self["issuer"])
522-
memoObj = Memo(from_account=account, to_account=to, blockchain_instance=self)
552+
memoObj = Memo(
553+
from_account=account, to_account=to, blockchain_instance=self.blockchain
554+
)
523555

524556
# append operation
525557
op = operations.Asset_issue(
@@ -538,4 +570,4 @@ def issue(self, amount, to, memo=None, **kwargs):
538570
"extensions": [],
539571
}
540572
)
541-
return self.exbet.finalizeOp(op, self["issuer"], "active", **kwargs)
573+
return self.blockchain.finalizeOp(op, self["issuer"], "active", **kwargs)

bitshares/instance.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# -*- coding: utf-8 -*-
2-
from graphenecommon.instance import AbstractBlockchainInstanceProvider, SharedInstance
2+
from graphenecommon.instance import AbstractBlockchainInstanceProvider
3+
4+
5+
class SharedInstance:
6+
""" This class merely offers a singelton for the Blockchain Instance
7+
"""
8+
9+
instance = None
10+
config = {}
311

412

513
class BlockchainInstance(AbstractBlockchainInstanceProvider):
614
""" This is a class that allows compatibility with previous
715
naming conventions
816
"""
917

18+
_sharedInstance = SharedInstance
19+
1020
def __init__(self, *args, **kwargs):
1121
# Also allow 'bitshares_instance'
1222
if kwargs.get("bitshares_instance"):
@@ -33,11 +43,12 @@ def shared_blockchain_instance():
3343

3444
def set_shared_blockchain_instance(instance):
3545
instance.clear_cache()
36-
instance.set_shared_instance()
46+
# instance.set_shared_instance()
47+
BlockchainInstance.set_shared_blockchain_instance(instance)
3748

3849

3950
def set_shared_config(config):
40-
shared_blockchain_instance().set_shared_config(config)
51+
BlockchainInstance.set_shared_config(config)
4152

4253

4354
shared_bitshares_instance = shared_blockchain_instance

bitshares/market.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def buy(
505505

506506
tx = self.blockchain.finalizeOp(order, account["name"], "active", **kwargs)
507507

508-
if returnOrderId:
508+
if returnOrderId and tx.get("operation_results"):
509509
tx["orderid"] = tx["operation_results"][0][1]
510510
self.blockchain.blocking = prevblocking
511511

bitsharesapi/bitsharesnoderpc.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import re
23

34
from bitsharesbase.chains import known_chains
@@ -35,7 +36,9 @@ def get_network(self):
3536
for k, v in known_chains.items():
3637
if v["chain_id"] == chain_id:
3738
return v
38-
raise Exception("Connecting to unknown network!")
39+
raise exceptions.UnknownNetworkException(
40+
"Connecting to unknown network (chain_id: {})!".format(props["chain_id"])
41+
)
3942

4043
def get_account(self, name, **kwargs):
4144
""" Get full account details from account name or id

bitsharesapi/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
import re
23

34
from grapheneapi.exceptions import RPCError
@@ -48,3 +49,10 @@ class AccountCouldntBeFoundException(Exception):
4849

4950
class InvalidAccountNameException(Exception):
5051
pass
52+
53+
54+
class UnknownNetworkException(Exception):
55+
""" Thrown when we don't recognize the chain id
56+
"""
57+
58+
pass

bitsharesbase/operationids.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
#: Operation ids
23
ops = [
34
"transfer",
@@ -65,3 +66,18 @@ def getOperationNameForId(i):
6566
if int(operations[key]) is int(i):
6667
return key
6768
return "Unknown Operation ID %d" % i
69+
70+
71+
def getOperationName(id: str):
72+
""" This method returns the name representation of an operation given
73+
its value as used in the API
74+
"""
75+
if isinstance(id, str):
76+
# Some graphene chains (e.g. steem) do not encode the
77+
# operation_type as id but in its string form
78+
assert id in operations.keys(), "Unknown operation {}".format(id)
79+
return id
80+
elif isinstance(id, int):
81+
return getOperationNameForId(id)
82+
else:
83+
raise ValueError

bitsharesbase/operations.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,21 @@ def detail(self, *args, **kwargs):
911911
)
912912

913913

914+
class Balance_claim(GrapheneObject):
915+
def detail(self, *args, **kwargs):
916+
# New pygraphene interface!
917+
prefix = kwargs.pop("prefix", default_prefix)
918+
return OrderedDict(
919+
[
920+
("fee", Asset(kwargs["fee"])),
921+
("deposit_to_account", ObjectId(kwargs["deposit_to_account"], "account")),
922+
("balance_to_claim", ObjectId(kwargs["balance_to_claim"], "balance")),
923+
("balance_owner_key", PublicKey(kwargs["balance_owner_key"], prefix=prefix)),
924+
("total_claimed", Asset(kwargs["total_claimed"])),
925+
]
926+
)
927+
928+
914929
class Asset_settle(GrapheneObject):
915930
def detail(self, *args, **kwargs):
916931
# New pygraphene interface!

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
graphenelib==1.1.12
1+
graphenelib==1.1.14
22
bitshares==0.3.0
33
autobahn>=0.14
44
pycryptodome==3.8.0

requirements-test.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Unit testing
2-
pytest==4.3.1
3-
pytest-mock==1.10.2
2+
pytest==4.4.0
3+
pytest-mock==1.10.3
44
coverage==4.5.3
55
mock==2.0.0
66

77
# Code style
88
flake8==3.7.7
99
# black
1010
isort==4.3.16
11-
pre-commit==1.14.4
11+
pre-commit==1.15.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ascii = codecs.lookup("ascii")
1414
codecs.register(lambda name, enc=ascii: {True: enc}.get(name == "mbcs"))
1515

16-
VERSION = "0.3.1"
16+
VERSION = "0.3.2"
1717
URL = "https://github.com/bitshares/python-bitshares"
1818

1919
setup(

tests/test_transactions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ def test_bid_collateral(self):
515515
)
516516
self.doit()
517517

518+
def test_balance_claim(self):
519+
self.op = operations.Balance_claim(
520+
**{
521+
"fee": {"amount": 0, "asset_id": "1.3.0"},
522+
"deposit_to_account": "1.2.121",
523+
"balance_to_claim": "1.15.0",
524+
"balance_owner_key": "BTS7YFfmNBLpcrhe7hf39NLQfgBjGvtYBtAAc4nDvZKWxVQjF4CeL",
525+
"total_claimed": {"amount": 229174, "asset_id": "1.3.0"},
526+
"prefix": prefix,
527+
}
528+
)
529+
self.cm = (
530+
"f68585abf4dce7c8045701250000000000000000007900035d2"
531+
"3de4ecd631e7aae2ec37ace7da12ffceea9fae1722ff4c8fa04"
532+
"2ba9ecd3c2367f03000000000000000120056c75aa663a9bc3f"
533+
"8d8806c0c32b820d539ee938684b581657a8179769f9f604c3d"
534+
"1b4d7dcdc04be31ea28722da45aace8f5b983cc1a5c5a42ca79"
535+
"751d4d0fa"
536+
)
537+
self.doit()
538+
518539
def test_asset_create(self):
519540
self.op = operations.Asset_create(
520541
**{

0 commit comments

Comments
 (0)