Added a util function to convert from byte buffer to uint128_t

This commit is contained in:
Alexandre Paillier
2022-06-08 11:38:08 +02:00
parent f3e307423e
commit bbcfe5abc3
3 changed files with 14 additions and 2 deletions

View File

@@ -20,6 +20,7 @@
#include "ethUstream.h"
#include "ethUtils.h"
#include "uint128.h"
#include "uint256.h"
#include "tokens.h"
#include "utils.h"
@@ -33,10 +34,19 @@ void array_hexstr(char *strbuf, const void *bin, unsigned int len) {
*strbuf = 0; // EOS
}
void convertUint128BE(const uint8_t *const data, uint32_t length, uint128_t *const target) {
uint8_t tmp[INT128_LENGTH];
memset(tmp, 0, sizeof(tmp) - length);
memmove(tmp + sizeof(tmp) - length, data, length);
readu128BE(tmp, target);
}
void convertUint256BE(const uint8_t *const data, uint32_t length, uint256_t *const target) {
uint8_t tmp[INT256_LENGTH];
memset(tmp, 0, 32);
memmove(tmp + 32 - length, data, length);
memset(tmp, 0, sizeof(tmp) - length);
memmove(tmp + sizeof(tmp) - length, data, length);
readu256BE(tmp, target);
}

View File

@@ -24,6 +24,7 @@
void array_hexstr(char* strbuf, const void* bin, unsigned int len);
void convertUint128BE(const uint8_t *const data, uint32_t length, uint128_t *const target);
void convertUint256BE(const uint8_t *const data, uint32_t length, uint256_t *const target);
uint64_t u64_from_BE(const uint8_t* in, uint8_t size);

View File

@@ -37,6 +37,7 @@ typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
#define TX_FLAG_TYPE 0x01
#define ADDRESS_LENGTH 20
#define INT128_LENGTH 16
#define INT256_LENGTH 32
// First variant of every Tx enum.