Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

Commit

Permalink
[Steem] Add 'account_update' operations
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Oct 17, 2016
1 parent fd35800 commit 3312fa3
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 71 deletions.
141 changes: 115 additions & 26 deletions firmware/fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1087,18 +1087,28 @@ void fsm_msgSteemSignTx(SteemSignTx *msg)
{
RESP_INIT(SteemTxSignature);

layout_steem_confirm_transfer(
msg->transfer.from,
msg->transfer.to,
msg->transfer.asset,
msg->transfer.amount
);
// true: right, false: left
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing Canceled");
layoutHome();
return;
}
if (msg->has_transfer) {
layout_steem_confirm_transfer(
msg->transfer.from,
msg->transfer.to,
msg->transfer.asset,
msg->transfer.amount
);
// true: right, false: left
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing Canceled");
layoutHome();
return;
}
} else if (msg->has_account_update) {
layout_steem_confirm_account_update(msg->account_update.account);
// true: right, false: left
if (!protectButton(ButtonRequestType_ButtonRequest_SignTx, false)) {
fsm_sendFailure(FailureType_Failure_ActionCancelled, "Signing Canceled");
layoutHome();
return;
}
}

const uint8_t chainid[32] = {0};

Expand All @@ -1112,22 +1122,101 @@ void fsm_msgSteemSignTx(SteemSignTx *msg)

gph_ser_varint(&ctx, 1); // one operation

/**
* Transfer specific
*/
gph_ser_varint(&ctx, 2); // transfer operation
gph_ser_string(&ctx, msg->transfer.from);
gph_ser_string(&ctx, msg->transfer.to);
if(steem_ser_amount(&ctx, msg->transfer.amount, msg->transfer.asset))
{
fsm_sendFailure(FailureType_Failure_Other, "Unknown Asset");
}
if (msg->transfer.has_memo && msg->transfer.memo) {
gph_ser_string(&ctx, msg->transfer.memo);
}
/**
* transfer specific
*/
if (msg->has_transfer) {
gph_ser_varint(&ctx, 2); // transfer operation
gph_ser_string(&ctx, msg->transfer.from);
gph_ser_string(&ctx, msg->transfer.to);
if(steem_ser_amount(&ctx, msg->transfer.amount, msg->transfer.asset))
{
fsm_sendFailure(FailureType_Failure_Other, "Unknown Asset");
}
if (msg->transfer.has_memo) {
gph_ser_string(&ctx, msg->transfer.memo);
} else {
gph_ser_string(&ctx, "");
}

/**
* account_update specific
*/
} else if (msg->has_account_update) {
gph_ser_varint(&ctx, 10); // account_update
// account
gph_ser_string(&ctx, msg->account_update.account);
// owner
gph_ser_bool(&ctx, msg->account_update.has_owner); // Optional(owner)
if (msg->account_update.has_owner)
{
// weight_threshold
gph_ser_int32(&ctx, msg->account_update.owner.weight_threshold);
// account_auths
gph_ser_varint(&ctx, msg->account_update.owner.account_auths_count);
for ( uint8_t i = 0; i < msg->account_update.owner.account_auths_count; ++i)
{
gph_ser_string(&ctx, msg->account_update.owner.account_auths[i].account);
gph_ser_int16(&ctx, msg->account_update.owner.account_auths[i].weight);
}
// key_auths
gph_ser_varint(&ctx, msg->account_update.owner.key_auths_count);
for ( uint8_t i = 0; i < msg->account_update.owner.key_auths_count; ++i)
{
gph_ser_bytes(&ctx, msg->account_update.owner.key_auths[i].pubkey.bytes, 33);
gph_ser_int16(&ctx, msg->account_update.owner.key_auths[i].weight);
}
}
// active
gph_ser_bool(&ctx, msg->account_update.has_active); // Optional(active)
if (msg->account_update.has_active)
{
// weight_threshold
gph_ser_int32(&ctx, msg->account_update.active.weight_threshold);
// account_auths
gph_ser_varint(&ctx, msg->account_update.active.account_auths_count);
for ( uint8_t i = 0; i < msg->account_update.active.account_auths_count; ++i)
{
gph_ser_string(&ctx, msg->account_update.active.account_auths[i].account);
gph_ser_int16(&ctx, msg->account_update.active.account_auths[i].weight);
}
// key_auths
gph_ser_varint(&ctx, msg->account_update.active.key_auths_count);
for ( uint8_t i = 0; i < msg->account_update.active.key_auths_count; ++i)
{
gph_ser_bytes(&ctx, msg->account_update.active.key_auths[i].pubkey.bytes, 33);
gph_ser_int16(&ctx, msg->account_update.active.key_auths[i].weight);
}
}
// posting
gph_ser_bool(&ctx, msg->account_update.has_posting); // Optional(posting)
if (msg->account_update.has_posting)
{
// weight_threshold
gph_ser_int32(&ctx, msg->account_update.posting.weight_threshold);
// account_auths
gph_ser_varint(&ctx, msg->account_update.posting.account_auths_count);
for ( uint8_t i = 0; i < msg->account_update.posting.account_auths_count; ++i)
{
gph_ser_string(&ctx, msg->account_update.posting.account_auths[i].account);
gph_ser_int16(&ctx, msg->account_update.posting.account_auths[i].weight);
}
// key_auths
gph_ser_varint(&ctx, msg->account_update.posting.key_auths_count);
for ( uint8_t i = 0; i < msg->account_update.posting.key_auths_count; ++i)
{
gph_ser_bytes(&ctx, msg->account_update.posting.key_auths[i].pubkey.bytes, 33);
gph_ser_int16(&ctx, msg->account_update.posting.key_auths[i].weight);
}
}
// memo_key
gph_ser_bytes(&ctx, msg->account_update.memo_key.bytes, 33);
// json_metadata
gph_ser_string(&ctx, "");
}

