Skip to content

Commit

Permalink
Convert uint256 to array or reversed array (#1955)
Browse files Browse the repository at this point in the history
* Add HD Wallet Ethereum address support

* Add dummy FFI file

* Add EVM attribute

* Add EVM context

* Convert uint256 to array or reversed array

* Fix failing test

* Remove now invalid test types from valid data

* Use hex variable in argument to IsHex

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>

* Rename array

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>

* Add missing include

* Minor changes. Skip OP_16 in test.

* Make IsEVMEnabled standalone function

* Move function to cpp file

---------

Co-authored-by: Mihailo Milenkovic <mihailo.milenkovic84@gmail.com>
  • Loading branch information
Bushstar and Mixa84 authored May 3, 2023
1 parent 661c920 commit a768a03
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifndef DEFI_UINT256_H
#define DEFI_UINT256_H

#include <array>
#include <assert.h>
#include <cstring>
#include <stdexcept>
Expand Down Expand Up @@ -52,6 +53,20 @@ class base_blob
void SetHex(const std::string& str);
std::string ToString() const;

[[nodiscard]] std::array<uint8_t, WIDTH> ToArray() const
{
std::array<uint8_t, WIDTH> array;
std::copy(data, data + sizeof(data), array.begin());
return array;
}

[[nodiscard]] std::array<uint8_t, WIDTH> ToArrayReversed() const
{
std::array<uint8_t, WIDTH> reversedArray;
std::copy(std::reverse_iterator<const uint8_t*>(data + sizeof(data)), std::reverse_iterator<const uint8_t*>(data), reversedArray.begin());
return reversedArray;
}

unsigned char* begin()
{
return &data[0];
Expand Down

0 comments on commit a768a03

Please sign in to comment.