async def _memo(ctx, w: bytearray, msg: StellarSignTx): if msg.memo_type is None: msg.memo_type = consts.MEMO_TYPE_NONE writers.write_uint32(w, msg.memo_type) if msg.memo_type == consts.MEMO_TYPE_NONE: # nothing is serialized memo_confirm_text = "" elif msg.memo_type == consts.MEMO_TYPE_TEXT: # Text: 4 bytes (size) + up to 28 bytes if len(msg.memo_text) > 28: raise ProcessError( "Stellar: max length of a memo text is 28 bytes") writers.write_string(w, msg.memo_text) memo_confirm_text = msg.memo_text elif msg.memo_type == consts.MEMO_TYPE_ID: # ID: 64 bit unsigned integer writers.write_uint64(w, msg.memo_id) memo_confirm_text = str(msg.memo_id) elif msg.memo_type in (consts.MEMO_TYPE_HASH, consts.MEMO_TYPE_RETURN): # Hash/Return: 32 byte hash writers.write_bytes_unchecked(w, bytearray(msg.memo_hash)) memo_confirm_text = hexlify(msg.memo_hash).decode() else: raise ProcessError("Stellar invalid memo type") await layout.require_confirm_memo(ctx, msg.memo_type, memo_confirm_text)
def serialize_manage_offer_op(w, msg: StellarManageOfferOp): _serialize_asset(w, msg.selling_asset) _serialize_asset(w, msg.buying_asset) writers.write_uint64(w, msg.amount) # amount to sell writers.write_uint32(w, msg.price_n) # numerator writers.write_uint32(w, msg.price_d) # denominator writers.write_uint64(w, msg.offer_id)
def _timebounds(w: bytearray, start: int, end: int): # timebounds are only present if timebounds_start or timebounds_end is non-zero if start or end: writers.write_bool(w, True) # timebounds are sent as uint32s since that's all we can display, but they must be hashed as 64bit writers.write_uint64(w, start) writers.write_uint64(w, end) else: writers.write_bool(w, False)
def serialize_path_payment_op(w, msg: StellarPathPaymentOp): _serialize_asset(w, msg.send_asset) writers.write_uint64(w, msg.send_max) writers.write_pubkey(w, msg.destination_account) _serialize_asset(w, msg.destination_asset) writers.write_uint64(w, msg.destination_amount) writers.write_uint32(w, len(msg.paths)) for p in msg.paths: _serialize_asset(w, p)
async def _timebounds(ctx, w: bytearray, start: int, end: int): # timebounds are only present if timebounds_start or timebounds_end is non-zero if start or end: # confirm dialog await layout.require_confirm_timebounds(ctx, start, end) writers.write_bool(w, True) # timebounds are sent as uint32s since that's all we can display, but they must be hashed as 64bit writers.write_uint64(w, start or 0) writers.write_uint64(w, end or 0) else: writers.write_bool(w, False)
async def _init(ctx, w: bytearray, pubkey: bytes, msg: StellarSignTx): network_passphrase_hash = sha256(msg.network_passphrase).digest() writers.write_bytes(w, network_passphrase_hash) writers.write_bytes(w, consts.TX_TYPE) address = helpers.address_from_public_key(pubkey) writers.write_pubkey(w, address) if helpers.public_key_from_address(msg.source_account) != pubkey: raise ProcessError("Stellar: source account does not match address_n") writers.write_uint32(w, msg.fee) writers.write_uint64(w, msg.sequence_number) # confirm init await layout.require_confirm_init(ctx, address, msg.network_passphrase)
async def _init(ctx, w: bytearray, pubkey: bytes, msg: StellarSignTx): network_passphrase_hash = sha256(msg.network_passphrase).digest() writers.write_bytes_unchecked(w, network_passphrase_hash) writers.write_bytes_unchecked(w, consts.TX_TYPE) address = helpers.address_from_public_key(pubkey) accounts_match = msg.source_account == address writers.write_pubkey(w, msg.source_account) writers.write_uint32(w, msg.fee) writers.write_uint64(w, msg.sequence_number) # confirm init await layout.require_confirm_init(ctx, msg.source_account, msg.network_passphrase, accounts_match)
def serialize_payment_op(w, msg: StellarPaymentOp): writers.write_pubkey(w, msg.destination_account) _serialize_asset(w, msg.asset) writers.write_uint64(w, msg.amount)
def serialize_create_passive_offer_op(w, msg: StellarCreatePassiveOfferOp): _serialize_asset(w, msg.selling_asset) _serialize_asset(w, msg.buying_asset) writers.write_uint64(w, msg.amount) writers.write_uint32(w, msg.price_n) writers.write_uint32(w, msg.price_d)
def serialize_create_account_op(w, msg: StellarCreateAccountOp): writers.write_pubkey(w, msg.new_account) writers.write_uint64(w, msg.starting_balance)
def serialize_change_trust_op(w, msg: StellarChangeTrustOp): _serialize_asset(w, msg.asset) writers.write_uint64(w, msg.limit)
def serialize_bump_sequence_op(w, msg: StellarBumpSequenceOp): writers.write_uint64(w, msg.bump_to)