/**
* End of transfer specific
* End of operation specific
*/
gph_ser_varint(&ctx, 0); // extension

Expand Down
8 changes: 7 additions & 1 deletion firmware/protob/messages.options
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ SteemOperationTransfer.from max_size:16
SteemOperationTransfer.to max_size:16
SteemOperationTransfer.asset max_size:8
SteemOperationTransfer.memo max_size:64
SteemOperationAccountUpdate.account max_size:16
SteemOperationAccountUpdate.memo_key max_size:33
SteemOperationAccountUpdate.json_metadata max_size:256
SteemPermission.account_auths max_count:4
SteemPermission.key_auths max_count:4
SteemAccountKeyAuth.pubkey max_size:33
SteemAccountAccountAuth.account max_size:16
SteemPublicKey.pubkey max_size:33
SteemPublicKey.address max_size:20
SteemTxSignature.signature max_size:65
SteemTxSignature.digest max_size:32

Expand Down
41 changes: 34 additions & 7 deletions firmware/protob/messages.pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "messages.pb.h"

const char GetAddress_coin_name_default[17] = "Bitcoin";
const InputScriptType GetAddress_script_type_default = InputScriptType_SPENDADDRESS;
const char LoadDevice_language_default[17] = "english";
const uint32_t ResetDevice_strength_default = 256u;
const char ResetDevice_language_default[17] = "english";
Expand All @@ -29,7 +28,7 @@ const pb_field_t GetFeatures_fields[1] = {
PB_LAST_FIELD
};

