Skip to content

Commit ec397c9

Browse files
Add transfer_to_users method
1 parent 5632b2c commit ec397c9

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

pysrc/mixin_bot_api.py

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, mixin_config):
6161
def decode_ed25519(cls, priv):
6262
if not len(priv) % 4 == 0:
6363
priv = priv + '===='
64-
priv = base64.b64decode(priv, altchars=b'-_')
64+
priv = base64.urlsafe_b64decode(priv)
6565
return ed25519.Ed25519PrivateKey.from_private_bytes(priv[:32])
6666

6767
def generate_sig(self, method, uri, body):
@@ -517,19 +517,38 @@ async def get_address(self, address_id):
517517
"""
518518
return await self.__genNetworkGetRequest('/addresses/' + address_id)
519519

520-
async def transfer_to(self, to_user_id, to_asset_id, to_asset_amount, memo, trace_uuid=""):
521-
"""
522-
Transfer of assets between Mixin Network users.
523-
"""
524-
# generate encrypted pin
520+
async def transfer_to(self, user_id, asset_id, amount, memo, trace_id=None):
525521
encrypted_pin = self.gen_encrypted_pin()
522+
if not trace_id:
523+
trace_id = str(uuid.uuid1())
524+
if isinstance(user_id, str):
525+
body = {
526+
'asset_id': asset_id,
527+
'counter_user_id': user_id,
528+
'amount': str(amount),
529+
'pin': encrypted_pin,
530+
'trace_id': trace_id,
531+
'memo': memo
532+
}
533+
return await self.__genNetworkPostRequest('/transfers', body)
526534

527-
body = {'asset_id': to_asset_id, 'counter_user_id': to_user_id, 'amount': str(to_asset_amount),
528-
'pin': encrypted_pin, 'trace_id': trace_uuid, 'memo': memo}
529-
if trace_uuid == "":
530-
body['trace_id'] = str(uuid.uuid1())
535+
async def transfer_to_users(self, user_ids, threshold, asset_id, amount, memo, trace_id=None):
536+
encrypted_pin = self.gen_encrypted_pin()
537+
if not trace_id:
538+
trace_id = str(uuid.uuid1())
531539

532-
return await self.__genNetworkPostRequest('/transfers', body)
540+
body = {
541+
"asset_id": asset_id,
542+
"amount": str(amount),
543+
"trace_id": trace_id,
544+
"memo": memo,
545+
"opponent_multisig": {
546+
"receivers" : user_ids,
547+
"threshold": threshold
548+
},
549+
"pin": encrypted_pin
550+
}
551+
return await self.__genNetworkPostRequest('/transactions', body)
533552

534553
async def get_transfer(self, trace_id):
535554
"""

0 commit comments

Comments
 (0)