From 0a25a4dd163d588f7f1ae7e610e5f84fac127666 Mon Sep 17 00:00:00 2001 From: Fabian Schuh Date: Mon, 21 Jan 2019 13:57:01 +0100 Subject: [PATCH] New operation --- bitshares/asset.py | 20 ++++++++++++++++ bitsharesbase/operations.py | 42 +++++++++++++++++++++++---------- tests/test_transactions.py | 47 +++++++++++++++++++++++++++++-------- 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/bitshares/asset.py b/bitshares/asset.py index f72b1364..4bff63b1 100644 --- a/bitshares/asset.py +++ b/bitshares/asset.py @@ -486,3 +486,23 @@ def update_feed_producers(self, producers): } ) return self.blockchain.finalizeOp(op, self["issuer"], "active") + + def change_issuer(self, new_issuer, **kwargs): + """ Change asset issuer (needs signing with owner key!) + + :param str type: ``blacklist`` or ``whitelist`` + :param list authorities: List of authorities (Accounts) + """ + from .account import Account + + new_issuer = Account(new_issuer) + op = operations.Asset_update_issuer( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "issuer": self["issuer"], + "asset_to_update": self["id"], + "new_issuer": new_issuer["id"], + "extensions": [], + } + ) + return self.blockchain.finalizeOp(op, self["issuer"], "owner", **kwargs) diff --git a/bitsharesbase/operations.py b/bitsharesbase/operations.py index da05328c..8c64e02e 100644 --- a/bitsharesbase/operations.py +++ b/bitsharesbase/operations.py @@ -28,7 +28,7 @@ VoteId, Ripemd160, Sha1, - Sha256 + Sha256, ) from .account import PublicKey @@ -178,9 +178,9 @@ def __init__(self, *args, **kwargs): if len(args) == 1 and len(kwargs) == 0: kwargs = args[0] if "new_issuer" in kwargs: - new_issuer = Optional(ObjectId(kwargs["new_issuer"], "account")) - else: - new_issuer = Optional(None) + raise ValueError( + "Cannot change asset_issuer with Asset_update anylonger! (BSIP29)" + ) super().__init__( OrderedDict( [ @@ -190,7 +190,7 @@ def __init__(self, *args, **kwargs): "asset_to_update", ObjectId(kwargs["asset_to_update"], "asset"), ), - ("new_issuer", new_issuer), + ("new_issuer", Optional(None)), ("new_options", AssetOptions(kwargs["new_options"])), ("extensions", Set([])), ] @@ -861,6 +861,7 @@ def detail(self, *args, **kwargs): class HtlcHash(Static_variant): elements = [Ripemd160, Sha1, Sha256] + def __init__(self, o): id = o[0] if len(self.elements) <= id: @@ -892,13 +893,9 @@ def detail(self, *args, **kwargs): ("fee", Asset(kwargs["fee"])), ("htlc_id", ObjectId(kwargs["htlc_id"], "htlc")), ("redeemer", ObjectId(kwargs["redeemer"], "account")), - ("preimage", # Bytes(kwargs["preimage"]) - Array( - [ - Uint8(o) - for o in unhexlify(kwargs["preimage"]) - ] - ), + ( + "preimage", # Bytes(kwargs["preimage"]) + Array([Uint8(o) for o in unhexlify(kwargs["preimage"])]), ), ("extensions", Set([])), ] @@ -918,4 +915,25 @@ def detail(self, *args, **kwargs): ) +class Asset_update_issuer(GrapheneObject): + def __init__(self, *args, **kwargs): + if isArgsThisClass(self, args): + self.data = args[0].data + else: + super().__init__( + OrderedDict( + [ + ("fee", Asset(kwargs["fee"])), + ("issuer", ObjectId(kwargs["issuer"], "account")), + ( + "asset_to_update", + ObjectId(kwargs["asset_to_update"], "asset"), + ), + ("new_issuer", ObjectId(kwargs["new_issuer"], "account")), + ("extensions", Set([])), + ] + ) + ) + + fill_classmaps() diff --git a/tests/test_transactions.py b/tests/test_transactions.py index c4048294..cd6b150f 100644 --- a/tests/test_transactions.py +++ b/tests/test_transactions.py @@ -10,6 +10,7 @@ from bitsharesbase.objects import Operation from bitsharesbase.signedtransactions import Signed_Transaction from bitsharesbase.account import PrivateKey +from graphenebase.base58 import ripemd160 from .fixtures import fixture_data, bitshares, wif @@ -598,6 +599,36 @@ def test_asset_update(self): ) self.doit() + def test_asset_update_issuer_fail(self): + with self.assertRaises(ValueError): + self.op = operations.Asset_update( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "issuer": "1.2.0", + "asset_to_update": "1.3.0", + "new_issuer": "1.2.1", + "extensions": [], + } + ) + + def test_asset_update_issuer(self): + self.op = operations.Asset_update_issuer( + **{ + "fee": {"amount": 0, "asset_id": "1.3.0"}, + "issuer": "1.2.0", + "asset_to_update": "1.3.0", + "new_issuer": "1.2.1", + "extensions": [], + } + ) + self.cm = ( + "f68585abf4dce7c804570130000000000000000000000001000" + "001207d24b86eb3e6ae1de872829223d205123aaf2c5d11eab4" + "6d8a80dbe83a42af03687cd3c43a5dd1d7f4d7a7b5afdf8d69c" + "42acf9224354b1af7d81bd556724a43" + ) + self.doit() + def test_asset_update_bitasset(self): self.op = operations.Asset_update_bitasset( **{ @@ -757,13 +788,6 @@ def test_asset_settle(self): self.doit() def test_htlc_create(self): - from binascii import unhexlify - def ripemd160(s): - import hashlib - ripemd160 = hashlib.new("ripemd160") - ripemd160.update(bytes(s, "utf-8")) - return ripemd160.hexdigest() - self.op = operations.Htlc_create( **{ "fee": {"amount": 0, "asset_id": "1.3.0"}, @@ -782,7 +806,8 @@ def ripemd160(s): "2e04fc41c800780000000000012071efeadf31703b98d155e1" "c196cf12bcda11c363518075be2aaca0443382648e2428d277" "e79b80bab4ff0b48fd00ed91e7e41d88974a00d50b832a198a" - "00d62d") + "00d62d" + ) self.doit(False) def test_htlc_redeem(self): @@ -799,7 +824,8 @@ def test_htlc_redeem(self): "f68585abf4dce7c80457013200000000000000000084017c06" "666f6f6261720000011f21a8d2fa9a0f7c9bcc32a0dbcbf901" "5051f8190c4b2239472f900458eae0bb4a7f7be8d88c60eba0" - "a8972f2e1b397d4e23f1b91eef12c38f11a01307809e4143") + "a8972f2e1b397d4e23f1b91eef12c38f11a01307809e4143" + ) self.doit(0) def test_htlc_extend(self): @@ -816,7 +842,8 @@ def test_htlc_extend(self): "f68585abf4dce7c80457013400000000000000000084017c78" "000000000001206aaf202129fea824e70b92113d0812fac654" "00529d86210674498f03ef33d4bd1055d17020db57092ee95d" - "c6320840059f85da3fbebaf2a965bb5eca15179f30") + "c6320840059f85da3fbebaf2a965bb5eca15179f30" + ) self.doit(0) def compareConstructedTX(self):