const pb_field_t Features_fields[19] = {
const pb_field_t Features_fields[18] = {
PB_FIELD2( 1, STRING , OPTIONAL, STATIC , FIRST, Features, vendor, vendor, 0),
PB_FIELD2( 2, UINT32 , OPTIONAL, STATIC , OTHER, Features, major_version, vendor, 0),
PB_FIELD2( 3, UINT32 , OPTIONAL, STATIC , OTHER, Features, minor_version, major_version, 0),
Expand All @@ -47,7 +46,6 @@ const pb_field_t Features_fields[19] = {
PB_FIELD2( 15, BOOL , OPTIONAL, STATIC , OTHER, Features, imported, bootloader_hash, 0),
PB_FIELD2( 16, BOOL , OPTIONAL, STATIC , OTHER, Features, pin_cached, imported, 0),
PB_FIELD2( 17, BOOL , OPTIONAL, STATIC , OTHER, Features, passphrase_cached, pin_cached, 0),
PB_FIELD2( 18, BOOL , OPTIONAL, STATIC , OTHER, Features, firmware_present, passphrase_cached, 0),
PB_LAST_FIELD
};

Expand Down Expand Up @@ -143,12 +141,11 @@ const pb_field_t PublicKey_fields[3] = {
PB_LAST_FIELD
};

const pb_field_t GetAddress_fields[6] = {
const pb_field_t GetAddress_fields[5] = {
PB_FIELD2( 1, UINT32 , REPEATED, STATIC , FIRST, GetAddress, address_n, address_n, 0),
PB_FIELD2( 2, STRING , OPTIONAL, STATIC , OTHER, GetAddress, coin_name, address_n, &GetAddress_coin_name_default),
PB_FIELD2( 3, BOOL , OPTIONAL, STATIC , OTHER, GetAddress, show_display, coin_name, 0),
PB_FIELD2( 4, MESSAGE , OPTIONAL, STATIC , OTHER, GetAddress, multisig, show_display, &MultisigRedeemScriptType_fields),
PB_FIELD2( 5, ENUM , OPTIONAL, STATIC , OTHER, GetAddress, script_type, multisig, &GetAddress_script_type_default),
PB_LAST_FIELD
};

Expand Down Expand Up @@ -454,6 +451,35 @@ const pb_field_t DebugLinkFlashErase_fields[2] = {
PB_LAST_FIELD
};

const pb_field_t SteemAccountKeyAuth_fields[3] = {
PB_FIELD2( 1, BYTES , REQUIRED, STATIC , FIRST, SteemAccountKeyAuth, pubkey, pubkey, 0),
PB_FIELD2( 2, UINT32 , REQUIRED, STATIC , OTHER, SteemAccountKeyAuth, weight, pubkey, 0),
PB_LAST_FIELD
};

const pb_field_t SteemAccountAccountAuth_fields[3] = {
PB_FIELD2( 1, STRING , REQUIRED, STATIC , FIRST, SteemAccountAccountAuth, account, account, 0),
PB_FIELD2( 2, UINT32 , REQUIRED, STATIC , OTHER, SteemAccountAccountAuth, weight, account, 0),
PB_LAST_FIELD
};

const pb_field_t SteemPermission_fields[4] = {
PB_FIELD2( 1, UINT32 , REQUIRED, STATIC , FIRST, SteemPermission, weight_threshold, weight_threshold, 0),
PB_FIELD2( 2, MESSAGE , REPEATED, STATIC , OTHER, SteemPermission, account_auths, weight_threshold, &SteemAccountAccountAuth_fields),
PB_FIELD2( 3, MESSAGE , REPEATED, STATIC , OTHER, SteemPermission, key_auths, account_auths, &SteemAccountKeyAuth_fields),
PB_LAST_FIELD
};

const pb_field_t SteemOperationAccountUpdate_fields[7] = {
PB_FIELD2( 1, STRING , REQUIRED, STATIC , FIRST, SteemOperationAccountUpdate, account, account, 0),
PB_FIELD2( 2, BYTES , REQUIRED, STATIC , OTHER, SteemOperationAccountUpdate, memo_key, account, 0),
PB_FIELD2( 3, STRING , REQUIRED, STATIC , OTHER, SteemOperationAccountUpdate, json_metadata, memo_key, 0),
PB_FIELD2( 4, MESSAGE , OPTIONAL, STATIC , OTHER, SteemOperationAccountUpdate, owner, json_metadata, &SteemPermission_fields),
PB_FIELD2( 5, MESSAGE , OPTIONAL, STATIC , OTHER, SteemOperationAccountUpdate, active, owner, &SteemPermission_fields),
PB_FIELD2( 6, MESSAGE , OPTIONAL, STATIC , OTHER, SteemOperationAccountUpdate, posting, active, &SteemPermission_fields),
PB_LAST_FIELD
};

const pb_field_t SteemOperationTransfer_fields[6] = {
PB_FIELD2( 1, STRING , REQUIRED, STATIC , FIRST, SteemOperationTransfer, from, from, 0),
PB_FIELD2( 2, STRING , REQUIRED, STATIC , OTHER, SteemOperationTransfer, to, from, 0),
Expand All @@ -463,11 +489,12 @@ const pb_field_t SteemOperationTransfer_fields[6] = {
PB_LAST_FIELD
};

const pb_field_t SteemSignTx_fields[5] = {
const pb_field_t SteemSignTx_fields[6] = {
PB_FIELD2( 1, UINT32 , REQUIRED, STATIC , FIRST, SteemSignTx, ref_block_num, ref_block_num, 0),
PB_FIELD2( 2, UINT32 , REQUIRED, STATIC , OTHER, SteemSignTx, ref_block_prefix, ref_block_num, 0),
PB_FIELD2( 3, UINT32 , REQUIRED, STATIC , OTHER, SteemSignTx, expiration, ref_block_prefix, 0),
PB_FIELD2( 4, MESSAGE , OPTIONAL, STATIC , OTHER, SteemSignTx, transfer, expiration, &SteemOperationTransfer_fields),
PB_FIELD2( 5, MESSAGE , OPTIONAL, STATIC , OTHER, SteemSignTx, account_update, transfer, &SteemOperationAccountUpdate_fields),
PB_LAST_FIELD
};

Expand Down Expand Up @@ -498,7 +525,7 @@ const pb_field_t SteemPublicKey_fields[2] = {
* numbers or field sizes that are larger than what can fit in 8 or 16 bit
* field descriptors.
*/
STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536 && pb_membersize(SteemSignTx, transfer) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_SetU2FCounter_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase_SteemOperationTransfer_SteemSignTx_SteemTxSignature_SteemGetPublicKey_SteemPublicKey)
STATIC_ASSERT((pb_membersize(Features, coins[0]) < 65536 && pb_membersize(PublicKey, node) < 65536 && pb_membersize(GetAddress, multisig) < 65536 && pb_membersize(LoadDevice, node) < 65536 && pb_membersize(SimpleSignTx, inputs[0]) < 65536 && pb_membersize(SimpleSignTx, outputs[0]) < 65536 && pb_membersize(SimpleSignTx, transactions[0]) < 65536 && pb_membersize(TxRequest, details) < 65536 && pb_membersize(TxRequest, serialized) < 65536 && pb_membersize(TxAck, tx) < 65536 && pb_membersize(SignIdentity, identity) < 65536 && pb_membersize(GetECDHSessionKey, identity) < 65536 && pb_membersize(DebugLinkState, node) < 65536 && pb_membersize(SteemPermission, account_auths[0]) < 65536 && pb_membersize(SteemPermission, key_auths[0]) < 65536 && pb_membersize(SteemOperationAccountUpdate, owner) < 65536 && pb_membersize(SteemOperationAccountUpdate, active) < 65536 && pb_membersize(SteemOperationAccountUpdate, posting) < 65536 && pb_membersize(SteemSignTx, transfer) < 65536 && pb_membersize(SteemSignTx, account_update) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Initialize_GetFeatures_Features_ClearSession_ApplySettings_ChangePin_Ping_Success_Failure_ButtonRequest_ButtonAck_PinMatrixRequest_PinMatrixAck_Cancel_PassphraseRequest_PassphraseAck_GetEntropy_Entropy_GetPublicKey_PublicKey_GetAddress_EthereumGetAddress_Address_EthereumAddress_WipeDevice_LoadDevice_ResetDevice_EntropyRequest_EntropyAck_RecoveryDevice_WordRequest_WordAck_SignMessage_VerifyMessage_MessageSignature_EncryptMessage_EncryptedMessage_DecryptMessage_DecryptedMessage_CipherKeyValue_CipheredKeyValue_EstimateTxSize_TxSize_SignTx_SimpleSignTx_TxRequest_TxAck_EthereumSignTx_EthereumTxRequest_EthereumTxAck_SignIdentity_SignedIdentity_GetECDHSessionKey_ECDHSessionKey_SetU2FCounter_FirmwareErase_FirmwareUpload_DebugLinkDecision_DebugLinkGetState_DebugLinkState_DebugLinkStop_DebugLinkLog_DebugLinkMemoryRead_DebugLinkMemory_DebugLinkMemoryWrite_DebugLinkFlashErase_SteemAccountKeyAuth_SteemAccountAccountAuth_SteemPermission_SteemOperationAccountUpdate_SteemOperationTransfer_SteemSignTx_SteemTxSignature_SteemGetPublicKey_SteemPublicKey)
#endif

#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
Expand Down
Loading

0 comments on commit 3312fa3

Please sign in to comment.