1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-13 19:18:56 +00:00

nem2: Handle Mosaic Supply Change transactions

This commit is contained in:
Saleem Rashid 2017-07-23 15:45:20 +01:00
parent 327736ca96
commit a10e131ecd
3 changed files with 92 additions and 1 deletions

View File

@ -1154,7 +1154,7 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
CHECK_PARAM(msg->has_transaction, _("No common provided"));
// Ensure exactly one transaction is provided
unsigned int provided = msg->has_transfer + msg->has_provision_namespace + msg->has_mosaic_creation;
unsigned int provided = msg->has_transfer + msg->has_provision_namespace + msg->has_mosaic_creation + msg->has_supply_change;
CHECK_PARAM(provided != 0, _("No transaction provided"));
CHECK_PARAM(provided == 1, _("More than one transaction provided"));
@ -1162,6 +1162,7 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
NEM_CHECK_PARAM_WHEN(msg->has_transfer, nem_validate_transfer(&msg->transfer, msg->transaction.network));
NEM_CHECK_PARAM_WHEN(msg->has_provision_namespace, nem_validate_provision_namespace(&msg->provision_namespace, msg->transaction.network));
NEM_CHECK_PARAM_WHEN(msg->has_mosaic_creation, nem_validate_mosaic_creation(&msg->mosaic_creation, msg->transaction.network));
NEM_CHECK_PARAM_WHEN(msg->has_supply_change, nem_validate_supply_change(&msg->supply_change));
bool cosigning = msg->has_cosigning && msg->cosigning;
if (msg->has_multisig) {
@ -1218,6 +1219,12 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
return;
}
if (msg->has_supply_change && !nem_askSupplyChange(common, &msg->supply_change, network)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, _("Signing cancelled by user"));
layoutHome();
return;
}
nem_transaction_ctx context;
nem_transaction_start(&context, &node->public_key[1], resp->data.bytes, sizeof(resp->data.bytes));
@ -1242,6 +1249,11 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
return;
}
if (msg->has_supply_change && !nem_fsmSupplyChange(&inner, &msg->multisig, &msg->supply_change)) {
layoutHome();
return;
}
if (!nem_fsmMultisig(&context, &msg->transaction, &inner, cosigning)) {
layoutHome();
return;
@ -1261,6 +1273,11 @@ void fsm_msgNEMSignTx(NEMSignTx *msg) {
layoutHome();
return;
}
if (msg->has_supply_change && !nem_fsmSupplyChange(&context, &msg->transaction, &msg->supply_change)) {
layoutHome();
return;
}
}
resp->has_data = true;

View File

@ -128,6 +128,15 @@ const char *nem_validate_mosaic_creation(const NEMMosaicCreation *mosaic_creatio
return NULL;
}
const char *nem_validate_supply_change(const NEMMosaicSupplyChange *supply_change) {
if (!supply_change->has_namespace) return _("No namespace provided");
if (!supply_change->has_mosaic) return _("No mosaic provided");
if (!supply_change->has_type) return _("No type provided");
if (!supply_change->has_delta) return _("No delta provided");
return NULL;
}
bool nem_askTransfer(const NEMTransactionCommon *common, const NEMTransfer *transfer, const char *desc) {
if (transfer->mosaics_count) {
struct {
@ -457,6 +466,67 @@ bool nem_fsmMosaicCreation(nem_transaction_ctx *context, const NEMTransactionCom
mosaic_creation->fee);
}
bool nem_askSupplyChange(const NEMTransactionCommon *common, const NEMMosaicSupplyChange *supply_change, const char *desc) {
layoutDialogSwipe(&bmp_icon_question,
_("Cancel"),
_("Next"),
desc,
_("Modify supply for"),
supply_change->mosaic,
_("under namespace"),
supply_change->namespace,
NULL,
NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmOutput, false)) {
return false;
}
char str_out[32];
bignum256 amnt;
bn_read_uint64(supply_change->delta, &amnt);
bn_format(&amnt, NULL, NULL, 0, str_out, sizeof(str_out));
char *decimal = strchr(str_out, '.');
if (decimal != NULL) {
*decimal = '\0';
}
layoutDialogSwipe(&bmp_icon_question,
_("Cancel"),
_("Next"),
desc,
supply_change->type == NEMSupplyChangeType_SupplyChange_Increase ? _("Increase supply by") : _("Decrease supply by"),
str_out,
_("whole units"),
NULL,
NULL,
NULL);
if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmOutput, false)) {
return false;
}
layoutNEMNetworkFee(desc, true, _("Confirm network fee"), common->fee, NULL, 0);
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
return false;
}
return true;
}
bool nem_fsmSupplyChange(nem_transaction_ctx *context, const NEMTransactionCommon *common, const NEMMosaicSupplyChange *supply_change) {
return nem_transaction_create_mosaic_supply_change(context,
common->network,
common->timestamp,
NULL,
common->fee,
common->deadline,
supply_change->namespace,
supply_change->mosaic,
supply_change->type,
supply_change->delta);
}
bool nem_askMultisig(const char *address, const char *desc, bool cosigning, uint64_t fee) {
layoutNEMDialog(&bmp_icon_question,
_("Cancel"),

View File

@ -32,6 +32,7 @@ const char *nem_validate_common(NEMTransactionCommon *common, bool inner);
const char *nem_validate_transfer(const NEMTransfer *transfer, uint8_t network);
const char *nem_validate_provision_namespace(const NEMProvisionNamespace *provision_namespace, uint8_t network);
const char *nem_validate_mosaic_creation(const NEMMosaicCreation *mosaic_creation, uint8_t network);
const char *nem_validate_supply_change(const NEMMosaicSupplyChange *supply_change);
bool nem_askTransfer(const NEMTransactionCommon *common, const NEMTransfer *transfer, const char *desc);
bool nem_fsmTransfer(nem_transaction_ctx *context, const HDNode *node, const NEMTransactionCommon *common, const NEMTransfer *transfer);
@ -42,6 +43,9 @@ bool nem_fsmProvisionNamespace(nem_transaction_ctx *context, const NEMTransactio
bool nem_askMosaicCreation(const NEMTransactionCommon *common, const NEMMosaicCreation *mosaic_creation, const char *desc, const char *address);
bool nem_fsmMosaicCreation(nem_transaction_ctx *context, const NEMTransactionCommon *common, const NEMMosaicCreation *mosaic_creation);
bool nem_askSupplyChange(const NEMTransactionCommon *common, const NEMMosaicSupplyChange *supply_change, const char *desc);
bool nem_fsmSupplyChange(nem_transaction_ctx *context, const NEMTransactionCommon *common, const NEMMosaicSupplyChange *supply_change);
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);