Skip to content

Commit de9c789

Browse files
committed
fix: merge problems and fixing unittests
2 parents 20a41e9 + d3ed3bf commit de9c789

File tree

4 files changed

+262
-27
lines changed

4 files changed

+262
-27
lines changed

bitsharesbase/objects.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,5 +454,46 @@ def __init__(self, *args, **kwargs):
454454
elif id == 2:
455455
data = Block_id_predicate(o[1])
456456
else:
457-
raise ValueError("Unknown {}".format(self.__class__.name))
457+
raise ValueError("Unknown {}".format(self.__class__.__name__))
458+
super().__init__(data, id)
459+
460+
461+
class LimitOrderAutoAction(Static_variant):
462+
def __init__(self, o):
463+
class Create_take_profit_order_action(GrapheneObject):
464+
def __init__(self, *args, **kwargs):
465+
kwargs.update(args[0])
466+
super().__init__(
467+
OrderedDict(
468+
[
469+
("fee_asset_id", ObjectId(kwargs["fee_asset_id"], "asset")),
470+
("spread_percent", Uint16(kwargs["spread_percent"])),
471+
("size_percent", Uint16(kwargs["size_percent"])),
472+
(
473+
"expiration_seconds",
474+
Uint32(kwargs["expiration_seconds"]),
475+
),
476+
("repeat", Bool(kwargs["repeat"])),
477+
("extensions", Set([])),
478+
]
479+
)
480+
)
481+
482+
id = o[0]
483+
if id == 0:
484+
data = Create_take_profit_order_action(o[1])
485+
else:
486+
raise ValueError("Unknown {}".format(self.__class__.__name__))
458487
super().__init__(data, id)
488+
489+
490+
class LimitOrderCreateExtensions(Extension):
491+
def NestedLimitOrderAutoAction(value):
492+
if value:
493+
return Array([LimitOrderAutoAction(o) for o in value])
494+
else:
495+
return None
496+
497+
sorted_options = [
498+
("on_fill", NestedLimitOrderAutoAction),
499+
]

bitsharesbase/operations.py

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
Worker_initializer,
4646
isArgsThisClass,
4747
AssertPredicate,
48+
LimitOrderAutoAction,
49+
LimitOrderCreateExtensions,
4850
)
4951
from .operationids import operations
5052

@@ -54,22 +56,6 @@
5456
class_namemap = {}
5557

5658

57-
class VirtualOperationException(Exception):
58-
pass
59-
60-
61-
class ChainParameters(NotImplementedError):
62-
pass
63-
64-
65-
class CustomRestriction(NotImplementedError):
66-
pass
67-
68-
69-
class VestingPolicy(NotImplementedError):
70-
pass
71-
72-
7359
def fill_classmaps():
7460
for name, ind in operations.items():
7561
classname = name[0:1].upper() + name[1:]
@@ -402,7 +388,10 @@ def __init__(self, *args, **kwargs):
402388
("min_to_receive", Asset(kwargs["min_to_receive"])),
403389
("expiration", PointInTime(kwargs["expiration"])),
404390
("fill_or_kill", Bool(kwargs["fill_or_kill"])),
405-
("extensions", Set([])),
391+
(
392+
"extensions",
393+
LimitOrderCreateExtensions(kwargs["extensions"]),
394+
),
406395
]
407396
)
408397
)
@@ -1532,4 +1521,104 @@ def __init__(self, *args, **kwargs):
15321521
)
15331522

15341523

