|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
import binascii
|
|
|
|
|
|
|
|
|
|
from . import messages as proto
|
|
|
|
|
from .tools import CallException, expect, normalize_nfc
|
|
|
|
|
from .tools import CallException, expect, normalize_nfc, dict_from_camelcase
|
|
|
|
|
from .protobuf import dict_to_proto
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@expect(proto.LiskAddress, field="address")
|
|
|
|
@ -33,46 +34,11 @@ def verify_message(client, pubkey, signature, message):
|
|
|
|
|
return isinstance(resp, proto.Success)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _asset_to_proto(asset):
|
|
|
|
|
msg = proto.LiskTransactionAsset()
|
|
|
|
|
|
|
|
|
|
if "votes" in asset:
|
|
|
|
|
msg.votes = asset["votes"]
|
|
|
|
|
if "data" in asset:
|
|
|
|
|
msg.data = asset["data"]
|
|
|
|
|
if "signature" in asset:
|
|
|
|
|
msg.signature = proto.LiskSignatureType()
|
|
|
|
|
msg.signature.public_key = binascii.unhexlify(asset["signature"]["publicKey"])
|
|
|
|
|
if "delegate" in asset:
|
|
|
|
|
msg.delegate = proto.LiskDelegateType()
|
|
|
|
|
msg.delegate.username = asset["delegate"]["username"]
|
|
|
|
|
if "multisignature" in asset:
|
|
|
|
|
msg.multisignature = proto.LiskMultisignatureType()
|
|
|
|
|
msg.multisignature.min = asset["multisignature"]["min"]
|
|
|
|
|
msg.multisignature.life_time = asset["multisignature"]["lifetime"]
|
|
|
|
|
msg.multisignature.keys_group = asset["multisignature"]["keysgroup"]
|
|
|
|
|
return msg
|
|
|
|
|
RENAMES = {"lifetime": "life_time", "keysgroup": "keys_group"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@expect(proto.LiskSignedTx)
|
|
|
|
|
def sign_tx(client, n, transaction):
|
|
|
|
|
msg = proto.LiskTransactionCommon()
|
|
|
|
|
|
|
|
|
|
msg.type = transaction["type"]
|
|
|
|
|
msg.fee = int(
|
|
|
|
|
transaction["fee"]
|
|
|
|
|
) # Lisk use strings for big numbers (javascript issue)
|
|
|
|
|
msg.amount = int(transaction["amount"]) # And we convert it back to number
|
|
|
|
|
msg.timestamp = transaction["timestamp"]
|
|
|
|
|
|
|
|
|
|
if "recipientId" in transaction:
|
|
|
|
|
msg.recipient_id = transaction["recipientId"]
|
|
|
|
|
if "senderPublicKey" in transaction:
|
|
|
|
|
msg.sender_public_key = binascii.unhexlify(transaction["senderPublicKey"])
|
|
|
|
|
if "requesterPublicKey" in transaction:
|
|
|
|
|
msg.requester_public_key = binascii.unhexlify(transaction["requesterPublicKey"])
|
|
|
|
|
if "signature" in transaction:
|
|
|
|
|
msg.signature = binascii.unhexlify(transaction["signature"])
|
|
|
|
|
|
|
|
|
|
msg.asset = _asset_to_proto(transaction["asset"])
|
|
|
|
|
transaction = dict_from_camelcase(transaction, renames=RENAMES)
|
|
|
|
|
msg = dict_to_proto(proto.LiskTransactionCommon, transaction)
|
|
|
|
|
return client.call(proto.LiskSignTx(address_n=n, transaction=msg))
|
|
|
|
|