Skip to content

Commit

Permalink
New operation
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Jan 21, 2019
1 parent 13e0168 commit 0a25a4d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
20 changes: 20 additions & 0 deletions bitshares/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
42 changes: 30 additions & 12 deletions bitsharesbase/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
VoteId,
Ripemd160,
Sha1,
Sha256
Sha256,
)

from .account import PublicKey
Expand Down Expand Up @@ -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(
[
Expand All @@ -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([])),
]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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([])),
]
Expand All @@ -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()
47 changes: 37 additions & 10 deletions tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
**{
Expand Down Expand Up @@ -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"},
Expand All @@ -782,7 +806,8 @@ def ripemd160(s):
"2e04fc41c800780000000000012071efeadf31703b98d155e1"
"c196cf12bcda11c363518075be2aaca0443382648e2428d277"
"e79b80bab4ff0b48fd00ed91e7e41d88974a00d50b832a198a"
"00d62d")
"00d62d"
)
self.doit(False)

def test_htlc_redeem(self):
Expand All @@ -799,7 +824,8 @@ def test_htlc_redeem(self):
"f68585abf4dce7c80457013200000000000000000084017c06"
"666f6f6261720000011f21a8d2fa9a0f7c9bcc32a0dbcbf901"
"5051f8190c4b2239472f900458eae0bb4a7f7be8d88c60eba0"
"a8972f2e1b397d4e23f1b91eef12c38f11a01307809e4143")
"a8972f2e1b397d4e23f1b91eef12c38f11a01307809e4143"
)
self.doit(0)

def test_htlc_extend(self):
Expand All @@ -816,7 +842,8 @@ def test_htlc_extend(self):
"f68585abf4dce7c80457013400000000000000000084017c78"
"000000000001206aaf202129fea824e70b92113d0812fac654"
"00529d86210674498f03ef33d4bd1055d17020db57092ee95d"
"c6320840059f85da3fbebaf2a965bb5eca15179f30")
"c6320840059f85da3fbebaf2a965bb5eca15179f30"
)
self.doit(0)

def compareConstructedTX(self):
Expand Down

0 comments on commit 0a25a4d

Please sign in to comment.