clang format

This commit is contained in:
pscott
2021-06-29 16:07:28 +02:00
parent 0294c5e60f
commit 032bd7b7ee
3 changed files with 35 additions and 33 deletions

View File

@@ -528,12 +528,13 @@ static parserStatus_e processTxInternal(txContext_t *context) {
if (PARSING_IS_DONE(context)) {
return USTREAM_FINISHED;
}
// Old style transaction (pre EIP-155). Transations could just skip `v,r,s` so we needed to cut parsing here.
// commandLength == 0 could happen in two cases :
// Old style transaction (pre EIP-155). Transations could just skip `v,r,s` so we needed to
// cut parsing here. commandLength == 0 could happen in two cases :
// 1. We are in an old style transaction : just return `USTREAM_FINISHED`.
// 2. We are at the end of an APDU in a multi-apdu process. This would make us return `USTREAM_FINISHED` preemptively.
// Case number 2 should NOT happen as it is up to `ledgerjs` to correctly decrease the size of the
// APDU (`commandLength`) so that this situation doesn't happen.
// 2. We are at the end of an APDU in a multi-apdu process. This would make us return
// `USTREAM_FINISHED` preemptively. Case number 2 should NOT happen as it is up to
// `ledgerjs` to correctly decrease the size of the APDU (`commandLength`) so that this
// situation doesn't happen.
if ((context->txType == LEGACY && context->currentField == LEGACY_RLP_V) &&
(context->commandLength == 0)) {
context->content->vLength = 0;

View File

@@ -42,15 +42,15 @@ typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
// First variant of every Tx enum.
#define RLP_NONE 0
#define PARSING_IS_DONE(ctx) \
((ctx->txType == LEGACY && ctx->currentField == LEGACY_RLP_DONE) || \
(ctx->txType == EIP2930 && ctx->currentField == EIP2930_RLP_DONE) || \
(ctx->txType == EIP1559 && ctx->currentField == EIP1559_RLP_DONE))
#define PARSING_IS_DONE(ctx) \
((ctx->txType == LEGACY && ctx->currentField == LEGACY_RLP_DONE) || \
(ctx->txType == EIP2930 && ctx->currentField == EIP2930_RLP_DONE) || \
(ctx->txType == EIP1559 && ctx->currentField == EIP1559_RLP_DONE))
typedef enum rlpLegacyTxField_e {
LEGACY_RLP_NONE = RLP_NONE,
LEGACY_RLP_CONTENT,
LEGACY_RLP_TYPE, // For wanchain
LEGACY_RLP_TYPE, // For wanchain
LEGACY_RLP_NONCE,
LEGACY_RLP_GASPRICE,
LEGACY_RLP_STARTGAS,
@@ -66,7 +66,7 @@ typedef enum rlpLegacyTxField_e {
typedef enum rlpEIP2930TxField_e {
EIP2930_RLP_NONE = RLP_NONE,
EIP2930_RLP_CONTENT,
EIP2930_RLP_TYPE, // For wanchain
EIP2930_RLP_TYPE, // For wanchain
EIP2930_RLP_CHAINID,
EIP2930_RLP_NONCE,
EIP2930_RLP_GASPRICE,
@@ -84,7 +84,7 @@ typedef enum rlpEIP2930TxField_e {
typedef enum rlpEIP1559TxField_e {
EIP1559_RLP_NONE = RLP_NONE,
EIP1559_RLP_CONTENT,
EIP1559_RLP_TYPE, // For wanchain
EIP1559_RLP_TYPE, // For wanchain
EIP1559_RLP_CHAINID,
EIP1559_RLP_NONCE,
EIP1559_RLP_MAX_PRIORITY_FEE_PER_GAS,
@@ -125,8 +125,8 @@ typedef struct txInt256_t {
} txInt256_t;
typedef struct txContent_t {
txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions.
txInt256_t startgas; // Also known as `gasLimit`.
txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions.
txInt256_t startgas; // Also known as `gasLimit`.
txInt256_t value;
txInt256_t nonce;
txInt256_t chainID;

View File

@@ -194,23 +194,16 @@ void reportFinalizeError(bool direct) {
}
}
// Convert `BEgasPrice` and `BEgasLimit` to Uint256 and then stores the multiplication of both in `output`.
// Convert `BEgasPrice` and `BEgasLimit` to Uint256 and then stores the multiplication of both in
// `output`.
static void computeFees(txInt256_t *BEgasPrice, txInt256_t *BEgasLimit, uint256_t *output) {
uint256_t gasPrice = {0};
uint256_t gasLimit = {0};
PRINTF("Gas price %.*H\n",
BEgasPrice->length,
BEgasPrice->value);
PRINTF("Gas limit %.*H\n",
BEgasLimit->length,
BEgasLimit->value);
convertUint256BE(BEgasPrice->value,
BEgasPrice->length,
&gasPrice);
convertUint256BE(BEgasLimit->value,
BEgasLimit->length,
&gasLimit);
PRINTF("Gas price %.*H\n", BEgasPrice->length, BEgasPrice->value);
PRINTF("Gas limit %.*H\n", BEgasLimit->length, BEgasLimit->value);
convertUint256BE(BEgasPrice->value, BEgasPrice->length, &gasPrice);
convertUint256BE(BEgasLimit->value, BEgasLimit->length, &gasLimit);
mul256(&gasPrice, &gasLimit, output);
}
@@ -244,15 +237,22 @@ static void feesToString(uint256_t *rawFee, char *displayBuffer, uint32_t displa
PRINTF("Displayed fees: %s\n", displayBuffer);
}
// Compute the fees, transform it to a string, prepend a ticker to it and copy everything to `displayBuffer`.
void prepareAndCopyFees(txInt256_t *BEGasPrice, txInt256_t *BEGasLimit, char *displayBuffer, uint32_t displayBufferSize) {
// Compute the fees, transform it to a string, prepend a ticker to it and copy everything to
// `displayBuffer`.
void prepareAndCopyFees(txInt256_t *BEGasPrice,
txInt256_t *BEGasLimit,
char *displayBuffer,
uint32_t displayBufferSize) {
uint256_t rawFee = {0};
computeFees(BEGasPrice, BEGasLimit, &rawFee);
feesToString(&rawFee, displayBuffer, displayBufferSize);
}
void prepareFeeDisplay() {
prepareAndCopyFees(&tmpContent.txContent.gasprice, &tmpContent.txContent.startgas, strings.common.maxFee, sizeof(strings.common.maxFee));
prepareAndCopyFees(&tmpContent.txContent.gasprice,
&tmpContent.txContent.startgas,
strings.common.maxFee,
sizeof(strings.common.maxFee));
}
uint32_t get_chainID() {
@@ -261,9 +261,10 @@ uint32_t get_chainID() {
if (txContext.txType == LEGACY) {
chain_id = u32_from_BE(txContext.content->v, txContext.content->vLength, true);
} else if (txContext.txType == EIP2930 || txContext.txType == EIP1559) {
chain_id = u32_from_BE(tmpContent.txContent.chainID.value, tmpContent.txContent.chainID.length, true);
}
else {
chain_id = u32_from_BE(tmpContent.txContent.chainID.value,
tmpContent.txContent.chainID.length,
true);
} else {
PRINTF("Txtype `%u` not supported while generating chainID\n", txContext.txType);
}
PRINTF("ChainID: %d\n", chain_id);