1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-28 09:08:07 +00:00

refactor(common & core & legacy): Stellar, rename StellarManageOfferOp to StellarManageSellOfferOp and rename StellarPathPaymentOp to StellarPathPaymentStrictReceiveOp.

This commit is contained in:
Jun Luo 2021-10-07 09:58:52 +08:00 committed by matejcik
parent 0068c12f77
commit 3a5768c4bf
22 changed files with 81 additions and 69 deletions

View File

@ -74,8 +74,8 @@ message StellarSignTx {
* Response: device is ready for client to send the next operation
* @next StellarPaymentOp
* @next StellarCreateAccountOp
* @next StellarPathPaymentOp
* @next StellarManageOfferOp
* @next StellarPathPaymentStrictReceiveOp
* @next StellarManageSellOfferOp
* @next StellarCreatePassiveOfferOp
* @next StellarSetOptionsOp
* @next StellarChangeTrustOp
@ -115,7 +115,7 @@ message StellarCreateAccountOp {
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarPathPaymentOp {
message StellarPathPaymentStrictReceiveOp {
optional string source_account = 1; // (optional) source address
required StellarAsset send_asset = 2;
required sint64 send_max = 3;
@ -130,7 +130,7 @@ message StellarPathPaymentOp {
* @next StellarTxOpRequest
* @next StellarSignedTx
*/
message StellarManageOfferOp {
message StellarManageSellOfferOp {
optional string source_account = 1; // (optional) source account address
required StellarAsset selling_asset = 2;
required StellarAsset buying_asset = 3;

View File

@ -229,8 +229,8 @@ enum MessageType {
MessageType_StellarAddress = 208 [(wire_out) = true];
MessageType_StellarCreateAccountOp = 210 [(wire_in) = true];
MessageType_StellarPaymentOp = 211 [(wire_in) = true];
MessageType_StellarPathPaymentOp = 212 [(wire_in) = true];
MessageType_StellarManageOfferOp = 213 [(wire_in) = true];
MessageType_StellarPathPaymentStrictReceiveOp = 212 [(wire_in) = true];
MessageType_StellarManageSellOfferOp = 213 [(wire_in) = true];
MessageType_StellarCreatePassiveOfferOp = 214 [(wire_in) = true];
MessageType_StellarSetOptionsOp = 215 [(wire_in) = true];
MessageType_StellarChangeTrustOp = 216 [(wire_in) = true];

View File

@ -336,7 +336,7 @@
}
},
{
"name": "StellarManageOfferOp",
"name": "StellarManageSellOfferOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAAAwAAAAJBQkNERUZHSElKS0wAAAAAKYSWAsIOWDZfEjwS2HocpFUNEM0hsK4OGNROPlb9ahUAAAABWAAAAAAAAAAphJYCwg5YNl8SPBLYehykVQ0QzSGwrg4Y1E4+Vv1qFQAAAAAdzxaYAAAAAwAAAAQAAAAAAAAFOQAAAAAAAAAA",
"address_n": "m/44'/148'/0'",
@ -351,7 +351,7 @@
},
"operations": [
{
"_message_type": "StellarManageOfferOp",
"_message_type": "StellarManageSellOfferOp",
"selling_asset": {
"type": "ALPHANUM12",
"code": "ABCDEFGHIJKL",
@ -375,7 +375,7 @@
}
},
{
"name": "StellarPathPaymentOp",
"name": "StellarPathPaymentStrictReceiveOp",
"parameters": {
"xdr": "AAAAAgAAAAAvIrnGLwi3dPPr5t1ufbk8PsLL3gJ5Vho9nFIluMMikgAAAGQAAAAAAAAD6AAAAAEAAAAAG4J3zQAAAABd5CqEAAAAAAAAAAEAAAAAAAAAAgAAAAFYAAAAAAAAACmElgLCDlg2XxI8Eth6HKRVDRDNIbCuDhjUTj5W/WoVAAAAAB3PFpgAAAAAXVVkJGaxhbhDFS6eIZFR28WJICfsQBAaUXvtXKAwwuAAAAACQUJDREVGR0hJSktMAAAAACmElgLCDlg2XxI8Eth6HKRVDRDNIbCuDhjUTj5W/WoVAAAAAAAB4kAAAAAAAAAAAAAAAAA=",
"address_n": "m/44'/148'/0'",
@ -390,7 +390,7 @@
},
"operations": [
{
"_message_type": "StellarPathPaymentOp",
"_message_type": "StellarPathPaymentStrictReceiveOp",
"send_asset": {
"type": "ALPHANUM4",
"code": "X",

View File

@ -0,0 +1 @@
Stellar: rename StellarManageOfferOp to StellarManageSellOfferOp and StellarPathPaymentOp to StellarPathPaymentStrictReceiveOp.

View File

@ -25,8 +25,8 @@ Stellar transaction is composed of one or more operations. We support all [opera
- Create Account
- Create Passive Offer
- Manage Data
- Manage Offer
- Path Payment
- Manage Sell Offer
- Path Payment Strict Receive
- Payment
- Set Options

View File

@ -14,8 +14,8 @@ if False:
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPaymentOp,
StellarSetOptionsOp,
)
@ -28,8 +28,8 @@ if False:
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPaymentOp,
StellarSetOptionsOp,
]
@ -47,8 +47,8 @@ op_codes: dict[int, int] = {
MessageType.StellarCreateAccountOp: 0,
MessageType.StellarCreatePassiveOfferOp: 4,
MessageType.StellarManageDataOp: 10,
MessageType.StellarManageOfferOp: 3,
MessageType.StellarPathPaymentOp: 2,
MessageType.StellarManageSellOfferOp: 3,
MessageType.StellarPathPaymentStrictReceiveOp: 2,
MessageType.StellarPaymentOp: 1,
MessageType.StellarSetOptionsOp: 5,
}
@ -61,8 +61,8 @@ op_wire_types = [
MessageType.StellarCreateAccountOp,
MessageType.StellarCreatePassiveOfferOp,
MessageType.StellarManageDataOp,
MessageType.StellarManageOfferOp,
MessageType.StellarPathPaymentOp,
MessageType.StellarManageSellOfferOp,
MessageType.StellarPathPaymentStrictReceiveOp,
MessageType.StellarPaymentOp,
MessageType.StellarSetOptionsOp,
]

View File

@ -34,12 +34,12 @@ async def process_operation(
elif serialize.StellarManageDataOp.is_type_of(op):
await layout.confirm_manage_data_op(ctx, op)
serialize.write_manage_data_op(w, op)
elif serialize.StellarManageOfferOp.is_type_of(op):
await layout.confirm_manage_offer_op(ctx, op)
serialize.write_manage_offer_op(w, op)
elif serialize.StellarPathPaymentOp.is_type_of(op):
await layout.confirm_path_payment_op(ctx, op)
serialize.write_path_payment_op(w, op)
elif serialize.StellarManageSellOfferOp.is_type_of(op):
await layout.confirm_manage_sell_offer_op(ctx, op)
serialize.write_manage_sell_offer_op(w, op)
elif serialize.StellarPathPaymentStrictReceiveOp.is_type_of(op):
await layout.confirm_path_payment_strict_receive_op(ctx, op)
serialize.write_path_payment_strict_receive_op(w, op)
elif serialize.StellarPaymentOp.is_type_of(op):
await layout.confirm_payment_op(ctx, op)
serialize.write_payment_op(w, op)

View File

@ -8,8 +8,8 @@ from trezor.messages import (
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPaymentOp,
StellarSetOptionsOp,
)
@ -106,7 +106,9 @@ async def confirm_create_passive_offer_op(
await _confirm_offer(ctx, text, op)
async def confirm_manage_offer_op(ctx: Context, op: StellarManageOfferOp) -> None:
async def confirm_manage_sell_offer_op(
ctx: Context, op: StellarManageSellOfferOp
) -> None:
if op.offer_id == 0:
text = "New Offer"
else:
@ -121,7 +123,7 @@ async def confirm_manage_offer_op(ctx: Context, op: StellarManageOfferOp) -> Non
async def _confirm_offer(
ctx: Context,
title: str,
op: StellarCreatePassiveOfferOp | StellarManageOfferOp,
op: StellarCreatePassiveOfferOp | StellarManageSellOfferOp,
) -> None:
await confirm_properties(
ctx,
@ -161,7 +163,9 @@ async def confirm_manage_data_op(ctx: Context, op: StellarManageDataOp) -> None:
)
async def confirm_path_payment_op(ctx: Context, op: StellarPathPaymentOp) -> None:
async def confirm_path_payment_strict_receive_op(
ctx: Context, op: StellarPathPaymentStrictReceiveOp
) -> None:
await confirm_output(
ctx,
address=op.destination_account,
@ -175,7 +179,7 @@ async def confirm_path_payment_op(ctx: Context, op: StellarPathPaymentOp) -> Non
title="Debited amount",
amount=format_amount(op.send_max, op.send_asset),
description="Pay at most:",
br_type="op_path_payment",
br_type="op_path_payment_strict_receive",
)
await confirm_asset_issuer(ctx, op.send_asset)

View File

@ -8,8 +8,8 @@ from trezor.messages import (
StellarCreateAccountOp,
StellarCreatePassiveOfferOp,
StellarManageDataOp,
StellarManageOfferOp,
StellarPathPaymentOp,
StellarManageSellOfferOp,
StellarPathPaymentStrictReceiveOp,
StellarPaymentOp,
StellarSetOptionsOp,
)
@ -65,7 +65,7 @@ def write_manage_data_op(w: Writer, msg: StellarManageDataOp) -> None:
writers.write_string(w, msg.value)
def write_manage_offer_op(w: Writer, msg: StellarManageOfferOp) -> None:
def write_manage_sell_offer_op(w: Writer, msg: StellarManageSellOfferOp) -> None:
_write_asset(w, msg.selling_asset)
_write_asset(w, msg.buying_asset)
writers.write_uint64(w, msg.amount) # amount to sell
@ -74,7 +74,9 @@ def write_manage_offer_op(w: Writer, msg: StellarManageOfferOp) -> None:
writers.write_uint64(w, msg.offer_id)
def write_path_payment_op(w: Writer, msg: StellarPathPaymentOp) -> None:
def write_path_payment_strict_receive_op(
w: Writer, msg: StellarPathPaymentStrictReceiveOp
) -> None:
_write_asset(w, msg.send_asset)
writers.write_uint64(w, msg.send_max)
writers.write_pubkey(w, msg.destination_account)

View File

@ -121,8 +121,8 @@ if not utils.BITCOIN_ONLY:
StellarAddress = 208
StellarCreateAccountOp = 210
StellarPaymentOp = 211
StellarPathPaymentOp = 212
StellarManageOfferOp = 213
StellarPathPaymentStrictReceiveOp = 212
StellarManageSellOfferOp = 213
StellarCreatePassiveOfferOp = 214
StellarSetOptionsOp = 215
StellarChangeTrustOp = 216

View File

@ -126,8 +126,8 @@ if TYPE_CHECKING:
StellarAddress = 208
StellarCreateAccountOp = 210
StellarPaymentOp = 211
StellarPathPaymentOp = 212
StellarManageOfferOp = 213
StellarPathPaymentStrictReceiveOp = 212
StellarManageSellOfferOp = 213
StellarCreatePassiveOfferOp = 214
StellarSetOptionsOp = 215
StellarChangeTrustOp = 216

View File

@ -4772,7 +4772,7 @@ if TYPE_CHECKING:
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["StellarCreateAccountOp"]:
return isinstance(msg, cls)
class StellarPathPaymentOp(protobuf.MessageType):
class StellarPathPaymentStrictReceiveOp(protobuf.MessageType):
source_account: "str | None"
send_asset: "StellarAsset"
send_max: "int"
@ -4795,10 +4795,10 @@ if TYPE_CHECKING:
pass
@classmethod
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["StellarPathPaymentOp"]:
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["StellarPathPaymentStrictReceiveOp"]:
return isinstance(msg, cls)
class StellarManageOfferOp(protobuf.MessageType):
class StellarManageSellOfferOp(protobuf.MessageType):
source_account: "str | None"
selling_asset: "StellarAsset"
buying_asset: "StellarAsset"
@ -4821,7 +4821,7 @@ if TYPE_CHECKING:
pass
@classmethod
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["StellarManageOfferOp"]:
def is_type_of(cls, msg: protobuf.MessageType) -> TypeGuard["StellarManageSellOfferOp"]:
return isinstance(msg, cls)
class StellarCreatePassiveOfferOp(protobuf.MessageType):

View File

@ -0,0 +1 @@
Stellar: rename StellarManageOfferOp to StellarManageSellOfferOp and StellarPathPaymentOp to StellarPathPaymentStrictReceiveOp.

View File

@ -118,8 +118,9 @@ void fsm_msgStellarGetAddress(const StellarGetAddress *msg);
void fsm_msgStellarSignTx(const StellarSignTx *msg);
void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg);
void fsm_msgStellarCreateAccountOp(const StellarCreateAccountOp *msg);
void fsm_msgStellarPathPaymentOp(const StellarPathPaymentOp *msg);
void fsm_msgStellarManageOfferOp(const StellarManageOfferOp *msg);
void fsm_msgStellarPathPaymentStrictReceiveOp(
const StellarPathPaymentStrictReceiveOp *msg);
void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg);
void fsm_msgStellarCreatePassiveOfferOp(const StellarCreatePassiveOfferOp *msg);
void fsm_msgStellarSetOptionsOp(const StellarSetOptionsOp *msg);
void fsm_msgStellarChangeTrustOp(const StellarChangeTrustOp *msg);

View File

@ -109,8 +109,9 @@ void fsm_msgStellarPaymentOp(const StellarPaymentOp *msg) {
}
}
void fsm_msgStellarPathPaymentOp(const StellarPathPaymentOp *msg) {
if (!stellar_confirmPathPaymentOp(msg)) return;
void fsm_msgStellarPathPaymentStrictReceiveOp(
const StellarPathPaymentStrictReceiveOp *msg) {
if (!stellar_confirmPathPaymentStrictReceiveOp(msg)) return;
if (stellar_allOperationsConfirmed()) {
RESP_INIT(StellarSignedTx);
@ -127,8 +128,8 @@ void fsm_msgStellarPathPaymentOp(const StellarPathPaymentOp *msg) {
}
}
void fsm_msgStellarManageOfferOp(const StellarManageOfferOp *msg) {
if (!stellar_confirmManageOfferOp(msg)) return;
void fsm_msgStellarManageSellOfferOp(const StellarManageSellOfferOp *msg) {
if (!stellar_confirmManageSellOfferOp(msg)) return;
if (stellar_allOperationsConfirmed()) {
RESP_INIT(StellarSignedTx);

View File

@ -17,12 +17,12 @@ StellarPaymentOp.destination_account max_size:57
StellarCreateAccountOp.source_account max_size:57
StellarCreateAccountOp.new_account max_size:57
StellarPathPaymentOp.source_account max_size:57
StellarPathPaymentOp.destination_account max_size:57
StellarPathPaymentOp.paths max_count:5
StellarPathPaymentStrictReceiveOp.source_account max_size:57
StellarPathPaymentStrictReceiveOp.destination_account max_size:57
StellarPathPaymentStrictReceiveOp.paths max_count:5
StellarManageOfferOp.source_account max_size:57
StellarManageSellOfferOp.source_account max_size:57
StellarCreatePassiveOfferOp.source_account max_size:57

View File

@ -289,7 +289,8 @@ bool stellar_confirmPaymentOp(const StellarPaymentOp *msg) {
return true;
}
bool stellar_confirmPathPaymentOp(const StellarPathPaymentOp *msg) {
bool stellar_confirmPathPaymentStrictReceiveOp(
const StellarPathPaymentStrictReceiveOp *msg) {
if (!stellar_signing) return false;
if (!stellar_confirmSourceAccount(msg->has_source_account,
@ -387,7 +388,7 @@ bool stellar_confirmPathPaymentOp(const StellarPathPaymentOp *msg) {
return true;
}
bool stellar_confirmManageOfferOp(const StellarManageOfferOp *msg) {
bool stellar_confirmManageSellOfferOp(const StellarManageSellOfferOp *msg) {
if (!stellar_signing) return false;
if (!stellar_confirmSourceAccount(msg->has_source_account,

View File

@ -59,8 +59,9 @@ bool stellar_confirmSourceAccount(bool has_source_account,
const char *str_account);
bool stellar_confirmCreateAccountOp(const StellarCreateAccountOp *msg);
bool stellar_confirmPaymentOp(const StellarPaymentOp *msg);
bool stellar_confirmPathPaymentOp(const StellarPathPaymentOp *msg);
bool stellar_confirmManageOfferOp(const StellarManageOfferOp *msg);
bool stellar_confirmPathPaymentStrictReceiveOp(
const StellarPathPaymentStrictReceiveOp *msg);
bool stellar_confirmManageSellOfferOp(const StellarManageSellOfferOp *msg);
bool stellar_confirmCreatePassiveOfferOp(
const StellarCreatePassiveOfferOp *msg);
bool stellar_confirmSetOptionsOp(const StellarSetOptionsOp *msg);

View File

@ -147,8 +147,8 @@ class MessageType(IntEnum):
StellarAddress = 208
StellarCreateAccountOp = 210
StellarPaymentOp = 211
StellarPathPaymentOp = 212
StellarManageOfferOp = 213
StellarPathPaymentStrictReceiveOp = 212
StellarManageSellOfferOp = 213
StellarCreatePassiveOfferOp = 214
StellarSetOptionsOp = 215
StellarChangeTrustOp = 216
@ -6324,7 +6324,7 @@ class StellarCreateAccountOp(protobuf.MessageType):
self.source_account = source_account
class StellarPathPaymentOp(protobuf.MessageType):
class StellarPathPaymentStrictReceiveOp(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 212
FIELDS = {
1: protobuf.Field("source_account", "string", repeated=False, required=False),
@ -6356,7 +6356,7 @@ class StellarPathPaymentOp(protobuf.MessageType):
self.source_account = source_account
class StellarManageOfferOp(protobuf.MessageType):
class StellarManageSellOfferOp(protobuf.MessageType):
MESSAGE_WIRE_TYPE = 213
FIELDS = {
1: protobuf.Field("source_account", "string", repeated=False, required=False),

View File

@ -128,7 +128,7 @@ def _read_operation(op: "Operation"):
amount=_read_amount(op.amount),
)
if isinstance(op, PathPaymentStrictReceive):
operation = messages.StellarPathPaymentOp(
operation = messages.StellarPathPaymentStrictReceiveOp(
source_account=source_account,
send_asset=_read_asset(op.send_asset),
send_max=_read_amount(op.send_max),
@ -140,7 +140,7 @@ def _read_operation(op: "Operation"):
return operation
if isinstance(op, ManageSellOffer):
price = _read_price(op.price)
return messages.StellarManageOfferOp(
return messages.StellarManageSellOfferOp(
source_account=source_account,
selling_asset=_read_asset(op.selling),
buying_asset=_read_asset(op.buying),

View File

@ -325,7 +325,7 @@ def test_path_payment_strict_receive():
tx, operations = stellar.from_envelope(envelope)
assert len(operations) == 1
assert isinstance(operations[0], messages.StellarPathPaymentOp)
assert isinstance(operations[0], messages.StellarPathPaymentStrictReceiveOp)
assert operations[0].source_account == operation_source
assert operations[0].destination_account == destination
assert operations[0].send_asset.type == messages.StellarAssetType.NATIVE
@ -368,7 +368,7 @@ def test_manage_sell_offer_new_offer():
tx, operations = stellar.from_envelope(envelope)
assert len(operations) == 1
assert isinstance(operations[0], messages.StellarManageOfferOp)
assert isinstance(operations[0], messages.StellarManageSellOfferOp)
assert operations[0].source_account == operation_source
assert operations[0].selling_asset.type == messages.StellarAssetType.NATIVE
assert operations[0].buying_asset.type == messages.StellarAssetType.ALPHANUM4
@ -408,7 +408,7 @@ def test_manage_sell_offer_update_offer():
tx, operations = stellar.from_envelope(envelope)
assert len(operations) == 1
assert isinstance(operations[0], messages.StellarManageOfferOp)
assert isinstance(operations[0], messages.StellarManageSellOfferOp)
assert operations[0].source_account == operation_source
assert operations[0].selling_asset.type == messages.StellarAssetType.NATIVE
assert operations[0].buying_asset.type == messages.StellarAssetType.ALPHANUM4

View File

@ -846,8 +846,8 @@
"test_stellar.py::test_sign_tx[StellarCreateAccountOp]": "2582717c25974d2b3ee156624b00375148ff7fd12eeea73625a7c367fa610373",
"test_stellar.py::test_sign_tx[StellarCreatePassiveOfferOp]": "6b0f0d2b746f98e2c85006ea7e2d5c49cd9277662e47f223138ff418066791e3",
"test_stellar.py::test_sign_tx[StellarManageDataOp]": "8fbec6547a8f9d1f002181db0cbe57fe86abef8d365b1c06fd14292cd0b068a7",
"test_stellar.py::test_sign_tx[StellarManageOfferOp]": "6ed84765b2ed46711be0ed1219d91c27e927119d352f37b2baf8c6501186bbce",
"test_stellar.py::test_sign_tx[StellarPathPaymentOp]": "58f3bfaece0706bc172d6e6564b728ec0b7f8e2629d8c64dc60672786586076d",
"test_stellar.py::test_sign_tx[StellarManageSellOfferOp]": "6ed84765b2ed46711be0ed1219d91c27e927119d352f37b2baf8c6501186bbce",
"test_stellar.py::test_sign_tx[StellarPathPaymentStrictReceiveOp]": "58f3bfaece0706bc172d6e6564b728ec0b7f8e2629d8c64dc60672786586076d",
"test_stellar.py::test_sign_tx[StellarPaymentOp-asset12]": "1d8e9d5d65420a259f7e2deef1efaf0ce5be966a0f1e5b8e95b832f176f00de2",
"test_stellar.py::test_sign_tx[StellarPaymentOp-asset4]": "0de0b815dad5d348a3b9d06e37da94800363e5de8e6ca9cd0f84e5070f7e1b22",
"test_stellar.py::test_sign_tx[StellarPaymentOp-native_asset]": "b2015b9e0f9ff60e2ea4fca2942e97b70a320386c2043fb36acde4a830272098",