1524+
class Liquidity_pool_update(GrapheneObject):
1525+
def __init__(self, *args, **kwargs):
1526+
if isArgsThisClass(self, args):
1527+
self.data = args[0].data
1528+
else:
1529+
if len(args) == 1 and len(kwargs) == 0:
1530+
kwargs = args[0]
1531+
1532+
if kwargs.get("taker_fee_percent"):
1533+
taker_fee_percent = Optional(Uint16(kwargs["taker_fee_percent"]))
1534+
else:
1535+
taker_fee_percent = Optional(None)
1536+
1537+
if kwargs.get("withdrawal_fee_percent"):
1538+
withdrawal_fee_percent = Optional(
1539+
Uint16(kwargs["withdrawal_fee_percent"])
1540+
)
1541+
else:
1542+
withdrawal_fee_percent = Optional(None)
1543+
1544+
super().__init__(
1545+
OrderedDict(
1546+
[
1547+
("fee", Asset(kwargs["fee"])),
1548+
("account", ObjectId(kwargs["account"], "account")),
1549+
("pool", ObjectId(kwargs["pool"], "liquidity_pool")),
1550+
("taker_fee_percent", taker_fee_percent),
1551+
("withdrawal_fee_percent", withdrawal_fee_percent),
1552+
("extensions", Set([])),
1553+
]
1554+
)
1555+
)
1556+
1557+
1558+
class Credit_deal_update(GrapheneObject):
1559+
def __init__(self, *args, **kwargs):
1560+
if isArgsThisClass(self, args):
1561+
self.data = args[0].data
1562+
else:
1563+
if len(args) == 1 and len(kwargs) == 0:
1564+
kwargs = args[0]
1565+
super().__init__(
1566+
OrderedDict(
1567+
[
1568+
("fee", Asset(kwargs["fee"])),
1569+
("account", ObjectId(kwargs["account"], "account")),
1570+
("deal_id", ObjectId(kwargs["deal_id"], "credit_deal")),
1571+
("auto_repay", Uint8(kwargs["auto_repay"])),
1572+
("extensions", Set([])),
1573+
]
1574+
)
1575+
)
1576+
1577+
1578+
class Limit_order_update(GrapheneObject):
1579+
def __init__(self, *args, **kwargs):
1580+
if isArgsThisClass(self, args):
1581+
self.data = args[0].data
1582+
else:
1583+
if len(args) == 1 and len(kwargs) == 0:
1584+
kwargs = args[0]
1585+
1586+
if kwargs.get("new_price"):
1587+
new_price = Optional(Price(kwargs["new_price"]))
1588+
else:
1589+
new_price = Optional(None)
1590+
1591+
if kwargs.get("delta_amount_to_sell"):
1592+
delta_amount_to_sell = Optional(Asset(kwargs["delta_amount_to_sell"]))
1593+
else:
1594+
delta_amount_to_sell = Optional(None)
1595+
1596+
if kwargs.get("new_expiration"):
1597+
new_expiration = Optional(PointInTime(kwargs["new_expiration"]))
1598+
else:
1599+
new_expiration = Optional(None)
1600+
1601+
if kwargs.get("on_fill"):
1602+
on_fill = Optional(
1603+
Array([LimitOrderAutoAction(o) for o in kwargs["on_fill"]])
1604+
)
1605+
else:
1606+
on_fill = Optional(None)
1607+
1608+
super().__init__(
1609+
OrderedDict(
1610+
[
1611+
("fee", Asset(kwargs["fee"])),
1612+
("seller", ObjectId(kwargs["seller"], "account")),
1613+
("order", ObjectId(kwargs["order"], "limit_order")),
1614+
("new_price", new_price),
1615+
("delta_amount_to_sell", delta_amount_to_sell),
1616+
("new_expiration", new_expiration),
1617+
("on_fill", on_fill),
1618+
("extensions", Set([])),
1619+
]
1620+
)
1621+
)
1622+
1623+
15351624
fill_classmaps()

tests/test_bitshares.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ def test_create_asset(self):
152152
self.assertEqual(op["symbol"], symbol)
153153
self.assertEqual(op["precision"], precision)
154154
self.assertEqual(
155-
op["common_options"]["max_supply"], int(max_supply * 10 ** precision)
155+
op["common_options"]["max_supply"], int(max_supply * 10**precision)
156156
)
157157
self.assertEqual(
158158
op["common_options"]["market_fee_percent"], int(market_fee_percent * 100)
159159
)
160160
self.assertEqual(
161161
op["common_options"]["max_market_fee"],
162-
int(max_market_fee * 10 ** precision),
162+
int(max_market_fee * 10**precision),
163163
)
164164
self.assertEqual(op["common_options"]["description"], description)
165165
self.assertEqual(
@@ -211,7 +211,7 @@ def test_allow(self):
211211
op = tx["operations"][0][1]
212212
self.assertIn("owner", op)
213213
self.assertIn(
214-
["BTS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", "1"],
214+
["BTS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", 1],
215215
op["owner"]["key_auths"],
216216
)
217217
self.assertEqual(op["owner"]["weight_threshold"], 1)

tests/test_transactions.py

Lines changed: 111 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,29 @@ def test_limit_order_create(self):
8383
"min_to_receive": {"amount": 10000, "asset_id": "1.3.105"},
8484
"expiration": "2016-05-18T09:22:05",
8585
"fill_or_kill": False,
86-
"extensions": [],
86+
"extensions": {
87+
"on_fill": [
88+
[
89+
0,
90+
{
91+
"fee_asset_id": "1.3.0",
92+
"spread_percent": 100,
93+
"size_percent": 1000,
94+
"expiration_seconds": 3600,
95+
"repeat": True,
96+
"extensions": [],
97+
},
98+
]
99+
]
100+
},
87101
}
88102
)
89103
self.cm = (
90-
"f68585abf4dce7c8045701016400000000000000001da08601000"
91-
"0000000001027000000000000693d343c57000000011f75cbfd49"
92-
"ae8d9b04af76cc0a7de8b6e30b71167db7fe8e2197ef9d858df18"
93-
"77043493bc24ffdaaffe592357831c978fd8a296b913979f106de"
94-
"be940d60d77b50"
104+
"f68585abf4dce7c8045701016400000000000000001da0860100000"
105+
"00000001027000000000000693d343c570001000100006400e80310"
106+
"0e0000010000011f5ddffd232fd713e106aec3068646f5a74ae145e"
107+
"08e1e13f7464885a507e808e365594f5e7c14049d9432bcf1ca2330"
108+
"a65d1b7ab88aa08b355970ca6f23e06aa0"
95109
)
96110
self.doit()
97111

