-
Notifications
You must be signed in to change notification settings - Fork 165
/
bitshares.py
1974 lines (1723 loc) · 75.3 KB
/
bitshares.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import logging
from datetime import datetime, timedelta
from graphenecommon.chain import AbstractGrapheneChain
from bitsharesapi.bitsharesnoderpc import BitSharesNodeRPC
from bitsharesbase import operations
from bitsharesbase.account import PublicKey
from bitsharesbase.asset_permissions import asset_permissions, toint
from .account import Account
from .amount import Amount
from .asset import Asset
from .committee import Committee
from .exceptions import AccountExistsException, KeyAlreadyInStoreException
from .instance import set_shared_blockchain_instance, shared_blockchain_instance
from .price import Price
from .storage import get_default_config_store
from .transactionbuilder import ProposalBuilder, TransactionBuilder
from .vesting import Vesting
from .wallet import Wallet
from .witness import Witness
from .worker import Worker
from .htlc import Htlc
# from .utils import formatTime
log = logging.getLogger(__name__)
class BitShares(AbstractGrapheneChain):
"""
Connect to the BitShares network.
:param str node: Node to connect to *(optional)*
:param str rpcuser: RPC user *(optional)*
:param str rpcpassword: RPC password *(optional)*
:param bool nobroadcast: Do **not** broadcast a transaction!
*(optional)*
:param bool debug: Enable Debugging *(optional)*
:param array,dict,string keys: Predefine the wif keys to shortcut the
wallet database *(optional)*
:param bool offline: Boolean to prevent connecting to network (defaults
to ``False``) *(optional)*
:param str proposer: Propose a transaction using this proposer
*(optional)*
:param int proposal_expiration: Expiration time (in seconds) for the
proposal *(optional)*
:param int proposal_review: Review period (in seconds) for the proposal
*(optional)*
:param int expiration: Delay in seconds until transactions are supposed
to expire *(optional)*
:param str blocking: Wait for broadcasted transactions to be included
in a block and return full transaction (can be "head" or
"irrversible")
:param bool bundle: Do not broadcast transactions right away, but allow
to bundle operations *(optional)*
Three wallet operation modes are possible:
* **Wallet Database**: Here, the bitshareslibs load the keys from the
locally stored wallet SQLite database (see ``storage.py``).
To use this mode, simply call ``BitShares()`` without the
``keys`` parameter
* **Providing Keys**: Here, you can provide the keys for
your accounts manually. All you need to do is add the wif
keys for the accounts you want to use as a simple array
using the ``keys`` parameter to ``BitShares()``.
* **Force keys**: This more is for advanced users and
requires that you know what you are doing. Here, the
``keys`` parameter is a dictionary that overwrite the
``active``, ``owner``, or ``memo`` keys for
any account. This mode is only used for *foreign*
signatures!
If no node is provided, it will connect to the node of
http://uptick.rocks. It is **highly** recommended that you
pick your own node instead. Default settings can be changed with:
.. code-block:: python
uptick set node <host>
where ``<host>`` starts with ``ws://`` or ``wss://``.
The purpose of this class it to simplify interaction with
BitShares.
The idea is to have a class that allows to do this:
.. code-block:: python
from bitshares import BitShares
bitshares = BitShares()
print(bitshares.info())
All that is requires is for the user to have added a key with
``uptick``
.. code-block:: bash
uptick addkey
and setting a default author:
.. code-block:: bash
uptick set default_account xeroc
This class also deals with edits, votes and reading content.
"""
def define_classes(self):
from .blockchainobject import BlockchainObject
self.wallet_class = Wallet
self.account_class = Account
self.rpc_class = BitSharesNodeRPC
self.default_key_store_app_name = "bitshares"
self.proposalbuilder_class = ProposalBuilder
self.transactionbuilder_class = TransactionBuilder
self.blockchainobject_class = BlockchainObject
# -------------------------------------------------------------------------
# Simple Transfer
# -------------------------------------------------------------------------
def transfer(self, to, amount, asset, memo="", account=None, **kwargs):
"""
Transfer an asset to another account.
:param str to: Recipient
:param float amount: Amount to transfer
:param str asset: Asset to transfer
:param str memo: (optional) Memo, may begin with `#` for encrypted
messaging
:param str account: (optional) the source account for the transfer
if not ``default_account``
"""
from .memo import Memo
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
amount = Amount(amount, asset, blockchain_instance=self)
to = Account(to, blockchain_instance=self)
memoObj = Memo(from_account=account, to_account=to, blockchain_instance=self)
op = operations.Transfer(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"from": account["id"],
"to": to["id"],
"amount": {"amount": int(amount), "asset_id": amount.asset["id"]},
"memo": memoObj.encrypt(memo),
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account, "active", **kwargs)
# -------------------------------------------------------------------------
# Account related calls
# -------------------------------------------------------------------------
def _store_keys(self, *args):
for k in args:
try:
self.wallet.addPrivateKey(str(k))
except KeyAlreadyInStoreException:
pass
def create_account(
self,
account_name,
registrar=None,
referrer="1.2.35641",
referrer_percent=50,
owner_key=None,
active_key=None,
memo_key=None,
owner_account=None,
active_account=None,
password=None,
additional_owner_keys=None,
additional_active_keys=None,
additional_owner_accounts=None,
additional_active_accounts=None,
proxy_account="proxy-to-self",
storekeys=True,
**kwargs
):
"""
Create new account on BitShares.
The brainkey/password can be used to recover all generated keys
(see `bitsharesbase.account` for more details.
By default, this call will use ``default_account`` to
register a new name ``account_name`` with all keys being
derived from a new brain key that will be returned. The
corresponding keys will automatically be installed in the
wallet.
.. warning:: Don't call this method unless you know what
you are doing! Be sure to understand what this
method does and where to find the private keys
for your account.
.. note:: Please note that this imports private keys
(if password is present) into the wallet by
default. However, it **does not import the owner
key** for security reasons. Do NOT expect to be
able to recover it from the wallet if you lose
your password!
:param str account_name: (**required**) new account name
:param str registrar: which account should pay the registration fee
(defaults to ``default_account``)
:param str owner_key: Main owner key
:param str active_key: Main active key
:param str memo_key: Main memo_key
:param str password: Alternatively to providing keys, one
can provide a password from which the
keys will be derived
:param array additional_owner_keys: Additional owner public keys
:param array additional_active_keys: Additional active public keys
:param array additional_owner_accounts: Additional owner account
names
:param array additional_active_accounts: Additional acctive account
names
:param bool storekeys: Store new keys in the wallet (default:
``True``)
:raises AccountExistsException: if the account already exists on
the blockchain
"""
if not registrar and self.config["default_account"]:
registrar = self.config["default_account"]
if not registrar:
raise ValueError(
"Not registrar account given. Define it with "
+ "registrar=x, or set the default_account using uptick"
)
if password and (owner_key or active_key or memo_key):
raise ValueError("You cannot use 'password' AND provide keys!")
if additional_owner_keys is None:
additional_owner_keys = []
if additional_active_keys is None:
additional_active_keys = []
if additional_owner_accounts is None:
additional_owner_accounts = []
if additional_active_accounts is None:
additional_active_accounts = []
try:
Account(account_name, blockchain_instance=self)
raise AccountExistsException
except Exception:
pass
referrer = Account(referrer, blockchain_instance=self)
registrar = Account(registrar, blockchain_instance=self)
" Generate new keys from password"
from bitsharesbase.account import PasswordKey, PublicKey
owner_key_authority = []
active_key_authority = []
owner_accounts_authority = []
active_accounts_authority = []
if password:
active_key = PasswordKey(account_name, password, role="active")
owner_key = PasswordKey(account_name, password, role="owner")
memo_key = PasswordKey(account_name, password, role="memo")
active_pubkey = active_key.get_public_key()
owner_pubkey = owner_key.get_public_key()
memo_pubkey = memo_key.get_public_key()
active_privkey = active_key.get_private_key()
# owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()
# store private keys
if storekeys:
self._store_keys(active_privkey, memo_privkey)
owner_key_authority = [[format(owner_pubkey, self.prefix), 1]]
active_key_authority = [[format(active_pubkey, self.prefix), 1]]
memo = format(memo_pubkey, self.prefix)
elif owner_key and active_key and memo_key:
active_pubkey = PublicKey(active_key, prefix=self.prefix)
owner_pubkey = PublicKey(owner_key, prefix=self.prefix)
memo_pubkey = PublicKey(memo_key, prefix=self.prefix)
owner_key_authority = [[format(owner_pubkey, self.prefix), 1]]
active_key_authority = [[format(active_pubkey, self.prefix), 1]]
memo = format(memo_pubkey, self.prefix)
elif owner_account and active_account and memo_key:
memo_pubkey = PublicKey(memo_key, prefix=self.prefix)
memo = format(memo_pubkey, self.prefix)
owner_account = Account(owner_account, blockchain_instance=self)
active_account = Account(active_account, blockchain_instance=self)
owner_accounts_authority = [[owner_account["id"], 1]]
active_accounts_authority = [[active_account["id"], 1]]
else:
raise ValueError(
"Call incomplete! Provide either a password, owner/active public keys "
"or owner/active accounts + memo key!"
)
# additional authorities
for k in additional_owner_keys:
PublicKey(k, prefix=self.prefix)
owner_key_authority.append([k, 1])
for k in additional_active_keys:
PublicKey(k, prefix=self.prefix)
active_key_authority.append([k, 1])
for k in additional_owner_accounts:
addaccount = Account(k, blockchain_instance=self)
owner_accounts_authority.append([addaccount["id"], 1])
for k in additional_active_accounts:
addaccount = Account(k, blockchain_instance=self)
active_accounts_authority.append([addaccount["id"], 1])
# voting account
voting_account = Account(
proxy_account or "proxy-to-self", blockchain_instance=self
)
op = {
"fee": {"amount": 0, "asset_id": "1.3.0"},
"registrar": registrar["id"],
"referrer": referrer["id"],
"referrer_percent": int(referrer_percent * 100),
"name": account_name,
"owner": {
"account_auths": owner_accounts_authority,
"key_auths": owner_key_authority,
"address_auths": [],
"weight_threshold": 1,
},
"active": {
"account_auths": active_accounts_authority,
"key_auths": active_key_authority,
"address_auths": [],
"weight_threshold": 1,
},
"options": {
"memo_key": memo,
"voting_account": voting_account["id"],
"num_witness": 0,
"num_committee": 0,
"votes": [],
"extensions": [],
},
"extensions": {},
"prefix": self.prefix,
}
op = operations.Account_create(**op)
return self.finalizeOp(op, registrar, "active", **kwargs)
def upgrade_account(self, account=None, **kwargs):
"""
Upgrade an account to Lifetime membership.
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
op = operations.Account_upgrade(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account_to_upgrade": account["id"],
"upgrade_to_lifetime_member": True,
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def _test_weights_treshold(self, authority):
"""
This method raises an error if the threshold of an authority cannot be reached
by the weights.
:param dict authority: An authority of an account
:raises ValueError: if the threshold is set too high
"""
weights = 0
for a in authority["account_auths"]:
weights += int(a[1])
for a in authority["key_auths"]:
weights += int(a[1])
if authority["weight_threshold"] > weights:
raise ValueError("Threshold too restrictive!")
if authority["weight_threshold"] == 0:
raise ValueError("Cannot have threshold of 0")
def allow(
self,
foreign,
weight=None,
permission="active",
account=None,
threshold=None,
**kwargs
):
"""
Give additional access to an account by some other public key or account.
:param str foreign: The foreign account that will obtain access
:param int weight: (optional) The weight to use. If not
define, the threshold will be used. If the weight is
smaller than the threshold, additional signatures will
be required. (defaults to threshold)
:param str permission: (optional) The actual permission to
modify (defaults to ``active``)
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
:param int threshold: The threshold that needs to be reached
by signatures to be able to interact
"""
from copy import deepcopy
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
if permission not in ["owner", "active"]:
raise ValueError("Permission needs to be either 'owner', or 'active")
account = Account(account, blockchain_instance=self)
if not weight:
weight = account[permission]["weight_threshold"]
authority = deepcopy(account[permission])
try:
pubkey = PublicKey(foreign, prefix=self.prefix)
authority["key_auths"].append([str(pubkey), weight])
except Exception:
try:
foreign_account = Account(foreign, blockchain_instance=self)
authority["account_auths"].append([foreign_account["id"], weight])
except Exception:
raise ValueError("Unknown foreign account or invalid public key")
if threshold:
authority["weight_threshold"] = threshold
self._test_weights_treshold(authority)
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
permission: authority,
"extensions": {},
"prefix": self.prefix,
}
)
if permission == "owner":
return self.finalizeOp(op, account["name"], "owner", **kwargs)
else:
return self.finalizeOp(op, account["name"], "active", **kwargs)
def disallow(
self, foreign, permission="active", account=None, threshold=None, **kwargs
):
"""
Remove additional access to an account by some other public key or account.
:param str foreign: The foreign account that will obtain access
:param str permission: (optional) The actual permission to
modify (defaults to ``active``)
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
:param int threshold: The threshold that needs to be reached
by signatures to be able to interact
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
if permission not in ["owner", "active"]:
raise ValueError("Permission needs to be either 'owner', or 'active")
account = Account(account, blockchain_instance=self)
authority = account[permission]
try:
pubkey = PublicKey(foreign, prefix=self.prefix)
affected_items = list(
filter(lambda x: x[0] == str(pubkey), authority["key_auths"])
)
authority["key_auths"] = list(
filter(lambda x: x[0] != str(pubkey), authority["key_auths"])
)
except Exception:
try:
foreign_account = Account(foreign, blockchain_instance=self)
affected_items = list(
filter(
lambda x: x[0] == foreign_account["id"],
authority["account_auths"],
)
)
authority["account_auths"] = list(
filter(
lambda x: x[0] != foreign_account["id"],
authority["account_auths"],
)
)
except Exception:
raise ValueError("Unknown foreign account or unvalid public key")
if not affected_items:
raise ValueError("Changes nothing!")
removed_weight = affected_items[0][1]
# Define threshold
if threshold:
authority["weight_threshold"] = threshold
# Correct threshold (at most by the amount removed from the
# authority)
try:
self._test_weights_treshold(authority)
except Exception:
log.critical(
"The account's threshold will be reduced by %d" % (removed_weight)
)
authority["weight_threshold"] -= removed_weight
self._test_weights_treshold(authority)
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
permission: authority,
"extensions": {},
}
)
if permission == "owner":
return self.finalizeOp(op, account["name"], "owner", **kwargs)
else:
return self.finalizeOp(op, account["name"], "active", **kwargs)
def update_memo_key(self, key, account=None, **kwargs):
"""
Update an account's memo public key.
This method does **not** add any private keys to your
wallet but merely changes the memo public key.
:param str key: New memo public key
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
PublicKey(key, prefix=self.prefix)
account = Account(account, blockchain_instance=self)
account["options"]["memo_key"] = key
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": account["options"],
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
# -------------------------------------------------------------------------
# Approval and Disapproval of witnesses, workers, committee, and proposals
# -------------------------------------------------------------------------
def approvewitness(self, witnesses, account=None, **kwargs):
"""
Approve a witness.
:param list witnesses: list of Witness name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(witnesses, (list, set, tuple)):
witnesses = {witnesses}
for witness in witnesses:
witness = Witness(witness, blockchain_instance=self)
options["votes"].append(witness["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_witness"] = len(
list(filter(lambda x: float(x.split(":")[0]) == 1, options["votes"]))
)
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def disapprovewitness(self, witnesses, account=None, **kwargs):
"""
Disapprove a witness.
:param list witnesses: list of Witness name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(witnesses, (list, set, tuple)):
witnesses = {witnesses}
for witness in witnesses:
witness = Witness(witness, blockchain_instance=self)
if witness["vote_id"] in options["votes"]:
options["votes"].remove(witness["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_witness"] = len(
list(filter(lambda x: float(x.split(":")[0]) == 1, options["votes"]))
)
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def approvecommittee(self, committees, account=None, **kwargs):
"""
Approve a committee.
:param list committees: list of committee member name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(committees, (list, set, tuple)):
committees = {committees}
for committee in committees:
committee = Committee(committee, blockchain_instance=self)
options["votes"].append(committee["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_committee"] = len(
list(filter(lambda x: float(x.split(":")[0]) == 0, options["votes"]))
)
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def disapprovecommittee(self, committees, account=None, **kwargs):
"""
Disapprove a committee.
:param list committees: list of committee name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(committees, (list, set, tuple)):
committees = {committees}
for committee in committees:
committee = Committee(committee, blockchain_instance=self)
if committee["vote_id"] in options["votes"]:
options["votes"].remove(committee["vote_id"])
options["votes"] = list(set(options["votes"]))
options["num_committee"] = len(
list(filter(lambda x: float(x.split(":")[0]) == 0, options["votes"]))
)
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def approveproposal(self, proposal_ids, account=None, approver=None, **kwargs):
"""
Approve Proposal.
:param list proposal_id: Ids of the proposals
:param str appprover: The account or key to use for approval
(defaults to ``account``)
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
from .proposal import Proposal
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
is_key = approver and approver[:3] == self.prefix
if not approver and not is_key:
approver = account
elif approver and not is_key:
approver = Account(approver, blockchain_instance=self)
else:
approver = PublicKey(approver)
if not isinstance(proposal_ids, (list, set, tuple)):
proposal_ids = {proposal_ids}
op = []
for proposal_id in proposal_ids:
proposal = Proposal(proposal_id, blockchain_instance=self)
update_dict = {
"fee": {"amount": 0, "asset_id": "1.3.0"},
"fee_paying_account": account["id"],
"proposal": proposal["id"],
"prefix": self.prefix,
}
if is_key:
update_dict.update({"key_approvals_to_add": [str(approver)]})
else:
update_dict.update({"active_approvals_to_add": [approver["id"]]})
op.append(operations.Proposal_update(**update_dict))
if is_key:
self.txbuffer.appendSigner(approver, "active")
return self.finalizeOp(op, account["name"], "active", **kwargs)
return self.finalizeOp(op, approver, "active", **kwargs)
def disapproveproposal(self, proposal_ids, account=None, approver=None, **kwargs):
"""
Disapprove Proposal.
:param list proposal_ids: Ids of the proposals
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
from .proposal import Proposal
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
if not approver:
approver = account
else:
approver = Account(approver, blockchain_instance=self)
if not isinstance(proposal_ids, (list, set, tuple)):
proposal_ids = {proposal_ids}
op = []
for proposal_id in proposal_ids:
proposal = Proposal(proposal_id, blockchain_instance=self)
op.append(
operations.Proposal_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"fee_paying_account": account["id"],
"proposal": proposal["id"],
"active_approvals_to_remove": [approver["id"]],
"prefix": self.prefix,
}
)
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def approveworker(self, workers, account=None, **kwargs):
"""
Approve a worker.
:param list workers: list of worker member name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(workers, (list, set, tuple)):
workers = {workers}
for worker in workers:
worker = Worker(worker, blockchain_instance=self)
options["votes"].append(worker["vote_for"])
options["votes"] = list(set(options["votes"]))
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def disapproveworker(self, workers, account=None, **kwargs):
"""
Disapprove a worker.
:param list workers: list of worker name or id
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
options = account["options"]
if not isinstance(workers, (list, set, tuple)):
workers = {workers}
for worker in workers:
worker = Worker(worker, blockchain_instance=self)
if worker["vote_for"] in options["votes"]:
options["votes"].remove(worker["vote_for"])
options["votes"] = list(set(options["votes"]))
options["voting_account"] = "1.2.5" # Account("proxy-to-self")["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def unset_proxy(self, account=None, **kwargs):
"""Unset the proxy account to start voting yourself."""
return self.set_proxy("proxy-to-self", account=account, **kwargs)
def set_proxy(self, proxy_account, account=None, **kwargs):
"""
Set a specific proxy for account.
:param bitshares.account.Account proxy_account: Account to be
proxied
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
proxy = Account(proxy_account, blockchain_instance=self)
options = account["options"]
options["voting_account"] = proxy["id"]
op = operations.Account_update(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"account": account["id"],
"new_options": options,
"extensions": {},
"prefix": self.prefix,
}
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def cancel(self, orderNumbers, account=None, **kwargs):
"""
Cancels an order you have placed in a given market. Requires only the
"orderNumbers". An order number takes the form ``1.7.xxx``.
:param str orderNumbers: The Order Object ide of the form
``1.7.xxxx``
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, full=False, blockchain_instance=self)
if not isinstance(orderNumbers, (list, set, tuple)):
orderNumbers = {orderNumbers}
op = []
for order in orderNumbers:
op.append(
operations.Limit_order_cancel(
**{
"fee": {"amount": 0, "asset_id": "1.3.0"},
"fee_paying_account": account["id"],
"order": order,
"extensions": [],
"prefix": self.prefix,
}
)
)
return self.finalizeOp(op, account["name"], "active", **kwargs)
def vesting_balance_withdraw(self, vesting_id, amount=None, account=None, **kwargs):
"""
Withdraw vesting balance.
:param str vesting_id: Id of the vesting object
:param bitshares.amount.Amount Amount: to withdraw ("all" if not
provided")
:param str account: (optional) the account to allow access
to (defaults to ``default_account``)
"""
if not account:
if "default_account" in self.config:
account = self.config["default_account"]
if not account:
raise ValueError("You need to provide an account")
account = Account(account, blockchain_instance=self)
if not amount:
obj = Vesting(vesting_id, blockchain_instance=self)
amount = obj.claimable