Skip to content

Commit

Permalink
chore: c code style
Browse files Browse the repository at this point in the history
  • Loading branch information
krigga committed Mar 5, 2024
1 parent 63a8560 commit 29965f1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 30 deletions.
15 changes: 7 additions & 8 deletions src/common/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@

#include "format.h"

int format_hex(const uint8_t *in, size_t in_len, char *out, size_t out_len)
{
int format_hex(const uint8_t *in, size_t in_len, char *out, size_t out_len) {
if (out_len < 2 * in_len + 1) {
return -1;
}

const char hex[] = "0123456789ABCDEF";
size_t i = 0;
int written = 0;
const char hex[] = "0123456789ABCDEF";
size_t i = 0;
int written = 0;

while (i < in_len && (i * 2 + (2 + 1)) <= out_len) {
uint8_t high_nibble = (in[i] & 0xF0) >> 4;
*out = hex[high_nibble];
*out = hex[high_nibble];
out++;

uint8_t low_nibble = in[i] & 0x0F;
*out = hex[low_nibble];
*out = hex[low_nibble];
out++;

i++;
Expand All @@ -47,7 +46,7 @@ int format_hex(const uint8_t *in, size_t in_len, char *out, size_t out_len)
return written + 1;
}

void format_u64(uint64_t in, char* out, size_t out_len) {
void format_u64(uint64_t in, char *out, size_t out_len) {
int len = 0;
if (in == 0) {
len = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/common/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
*/
int format_hex(const uint8_t *in, size_t in_len, char *out, size_t out_len);

void format_u64(uint64_t in, char* out, size_t out_len);
void format_u64(uint64_t in, char *out, size_t out_len);
5 changes: 3 additions & 2 deletions src/common/hints.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ void add_hint_hex(HintHolder_t* hints, const char* title, uint8_t* data, uint8_t
// Configure
hints->hints[hints->hints_count].title = title;
hints->hints[hints->hints_count].kind = SummaryHex;
memmove(hints->hints[hints->hints_count].hex.data, data, data_len > HASH_LEN ? HASH_LEN : data_len);
memmove(hints->hints[hints->hints_count].hex.data,
data,
data_len > HASH_LEN ? HASH_LEN : data_len);
hints->hints[hints->hints_count].hex.len = data_len;


// Next
hints->hints_count++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@

/**
* Default subwallet id, which will not be displayed.
*/
*/
#define DEFAULT_SUBWALLET_ID 698983191

/**
* Max length for cell_inline types
*/
*/
#define MAX_CELL_INLINE_LEN 32
10 changes: 5 additions & 5 deletions src/transaction/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ bool hash_tx(transaction_ctx_t *ctx) {

struct CellRef_t orderRef;
BitString_init(&bits);
BitString_storeUint(&bits, ctx->transaction.subwallet_id, 32); // Wallet ID
BitString_storeUint(&bits, ctx->transaction.timeout, 32); // Timeout
BitString_storeUint(&bits, ctx->transaction.seqno, 32); // Seqno
BitString_storeUint(&bits, ctx->transaction.subwallet_id, 32); // Wallet ID
BitString_storeUint(&bits, ctx->transaction.timeout, 32); // Timeout
BitString_storeUint(&bits, ctx->transaction.seqno, 32); // Seqno
if (ctx->transaction.include_wallet_op) {
BitString_storeUint(&bits, 0, 8); // Simple order
BitString_storeUint(&bits, 0, 8); // Simple order
}
BitString_storeUint(&bits, ctx->transaction.send_mode, 8); // Send Mode
BitString_storeUint(&bits, ctx->transaction.send_mode, 8); // Send Mode
struct CellRef_t orderRefs[1] = {internalMessageRef};
if (!hash_Cell(&bits, orderRefs, 1, &orderRef)) {
return false;
Expand Down
44 changes: 33 additions & 11 deletions src/transaction/transaction_hints.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
return false; \
}

static const uint8_t dns_key_wallet[32] = {0xe8, 0xd4, 0x40, 0x50, 0x87, 0x3d, 0xba, 0x86, 0x5a, 0xa7, 0xc1, 0x70, 0xab, 0x4c, 0xce, 0x64, 0xd9, 0x08, 0x39, 0xa3, 0x4d, 0xcf, 0xd6, 0xcf, 0x71, 0xd1, 0x4e, 0x02, 0x05, 0x44, 0x3b, 0x1b};
static const uint8_t dns_key_wallet[32] = {
0xe8, 0xd4, 0x40, 0x50, 0x87, 0x3d, 0xba, 0x86, 0x5a, 0xa7, 0xc1, 0x70, 0xab, 0x4c, 0xce, 0x64,
0xd9, 0x08, 0x39, 0xa3, 0x4d, 0xcf, 0xd6, 0xcf, 0x71, 0xd1, 0x4e, 0x02, 0x05, 0x44, 0x3b, 0x1b};

bool process_hints(transaction_t* tx) {
// Default title
Expand Down Expand Up @@ -274,9 +276,12 @@ bool process_hints(transaction_t* tx) {
snprintf(tx->recipient, sizeof(tx->recipient), "Jetton wallet");
}

if (tx->hints_type == TRANSACTION_ADD_WHITELIST || tx->hints_type == TRANSACTION_SINGLE_NOMINATOR_CHANGE_VALIDATOR) {
if (tx->hints_type == TRANSACTION_ADD_WHITELIST ||
tx->hints_type == TRANSACTION_SINGLE_NOMINATOR_CHANGE_VALIDATOR) {
BitString_init(&bits);
BitString_storeUint(&bits, tx->hints_type == TRANSACTION_ADD_WHITELIST ? 0x7258a69b : 0x1001, 32);
BitString_storeUint(&bits,
tx->hints_type == TRANSACTION_ADD_WHITELIST ? 0x7258a69b : 0x1001,
32);

SAFE(buffer_read_bool(&buf, &tmp));
if (tmp) {
Expand All @@ -291,7 +296,11 @@ bool process_hints(transaction_t* tx) {
SAFE(buffer_read_address(&buf, &addr));
BitString_storeAddress(&bits, addr.chain, addr.hash);

add_hint_address(&tx->hints, tx->hints_type == TRANSACTION_ADD_WHITELIST ? "New whitelist" : "New validator", addr, false);
add_hint_address(
&tx->hints,
tx->hints_type == TRANSACTION_ADD_WHITELIST ? "New whitelist" : "New validator",
addr,
false);

CHECK_END();

Expand All @@ -300,9 +309,17 @@ bool process_hints(transaction_t* tx) {
hasCell = true;

// Operation
snprintf(tx->title, sizeof(tx->title), tx->hints_type == TRANSACTION_ADD_WHITELIST ? "Add whitelist" : "Edit validator");
snprintf(tx->action, sizeof(tx->action), tx->hints_type == TRANSACTION_ADD_WHITELIST ? "add whitelist" : "change validator");
snprintf(tx->recipient, sizeof(tx->recipient), tx->hints_type == TRANSACTION_ADD_WHITELIST ? "Vesting wallet" : "Single Nominator");
snprintf(tx->title,
sizeof(tx->title),
tx->hints_type == TRANSACTION_ADD_WHITELIST ? "Add whitelist" : "Edit validator");
snprintf(
tx->action,
sizeof(tx->action),
tx->hints_type == TRANSACTION_ADD_WHITELIST ? "add whitelist" : "change validator");
snprintf(
tx->recipient,
sizeof(tx->recipient),
tx->hints_type == TRANSACTION_ADD_WHITELIST ? "Vesting wallet" : "Single Nominator");
}

if (tx->hints_type == TRANSACTION_SINGLE_NOMINATOR_WITHDRAW) {
Expand All @@ -323,7 +340,12 @@ bool process_hints(transaction_t* tx) {
SAFE(buffer_read_varuint(&buf, &amount_size, amount_buf, MAX_VALUE_BYTES_LEN));
BitString_storeCoinsBuf(&bits, amount_buf, amount_size);

add_hint_amount(&tx->hints, "Withdraw amount", "TON", amount_buf, amount_size, EXPONENT_SMALLEST_UNIT);
add_hint_amount(&tx->hints,
"Withdraw amount",
"TON",
amount_buf,
amount_size,
EXPONENT_SMALLEST_UNIT);

CHECK_END();

Expand Down Expand Up @@ -438,7 +460,7 @@ bool process_hints(transaction_t* tx) {
uint8_t type;
SAFE(buffer_read_u8(&buf, &type));

if (type == 0x00) { // wallet
if (type == 0x00) { // wallet
add_hint_text(&tx->hints, "Type", "Wallet", 6);

BitString_storeBuffer(&bits, dns_key_wallet, sizeof(dns_key_wallet));
Expand Down Expand Up @@ -477,7 +499,7 @@ bool process_hints(transaction_t* tx) {

hash_Cell(&inner_bits, NULL, 0, &refs[ref_count++]);
}
} else if (type == 0x01) { // unknown key
} else if (type == 0x01) { // unknown key
add_hint_text(&tx->hints, "Type", "Unknown", 7);

uint8_t key[32];
Expand All @@ -490,7 +512,7 @@ bool process_hints(transaction_t* tx) {
if (has_value) {
SAFE(buffer_read_cell_ref(&buf, &refs[ref_count++]));

add_hint_hash(&tx->hints, "Value", refs[ref_count-1].hash);
add_hint_hash(&tx->hints, "Value", refs[ref_count - 1].hash);
}
} else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/transaction/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef enum {
} parser_status_e;

typedef struct {
uint8_t tag; // tag (1 byte)
uint8_t tag; // tag (1 byte)
uint32_t subwallet_id;
bool include_wallet_op;
uint32_t seqno; // seqno (4 bytes)
Expand Down

0 comments on commit 29965f1

Please sign in to comment.