@@ -1292,6 +1306,97 @@ def test_credit_deal_expired(self):
12921306
)
12931307
self.doit()
12941308

1309+
def test_limit_order_update(self):
1310+
self.op = operations.Limit_order_update(
1311+
**{
1312+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1313+
"seller": "1.2.4",
1314+
"order": "1.7.12535",
1315+
"extensions": [],
1316+
}
1317+
)
1318+
self.cm = (
1319+
"f68585abf4dce7c80457014d00000000000000000004f76100"
1320+
"0000000000011f06d0b4467a5916ffb3d8ef4261c0719b1fb0"
1321+
"964aa5d3fbecbfbcbc9fe1117bc20e8a2c3f87e7817b83446c"
1322+
"45deb2a0d3d5b8b0d3b22fc8076ffc8eeb1a95e928"
1323+
)
1324+
self.doit(0)
1325+
1326+
self.op = operations.Limit_order_update(
1327+
**{
1328+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1329+
"seller": "1.2.4",
1330+
"order": "1.7.12535",
1331+
"new_price": {
1332+
"base": {"amount": 1123456, "asset_id": "1.3.0"},
1333+
"quote": {"amount": 78901122, "asset_id": "1.3.0"},
1334+
},
1335+
"delta_amount_to_sell": {"amount": 12562, "asset_id": "1.3.0"},
1336+
"new_expiration": "2023-12-18T09:22:05",
1337+
"on_fill": [
1338+
[
1339+
0,
1340+
{
1341+
"fee_asset_id": "1.3.0",
1342+
"spread_percent": 100,
1343+
"size_percent": 1000,
1344+
"expiration_seconds": 3600,
1345+
"repeat": True,
1346+
"extensions": [],
1347+
},
1348+
]
1349+
],
1350+
"extensions": [],
1351+
}
1352+
)
1353+
self.cm = (
1354+
"f68585abf4dce7c80457014d00000000000000000004f76101"
1355+
"80241100000000000082efb304000000000001123100000000"
1356+
"000000013d0f8065010100006400e803100e00000100000001"
1357+
"2051a24fb550e4a8ec890ad404ea0e3cf6ea449d6ba397d280"
1358+
"64f7129153dd013e27846eb6567a88d8eea7557f32ddc02cdc"
1359+
"a614c5a30130c83141c4050ffc50e2"
1360+
)
1361+
self.doit()
1362+
1363+
def test_liquidity_pool_update(self):
1364+
self.op = operations.Liquidity_pool_update(
1365+
**{
1366+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1367+
"account": "1.2.4",
1368+
"pool": "1.19.13356",
1369+
"taker_fee_percent": 124,
1370+
"withdrawal_fee_percent": 125,
1371+
"extensions": [],
1372+
}
1373+
)
1374+
self.cm = (
1375+
"f68585abf4dce7c80457014b00000000000000000004ac6801"
1376+
"7c00017d00000001202e3f140515ce936020348f845a4c034b"
1377+
"164441049dfe0a59a6c0fe27cbef740c10fa0d315e14e77e62"
1378+
"d8dae4f45d95fef358ff79f5304a420d6fc13abfd9374b"
1379+
)
1380+
self.doit(0)
1381+
1382+
def test_credit_deal_update(self):
1383+
self.op = operations.Credit_deal_update(
1384+
**{
1385+
"fee": {"amount": 0, "asset_id": "1.3.0"},
1386+
"account": "1.2.4",
1387+
"deal_id": "1.22.2356",
1388+
"auto_repay": 24,
1389+
"extensions": [],
1390+
}
1391+
)
1392+
self.cm = (
1393+
"f68585abf4dce7c80457014c00000000000000000004b41218"
1394+
"0000012026b59b7796cb9ca40d92b1d339558a94aa9f70d2f6"
1395+
"d8a7b8b0155c943b89bd602a1ecc9df3143664f801f401a728"
1396+
"78cce9f064dbcfc1af65826ce68a2177a38d"
1397+
)
1398+
self.doit()
1399+
12951400
def compareConstructedTX(self):
12961401
self.maxDiff = None
12971402
self.op = operations.Call_order_update(

0 commit comments

Comments
 (0)