1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-23 06:48:16 +00:00

nem_mosaics: Whitelist networks

This commit is contained in:
Saleem Rashid 2017-07-22 20:07:03 +01:00
parent 17e33d5517
commit 327736ca96
6 changed files with 41 additions and 21 deletions

View File

@ -528,13 +528,13 @@ void layoutNEMNetworkFee(const char *desc, bool confirm, const char *fee1_desc,
NULL);
}
void layoutNEMTransferMosaic(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier) {
void layoutNEMTransferMosaic(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, uint8_t network) {
char str_out[32], str_levy[32];
nem_mosaicFormatAmount(definition, quantity, multiplier, str_out, sizeof(str_out));
if (definition->has_levy) {
nem_mosaicFormatLevy(definition, quantity, multiplier, str_levy, sizeof(str_levy));
nem_mosaicFormatLevy(definition, quantity, multiplier, network, str_levy, sizeof(str_levy));
}
layoutDialogSwipe(&bmp_icon_question,
@ -597,12 +597,12 @@ void layoutNEMMosaicDescription(const char *description) {
str[0], str[1], str[2], str[3], NULL, NULL);
}
void layoutNEMLevy(const NEMMosaicDefinition *definition) {
void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network) {
const NEMMosaicDefinition *mosaic;
if (nem_mosaicMatches(definition, definition->levy_namespace, definition->levy_mosaic)) {
if (nem_mosaicMatches(definition, definition->levy_namespace, definition->levy_mosaic, network)) {
mosaic = definition;
} else {
mosaic = nem_mosaicByName(definition->levy_namespace, definition->levy_mosaic);
mosaic = nem_mosaicByName(definition->levy_namespace, definition->levy_mosaic, network);
}
char mosaic_name[32];

View File

@ -51,10 +51,10 @@ void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appico
void layoutNEMDialog(const BITMAP *icon, const char *btnNo, const char *btnYes, const char *desc, const char *line1, const char *address);
void layoutNEMTransferXEM(const char *desc, uint64_t quantity, const bignum256 *multiplier, uint64_t fee);
void layoutNEMNetworkFee(const char *desc, bool confirm, const char *fee1_desc, uint64_t fee1, const char *fee2_desc, uint64_t fee2);
void layoutNEMTransferMosaic(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier);
void layoutNEMTransferMosaic(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, uint8_t network);
void layoutNEMTransferUnknownMosaic(const char *namespace, const char *mosaic, uint64_t quantity, const bignum256 *multiplier);
void layoutNEMTransferPayload(const uint8_t *payload, size_t length, bool encrypted);
void layoutNEMMosaicDescription(const char *description);
void layoutNEMLevy(const NEMMosaicDefinition *definition);
void layoutNEMLevy(const NEMMosaicDefinition *definition, uint8_t network);
#endif

View File

@ -102,6 +102,7 @@ const char *nem_validate_mosaic_creation(const NEMMosaicCreation *mosaic_creatio
if (mosaic_creation->definition.has_name) return _("Name not allowed in mosaic creation transactions");
if (mosaic_creation->definition.has_ticker) return _("Ticker not allowed in mosaic creation transactions");
if (mosaic_creation->definition.networks_count) return _("Networks not allowed in mosaic creation transactions");
if (!mosaic_creation->definition.has_namespace) return _("No mosaic namespace provided");
if (!mosaic_creation->definition.has_mosaic) return _("No mosaic name provided");
@ -145,7 +146,7 @@ bool nem_askTransfer(const NEMTransactionCommon *common, const NEMTransfer *tran
const NEMMosaic *mosaic = &transfer->mosaics[i];
if ((mosaics[i].definition = nem_mosaicByName(mosaic->namespace, mosaic->mosaic))) {
if ((mosaics[i].definition = nem_mosaicByName(mosaic->namespace, mosaic->mosaic, common->network))) {
// XEM is displayed separately
if (mosaics[i].definition == NEM_MOSAIC_DEFINITION_XEM) {
// Do not display as a mosaic
@ -160,7 +161,7 @@ bool nem_askTransfer(const NEMTransactionCommon *common, const NEMTransfer *tran
for (size_t j = i + 1; j < transfer->mosaics_count; j++) {
const NEMMosaic *new_mosaic = &transfer->mosaics[j];
if (nem_mosaicMatches(mosaics[i].definition, new_mosaic->namespace, new_mosaic->mosaic)) {
if (nem_mosaicMatches(mosaics[i].definition, new_mosaic->namespace, new_mosaic->mosaic, common->network)) {
// Merge duplicate mosaics
mosaics[j].skip = true;
mosaics[i].quantity += new_mosaic->quantity;
@ -199,7 +200,7 @@ bool nem_askTransfer(const NEMTransactionCommon *common, const NEMTransfer *tran
const NEMMosaic *mosaic = &transfer->mosaics[i];
if (mosaics[i].definition) {
layoutNEMTransferMosaic(mosaics[i].definition, mosaics[i].quantity, &multiplier);
layoutNEMTransferMosaic(mosaics[i].definition, mosaics[i].quantity, &multiplier, common->network);
} else {
layoutNEMTransferUnknownMosaic(mosaic->namespace, mosaic->mosaic, mosaics[i].quantity, &multiplier);
}
@ -395,7 +396,7 @@ bool nem_askMosaicCreation(const NEMTransactionCommon *common, const NEMMosaicCr
}
if (mosaic_creation->definition.has_levy) {
layoutNEMLevy(&mosaic_creation->definition);
layoutNEMLevy(&mosaic_creation->definition, common->network);
if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmOutput, false)) {
return false;
}
@ -503,11 +504,11 @@ bool nem_fsmMultisig(nem_transaction_ctx *context, const NEMTransactionCommon *c
return true;
}
const NEMMosaicDefinition *nem_mosaicByName(const char *namespace, const char *mosaic) {
const NEMMosaicDefinition *nem_mosaicByName(const char *namespace, const char *mosaic, uint8_t network) {
for (size_t i = 0; i < NEM_MOSAIC_DEFINITIONS_COUNT; i++) {
const NEMMosaicDefinition *definition = &NEM_MOSAIC_DEFINITIONS[i];
if (nem_mosaicMatches(definition, namespace, mosaic)) {
if (nem_mosaicMatches(definition, namespace, mosaic, network)) {
return definition;
}
}
@ -561,14 +562,14 @@ void nem_mosaicFormatAmount(const NEMMosaicDefinition *definition, uint64_t quan
format_amount(definition, quantity, multiplier, NULL, 0, str_out, size);
}
bool nem_mosaicFormatLevy(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, char *str_out, size_t size) {
bool nem_mosaicFormatLevy(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, uint8_t network, char *str_out, size_t size) {
bignum256 multiplier2;
if (!definition->has_levy || !definition->has_fee) {
return false;
}
const NEMMosaicDefinition *levy_mosaic = nem_mosaicByName(definition->levy_namespace, definition->levy_mosaic);
const NEMMosaicDefinition *levy_mosaic = nem_mosaicByName(definition->levy_namespace, definition->levy_mosaic, network);
switch (definition->levy) {
case NEMMosaicLevy_MosaicLevy_Absolute:

View File

@ -45,13 +45,26 @@ bool nem_fsmMosaicCreation(nem_transaction_ctx *context, const NEMTransactionCom
bool nem_askMultisig(const char *address, const char *desc, bool cosigning, uint64_t fee);
bool nem_fsmMultisig(nem_transaction_ctx *context, const NEMTransactionCommon *common, const nem_transaction_ctx *inner, bool cosigning);
const NEMMosaicDefinition *nem_mosaicByName(const char *namespace, const char *mosaic);
const NEMMosaicDefinition *nem_mosaicByName(const char *namespace, const char *mosaic, uint8_t network);
void nem_mosaicFormatAmount(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, char *str_out, size_t size);
bool nem_mosaicFormatLevy(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, char *str_out, size_t size);
bool nem_mosaicFormatLevy(const NEMMosaicDefinition *definition, uint64_t quantity, const bignum256 *multiplier, uint8_t network, char *str_out, size_t size);
void nem_mosaicFormatName(const char *namespace, const char *mosaic, char *str_out, size_t size);
static inline bool nem_mosaicMatches(const NEMMosaicDefinition *definition, const char *namespace, const char *mosaic) {
return strcmp(namespace, definition->namespace) == 0 && strcmp(mosaic, definition->mosaic) == 0;
static inline bool nem_mosaicMatches(const NEMMosaicDefinition *definition, const char *namespace, const char *mosaic, uint8_t network) {
if (strcmp(namespace, definition->namespace) == 0 && strcmp(mosaic, definition->mosaic) == 0) {
if (definition->networks_count == 0) {
return true;
}
for (size_t i = 0; i < definition->networks_count; i++) {
if (definition->networks[i] == network) {
return true;
}
}
}
return false;
}
#endif

View File

@ -33,6 +33,8 @@ const NEMMosaicDefinition NEM_MOSAIC_DEFINITIONS[NEM_MOSAIC_DEFINITIONS_COUNT] =
.levy_namespace = "dim",
.has_levy_mosaic = true,
.levy_mosaic = "coin",
.networks_count = 1,
.networks = { 104 },
},
{
.has_name = true,
@ -45,6 +47,8 @@ const NEMMosaicDefinition NEM_MOSAIC_DEFINITIONS[NEM_MOSAIC_DEFINITIONS_COUNT] =
.mosaic = "token",
.has_divisibility = true,
.divisibility = 6,
.networks_count = 1,
.networks = { 104 },
}};
const NEMMosaicDefinition *NEM_MOSAIC_DEFINITION_XEM = NEM_MOSAIC_DEFINITIONS;

View File

@ -15,13 +15,15 @@
"levy": "MosaicLevy_Percentile",
"fee": 10,
"levy_namespace": "dim",
"levy_mosaic": "coin"
"levy_mosaic": "coin",
"networks": [ 104 ]
},
{
"name": "DIM TOKEN",
"ticker": " DIMTOK",
"namespace": "dim",
"mosaic": "token",
"divisibility": 6
"divisibility": 6,
"networks": [ 104 ]
}
]